intial changes for commit #495

This commit is contained in:
Xonk
2024-11-15 17:54:18 -05:00
parent b32041d4fc
commit b93d6f1a12
56 changed files with 3550 additions and 2274 deletions

View File

@ -0,0 +1,50 @@
#include "/lib/settings.glsl"
varying vec4 pos;
varying vec4 gcolor;
uniform vec2 texelSize;
uniform vec3 cameraPosition;
uniform sampler2D depthtex1;
uniform mat4 gbufferModelViewInverse;
uniform float far;
uniform int frameCounter;
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
float interleaved_gradientNoise_temporal(){
#ifdef TAA
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter);
#else
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887);
#endif
}
/* RENDERTARGETS:2 */
void main() {
if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) {
vec3 viewPos = pos.xyz;
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
float falloff = exp(-10.0 * (1.0-clamp(1.0 - playerPos.y/5000.0,0.0,1.0)));
#ifdef DH_OVERDRAW_PREVENTION
#if OVERDRAW_MAX_DISTANCE == 0
float maxOverdrawDistance = far;
#else
float maxOverdrawDistance = OVERDRAW_MAX_DISTANCE;
#endif
if(length(playerPos) < clamp(far-16*4, 16, maxOverdrawDistance) || texture2D(depthtex1, gl_FragCoord.xy*texelSize).x < 1.0){ discard; return;}
#endif
vec3 Albedo = toLinear(gcolor.rgb) ;
gl_FragData[0] = vec4(Albedo * Emissive_Brightness * 0.1, gcolor.a);
}
}

View File

@ -0,0 +1,52 @@
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
varying vec4 pos;
varying vec4 gcolor;
uniform vec2 texelSize;
uniform int framemod8;
#if DOF_QUALITY == 5
uniform int hideGUI;
uniform int frameCounter;
uniform float aspectRatio;
uniform float screenBrightness;
uniform float far;
#include "/lib/bokeh.glsl"
#endif
#include "/lib/TAA_jitter.glsl"
void main() {
gl_Position = ftransform();
#ifdef TAA_UPSCALING
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
#endif
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
pos = gl_ModelViewMatrix * gl_Vertex;
gcolor = gl_Color;
#if DOF_QUALITY == 5
vec2 jitter = clamp(jitter_offsets[frameCounter % 64], -1.0, 1.0);
jitter = rotate(radians(float(frameCounter))) * jitter;
jitter.y *= aspectRatio;
jitter.x *= DOF_ANAMORPHIC_RATIO;
#if MANUAL_FOCUS == -2
float focusMul = 0;
#elif MANUAL_FOCUS == -1
float focusMul = gl_Position.z + (far / 3.0) - mix(pow(512.0, screenBrightness), 512.0 * screenBrightness, 0.25);
#else
float focusMul = gl_Position.z + (far / 3.0) - MANUAL_FOCUS;
#endif
vec2 totalOffset = (jitter * JITTER_STRENGTH) * focusMul * 1e-2;
gl_Position.xy += hideGUI >= 1 ? totalOffset : vec2(0);
#endif
}

View File

@ -2,6 +2,7 @@
varying vec4 pos;
varying vec4 localPos;
varying vec4 gcolor;
varying vec2 lightmapCoords;
varying vec4 normals_and_materials;
@ -10,6 +11,7 @@ flat varying float EMISSIVE;
flat varying int dh_material_id;
uniform float far;
uniform float nightVision;
// uniform int hideGUI;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
@ -53,6 +55,7 @@ float encodeVec2(float x,float y){
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform vec3 cameraPosition;
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
@ -95,7 +98,48 @@ float densityAtPos(in vec3 pos){
return mix(xy.r,xy.g, f.y);
}
uniform vec3 cameraPosition;
// https://gitlab.com/jeseibel/distant-horizons-core/-/blob/main/core/src/main/resources/shaders/flat_shaded.frag?ref_type=heads
// Property of Distant Horizons [mod]
const int noiseSteps = 4;
const float noiseIntensity = 10.0;
const int noiseDropoff = 1024;
float rand(float co) { return fract(sin(co*(91.3458)) * 47453.5453); }
float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); }
float rand(vec3 co) { return rand(co.xy + rand(co.z)); }
vec3 quantize(const in vec3 val, const in int stepSize) {
return floor(val * stepSize) / stepSize;
}
vec4 applyNoise(in vec4 fragColor, const in vec3 viewPos, const in float viewDist) {
// vec3 vertexNormal = normalize(cross(dFdy(vPos.xyz), dFdx(vPos.xyz)));
// // This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable
// vec3 fixedVPos = vPos.xyz + vertexNormal * 0.001;
float noiseAmplification = noiseIntensity * 0.01;
float lum = (fragColor.r + fragColor.g + fragColor.b) / 3.0;
noiseAmplification = (1.0 - pow(lum * 2.0 - 1.0, 2.0)) * noiseAmplification; // Lessen the effect on depending on how dark the object is, equasion for this is -(2x-1)^{2}+1
noiseAmplification *= fragColor.a; // The effect would lessen on transparent objects
// Random value for each position
float randomValue = rand(quantize(viewPos, noiseSteps))
* 2.0 * noiseAmplification - noiseAmplification;
// Modifies the color
// A value of 0 on the randomValue will result in the original color, while a value of 1 will result in a fully bright color
vec3 newCol = fragColor.rgb + (1.0 - fragColor.rgb) * randomValue;
newCol = clamp(newCol, 0.0, 1.0);
if (noiseDropoff != 0) {
float distF = min(viewDist / noiseDropoff, 1.0);
newCol = mix(newCol, fragColor.rgb, distF); // The further away it gets, the less noise gets applied
}
return vec4(newCol,1.0);
}
/* RENDERTARGETS:1,7,8 */
void main() {
@ -107,7 +151,7 @@ void main() {
float maxOverdrawDistance = OVERDRAW_MAX_DISTANCE;
#endif
if(clamp(1.0-length(pos.xyz)/clamp(far - 32.0,32.0,maxOverdrawDistance),0.0,1.0) > 0.0 ){
if(clamp(1.0-length(localPos.xyz)/clamp(far - 32.0,32.0,maxOverdrawDistance),0.0,1.0) > 0.0 ){
discard;
return;
}
@ -120,11 +164,14 @@ void main() {
// PackLightmaps.y *= 1.05;
PackLightmaps = min(max(PackLightmaps,0.0)*1.05,1.0);
vec4 data1 = clamp( encode(normals, PackLightmaps), 0.0, 1.0);
vec4 data1 = clamp( encode(viewToWorld(normals), PackLightmaps), 0.0, 1.0);
// alpha is material masks, set it to 0.65 to make a DH LODs mask.
vec4 Albedo = vec4(gcolor.rgb, 1.0);
#ifdef DH_NOISE_TEXTURE
vec4 Albedo = applyNoise(gcolor, localPos.rgb+cameraPosition, length(localPos.xyz));
#else
vec4 Albedo = vec4(gcolor.rgb, 1.0);
#endif
// vec3 worldPos = mat3(gbufferModelViewInverse)*pos.xyz + cameraPosition;
// worldPos = (worldPos*vec3(1.0,1./48.,1.0)/4) ;
// worldPos = floor(worldPos * 4.0 + 0.001) / 32.0;

View File

@ -2,12 +2,14 @@
#include "/lib/res_params.glsl"
varying vec4 pos;
varying vec4 localPos;
varying vec4 gcolor;
varying vec2 lightmapCoords;
varying vec4 normals_and_materials;
flat varying float SSSAMOUNT;
flat varying float EMISSIVE;
flat varying int dh_material_id;
uniform float nightVision;
uniform vec2 texelSize;
uniform int framemod8;
@ -25,9 +27,9 @@ uniform float far;
/*
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform float far;
uniform mat4 dhProjection;
uniform vec3 cameraPosition;
@ -37,38 +39,45 @@ uniform vec3 cameraPosition;
vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(dhProjection, viewSpacePosition),-viewSpacePosition.z);
}
*/
#define SEASONS_VSH
#define DH_SEASONS
#include "/lib/climate_settings.glsl"
void main() {
gl_Position = ftransform();
/*
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
// vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
// vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
// #ifdef PLANET_CURVATURE
// float curvature = length(worldpos) / (16*8);
// worldpos.y -= curvature*curvature * CURVATURE_AMOUNT;
// #endif
// position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
float cellSize = 32*2;
vec3 modulusWorldPos = vec3(worldpos.x,worldpos.y,worldpos.z) + fract(cameraPosition/cellSize)*cellSize - cellSize*0.5;
// gl_Position = toClipSpace3(position);
vec4 vPos = gl_Vertex;
vec3 cameraOffset = fract(cameraPosition);
vPos.xyz = floor(vPos.xyz + cameraOffset + 0.5) - cameraOffset;
vec4 viewPos = gl_ModelViewMatrix * vPos;
localPos = gbufferModelViewInverse * viewPos;
gl_Position = dhProjection * viewPos;
worldpos.y -= (clamp(1.0-length(modulusWorldPos)/max(far-32,0.0),0.0,1.0)) * 50.0;
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
gl_Position = toClipSpace3(position);
*/
#ifdef TAA_UPSCALING
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
#endif
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
lightmapCoords = gl_MultiTexCoord1.xy; // is this even correct? lol'
lightmapCoords = (gl_TextureMatrix[1] * gl_MultiTexCoord1).xy;
gcolor = gl_Color;
pos = gl_ModelViewMatrix * gl_Vertex;
EMISSIVE = 0.0;
if(dhMaterialId == DH_BLOCK_ILLUMINATED || gl_MultiTexCoord1.x >= 0.95) EMISSIVE = 0.5;
@ -85,7 +94,6 @@ void main() {
normals_and_materials = vec4(normalize(gl_NormalMatrix * gl_Normal), MATERIALS);
dh_material_id = dhMaterialId;
#if defined Seasons && defined OVERWORLD_SHADER
YearCycleColor(gcolor.rgb, gl_Color.rgb, dhMaterialId == DH_BLOCK_LEAVES, dhMaterialId == DH_BLOCK_GRASS);
#endif

View File

@ -117,10 +117,22 @@ uniform int isEyeInWater;
uniform float rainStrength;
#ifdef OVERWORLD_SHADER
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#else
vec4 dailyWeatherParams0 = vec4(CloudLayer0_coverage, CloudLayer1_coverage, CloudLayer2_coverage, 0.0);
vec4 dailyWeatherParams1 = vec4(CloudLayer0_density, CloudLayer1_density, CloudLayer2_density, 0.0);
#endif
#define CLOUDSHADOWSONLY
#include "/lib/volumetricClouds.glsl"
#endif
#ifndef OVERWORLD_SHADER
#undef WATER_SUN_SPECULAR
#endif
float GGX(vec3 n, vec3 v, vec3 l, float r, float f0) {
r = max(pow(r,2.5), 0.0001);
@ -200,16 +212,30 @@ vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater)
return vec3(1.1);
}
float interleaved_gradientNoise_temporal(){
#ifdef TAA
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter);
#else
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887);
#endif
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float R2_dither(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
vec2 coord = gl_FragCoord.xy ;
#ifdef TAA
coord += + (frameCounter%40000) * 2.0;
#endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715) ) );
return noise ;
}
vec3 viewToWorld(vec3 viewPos) {
vec4 pos;
pos.xyz = viewPos;
@ -246,6 +272,10 @@ vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
return normalize(bump*tbnMatrix);
}
#define FORWARD_SPECULAR
#define FORWARD_ENVIORNMENT_REFLECTION
#define FORWARD_BACKGROUND_REFLECTION
#define FORWARD_ROUGH_REFLECTION
/* RENDERTARGETS:2,7 */
void main() {
@ -310,7 +340,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 Direct_lighting = vec3(0.0);
#ifdef OVERWORLD_SHADER
vec3 DirectLightColor = lightCol.rgb/80.0;
vec3 DirectLightColor = lightCol.rgb/2400.0;
float NdotL = clamp(dot(normals, normalize(WsunVec2)),0.0,1.0);
NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
@ -342,13 +372,14 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
Shadows = shadow2D(shadow, projectedShadowPosition + vec3(0.0,0.0, smallbias)).x;
}
#endif
#ifdef CLOUDS_SHADOWS
Shadows *= pow(GetCloudShadow(playerPos),3);
#endif
#ifdef CLOUDS_SHADOWS
Shadows *= GetCloudShadow(playerPos + cameraPosition, WsunVec);
#endif
Direct_lighting = DirectLightColor * NdotL * Shadows;
vec3 AmbientLightColor = averageSkyCol_Clouds/30.0;
vec3 AmbientLightColor = averageSkyCol_Clouds/900.0;
vec3 ambientcoefs = normals_and_materials.xyz / dot(abs(normals_and_materials.xyz), vec3(1.0));
float SkylightDir = ambientcoefs.y*1.5;
@ -366,7 +397,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
// specular
#ifdef WATER_REFLECTIONS
#ifdef FORWARD_SPECULAR
vec3 Reflections_Final = vec3(0.0);
vec4 Reflections = vec4(0.0);
vec3 BackgroundReflection = FinalColor;
@ -386,8 +417,8 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#ifdef SNELLS_WINDOW
if(isEyeInWater == 1) fresnel = pow(clamp(1.5 + normalDotEye,0.0,1.0), 25.0);
#endif
#if defined SCREENSPACE_REFLECTIONS && defined DH_SCREENSPACE_REFLECTIONS
vec3 rtPos = rayTrace(reflectedVector, viewPos, interleaved_gradientNoise(), fresnel, false);
#if defined FORWARD_ENVIORNMENT_REFLECTION && defined DH_SCREENSPACE_REFLECTIONS
vec3 rtPos = rayTrace(reflectedVector, viewPos, interleaved_gradientNoise_temporal(), fresnel, false);
if (rtPos.z < 1.){
vec3 previousPosition = mat3(gbufferModelViewInverse) * DH_toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
@ -398,11 +429,11 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
}
}
#endif
#ifdef WATER_BACKGROUND_SPECULAR
BackgroundReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0;
#ifdef FORWARD_BACKGROUND_REFLECTION
BackgroundReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 1200.0;
#endif
#ifdef WATER_SUN_SPECULAR
SunReflection = Direct_lighting * GGX(normalize(normals), -normalize(viewPos), normalize(WsunVec2), roughness, f0) * (1.0-Reflections.a);
SunReflection = (DirectLightColor * Shadows) * GGX(normalize(normals), -normalize(viewPos), normalize(WsunVec2), roughness, f0) * (1.0-Reflections.a);
#endif
Reflections_Final = mix(BackgroundReflection, Reflections.rgb, Reflections.a) * fresnel;

View File

@ -14,7 +14,7 @@ flat varying vec3 averageSkyCol_Clouds;
flat varying vec4 lightCol;
#ifdef OVERWORLD_SHADER
#if defined Daily_Weather
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
@ -56,11 +56,26 @@ vec4 toClipSpace3(vec3 viewSpacePosition) {
}
void main() {
gl_Position = ftransform();
gl_Position = dhProjection * gl_ModelViewMatrix * gl_Vertex;
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
// worldpos.y -= length(worldpos)/(16*2);
#ifdef PLANET_CURVATURE
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * CURVATURE_AMOUNT;
#endif
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
gl_Position = toClipSpace3(position);
pos = gl_ModelViewMatrix * gl_Vertex;
// vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
isWater = 0;
@ -68,13 +83,13 @@ void main() {
isWater = 1;
// offset water to not look like a full cube
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz ;
worldpos.y -= 1.8/16.0;
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
// vec3 worldpos = mat3(gbufferModelViewInverse) * position;// + gbufferModelViewInverse[3].xyz ;
// worldpos.y -= 1.8/16.0;
// position = mat3(gbufferModelView) * worldpos;// + gbufferModelView[3].xyz;
}
gl_Position = toClipSpace3(position);
// gl_Position = toClipSpace3(position);
normals_and_materials = vec4(normalize(gl_Normal), 1.0);
@ -83,7 +98,6 @@ void main() {
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;

View File

@ -62,17 +62,25 @@ uniform vec2 texelSize;
uniform ivec2 eyeBrightnessSmooth;
uniform float rainStrength;
uniform float nightVision;
flat varying float HELD_ITEM_BRIGHTNESS;
#ifndef OVERWORLD_SHADER
uniform float nightVision;
#endif
#include "/lib/util.glsl"
#ifdef OVERWORLD_SHADER
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#else
vec4 dailyWeatherParams0 = vec4(CloudLayer0_coverage, CloudLayer1_coverage, CloudLayer2_coverage, 0.0);
vec4 dailyWeatherParams1 = vec4(CloudLayer0_density, CloudLayer1_density, CloudLayer2_density, 0.0);
#endif
#define CLOUDSHADOWSONLY
#include "/lib/volumetricClouds.glsl"
#endif
@ -223,8 +231,8 @@ vec3 toClipSpace3(vec3 viewSpacePosition) {
}
flat varying vec3 WsunVec2;
const float mincoord = 1.0/4096.0;
const float maxcoord = 1.0-mincoord;
const float mincoord = 1.0/4096.0;
const float maxcoord = 1.0-mincoord;
uniform sampler2D normals;
varying vec4 tangent;
@ -373,7 +381,12 @@ void main() {
#else
vec3 playerCamPos = cameraPosition;
#endif
lightmap.x = max(lightmap.x, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length((feetPlayerPos+cameraPosition) - playerCamPos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
// lightmap.x = max(lightmap.x, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length((feetPlayerPos+cameraPosition) - playerCamPos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
if(HELD_ITEM_BRIGHTNESS > 0.0){
float pointLight = clamp(1.0-length((feetPlayerPos+cameraPosition)-playerCamPos)/HANDHELD_LIGHT_RANGE,0.0,1.0);
lightmap.x = mix(lightmap.x, HELD_ITEM_BRIGHTNESS, pointLight*pointLight);
}
#endif
#ifdef WEATHER
@ -402,7 +415,7 @@ void main() {
if(lightmap.x >= 0.9) Torch_Color *= LIT_PARTICLE_BRIGHTNESS;
#ifdef OVERWORLD_SHADER
directLightColor = lightCol.rgb/80.0;
directLightColor = lightCol.rgb/2400.0;
float Shadows = 1.0;
vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
@ -417,7 +430,7 @@ void main() {
Shadows = mix(LM_shadowMapFallback, Shadows, shadowMapFalloff2);
#ifdef CLOUDS_SHADOWS
Shadows *= GetCloudShadow(feetPlayerPos);
Shadows *= GetCloudShadow(feetPlayerPos+cameraPosition, WsunVec);
#endif
Direct_lighting = directLightColor * Shadows;
@ -426,7 +439,7 @@ void main() {
Direct_lighting *= phaseg(clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), 0.65)*2 + 0.5;
#endif
AmbientLightColor = averageSkyCol_Clouds / 30.0;
AmbientLightColor = averageSkyCol_Clouds / 900.0;
#ifdef IS_IRIS
AmbientLightColor *= 2.5;
@ -438,11 +451,11 @@ void main() {
#endif
#ifdef NETHER_SHADER
Indirect_lighting = skyCloudsFromTexLOD2(vec3(0.0,1.0,0.0), colortex4, 6).rgb / 30.0;
Indirect_lighting = volumetricsFromTex(vec3(0.0,1.0,0.0), colortex4, 6).rgb / 1200.0;
#endif
#ifdef END_SHADER
Indirect_lighting = vec3(0.3,0.6,1.0) * 0.5;
Indirect_lighting = vec3(0.3,0.6,1.0) * 0.1;
#endif
///////////////////////// BLOCKLIGHT LIGHTING OR LPV LIGHTING OR FLOODFILL COLORED LIGHTING

View File

@ -23,10 +23,12 @@ flat varying float exposure;
flat varying vec3 averageSkyCol_Clouds;
flat varying vec4 lightCol;
flat varying vec3 WsunVec;
#if defined Daily_Weather
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
#endif
@ -106,12 +108,12 @@ void main() {
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
bool istopv = worldpos.y > cameraPosition.y + 5.0 && lmtexcoord.w > 0.94;
bool istopv = worldpos.y > cameraPosition.y + 5.0 && lmtexcoord.w > 0.99;
if(!istopv){
worldpos.xyz -= cameraPosition;
worldpos.xyz -= cameraPosition - vec3(2.0,0.0,2.0) * min(max(eyeBrightnessSmooth.y/240.0-0.95,0.0)*11.0,1.0);
}else{
worldpos.xyz -= cameraPosition + vec3(2.0,0.0,2.0);
worldpos.xyz -= cameraPosition ;
}
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
@ -140,8 +142,8 @@ void main() {
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
#if defined Daily_Weather
dailyWeatherParams0 = vec4((texelFetch2D(colortex4,ivec2(1,1),0).rgb/150.0) / 2.0, 0.0);
dailyWeatherParams1 = vec4((texelFetch2D(colortex4,ivec2(2,1),0).rgb/150.0) / 2.0, 0.0);
dailyWeatherParams0 = vec4(texelFetch2D(colortex4,ivec2(1,1),0).rgb / 1500.0, 0.0);
dailyWeatherParams1 = vec4(texelFetch2D(colortex4,ivec2(2,1),0).rgb / 1500.0, 0.0);
#endif
#endif

View File

@ -94,25 +94,40 @@ flat varying int SIGN;
flat varying float HELD_ITEM_BRIGHTNESS;
uniform float noPuddleAreas;
uniform float nightVision;
// float interleaved_gradientNoise(){
// return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
// }
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
#ifdef TAA
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter);
#else
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887);
#endif
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float R2_dither(){
vec2 coord = gl_FragCoord.xy ;
#ifdef TAA
coord += + (frameCounter%40000) * 2.0;
#endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ;
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
float blueNoise(){
#ifdef TAA
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
#else
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887);
#endif
}
mat3 inverseMatrix(mat3 m) {
@ -311,7 +326,8 @@ void main() {
vec2 tempOffset = offsets[framemod8];
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
vec3 worldpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
vec3 playerpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 worldpos = playerpos + cameraPosition;
float torchlightmap = lmtexcoord.z;
@ -322,8 +338,11 @@ void main() {
vec3 playerCamPos = cameraPosition;
#endif
if(HELD_ITEM_BRIGHTNESS > 0.0) torchlightmap = max(torchlightmap, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length(worldpos-playerCamPos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
// if(HELD_ITEM_BRIGHTNESS > 0.0) torchlightmap = max(torchlightmap, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length(worldpos-playerCamPos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
if(HELD_ITEM_BRIGHTNESS > 0.0){
float pointLight = clamp(1.0-length(worldpos-playerCamPos)/HANDHELD_LIGHT_RANGE,0.0,1.0);
torchlightmap = mix(torchlightmap, HELD_ITEM_BRIGHTNESS, pointLight*pointLight);
}
#ifdef HAND
torchlightmap *= 0.9;
#endif
@ -331,17 +350,17 @@ void main() {
float lightmap = clamp( (lmtexcoord.w-0.9) * 10.0,0.,1.);
float rainfall = 0.0;
float Puddle_shape = 0.0;
// float rainfall = 1.0;
// float Puddle_shape = 0.0;
#if defined Puddles && defined WORLD && !defined ENTITIES && !defined HAND
rainfall = rainStrength * noPuddleAreas * lightmap;
// #if defined Puddles && defined WORLD && !defined ENTITIES && !defined HAND
// // rainfall = rainStrength * noPuddleAreas * lightmap;
Puddle_shape = clamp(lightmap - exp(-15.0 * pow(texture2D(noisetex, worldpos.xz * (0.020 * Puddle_Size) ).b,5.0)),0.0,1.0);
Puddle_shape *= clamp( viewToWorld(normal).y*0.5+0.5,0.0,1.0);
Puddle_shape *= rainStrength * noPuddleAreas ;
// // Puddle_shape = clamp(lightmap - exp(-15.0 * pow(texture2D(noisetex, worldpos.xz * (0.020 * Puddle_Size) ).b,5.0)),0.0,1.0);
// // Puddle_shape *= clamp( viewToWorld(normal).y*0.5+0.5,0.0,1.0);
// // Puddle_shape *= rainStrength * noPuddleAreas ;
#endif
// #endif
vec2 adjustedTexCoord = lmtexcoord.xy;
@ -351,31 +370,38 @@ void main() {
adjustedTexCoord = fract(vtexcoord.st)*vtexcoordam.pq+vtexcoordam.st;
// vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
vec3 viewVector = normalize(tbnMatrix*fragpos);
float dist = length(fragpos);
float dist = length(playerpos);
float falloff = min(max(1.0-dist/MAX_OCCLUSION_DISTANCE,0.0) * 2.0,1.0);
falloff = pow(1.0-pow(1.0-falloff,1.0),2.0);
// falloff = 1;
float maxdist = MAX_OCCLUSION_DISTANCE;
if(!ifPOM) maxdist = 0.0;
gl_FragDepth = gl_FragCoord.z;
if (dist < maxdist) {
if (falloff > 0.0) {
float depthmap = readNormal(vtexcoord.st).a;
float used_POM_DEPTH = 1.0;
float pomdepth = POM_DEPTH*falloff;
if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) {
float noise = blueNoise();
#ifdef Adaptive_Step_length
vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0);
vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * pomdepth) * clamp(1.0-pow(depthmap,2),0.1,1.0);
used_POM_DEPTH = 1.0;
#else
vec3 interval = viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS*POM_DEPTH;
vec3 interval = viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS*pomdepth;
#endif
vec3 coord = vec3(vtexcoord.st , 1.0);
coord += interval * noise * used_POM_DEPTH;
float sumVec = noise;
for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - POM_DEPTH + POM_DEPTH * readNormal(coord.st).a ) < coord.p && coord.p >= 0.0; ++loopCount) {
for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - pomdepth + pomdepth * readNormal(coord.st).a ) < coord.p && coord.p >= 0.0; ++loopCount) {
coord = coord + interval * used_POM_DEPTH;
sumVec += used_POM_DEPTH;
}
@ -403,7 +429,7 @@ void main() {
//////////////////////////////// ////////////////////////////////
float textureLOD = bias();
vec4 Albedo = texture2D_POMSwitch(texture, adjustedTexCoord.xy, vec4(dcdx,dcdy), ifPOM, textureLOD) * color;
// Albedo.rgb = vec3(1.0) * min(max(exp(-15.0 * pow(1.0-luma(Albedo.rgb),3.0)) - 0.2,0.0)*5.0,1.0);
#if defined HAND
if (Albedo.a < 0.1) discard;
#endif
@ -483,7 +509,7 @@ void main() {
NormalTex.xy = NormalTex.xy * 2.0-1.0;
NormalTex.z = sqrt(max(1.0 - dot(NormalTex.xy, NormalTex.xy), 0.0));
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0-Puddle_shape);
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
#endif
//////////////////////////////// ////////////////////////////////
@ -493,8 +519,8 @@ void main() {
#ifdef WORLD
vec4 SpecularTex = texture2D_POMSwitch(specular, adjustedTexCoord.xy, vec4(dcdx,dcdy), ifPOM,textureLOD);
SpecularTex.r = max(SpecularTex.r, rainfall);
SpecularTex.g = max(SpecularTex.g, max(Puddle_shape*0.02,0.02));
// SpecularTex.r = max(SpecularTex.r, rainfall);
// SpecularTex.g = max(SpecularTex.g, max(Puddle_shape*0.02,0.02));
gl_FragData[1].rg = SpecularTex.rg;
@ -543,24 +569,23 @@ void main() {
//////////////////////////////// ////////////////////////////////
#ifdef WORLD
#ifdef Puddles
float porosity = 0.4;
// #ifdef Puddles
// float porosity = 0.4;
#ifdef Porosity
porosity = SpecularTex.z >= 64.5/255.0 ? 0.0 : (SpecularTex.z*255.0/64.0)*0.65;
#endif
// #ifdef Porosity
// porosity = SpecularTex.z >= 64.5/255.0 ? 0.0 : (SpecularTex.z*255.0/64.0)*0.65;
// #endif
if(SpecularTex.g < 229.5/255.0) Albedo.rgb = mix(Albedo.rgb, vec3(0), Puddle_shape*porosity);
#endif
// // if(SpecularTex.g < 229.5/255.0) Albedo.rgb = mix(Albedo.rgb, vec3(0), Puddle_shape*porosity);
// #endif
// apply noise to lightmaps to reduce banding.
vec2 PackLightmaps = vec2(torchlightmap, lmtexcoord.w);
vec4 data1 = clamp( encode(viewToWorld(normal), PackLightmaps), 0.0, 1.0);
gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w));
gl_FragData[2] = vec4(FlatNormals * 0.5 + 0.5, VanillaAO);
gl_FragData[2] = vec4(viewToWorld(FlatNormals) * 0.5 + 0.5, VanillaAO);
#endif
}

View File

@ -83,7 +83,7 @@ flat varying int SIGN;
// in vec3 at_velocity;
// out vec3 velocity;
uniform float nightVision;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
@ -198,6 +198,8 @@ void main() {
VanillaAO = 1.0 - clamp(color.a,0,1);
if (color.a < 0.3) color.a = 1.0; // fix vanilla ao on some custom block models.
/////// ----- RANDOM STUFF ----- ///////
// gl_TextureMatrix[0] for animated things like charged creepers
@ -241,6 +243,7 @@ void main() {
NameTags = 0;
#ifdef ENTITIES
// disallow POM to work on item frames.
if(entityId == ENTITY_ITEM_FRAME) SIGN = 1;
@ -297,7 +300,7 @@ void main() {
mc_Entity.x == BLOCK_AMETHYST_BUD_MEDIUM || mc_Entity.x == BLOCK_AMETHYST_BUD_LARGE || mc_Entity.x == BLOCK_AMETHYST_CLUSTER ||
mc_Entity.x == BLOCK_BAMBOO || mc_Entity.x == BLOCK_SAPLING || mc_Entity.x == BLOCK_VINE
) {
SSSAMOUNT = 0.75;
SSSAMOUNT = 0.0;
}
// low
#ifdef MISC_BLOCK_SSS
@ -328,6 +331,7 @@ void main() {
#endif
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
#ifdef WAVY_PLANTS
// also use normal, so up/down facing geometry does not get detatched from its model parts.
@ -346,18 +350,24 @@ void main() {
) && abs(position.z) < 64.0
){
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
vec3 UnalteredWorldpos = worldpos;
// apply displacement for waving plant blocks
worldpos += calcMovePlants(worldpos + cameraPosition) * max(lmtexcoord.w,0.5);
// apply displacement for waving leaf blocks specifically, overwriting the other waving mode. these wave off of the air. they wave uniformly
if(mc_Entity.x == BLOCK_AIR_WAVING) worldpos = UnalteredWorldpos + calcMoveLeaves(worldpos + cameraPosition, 0.0040, 0.0064, 0.0043, 0.0035, 0.0037, 0.0041, vec3(1.0,0.2,1.0), vec3(0.5,0.1,0.5))*lmtexcoord.w;
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
}
#endif
#ifdef PLANET_CURVATURE
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * CURVATURE_AMOUNT;
#endif
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
gl_Position = toClipSpace3(position);
#endif

View File

@ -36,7 +36,6 @@ uniform vec4 entityColor;
flat varying float HELD_ITEM_BRIGHTNESS;
const bool colortex4MipmapEnabled = true;
uniform sampler2D noisetex;
uniform sampler2D depthtex1;
uniform sampler2D depthtex0;
@ -84,11 +83,15 @@ uniform float rainStrength;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform ivec2 eyeBrightnessSmooth;
uniform float nightVision;
uniform int frameCounter;
uniform float frameTimeCounter;
uniform vec2 texelSize;
uniform int framemod8;
uniform float viewWidth;
uniform float viewHeight;
uniform mat4 gbufferPreviousModelView;
uniform vec3 previousCameraPosition;
@ -110,11 +113,18 @@ uniform vec3 nsunColor;
#ifdef OVERWORLD_SHADER
flat varying float Flashing;
#include "/lib/lightning_stuff.glsl"
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#else
vec4 dailyWeatherParams0 = vec4(CloudLayer0_coverage, CloudLayer1_coverage, CloudLayer2_coverage, 0.0);
vec4 dailyWeatherParams1 = vec4(CloudLayer0_density, CloudLayer1_density, CloudLayer2_density, 0.0);
#endif
#define CLOUDSHADOWSONLY
#include "/lib/volumetricClouds.glsl"
#else
uniform float nightVision;
#endif
#ifdef END_SHADER
@ -132,14 +142,12 @@ uniform vec3 nsunColor;
#include "/lib/diffuse_lighting.glsl"
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
}
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
#ifdef TAA
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter);
#else
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887);
#endif
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
@ -147,20 +155,27 @@ float interleaved_gradientNoise(){
return noise;
}
float R2_dither(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
vec2 coord = gl_FragCoord.xy ;
#ifdef TAA
coord += + (frameCounter%40000) * 2.0;
#endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
float blueNoise(){
#ifdef TAA
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
#else
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887);
#endif
}
#include "/lib/TAA_jitter.glsl"
#define PW_DEPTH 1.5 //[0.5 1.0 1.5 2.0 2.5 3.0]
#define PW_POINTS 2 //[2 4 6 8 16 32]
@ -239,91 +254,10 @@ float encodeVec2(float x,float y){
}
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater, inout float reflectLength){
float quality = mix(15,SSR_STEPS,fresnel);
// quality = SSR_STEPS;
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
(-near -position.z) / dir.z : far*sqrt(3.);
vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space
direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
vec3 stepv = direction * mult / quality * vec3(RENDER_SCALE,1.0);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*dither;
float minZ = clipPosition.z;
float maxZ = spos.z+stepv.z*0.5;
spos.xy += offsets[framemod8]*texelSize*0.5/RENDER_SCALE;
float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
for (int i = 0; i <= int(quality); i++) {
// decode depth buffer
// float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0);
sp = invLinZ(sp);
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy/RENDER_SCALE,sp);
spos += stepv;
//small bias
if(inwater) {
minZ = maxZ-0.00035/ld(spos.z);
}else{
minZ = maxZ-0.0001/max(ld(spos.z), (0.0 + position.z*position.z*0.001));
}
maxZ += stepv.z;
reflectLength += 1.0 / quality; // for shit
}
return vec3(1.1);
}
float GGX(vec3 n, vec3 v, vec3 l, float r, float f0) {
r = max(pow(r,2.5), 0.0001);
vec3 h = l + v;
float hn = inversesqrt(dot(h, h));
float dotLH = clamp(dot(h,l)*hn,0.,1.);
float dotNH = clamp(dot(h,n)*hn,0.,1.) ;
float dotNL = clamp(dot(n,l),0.,1.);
float dotNHsq = dotNH*dotNH;
float denom = dotNHsq * r - dotNHsq + 1.;
float D = r / (3.141592653589793 * denom * denom);
float F = f0 + (1. - f0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
float k2 = .25 * r;
return dotNL * D * F / (dotLH*dotLH*(1.0-k2)+k2);
}
uniform float dhFarPlane;
#include "/lib/DistantHorizons_projections.glsl"
@ -426,12 +360,19 @@ void Emission(
float Emission,
float exposure
){
float autoBrightnessAdjust = mix(5.0, 100.0, clamp(exp(-10.0*exposure),0.0,1.0));
if( Emission < 254.5/255.0) Lighting = mix(Lighting, Albedo * Emissive_Brightness * autoBrightnessAdjust * 0.1, pow(Emission, Emissive_Curve)); // old method.... idk why
// float autoBrightnessAdjust = mix(5.0, 100.0, clamp(exp(-10.0*exposure),0.0,1.0));
if( Emission < 254.5/255.0) Lighting = mix(Lighting, Albedo * 5.0 * Emissive_Brightness, pow(Emission, Emissive_Curve)); // old method.... idk why
}
uniform vec3 eyePosition;
#define FORWARD_SPECULAR
#define FORWARD_ENVIORNMENT_REFLECTION
#define FORWARD_BACKGROUND_REFLECTION
#define FORWARD_ROUGH_REFLECTION
#include "/lib/specular.glsl"
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -486,7 +427,9 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
gl_FragData[0] = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color;
float UnchangedAlpha = gl_FragData[0].a;
// gl_FragData[0].a = pow(gl_FragData[0].a,3);
#ifdef WhiteWorld
gl_FragData[0].rgb = vec3(0.5);
gl_FragData[0].a = 1.0;
@ -532,8 +475,6 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 worldSpaceNormal = viewToWorld(normal).xyz;
vec2 TangentNormal = vec2(0); // for refractions
vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w);
mat3 tbnMatrix = mat3(tangent.x, tangent2.x, normal.x,
tangent.y, tangent2.y, normal.y,
@ -541,17 +482,14 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 NormalTex = vec3(texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).xy,0.0);
NormalTex.xy = NormalTex.xy*2.0-1.0;
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ;
// tangent space normals for refraction
TangentNormal = NormalTex.xy*0.5+0.5;
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0);
#ifndef HAND
if (isWater){
vec3 posxz = (mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz) + cameraPosition;
// make the waves flow in the direction the water faces, except for perfectly up facing parts.
if(abs(worldSpaceNormal.y) < 0.9995) posxz.xz -= (posxz.y + frameTimeCounter*3 * WATER_WAVE_SPEED) * normalize(worldSpaceNormal.xz) ;
if(abs(worldSpaceNormal.y) < 0.9995) posxz.xz -= posxz.y + normalize(worldSpaceNormal.xz*10.0) * frameTimeCounter * 3.0 * WATER_WAVE_SPEED;
posxz.xyz = getParallaxDisplacement(posxz);
vec3 bump = normalize(getWaveNormal(posxz, false));
@ -560,22 +498,24 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
NormalTex.xyz = bump;
// tangent space normals for refraction
TangentNormal = (bump.xy/3.0)*0.5+0.5;
}
#endif
// tangent space normals for refraction
TangentNormal = NormalTex.xy;
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(GLASS_TINT_COLORS.rg), encodeVec2(GLASS_TINT_COLORS.ba), 1.0);
// TangentNormal = clamp(TangentNormal + (blueNoise()*2.0-1.0)*0.005,-1.0,1.0);
gl_FragData[2] = vec4(encodeVec2(TangentNormal*0.5+0.5), encodeVec2(GLASS_TINT_COLORS.rg), encodeVec2(GLASS_TINT_COLORS.ba), 1.0);
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SPECULARS /////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
vec3 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rga;
vec3 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rga;
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// DIFFUSE LIGHTING //////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@ -594,7 +534,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#else
vec3 playerCamPos = cameraPosition;
#endif
lightmap.x = max(lightmap.x, HELD_ITEM_BRIGHTNESS*clamp( pow(max(1.0-length((feetPlayerPos+cameraPosition) - playerCamPos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
if(HELD_ITEM_BRIGHTNESS > 0.0){
float pointLight = clamp(1.0-length((feetPlayerPos+cameraPosition)-playerCamPos)/HANDHELD_LIGHT_RANGE,0.0,1.0);
lightmap.x = mix(lightmap.x , HELD_ITEM_BRIGHTNESS, pointLight*pointLight);
}
#endif
vec3 Indirect_lighting = vec3(0.0);
@ -604,7 +549,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 Direct_lighting = vec3(0.0);
#ifdef OVERWORLD_SHADER
vec3 DirectLightColor = lightCol.rgb/80.0;
vec3 DirectLightColor = lightCol.rgb/2400.0;
float NdotL = clamp(dot(normal, normalize(WsunVec*mat3(gbufferModelViewInverse))),0.0,1.0); NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
float Shadows = 1.0;
@ -619,11 +564,13 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
Shadows = mix(LM_shadowMapFallback, Shadows, shadowMapFalloff2);
Shadows *= pow(GetCloudShadow(feetPlayerPos),3);
#ifdef CLOUDS_SHADOWS
Shadows *= GetCloudShadow(feetPlayerPos+cameraPosition, WsunVec);
#endif
Direct_lighting = DirectLightColor * NdotL * Shadows;
vec3 AmbientLightColor = averageSkyCol_Clouds/30.0;
vec3 AmbientLightColor = averageSkyCol_Clouds/900.0;
vec3 ambientcoefs = worldSpaceNormal / dot(abs(worldSpaceNormal), vec3(1.0));
float SkylightDir = ambientcoefs.y*1.5;
@ -635,26 +582,41 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#endif
#ifdef NETHER_SHADER
Indirect_lighting = skyCloudsFromTexLOD2(worldSpaceNormal, colortex4, 6).rgb / 30.0 ;
Indirect_lighting = volumetricsFromTex(normalize(worldSpaceNormal), colortex4, 0).rgb / 1200.0 / 1.5;
#endif
#ifdef END_SHADER
// float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
// vec3 lightPos = LightSourcePosition(feetPlayerPos+cameraPosition, cameraPosition,vortexBounds);
// float lightningflash = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
// vec3 lightColors = LightSourceColors(vortexBounds, lightningflash);
// float NdotL = clamp(dot(worldSpaceNormal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
// NdotL *= NdotL;
// Direct_lighting = lightColors * endFogPhase(lightPos) * NdotL;
float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
vec3 lightPos = LightSourcePosition(feetPlayerPos+cameraPosition, cameraPosition,vortexBounds);
float lightningflash = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
vec3 lightColors = LightSourceColors(vortexBounds, lightningflash);
float NdotL = clamp(dot(worldSpaceNormal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
NdotL *= NdotL;
float end_NdotL = clamp(dot(worldSpaceNormal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
end_NdotL *= end_NdotL;
Direct_lighting = lightColors * endFogPhase(lightPos) * NdotL;
float fogShadow = GetEndFogShadow(feetPlayerPos+cameraPosition, lightPos);
float endPhase = endFogPhase(lightPos);
vec3 AmbientLightColor = vec3(0.3,0.6,1.0) * 0.5;
Direct_lighting += lightColors * endPhase * end_NdotL * fogShadow;
vec3 AmbientLightColor = vec3(0.3,0.6,1.0) ;
Indirect_lighting = AmbientLightColor + 0.7 * AmbientLightColor * dot(worldSpaceNormal, normalize(feetPlayerPos));
Indirect_lighting *= 0.1;
#endif
///////////////////////// BLOCKLIGHT LIGHTING OR LPV LIGHTING OR FLOODFILL COLORED LIGHTING
@ -680,136 +642,66 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
#if EMISSIVE_TYPE == 2 || EMISSIVE_TYPE == 3
Emission(FinalColor, Albedo, SpecularTex.b, exposure);
#endif
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SPECULAR LIGHTING /////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#ifdef DAMAGE_BLOCK_EFFECT
#undef WATER_REFLECTIONS
#undef FORWARD_SPECULAR
#endif
#ifndef OVERWORLD_SHADER
#undef WATER_SUN_SPECULAR
#endif
#ifdef FORWARD_SPECULAR
#ifdef WATER_REFLECTIONS
// vec2 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg;
float harcodedF0 = 0.02;
// if nothing is chosen, no smoothness and no reflectance
vec2 specularValues = vec2(1.0, 0.0);
// hardcode specular values for select blocks like glass, water, and slime
if(isReflective) specularValues = vec2(1.0, 0.02);
if(isReflective) specularValues = vec2(1.0, harcodedF0);
// detect if the specular texture is used, if it is, overwrite hardcoded values
if(SpecularTex.r > 0.0 && SpecularTex.g <= 1.0) specularValues = SpecularTex.rg;
float roughness = pow(1.0-specularValues.r,2.0);
float f0 = isReflective ? max(specularValues.g, 0.02) : specularValues.g;
float f0 = isReflective ? max(specularValues.g, harcodedF0) : specularValues.g;
#ifdef HAND
f0 = max(specularValues.g, 0.02);
f0 = max(specularValues.g, harcodedF0);
#endif
// f0 = SpecularTex.g;
// roughness = pow(1.0-specularValues.r,2.0);
// f0 = 0.9;
// roughness = 0.0;
vec3 Metals = f0 > 229.5/255.0 ? normalize(Albedo+1e-7) * (dot(Albedo,vec3(0.21, 0.72, 0.07)) * 0.7 + 0.3) : vec3(1.0);
// make sure zero alpha is not forced to be full alpha by fresnel on items with funny normal padding
float roughness = specularValues.r;
if(UnchangedAlpha <= 0.0 && !isReflective) f0 = 0.0;
if (f0 > 0.0){
if(isReflective) f0 = max(f0, harcodedF0);
float reflectance = 0.0;
if(isReflective) f0 = max(f0, 0.02);
vec3 Reflections_Final = vec3(0.0);
vec4 Reflections = vec4(0.0);
vec3 BackgroundReflection = FinalColor;
vec3 SunReflection = vec3(0.0);
float indoors = pow(1.0-pow(1.0-min(max(lightmap.y-0.6,0.0)*3.0,1.0),0.5),2.0);
vec3 reflectedVector = reflect(normalize(viewPos), normal);
float normalDotEye = dot(normal, normalize(viewPos));
float fresnel = pow(clamp(1.0 + normalDotEye, 0.0, 1.0),5.0);
/*
int seed = (frameCounter%40000) + frameCounter*2;
float noise = fract(R2_samples(seed).y + (1-blueNoise()));
mat3 Basis = CoordBase(viewToWorld(normal));
vec3 ViewDir = -normalize(feetPlayerPos)*Basis;
vec3 SamplePoints = SampleVNDFGGX(ViewDir, vec2(roughness), noise);
vec3 Ln = reflect(-ViewDir, SamplePoints);
vec3 L = Basis * Ln;
fresnel = pow(clamp(1.0 + dot(-Ln, SamplePoints),0.0,1.0), 5.0);
*/
#ifdef SNELLS_WINDOW
// snells window looking thing
if(isEyeInWater == 1) fresnel = pow(clamp(1.5 + normalDotEye,0.0,1.0), 25.0);
#if !defined OVERWORLD_SHADER
vec3 WsunVec = vec3(0.0);
vec3 DirectLightColor = WsunVec;
float Shadows = 0.0;
#endif
fresnel = mix(f0, 1.0, fresnel);
// Sun, Sky, and screen-space reflections
#ifdef OVERWORLD_SHADER
#ifdef WATER_SUN_SPECULAR
SunReflection = Direct_lighting * GGX(normal, -normalize(viewPos), WsunVec*mat3(gbufferModelViewInverse), max(roughness,0.035), f0) * Metals;
#endif
#ifdef WATER_BACKGROUND_SPECULAR
if(isEyeInWater == 0 && !isReflectiveEntity) BackgroundReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0 * Metals;
#endif
if(isEyeInWater == 1 && isWater) BackgroundReflection.rgb = exp(-8.0 * vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B)) * clamp(WsunVec.y*lightCol.a,0,1);
#else
#ifdef WATER_BACKGROUND_SPECULAR
if(isEyeInWater == 0) BackgroundReflection = skyCloudsFromTexLOD2(mat3(gbufferModelViewInverse) * reflectedVector, colortex4, 0).rgb / 30.0 * Metals;
#endif
#endif
#ifdef SCREENSPACE_REFLECTIONS
float reflectLength = 0.0;
vec3 rtPos = rayTrace(reflectedVector, viewPos.xyz, interleaved_gradientNoise_temporal(), fresnel, isEyeInWater == 1,reflectLength);
if (rtPos.z < 1.0){
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0) {
Reflections.a = 1.0;
Reflections.rgb = texture2D(colortex5, previousPosition.xy).rgb * Metals;
}
}
#endif
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1);
Reflections_Final = mix(mix(FinalColor, BackgroundReflection, indoors), Reflections.rgb, Reflections.a) * fresnel * visibilityFactor;
Reflections_Final += SunReflection;
//correct alpha channel with fresnel
float alpha0 = gl_FragData[0].a;
gl_FragData[0].a = -gl_FragData[0].a * fresnel + gl_FragData[0].a + fresnel;
// prevent reflections from being darkened by buffer blending
gl_FragData[0].rgb = clamp(FinalColor / gl_FragData[0].a*alpha0*(1.0-fresnel) * 0.1 + Reflections_Final / gl_FragData[0].a * 0.1,0.0,65100.0);
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.0);
} else {
gl_FragData[0].rgb = FinalColor*0.1;
vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), viewToWorld(normal), roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, false, reflectance);
gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * reflectance;
// invert the alpha blending darkening on the color so you can interpolate between diffuse and specular and keep buffer blending
gl_FragData[0].rgb = clamp(specularReflections / gl_FragData[0].a * 0.1,0.0,65000.0);
}else{
gl_FragData[0].rgb = clamp(FinalColor * 0.1,0.0,65000.0);
}
#else
gl_FragData[0].rgb = FinalColor*0.1;
#endif
#if EMISSIVE_TYPE == 2 || EMISSIVE_TYPE == 3
Emission(gl_FragData[0].rgb, Albedo, SpecularTex.b, exposure);
#endif
#if defined DISTANT_HORIZONS && defined DH_OVERDRAW_PREVENTION && !defined HAND
bool WATER = texture2D(colortex7, gl_FragCoord.xy*texelSize).a > 0.0 && length(feetPlayerPos) > far-16*4 && texture2D(depthtex1, gl_FragCoord.xy*texelSize).x >= 1.0;
@ -824,16 +716,20 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
#endif
#if DEBUG_VIEW == debug_NORMALS
gl_FragData[0].rgb = normalize(normal.xyz) * 0.1;
gl_FragData[0].rgb = viewToWorld(normalize(normal.xyz)) * 0.1;
gl_FragData[0].a = 1;
#endif
#if DEBUG_VIEW == debug_INDIRECT
gl_FragData[0].rgb = Indirect_lighting* 0.1;
gl_FragData[0].rgb = Indirect_lighting * 0.1;
#endif
#if DEBUG_VIEW == debug_DIRECT
gl_FragData[0].rgb = Direct_lighting * 0.1;
#endif
gl_FragData[3].a = clamp(lightmap.y,0.0,1.0);
// gl_FragData[3].a = clamp(lightmap.y,0.0,1.0);
gl_FragData[3] = vec4(encodeVec2(lightmap.x, lightmap.y), 1, 1, 1);
}
}

View File

@ -25,10 +25,11 @@ flat varying float exposure;
flat varying vec4 lightCol;
flat varying vec3 WsunVec;
#if defined Daily_Weather
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
#endif
varying vec4 normalMat;
@ -132,6 +133,15 @@ void main() {
position = mat3(gbufferModelView) * (displacedPos - cameraPosition) + gbufferModelView[3].xyz;
}
#endif
// vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
#ifdef PLANET_CURVATURE
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * CURVATURE_AMOUNT;
#endif
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
gl_Position = toClipSpace3(position);
HELD_ITEM_BRIGHTNESS = 0.0;
@ -149,7 +159,6 @@ void main() {
// water mask
if(mc_Entity.x == 8.0) {
mat = 1.0;
gl_Position.z -= 1e-4;
}
// translucent entities
@ -193,8 +202,8 @@ void main() {
// WsunVec = normalize(LightDir);
#if defined Daily_Weather
dailyWeatherParams0 = vec4((texelFetch2D(colortex4,ivec2(1,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams1 = vec4((texelFetch2D(colortex4,ivec2(2,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams0 = vec4(texelFetch2D(colortex4,ivec2(1,1),0).rgb / 1500.0, 0.0);
dailyWeatherParams1 = vec4(texelFetch2D(colortex4,ivec2(2,1),0).rgb / 1500.0, 0.0);
#endif
#endif

View File

@ -69,20 +69,20 @@ void main() {
minimumBrightness = 10.0;
#endif
float autoBrightnessAdjust = mix(minimumBrightness, 100.0, clamp(exp(-10.0*exposure),0.0,1.0));
// float autoBrightnessAdjust = mix(minimumBrightness, 100.0, clamp(exp(-10.0*exposure),0.0,1.0));
#ifdef DISABLE_VANILLA_EMISSIVES
vec3 emissiveColor = vec3(0.0);
Albedo.a = 0.0;
#else
vec3 emissiveColor = Albedo.rgb * color.a * autoBrightnessAdjust;
vec3 emissiveColor = Albedo.rgb * color.a ;//* autoBrightnessAdjust;
#endif
gl_FragData[0] = vec4(emissiveColor*0.1, Albedo.a * sqrt(color.a));
#endif
#ifdef ENCHANT_GLINT
float autoBrightnessAdjust = mix(0.1, 100.0, clamp(exp(-10.0*exposure),0.0,1.0));
// float autoBrightnessAdjust = mix(0.1, 100.0, clamp(exp(-10.0*exposure),0.0,1.0));
Albedo.rgb = clamp(Albedo.rgb ,0.0,1.0); // for safety
@ -90,7 +90,7 @@ void main() {
vec3 GlintColor = vec3(0.0);
Albedo.a = 0.0;
#else
vec3 GlintColor = Albedo.rgb * autoBrightnessAdjust * Emissive_Brightness;
vec3 GlintColor = Albedo.rgb * Emissive_Brightness;
#endif

View File

@ -21,11 +21,14 @@ uniform sampler2D depthtex1;
uniform sampler2D colortex1;
uniform sampler2D colortex3; // Noise
uniform sampler2D colortex6; // Noise
uniform sampler2D colortex7; // Noise
uniform sampler2D colortex8; // Noise
uniform sampler2D colortex14; // Noise
uniform sampler2D colortex10; // Noise
uniform sampler2D colortex12; // Noise
uniform sampler2D colortex13; // Noise
uniform sampler2D colortex15; // Noise
uniform int isEyeInWater;
uniform sampler2D shadow;
#ifdef TRANSLUCENT_COLORED_SHADOWS
@ -121,30 +124,39 @@ vec2 decodeVec2(float a){
}
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
vec2 coord = gl_FragCoord.xy;
#ifdef TAA
coord += (frameCounter*9)%40000;
#endif
return fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float R2_dither(){
#ifdef TAA
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#else
vec2 coord = gl_FragCoord.xy;
vec2 coord = gl_FragCoord.xy ;
#ifdef TAA
coord += (frameCounter*2)%40000;
#endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
#ifdef TAA
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
#else
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887);
#endif
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
}
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
@ -236,63 +248,53 @@ float convertHandDepth_2(in float depth, bool hand) {
ndcDepth /= MC_HAND_DEPTH;
return ndcDepth * 0.5 + 0.5;
}
vec2 SSAO(
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
){
// if(hand) return vec2(1.0,0.0);
int samples = 7;
float occlusion = 0.0;
float sss = 0.0;
vec3 normalizedNormals = normalize(normal);
vec2 jitterOffsets = TAA_Offset*texelSize*0.5 * RENDER_SCALE - texelSize*0.5;
float dist = 1.0 + clamp(viewPos.z*viewPos.z/50.0,0,5); // shrink sample size as distance increases
float mulfov2 = gbufferProjection[1][1]/(3 * dist);
float maxR2 = viewPos.z*viewPos.z*mulfov2*2.0 * 5.0 / mix(4.0, 50.0, clamp(viewPos.z*viewPos.z - 0.1,0,1));
#ifdef Ambient_SSS
float maxR2_2 = viewPos.z;//*viewPos.z*mulfov2*2.*2./4.0;
float dist3 = clamp(1-exp( viewPos.z*viewPos.z / -50),0,1);
// if(leaves) maxR2_2 = 0.1;
// if(leaves) maxR2_2 = mix(10, maxR2_2, dist3);
#endif
vec2 acc = -(TAA_Offset*(texelSize/2.0))*RENDER_SCALE ;
// scale the offset radius down as distance increases.
float linearViewDistance = length(viewPos);
float distanceScale = hand ? 30.0 : mix(40.0, 10.0, pow(clamp(1.0 - linearViewDistance/50.0,0.0,1.0),2.0));
float depthCancelation = (linearViewDistance*linearViewDistance) / distanceScale * 0.5;
// vec2 BLUENOISE = blueNoise(gl_FragCoord.xy).rg;
int n = 0;
float leaf = leaves ? -0.5 : 0.0;
int n = 0;
for (int i = 0; i < samples; i++) {
// vec2 sampleOffset = (SpiralSample(i, 7, 8 , noise)) * mulfov2 * clamp(0.05 + i*0.095, 0.0,0.3) ;
vec2 sampleOffset = CleanSample(i, samples - 1, noise) * mulfov2 * 0.3 ;
vec2 offsets = CleanSample(i, samples - 1, noise) / distanceScale;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE);
ivec2 offsetUV = ivec2(gl_FragCoord.xy + offsets*vec2(viewWidth, viewHeight*aspectRatio)*RENDER_SCALE);
if (offsetUV.x >= 0 && offsetUV.y >= 0 && offsetUV.x < viewWidth*RENDER_SCALE.x && offsetUV.y < viewHeight*RENDER_SCALE.y ) {
float sampleDepth = convertHandDepth_2(texelFetch2D(depthtex1, offsetUV, 0).x, hand);
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth*RENDER_SCALE.x && offset.y < viewHeight*RENDER_SCALE.y ) {
#ifdef DISTANT_HORIZONS
float dhdepth = texelFetch2D(dhDepthTex1, offset,0).x;
float sampleDHDepth = texelFetch2D(dhDepthTex1, offsetUV, 0).x;
vec3 offsetViewPos = toScreenSpace_DH((offsetUV*texelSize - jitterOffsets) * (1.0/RENDER_SCALE), sampleDepth, sampleDHDepth);
#else
float dhdepth = 0.0;
vec3 offsetViewPos = toScreenSpace(vec3((offsetUV*texelSize - jitterOffsets) * (1.0/RENDER_SCALE), sampleDepth));
#endif
vec3 t0 = toScreenSpace_DH((offset*texelSize+acc+0.5*texelSize) * (1.0/RENDER_SCALE), convertHandDepth_2(texelFetch2D(depthtex1, offset,0).x, hand), dhdepth);
vec3 vec = (t0.xyz - viewPos);
float dsquared = dot(vec, vec);
vec3 viewPosDiff = offsetViewPos - viewPos;
float viewPosDiffSquared = dot(viewPosDiff, viewPosDiff);
if (dsquared > 1e-5){
if( dsquared < maxR2){
float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.);
occlusion += NdotV * clamp(1.0-dsquared/maxR2,0.0,1.0);
if (viewPosDiffSquared > 1e-5){
if(viewPosDiffSquared < depthCancelation){
float NdotV = clamp(dot(viewPosDiff*inversesqrt(viewPosDiffSquared), normalizedNormals),0.0,1.0);
occlusion += NdotV * clamp(1.0-(viewPosDiffSquared/depthCancelation),0.0,1.0);
}
#ifdef Ambient_SSS
sss += clamp(leaf - dot(vec, normalize(normal)),0.0,1.0);
sss += clamp(0.0 - dot(viewPosDiff, normalizedNormals),0.0,1.0) * exp(-10.0 * occlusion);
#endif
n += 1;
@ -302,6 +304,52 @@ vec2 SSAO(
return max(1.0 - vec2(occlusion*AO_Strength, sss)/n, 0.0);
}
float ScreenSpace_SSS(
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
){
int samples = 7;
float occlusion = 0.0;
float sss = 0.0;
vec3 normalizedNormals = normalize(normal);
vec2 jitterOffsets = TAA_Offset*texelSize*0.5 * RENDER_SCALE - texelSize*0.5;
// scale the offset radius down as distance increases.
float linearViewDistance = length(viewPos);
float distanceScale = hand ? 30.0 : mix(40.0, 10.0, pow(clamp(1.0 - linearViewDistance/50.0,0.0,1.0),2.0));
float leaf = leaves ? -0.5 : 0.0;
int n = 0;
for (int i = 0; i < samples; i++) {
vec2 offsets = CleanSample(i, samples - 1, noise) / distanceScale;
ivec2 offsetUV = ivec2(gl_FragCoord.xy + offsets*vec2(viewWidth, viewHeight*aspectRatio)*RENDER_SCALE);
if (offsetUV.x >= 0 && offsetUV.y >= 0 && offsetUV.x < viewWidth*RENDER_SCALE.x && offsetUV.y < viewHeight*RENDER_SCALE.y ) {
float sampleDepth = convertHandDepth_2(texelFetch2D(depthtex1, offsetUV, 0).x, hand);
#ifdef DISTANT_HORIZONS
float sampleDHDepth = texelFetch2D(dhDepthTex1, offsetUV, 0).x;
vec3 offsetViewPos = toScreenSpace_DH((offsetUV*texelSize - jitterOffsets) * (1.0/RENDER_SCALE), sampleDepth, sampleDHDepth);
#else
vec3 offsetViewPos = toScreenSpace(vec3((offsetUV*texelSize - jitterOffsets) * (1.0/RENDER_SCALE), sampleDepth));
#endif
vec3 viewPosDiff = offsetViewPos - viewPos;
float viewPosDiffSquared = dot(viewPosDiff, viewPosDiff);
if (viewPosDiffSquared > 1e-5){
sss += clamp(leaf - dot(viewPosDiff, normalizedNormals),0.0,1.0);
n += 1;
}
}
}
return max(1.0 - sss/n, 0.0);
}
vec4 encode (vec3 n, vec2 lightmaps){
n.xy = n.xy / dot(abs(n), vec3(1.0));
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
@ -366,14 +414,59 @@ float sampleDepth(sampler2D depthTex, vec2 texcoord, bool hand){
return convertHandDepth_2(texture2D(depthTex, texcoord).r, hand);
}
flat varying vec3 zMults;
vec4 BilateralUpscale_VLFOG(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
ivec2 getRadius[5] = ivec2[](
ivec2(-1,-1),
ivec2( 1, 1),
ivec2(-1, 1),
ivec2( 1,-1),
ivec2( 0, 0)
);
#ifdef DISTANT_HORIZONS
float diffThreshold = 0.01;
#else
float diffThreshold = zMults.x;
#endif
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
for (int i = 0; i < 4; i++) {
ivec2 radius = getRadius[i];
#ifdef DISTANT_HORIZONS
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
#else
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
#endif
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
SUM += EDGES;
}
return RESULT / SUM;
}
/* RENDERTARGETS:3,14,12*/
#include "/lib/sky_gradient.glsl"
/* RENDERTARGETS:3,14,12,10*/
void main() {
float noise = R2_dither();
vec2 texcoord = gl_FragCoord.xy*texelSize;
float z = texture2D(depthtex1,texcoord).x;
@ -389,7 +482,7 @@ void main() {
vec4 SHADOWDATA = vec4(0.0);
vec4 data = texture2D(colortex1,texcoord);
vec4 data = texelFetch2D(colortex1,ivec2(gl_FragCoord.xy),0);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w));
vec3 normal = mat3(gbufferModelViewInverse) * clamp(worldToView( decode(dataUnpacked0.yw) ),-1.,1.);
@ -437,13 +530,11 @@ void main() {
gl_FragData[2] = vec4(vec3(0.0), 65000.0);
vec3 FlatNormals = texture2D(colortex15,texcoord).rgb * 2.0 - 1.0;
if(z >= 1.0){
FlatNormals = normal;
}
vec3 FlatNormals = normalize(texture2D(colortex15,texcoord).rgb * 2.0 - 1.0);
if(z >= 1.0) FlatNormals = normal;
vec2 SSAO_SSS = SSAO(viewPos, FlatNormals, hand, isLeaf, noise);
vec2 SSAO_SSS = SSAO(viewPos, worldToView(FlatNormals), hand, isLeaf, noise);
if(swappedDepth >= 1.0) SSAO_SSS = vec2(1.0,0.0);
@ -453,6 +544,21 @@ void main() {
#endif
/*------------- VOLUMETRICS BEHIND TRANSLUCENTS PASS-THROUGH -------------*/
// colortex10 is the history buffer used in reprojection of volumetrics, i can just hijack that.
gl_FragData[3] = texture2D(colortex10, texcoord);
// if(texture2D(colortex7,texcoord).a > 0.0) {
// vec4 VL = BilateralUpscale_VLFOG(colortex13, depthtex1, gl_FragCoord.xy - 1.5, ld(z));
// // gl_FragData[3].rgb += VL.rgb * gl_FragData[3].a;
// // gl_FragData[3].a *= VL.a;
// }
#ifdef OVERWORLD_SHADER
float SpecularTex = texture2D(colortex8,texcoord).z;
float LabSSS = clamp((-64.0 + SpecularTex * 255.0) / 191.0 ,0.0,1.0);
@ -463,9 +569,7 @@ void main() {
float minshadowfilt = Min_Shadow_Filter_Radius;
float maxshadowfilt = Max_Shadow_Filter_Radius;
// if(lightmap.y < 0.1 && !entities){
// maxshadowfilt = mix(minshadowfilt, maxshadowfilt, vanillAO);
// }
if(lightmap.y < 0.1) maxshadowfilt = min(maxshadowfilt, minshadowfilt);
#ifdef BASIC_SHADOW_FILTER
if (LabSSS > 0.0 && NdotL < 0.001){

View File

@ -12,6 +12,10 @@ uniform vec3 sunPosition;
uniform mat4 gbufferModelViewInverse;
flat varying vec3 zMults;
uniform float far;
uniform float near;
#include "/lib/util.glsl"
#include "/lib/res_params.glsl"
@ -26,6 +30,8 @@ void main() {
WsunVec = (float(sunElevation > 1e-5)*2-1.)*normalize(mat3(gbufferModelViewInverse) * sunPosition);
zMults = vec3(1.0/(far * near),far+near,far-near);
#ifdef TAA
TAA_Offset = offsets[framemod8];
#else

File diff suppressed because it is too large Load Diff

View File

@ -5,10 +5,11 @@
flat varying float Flashing;
#endif
#if defined Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
flat varying vec3 WsunVec;
flat varying vec3 unsigned_WsunVec;
@ -53,14 +54,14 @@ void main() {
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
WsunVec = lightCol.a*normalize(mat3(gbufferModelViewInverse) * sunPosition);
unsigned_WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
WsunVec = lightCol.a*unsigned_WsunVec;
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;
#if defined Daily_Weather
dailyWeatherParams0 = vec4((texelFetch2D(colortex4,ivec2(1,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams1 = vec4((texelFetch2D(colortex4,ivec2(2,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams0 = vec4(texelFetch2D(colortex4,ivec2(1,1),0).rgb / 1500.0, 0.0);
dailyWeatherParams1 = vec4(texelFetch2D(colortex4,ivec2(2,1),0).rgb / 1500.0, 0.0);
#endif
#ifdef TAA

View File

@ -106,7 +106,7 @@ vec2 texcoord = ((gl_FragCoord.xy)*2.0 + 0.5)*texelSize;
bloom += texture2D_bicubic(colortex6,texcoord/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb * weights[5]; //1/128 res
bloom += texture2D_bicubic(colortex6,texcoord/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb * weights[6]; //1/256 res
gl_FragData[0].rgb = bloom * 3.0;
gl_FragData[0].rgb = bloom * 2.0;
#endif
gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.);

View File

@ -14,7 +14,7 @@ uniform sampler2D colortex3;
// uniform sampler2D colortex6;
uniform sampler2D colortex7;
// uniform sampler2D colortex8; // specular
// uniform sampler2D colortex9; // specular
uniform sampler2D colortex9; // specular
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D noisetex;
@ -72,12 +72,6 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
return (near * far) / (depth * (near - far) + far);
}
float bloomWeight(){
float weights[7] = float[]( 1.0, 1.0/2.0, 1.0/3.0, 1.0/5.5, 1.0/8.0, 1.0/10.0, 1.0/12.0 );
@ -91,9 +85,102 @@ float bloomWeight(){
return result;
}
vec3 invTonemap(vec3 col){
return col/(1-luma(col));
}
#define linear_to_srgb(x) (pow(x, vec3(1.0/2.2)))
uniform sampler2D colortex6;
float w0(float a)
{
return (1.0/6.0)*(a*(a*(-a + 3.0) - 3.0) + 1.0);
}
float w1(float a)
{
return (1.0/6.0)*(a*a*(3.0*a - 6.0) + 4.0);
}
float w2(float a)
{
return (1.0/6.0)*(a*(a*(-3.0*a + 3.0) + 3.0) + 1.0);
}
float w3(float a)
{
return (1.0/6.0)*(a*a*a);
}
float g0(float a)
{
return w0(a) + w1(a);
}
float g1(float a)
{
return w2(a) + w3(a);
}
float h0(float a)
{
return -1.0 + w1(a) / (w0(a) + w1(a));
}
float h1(float a)
{
return 1.0 + w3(a) / (w2(a) + w3(a));
}
vec4 texture2D_bicubic(sampler2D tex, vec2 uv)
{
vec4 texelSize = vec4(texelSize,1.0/texelSize);
uv = uv*texelSize.zw;
vec2 iuv = floor( uv );
vec2 fuv = fract( uv );
float g0x = g0(fuv.x);
float g1x = g1(fuv.x);
float h0x = h0(fuv.x);
float h1x = h1(fuv.x);
float h0y = h0(fuv.y);
float h1y = h1(fuv.y);
vec2 p0 = (vec2(iuv.x + h0x, iuv.y + h0y) - 0.5) * texelSize.xy;
vec2 p1 = (vec2(iuv.x + h1x, iuv.y + h0y) - 0.5) * texelSize.xy;
vec2 p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - 0.5) * texelSize.xy;
vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - 0.5) * texelSize.xy;
return g0(fuv.y) * (g0x * texture2D(tex, p0) +
g1x * texture2D(tex, p1)) +
g1(fuv.y) * (g0x * texture2D(tex, p2) +
g1x * texture2D(tex, p3));
}
// vec3 lenseFlare(vec2 UV){
// float noise = blueNoise();
// float vignetteLength = 0.2;
// float vignette = 0.5+length(texcoord-0.5);//min(max(length(texcoord-0.5) - vignetteLength,0.0) / (1.0/(1.0-vignetteLength)),1.0);
// float aberrationStrength = vignette;//clamp(CHROMATIC_ABERRATION_STRENGTH * 0.01 * (1.0 - vignette),0.0,0.9) * vignette * 0.75;
// vec2 centeredUV = texcoord - 0.5;
// vec3 color = vec3(0.0);
// color = texture2D(colortex7, texcoord).rgb;
// vec2 distortedUV = (centeredUV - (centeredUV ) * aberrationStrength) + 0.5;
// color += texture2D(colortex7, distortedUV).rgb;
// // color.r = texture2D(colortex7, (centeredUV - (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).r;
// // color.g = texture2D(colortex7, texcoord).g;
// // color.b = texture2D(colortex7, (centeredUV + (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).b;
// return color;
// }
void main() {
/* DRAWBUFFERS:7 */
float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.);
@ -132,16 +219,21 @@ void main() {
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
vec2 resScale = vec2(1920.,1080.)/clampedRes;
vec2 bloomTileUV = (((gl_FragCoord.xy)*2.0 + 0.5)*texelSize/2.0) / clampedRes*vec2(1920.,1080.);
#ifdef OLD_BLOOM
vec3 bloom = texture2D(colortex3, texcoord/clampedRes*vec2(1920.,1080.)*BLOOM_QUALITY ).rgb / 2.0 / 7.0;
float lightScat = clamp((BLOOM_STRENGTH+3) * 0.05 * pow(exposure.a, 0.2) ,0.0,1.0) * vignette;
#else
vec3 bloom = texture2D(colortex3, texcoord/clampedRes*vec2(1920.,1080.)*BLOOM_QUALITY ).rgb / 3.0 / bloomWeight();
float lightScat = clamp(BLOOM_STRENGTH * 0.5 * pow(exposure.a, 0.2) ,0.0,1.0) * vignette;
#endif
vec3 bloomTile0 = texture2D_bicubic(colortex3, bloomTileUV/2.).rgb; //1/4 res
vec3 bloomTile1 = texture2D_bicubic(colortex6, bloomTileUV/4.).rgb; //1/8 res
vec3 bloomTile2 = texture2D_bicubic(colortex6, bloomTileUV/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res
vec3 bloomTile3 = texture2D_bicubic(colortex6, bloomTileUV/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res
vec3 bloomTile4 = texture2D_bicubic(colortex6, bloomTileUV/32.+vec2(0.4375*resScale.x+6.5*texelSize.x,.0)).rgb; //1/64 res
vec3 bloomTile5 = texture2D_bicubic(colortex6, bloomTileUV/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb; //1/128 res
vec3 bloomTile6 = texture2D_bicubic(colortex6, bloomTileUV/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb; //1/256 res
float weights[7] = float[]( 1.0, 1.0/2.0, 1.0/3.0, 1.0/5.5, 1.0/8.0, 1.0/10.0, 1.0/12.0 );
vec3 bloom = (bloomTile0*weights[0] + bloomTile1*weights[1] + bloomTile2*weights[2] + bloomTile3*weights[3] + bloomTile4*weights[4] + bloomTile5*weights[5] + bloomTile6*weights[6]) / bloomWeight();
vec3 fogBloom = (bloomTile0 + bloomTile1 + bloomTile2 + bloomTile3 + bloomTile4 + bloomTile5 + bloomTile6) / 7.0;
float VL_abs = texture2D(colortex7, texcoord*RENDER_SCALE).r;
#ifdef AUTO_EXPOSURE
float purkinje = clamp(exposure.a*exposure.a,0.0,1.0) * clamp(rodExposureDepth.x/(1.0+rodExposureDepth.x)*Purkinje_strength,0,1);
@ -149,9 +241,12 @@ void main() {
float purkinje = clamp(rodExposureDepth.x/(1.0+rodExposureDepth.x)*Purkinje_strength,0,1);
#endif
float lightScat = clamp(BLOOM_STRENGTH * 0.3,0.0,1.0) * vignette;
float VL_abs = texture2D(colortex7, texcoord*RENDER_SCALE).r;
VL_abs = clamp((1.0-VL_abs)*BLOOMY_FOG*0.75*(1.0+rainStrength) * (1.0-purkinje*0.3),0.0,1.0)*clamp(1.0-pow(cdist(texcoord.xy),15.0),0.0,1.0);
col = (mix(col, bloom, VL_abs) + bloom * lightScat) * exposure.rgb;
col = (mix(col, fogBloom, VL_abs) + bloom*lightScat) * exposure.rgb;
float lum = dot(col, vec3(0.15,0.3,0.55));
float lum2 = dot(col, vec3(0.85,0.7,0.45));

View File

@ -13,6 +13,7 @@ uniform float viewWidth;
uniform float aspectRatio;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform int hideGUI;
@ -134,11 +135,41 @@ vec3 saturationAndCrosstalk(vec3 color){
return color;
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
vec3 chromaticAberration(vec2 UV){
float noise = blueNoise() - 0.5;
vec2 centeredUV = (texcoord - 0.5);
// not stretched by aspect ratio; circular by choice :) it makes most the abberation on the left/right of the screen.
float vignette = 1.0 - clamp(1.0 - length(centeredUV * vec2(aspectRatio,1.0)) / 200.0,0.0,1.0);
float aberrationStrength = CHROMATIC_ABERRATION_STRENGTH * vignette;
vec3 color = vec3(0.0);
color.r = texture2D(colortex7, (centeredUV - (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).r;
color.g = texture2D(colortex7, texcoord).g;
color.b = texture2D(colortex7, (centeredUV + (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).b;
return color;
}
void main() {
/* DRAWBUFFERS:7 */
vec3 color = texture2D(colortex7,texcoord).rgb;
#ifdef CHROMATIC_ABERRATION
vec3 color = chromaticAberration(texcoord);
#else
vec3 color = texture2D(colortex7,texcoord).rgb;
#endif
#ifdef CONTRAST_ADAPTATIVE_SHARPENING
color = contrastAdaptiveSharpening(color, texcoord);
@ -153,6 +184,6 @@ void main() {
#ifdef COLOR_GRADING_ENABLED
color = colorGrading(color);
#endif
gl_FragData[0].rgb = clamp(int8Dither(color, texcoord),0.0,1.0);
}

View File

@ -22,6 +22,7 @@ uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform sampler2D colortex6;
uniform sampler2D colortex7;
uniform sampler2D colortex10;
flat varying vec3 WsunVec;
uniform vec3 sunVec;
@ -32,12 +33,21 @@ uniform float near;
uniform float dhFarPlane;
uniform float dhNearPlane;
// uniform mat4 gbufferModelViewInverse;
// uniform mat4 gbufferModelView;
uniform mat4 gbufferPreviousModelView;
// uniform mat4 gbufferProjectionInverse;
// uniform mat4 gbufferProjection;
// uniform mat4 gbufferPreviousProjection;
// uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
uniform int frameCounter;
uniform float frameTimeCounter;
// varying vec2 texcoord;
uniform vec2 texelSize;
// flat varying vec2 TAA_Offset;
flat varying vec2 TAA_Offset;
uniform int isEyeInWater;
uniform float rainStrength;
@ -110,17 +120,17 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
float LpvFadeF = cubicRadius.x*cubicRadius.y*cubicRadius.z;
if(LpvFadeF > 0.0){
// if(length(lpvSample.xyz) > 1e-5){
vec4 lpvSample = SampleLpvLinear(lpvPos);
vec3 lighting = SampleLpvLinear(lpvPos).rgb * (LPV_VL_FOG_ILLUMINATION_BRIGHTNESS/100.0);
// float density = exp(-5.0 * clamp( 1.0 - length(lpvSample.xyz) / 16.0,0.0,1.0)) * (LPV_VL_FOG_ILLUMINATION_BRIGHTNESS/100.0) * LpvFadeF;
float density = exp(-5.0 * (1.0-length(lighting.xyz))) * LpvFadeF;
// float density = (1-exp(-1.0-clamp(length(lighting.rgb),0.0,1.0),25) )* LpvFadeF;
if(length(lpvSample.xyz) > 1e-5){
vec3 LpvTorchLight = GetLpvBlockLight(lpvSample);
vec3 lighting = LpvTorchLight;
float density = exp(-5.0 * clamp( 1.0 - length(lpvSample.xyz) / 16.0,0.0,1.0)) * (LPV_VL_FOG_ILLUMINATION_BRIGHTNESS/100.0) * LpvFadeF;
// float density = 0.01 * LpvFadeF;
color = lighting - lighting * exp(-density*dd*dL);
}
// }
}
return color;
@ -130,21 +140,38 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
uniform float nightVision;
#ifdef OVERWORLD_SHADER
const bool shadowHardwareFiltering = true;
uniform sampler2DShadow shadow;
#ifdef TRANSLUCENT_COLORED_SHADOWS
uniform sampler2D shadowcolor0;
uniform sampler2DShadow shadowtex0;
uniform sampler2DShadow shadowtex1;
#endif
flat varying vec3 refractedSunVec;
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#else
vec4 dailyWeatherParams0 = vec4(CloudLayer0_coverage, CloudLayer1_coverage, CloudLayer2_coverage, 0.0);
vec4 dailyWeatherParams1 = vec4(CloudLayer0_density, CloudLayer1_density, CloudLayer2_density, 0.0);
#endif
// uniform int dhRenderDistance;
#define TIMEOFDAYFOG
#include "/lib/lightning_stuff.glsl"
#define CLOUDS_INTERSECT_TERRAIN
// #define CLOUDS_INTERSECT_TERRAIN
#include "/lib/volumetricClouds.glsl"
#include "/lib/climate_settings.glsl"
#include "/lib/overworld_fog.glsl"
#endif
#ifdef NETHER_SHADER
@ -159,7 +186,9 @@ uniform sampler2D colortex4;
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
@ -168,15 +197,15 @@ float interleaved_gradientNoise(){
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a+ 1.0/1.6180339887 * frameCounter );
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter );
}
float R2_dither(){
#ifdef TAA
// #ifdef TAA
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#else
vec2 coord = gl_FragCoord.xy;
#endif
// #else
// vec2 coord = gl_FragCoord.xy;
// #endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
@ -226,7 +255,7 @@ void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEn
}
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
vec3 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
int spCount = 8;
vec3 start = toShadowSpaceProjected(rayStart);
@ -236,35 +265,29 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,32.0)/(1e-8+rayLength);
dV *= maxZ;
vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
#ifdef OVERWORLD_SHADER
float phase = fogPhase(VdotL) * 5.0;
#endif
dV *= maxZ;
rayLength *= maxZ;
vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float YFade = pow(normalize(dVWorld).y*0.3+0.7,1.5);
#ifdef OVERWORLD_SHADER
float lowlightlevel = clamp(eyeBrightnessSmooth.y/240.0,0.1,1.0);
float lowlightlevel = clamp(eyeBrightnessSmooth.y/240.0,0.1,1.0);
float phase = fogPhase(VdotL) * 5.0;
#else
float lowlightlevel = 1.0;
float lowlightlevel = 1.0;
float phase = 0.0;
#endif
// lowlightlevel = pow(lowlightlevel,0.5);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); // exponential step position (0-1)
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative)
float d = (pow(expFactor, float(i+dither.x)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); // exponential step position (0-1)
float dd = pow(expFactor, float(i+dither.y)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative)
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
vec3 sh = vec3(1.0);
#ifdef OVERWORLD_SHADER
@ -276,15 +299,18 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE
#else
float distortFactor = 1.0;
#endif
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
// sh = shadow2D( shadow, pos).x;
// sh = shadow2D( shadow, pos).x;
#ifdef TRANSLUCENT_COLORED_SHADOWS
sh = vec3(shadow2D(shadowtex0, pos).x);
if(shadow2D(shadowtex1, pos).x > pos.z && sh.x < 1.0){
sh = normalize(texture2D(shadowcolor0, pos.xy).rgb+0.0001);
vec4 translucentShadow = texture2D(shadowcolor0, pos.xy);
if(translucentShadow.a < 0.9) sh = normalize(translucentShadow.rgb+0.0001);
}
#else
sh = vec3(shadow2D(shadow, pos).x);
@ -292,38 +318,28 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE
}
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow_VLFOG(progressW, WsunVec);
sh *= GetCloudShadow(progressW, WsunVec);
#endif
// float bubble = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - length(d*dVWorld) / (16),0.0)*5.0,1.0),2.0),2.0);
float bubble = exp( -7.0 * clamp(1.0 - length(d*dVWorld) / 16.0, 0.0,1.0) );
float bubble2 = max(pow(length(d*dVWorld)/24,5)*100.0,0.0) + 1;
float sunCaustics = (waterCaustics(progressW, WsunVec)) * mix(0.25,10.0,bubble) + 0.75;
vec3 sunMul = exp(-1 * d * waterCoefs * 1.1);
vec3 Directlight = ((lightSource* sh) * phase * sunMul * sunCaustics) * lowlightlevel * pow(abs(WsunVec.y),1);
#else
vec3 Directlight = vec3(0.0);
#endif
vec3 ambientMul = exp(-1 * d * waterCoefs);
vec3 Indirectlight = ambient * ambientMul * YFade * lowlightlevel;
vec3 light = (Indirectlight + Directlight) * scatterCoef;
float bubble = exp2(-10.0 * clamp(1.0 - length(d*dVWorld) / 16.0, 0.0,1.0));
float caustics = mix(max(max(waterCaustics(progressW, WsunVec), phase*0.5) * mix(0.5, 200.0, bubble), phase), 1.0, lowlightlevel);
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-waterCoefs * dd * rayLength);
vec3 Directlight = lightSource * sh * phase * caustics*abs(WsunVec.y) * lowlightlevel;
vec3 Indirectlight = ambient * lowlightlevel;
#if defined LPV_VL_FOG_ILLUMINATION && defined EXCLUDE_WRITE_TO_LUT
vL += LPV_FOG_ILLUMINATION(progressW-cameraPosition, dd, 1.0);
#endif
vec3 WaterAbsorbance = exp(-waterCoefs * rayLength * d);
vec3 light = (Indirectlight + Directlight) * WaterAbsorbance * scatterCoef;
vec3 volumeCoeff = exp(-waterCoefs * rayLength * dd);
vL += (light - light * volumeCoeff) / waterCoefs * absorbance;
absorbance *= volumeCoeff;
}
inColor += vL;
return vL;
}
// #endif
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
@ -351,9 +367,130 @@ float encodeVec2(vec2 a){
// uniform int framemod8;
// #include "/lib/TAA_jitter.glsl"
uniform int framemod8;
#include "/lib/TAA_jitter.glsl"
vec3 toClipSpace3Prev(vec3 viewSpacePosition) {
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth)
{
vec2 du = vec2(texelSize.x*2., 0.0);
vec2 dv = vec2(0.0, texelSize.y*2.);
vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x);
vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x);
vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x);
vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x);
vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x);
vec3 dmin = dmc;
dmin = dmin.z > dtr.z ? dtr : dmin;
dmin = dmin.z > dtl.z ? dtl : dmin;
dmin = dmin.z > dbl.z ? dbl : dmin;
dmin = dmin.z > dbr.z ? dbr : dmin;
#ifdef TAA_UPSCALING
dmin.xy = dmin.xy/RENDER_SCALE;
#endif
return dmin;
}
vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) {
#ifdef DISTANT_HORIZONS
mat4 projectionMatrix = depthCheck ? dhPreviousProjection : gbufferPreviousProjection;
return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
#else
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
#endif
}
vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) {
vec4 viewPos = vec4(0.0);
vec3 feetPlayerPos = vec3(0.0);
vec4 iProjDiag = vec4(0.0);
#ifdef DISTANT_HORIZONS
if (depthCheck) {
iProjDiag = vec4(dhProjectionInverse[0].x, dhProjectionInverse[1].y, dhProjectionInverse[2].zw);
feetPlayerPos = POS * 2.0 - 1.0;
viewPos = iProjDiag * feetPlayerPos.xyzz + dhProjectionInverse[3];
viewPos.xyz /= viewPos.w;
} else {
#endif
iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
feetPlayerPos = POS * 2.0 - 1.0;
viewPos = iProjDiag * feetPlayerPos.xyzz + gbufferProjectionInverse[3];
viewPos.xyz /= viewPos.w;
#ifdef DISTANT_HORIZONS
}
#endif
return viewPos.xyz;
}
vec4 VLTemporalFiltering(vec3 viewPos, bool depthCheck, vec4 color){
vec2 texcoord = gl_FragCoord.xy * texelSize;
vec2 VLtexCoord = texcoord/VL_RENDER_RESOLUTION;
// vec3 closestToCamera = closestToCamera5taps(texcoord, depthtex0);
// vec3 viewPos_5tap = toScreenSpace(closestToCamera);
// get previous frames position stuff for UV
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz;
previousPosition = toClipSpace3Prev(previousPosition);
vec2 velocity = previousPosition.xy - VLtexCoord/RENDER_SCALE;
previousPosition.xy = VLtexCoord + velocity;
vec4 currentFrame = color;
if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return currentFrame;
// vec4 col0 = currentFrame; // can use this because its the center sample.
// vec4 col1 = texture2D(colortex0, VLtexCoord + vec2( texelSize.x, texelSize.y));
// vec4 col2 = texture2D(colortex0, VLtexCoord + vec2( texelSize.x, -texelSize.y));
// vec4 col3 = texture2D(colortex0, VLtexCoord + vec2(-texelSize.x, -texelSize.y));
// vec4 col4 = texture2D(colortex0, VLtexCoord + vec2(-texelSize.x, texelSize.y));
// vec4 col5 = texture2D(colortex0, VLtexCoord + vec2( 0.0, texelSize.y));
// vec4 col6 = texture2D(colortex0, VLtexCoord + vec2( 0.0, -texelSize.y));
// vec4 col7 = texture2D(colortex0, VLtexCoord + vec2(-texelSize.x, 0.0));
// vec4 col8 = texture2D(colortex0, VLtexCoord + vec2( texelSize.x, 0.0));
// vec4 colMax = max(col0,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8))))))));
// vec4 colMin = min(col0,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8))))))));
// // colMin = 0.5 * (colMin + min(col0,min(col5,min(col6,min(col7,col8)))));
// // colMax = 0.5 * (colMax + max(col0,max(col5,max(col6,max(col7,col8)))));
vec4 frameHistory = texture2D(colortex10, previousPosition.xy*VL_RENDER_RESOLUTION);
vec4 clampedFrameHistory = frameHistory;
// vec4 clampedFrameHistory = clamp(frameHistory, colMin, colMax);
float blendFactor = 0.25;
blendFactor = clamp(length(velocity/texelSize),blendFactor,0.2);
// if(min(frameHistory.a,rejection) > 0.0) blendFactor = 1.0;
return mix(clampedFrameHistory, currentFrame, blendFactor);
}
float convertHandDepth(float depth) {
float ndcDepth = depth * 2.0 - 1.0;
ndcDepth /= MC_HAND_DEPTH;
return ndcDepth * 0.5 + 0.5;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -362,88 +499,95 @@ float encodeVec2(vec2 a){
void main() {
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
/* RENDERTARGETS:0,14 */
#else
/* RENDERTARGETS:0 */
#endif
float noise_1 = max(1.0 - R2_dither(),0.0015);
/* RENDERTARGETS:0 */
float noise_2 = blueNoise();
vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize + texelSize*0.5;
float noise_1 = max(1.0 - R2_dither(),0.0015);
// float noise_2 = interleaved_gradientNoise_temporal();
vec2 bnoise = blueNoise(gl_FragCoord.xy ).rg;
int seed = (frameCounter*5)%40000;
vec2 r2_sequence = R2_samples(seed).xy;
vec2 BN = fract(r2_sequence + bnoise);
// vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize + texelSize*0.5;
vec2 tc = gl_FragCoord.xy/VL_RENDER_RESOLUTION*texelSize;// + texelSize*0.5;
bool iswater = texture2D(colortex7,tc).a > 0.99;
float z0 = texture2D(depthtex0, tc).x;
vec2 jitter = TAA_Offset/VL_RENDER_RESOLUTION*texelSize*0.5;
float depth = texture2D(depthtex0, tc + jitter).x;
float z0 = depth < 0.56 ? convertHandDepth(depth) : depth;
#ifdef DISTANT_HORIZONS
float DH_z0 = texture2D(dhDepthTex,tc).x;
#else
float DH_z0 = 0.0;
#endif
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE , z0, DH_z0);
vec3 playerPos_normalized = normalize(mat3(gbufferModelViewInverse) * viewPos0 + gbufferModelViewInverse[3].xyz);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos0 + gbufferModelViewInverse[3].xyz;
vec3 playerPos_normalized = normalize(playerPos);
float dirtAmount = Dirt_Amount + 0.01;
float dirtAmount = Dirt_Amount;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 directLightColor = lightCol.rgb/80.0;
vec3 indirectLightColor = averageSkyCol/30.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds/30.0;
vec3 directLightColor = lightCol.rgb / 2400.0;
vec3 indirectLightColor = averageSkyCol / 1200.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds / 1200.0;
// indirectLightColor_dynamic += MIN_LIGHT_AMOUNT * 0.02 * 0.2 + nightVision*0.02;
vec3 cloudDepth = vec3(0.0);
vec3 fogDepth = vec3(0.0);
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
vec4 VolumetricClouds = renderClouds(viewPos0, vec2(noise_1,noise_2), directLightColor, indirectLightColor, cloudDepth);
#if defined OVERWORLD_SHADER
// z0 = texture2D(depthtex0, tc + jitter/VL_RENDER_RESOLUTION).x;
// viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
vec4 VolumetricClouds = GetVolumetricClouds(viewPos0, BN, WsunVec, directLightColor, indirectLightColor);
#ifdef CAVE_FOG
float skyhole = (1.0-pow(clamp(1.0-pow(max(playerPos_normalized.y - 0.6,0.0)*5.0,2.0),0.0,1.0),2)* caveDetection) ;
VolumetricClouds.rgb *= skyhole;
VolumetricClouds.a = mix(VolumetricClouds.a, 1.0, (1.0-skyhole) * caveDetection);
float skyhole = pow(clamp(1.0-pow(max(playerPos_normalized.y - 0.6,0.0)*5.0,2.0),0.0,1.0),2)* caveDetection;
VolumetricClouds.rgb *= 1.0-skyhole;
VolumetricClouds.a = mix(VolumetricClouds.a, 1.0, skyhole);
#endif
#endif
#ifdef OVERWORLD_SHADER
float atmosphereAlpha = 1.0;
vec4 VolumetricFog = GetVolumetricFog(viewPos0, vec2(noise_2,noise_1), directLightColor, indirectLightColor, averageSkyCol_Clouds/30.0, atmosphereAlpha);
VolumetricClouds.a *= atmosphereAlpha;
vec3 sceneColor = texelFetch2D(colortex3,ivec2(tc/texelSize),0).rgb * VolumetricClouds.a + VolumetricClouds.rgb;
vec4 VolumetricFog = GetVolumetricFog(viewPos0, BN, directLightColor, indirectLightColor, indirectLightColor_dynamic, atmosphereAlpha, VolumetricClouds.rgb);
#endif
#if defined NETHER_SHADER || defined END_SHADER
vec4 VolumetricFog = GetVolumetricFog(viewPos0, noise_1, noise_2);
#endif
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a * atmosphereAlpha + VolumetricFog.rgb, VolumetricFog.a);
vec4 VolumetricFog = GetVolumetricFog(viewPos0, BN.x, BN.y);
#endif
gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0);
#if defined OVERWORLD_SHADER
VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a*VolumetricClouds.a);
// VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a*VolumetricClouds.a);
#endif
if (isEyeInWater == 1){
float estEyeDepth = clamp(eyeBrightnessSmooth.y/240.0,0.,1.0);
// estEyeDepth = pow(estEyeDepth,3.0) * 32.0;
estEyeDepth = 0.0;
// vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
vec3 vl = vec3(0.0);
waterVolumetrics(vl, vec3(0.0), viewPos0, estEyeDepth, estEyeDepth, length(viewPos0), noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor , dot(normalize(viewPos0), normalize(sunVec* lightCol.a ) ));
vec3 underWaterFog = waterVolumetrics(vec3(0.0), viewPos0, length(viewPos0), BN, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor , dot(normalize(viewPos0), normalize(sunVec* lightCol.a ) ));
gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.);
VolumetricFog = vec4(underWaterFog, 1.0);
}
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
gl_FragData[1] = vec4(VolumetricClouds.a,0.0,0.0,0.0);
#endif
gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0);
// vec4 currentFrame = VolumetricFog;
// vec4 previousFrame = texture2D(colortex10, gl_FragCoord.xy * texelSize);
// vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos0, z0 >= 1.0, VolumetricFog);
// gl_FragData[1] = temporallyFilteredVL;
}

View File

@ -10,10 +10,11 @@ flat varying vec3 averageSkyCol_Clouds;
flat varying float exposure;
#endif
#if defined Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
@ -49,6 +50,7 @@ void main() {
gl_Position = ftransform();
gl_Position.xy = (gl_Position.xy*0.5+0.5)*(0.01+VL_RENDER_RESOLUTION)*2.0-1.0;
#ifdef OVERWORLD_SHADER
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
@ -56,11 +58,11 @@ void main() {
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
#if defined Daily_Weather
dailyWeatherParams0 = vec4((texelFetch2D(colortex4,ivec2(1,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams1 = vec4((texelFetch2D(colortex4,ivec2(2,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams0 = vec4(texelFetch2D(colortex4,ivec2(1,1),0).rgb / 1500.0, 0.0);
dailyWeatherParams1 = vec4(texelFetch2D(colortex4,ivec2(2,1),0).rgb / 1500.0, 0.0);
dailyWeatherParams0.a = (texelFetch2D(colortex4,ivec2(3,1),0).x/150.0)/2.0;
dailyWeatherParams1.a = (texelFetch2D(colortex4,ivec2(3,1),0).y/150.0)/2.0;
dailyWeatherParams0.a = texelFetch2D(colortex4,ivec2(3,1),0).x/1500.0;
dailyWeatherParams1.a = texelFetch2D(colortex4,ivec2(3,1),0).y/1500.0;
#endif
#endif
@ -68,7 +70,7 @@ void main() {
#ifdef NETHER_SHADER
lightCol.rgb = vec3(0.0);
averageSkyCol = vec3(0.0);
averageSkyCol_Clouds = vec3(2.0, 1.0, 0.5) * 10.0;
averageSkyCol_Clouds = vec3(0.0);
#endif
#ifdef END_SHADER
@ -78,7 +80,7 @@ void main() {
#endif
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition) ;
refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);

View File

@ -13,6 +13,7 @@ uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
// const bool colortex4MipmapEnabled = true;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
@ -36,8 +37,9 @@ uniform sampler2D colortex15;
uniform vec2 texelSize;
uniform sampler2D colortex4;
uniform float viewHeight;
uniform float viewWidth;
uniform float nightVision;
uniform vec3 sunVec;
uniform float frameTimeCounter;
uniform int frameCounter;
@ -56,6 +58,8 @@ uniform mat4 gbufferPreviousProjection;
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
uniform int hideGUI;
uniform int dhRenderDistance;
uniform int isEyeInWater;
uniform ivec2 eyeBrightnessSmooth;
uniform ivec2 eyeBrightness;
@ -69,14 +73,12 @@ uniform float caveDetection;
#include "/lib/res_params.glsl"
#ifdef OVERWORLD_SHADER
#include "/lib/sky_gradient.glsl"
#include "/lib/lightning_stuff.glsl"
#include "/lib/climate_settings.glsl"
#define CLOUDS_INTERSECT_TERRAIN
// #define CLOUDSHADOWSONLY
// #include "/lib/volumetricClouds.glsl"
#endif
#include "/lib/sky_gradient.glsl"
uniform float eyeAltitude;
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
@ -93,28 +95,49 @@ vec3 toLinear(vec3 sRGB){
}
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
vec3 playerPos = p * 2. - 1.;
vec4 fragposition = iProjDiag * playerPos.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
#include "/lib/DistantHorizons_projections.glsl"
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
}
vec3 normVec (vec3 vec){
return vec*inversesqrt(dot(vec,vec));
}
float interleaved_gradientNoise_temporal(){
#ifdef TAA
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter);
#else
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887);
#endif
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float R2_dither(){
vec2 coord = gl_FragCoord.xy ;
#ifdef TAA
coord += (frameCounter%40000) * 2.0;
#endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
float blueNoise(){
#ifdef TAA
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
#else
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887);
#endif
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
}
vec3 normVec (vec3 vec){
return vec*inversesqrt(dot(vec,vec));
}
float DH_ld(float dist) {
return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
@ -216,7 +239,8 @@ void ApplyDistortion(inout vec2 Texcoord, vec2 TangentNormals, float lineardista
float refractionStrength = isTranslucentEntity ? 0.25 : 1.0 ;
// Texcoord = abs(Texcoord + (TangentNormals * clamp((ld(depths.x) - ld(depths.y)) * 0.5,0.0,0.15)) * RENDER_SCALE * refractionStrength );
Texcoord = abs(Texcoord + (TangentNormals * mix(0.01, 0.1, pow(clamp(1.0-lineardistance/(32*4),0.0,1.0),2))) * RENDER_SCALE * refractionStrength );
// Texcoord = abs(Texcoord + (TangentNormals * mix(0.01, 0.1, pow(clamp(1.0-lineardistance/(32*4),0.0,1.0),2))) * RENDER_SCALE * refractionStrength );
Texcoord = abs(Texcoord + TangentNormals * RENDER_SCALE * 0.1 );
float DistortedAlpha = decodeVec2(texture2D(colortex11,Texcoord).b).g;
// float DistortedAlpha = decodeVec2(texelFetch2D(colortex11,ivec2(Texcoord/texelSize),0).b).g;
@ -225,17 +249,201 @@ void ApplyDistortion(inout vec2 Texcoord, vec2 TangentNormals, float lineardista
Texcoord = mix(Texcoord, UnalteredTexcoord, min(max(0.1-DistortedAlpha,0.0) * 1000.0,1.0)); // remove distortion on non-translucents
}
uniform int dhRenderDistance;
uniform float eyeAltitude;
vec3 doRefractionEffect( inout vec2 texcoord, vec2 normal, float linearDistance){
// make the tangent space normals match the directions of the texcoord UV, this greatly improves the refraction effect.
vec2 UVNormal = vec2(normal.x,-normal.y);
float refractionMult = 0.3 / (1.0 + linearDistance);
float diffractionMult = 0.035;
float smudgeMult = 1.0;
// for diffraction, i wanted to know *when* normals were at an angle, not what the
float clampValue = 0.2;
vec2 abberationOffset = (clamp(UVNormal,-clampValue, clampValue)/clampValue) * diffractionMult;
// return vec3(abs(abberationOffset), 0.0);
#ifdef REFRACTION_SMUDGE
vec2 directionalSmudge = abberationOffset * (blueNoise()-0.5) * smudgeMult;
#else
vec2 directionalSmudge = vec2(0.0);
#endif
vec2 refractedUV = texcoord - (UVNormal + directionalSmudge)*refractionMult;
// a max bound around screen edges and edges of the refracted screen
vec2 vignetteSides = clamp(min((1.0 - refractedUV)/0.05, refractedUV/0.05)+0.5,0.0,1.0);
float vignette = vignetteSides.x*vignetteSides.y;
refractionMult *= decodeVec2(texelFetch2D(colortex11, ivec2(refractedUV/texelSize),0).b).g > 0.0 ? 1.0 : 0.0;
vec3 color = vec3(0.0);
#ifdef FAKE_DISPERSION_EFFECT
//// RED
refractedUV = clamp(texcoord - ((UVNormal + abberationOffset) + directionalSmudge)*refractionMult ,0.0,1.0);
color.r = texelFetch2D(colortex3, ivec2(refractedUV/texelSize),0).r;
//// GREEN
refractedUV = clamp(texcoord - (UVNormal + directionalSmudge)*refractionMult ,0,1);
color.g = texelFetch2D(colortex3, ivec2(refractedUV/texelSize),0).g;
//// BLUE
refractedUV = clamp(texcoord - ((UVNormal - abberationOffset) + directionalSmudge)*refractionMult ,0.0,1.0);
color.b = texelFetch2D(colortex3, ivec2(refractedUV/texelSize),0).b;
#else
refractedUV = clamp(texcoord - UVNormal,0.0,1.0);
color = texture2D(colortex3, refractedUV).rgb;
#endif
// texcoord = texcoord - (UVNormal+directionalSmudge)*refractionMult*vignette;
return color;
}
vec3 toClipSpace3Prev(vec3 viewSpacePosition) {
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth)
{
vec2 du = vec2(texelSize.x*2., 0.0);
vec2 dv = vec2(0.0, texelSize.y*2.);
vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x);
vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x);
vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x);
vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x);
vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x);
vec3 dmin = dmc;
dmin = dmin.z > dtr.z ? dtr : dmin;
dmin = dmin.z > dtl.z ? dtl : dmin;
dmin = dmin.z > dbl.z ? dbl : dmin;
dmin = dmin.z > dbr.z ? dbr : dmin;
#ifdef TAA_UPSCALING
dmin.xy = dmin.xy/RENDER_SCALE;
#endif
return dmin;
}
vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) {
#ifdef DISTANT_HORIZONS
mat4 projectionMatrix = depthCheck ? dhPreviousProjection : gbufferPreviousProjection;
return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
#else
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
#endif
}
vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) {
vec4 viewPos = vec4(0.0);
vec3 feetPlayerPos = vec3(0.0);
vec4 iProjDiag = vec4(0.0);
#ifdef DISTANT_HORIZONS
if (depthCheck) {
iProjDiag = vec4(dhProjectionInverse[0].x, dhProjectionInverse[1].y, dhProjectionInverse[2].zw);
feetPlayerPos = POS * 2.0 - 1.0;
viewPos = iProjDiag * feetPlayerPos.xyzz + dhProjectionInverse[3];
viewPos.xyz /= viewPos.w;
} else {
#endif
iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
feetPlayerPos = POS * 2.0 - 1.0;
viewPos = iProjDiag * feetPlayerPos.xyzz + gbufferProjectionInverse[3];
viewPos.xyz /= viewPos.w;
#ifdef DISTANT_HORIZONS
}
#endif
return viewPos.xyz;
}
vec3 tonemap(vec3 col){
return col/(1+luma(col));
}
vec3 invTonemap(vec3 col){
return col/(1-luma(col));
}
vec4 VLTemporalFiltering(vec3 viewPos, bool depthCheck, out float DEBUG){
vec2 texcoord = ((gl_FragCoord.xy)*2.0 + 0.5)*texelSize/2.0;
vec2 VLtexCoord = texcoord * VL_RENDER_RESOLUTION;
// vec3 closestToCamera = closestToCamera5taps(texcoord, depthtex0);
// vec3 viewPos_5tap = toScreenSpace(closestToCamera);
// get previous frames position stuff for UV
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz;
previousPosition = toClipSpace3Prev(previousPosition);
vec2 velocity = previousPosition.xy - texcoord/RENDER_SCALE;
previousPosition.xy = texcoord + velocity;
// vec4 currentFrame = texture2D_bicubic(colortex0, VLtexCoord);
vec4 currentFrame = texture2D(colortex0, VLtexCoord );
// vec4 currentFrame = texelFetch2D(colortex0, ivec2(VLtexCoord/texelSize),0);
if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return currentFrame;
vec4 col1 = texture2D(colortex0, VLtexCoord + vec2( texelSize.x, texelSize.y));
vec4 col2 = texture2D(colortex0, VLtexCoord + vec2( texelSize.x, -texelSize.y));
vec4 col3 = texture2D(colortex0, VLtexCoord + vec2(-texelSize.x, -texelSize.y));
vec4 col4 = texture2D(colortex0, VLtexCoord + vec2(-texelSize.x, texelSize.y));
vec4 col5 = texture2D(colortex0, VLtexCoord + vec2( 0.0, texelSize.y));
vec4 col6 = texture2D(colortex0, VLtexCoord + vec2( 0.0, -texelSize.y));
vec4 col7 = texture2D(colortex0, VLtexCoord + vec2(-texelSize.x, 0.0));
vec4 col8 = texture2D(colortex0, VLtexCoord + vec2( texelSize.x, 0.0));
vec4 colMax = max(currentFrame,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8))))))));
vec4 colMin = min(currentFrame,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8))))))));
// colMin = 0.5 * (colMin + min(currentFrame,min(col5,min(col6,min(col7,col8)))));
// colMax = 0.5 * (colMax + max(currentFrame,max(col5,max(col6,max(col7,col8)))));
// vec4 col0 = texture(colortex0, VLtexCoord + vec2( texelSize.x, 0.0));
// vec4 col1 = texture(colortex0, VLtexCoord + vec2( 0.0, texelSize.y));
// vec4 col2 = texture(colortex0, VLtexCoord + vec2(-texelSize.x, 0.0));
// vec4 col3 = texture(colortex0, VLtexCoord + vec2( 0.0, -texelSize.y));
// vec4 colMin = min(currentFrame, min(col0, min(col1, min(col2, col3))));
// vec4 colMax = max(currentFrame, max(col0, max(col1, max(col2, col3))));
vec4 frameHistory = texture2D(colortex10, previousPosition.xy);
vec4 clampedFrameHistory = clamp(frameHistory, colMin, colMax);
float blendingFactor = 0.1;
// if((min(max(clampedFrameHistory.a - frameHistory.a,0.0) / 0.0000001, 1.0)) > 0.0) blendingFactor = 1.0;
// if(abs(clampedFrameHistory.a-frameHistory.a) > 0.1 && abs(currentFrame.a-frameHistory.a) > 0.1) blendingFactor = 1.0;
// if(abs(currentFrame.a - frameHistory.a) > 0.6) blendingFactor = 1.0;
if(abs(clampedFrameHistory.a - frameHistory.a) > 0.1) blendingFactor = 1.0;
// blendingFactor = clamp(blendingFactor + abs(clampedFrameHistory.a - frameHistory.a),0.0,1.0);
// DEBUG = abs(clampedFrameHistory.a - frameHistory.a) > 0.1 ? 0. : 1.0;
// DEBUG = clamp(abs(clampedFrameHistory.a - frameHistory.a),0.0,1.0);
return clamp(mix(clampedFrameHistory, currentFrame, blendingFactor),0.0,65000.0);
}
void main() {
/* DRAWBUFFERS:73 */
/* RENDERTARGETS:7,3,10 */
////// --------------- SETUP STUFF --------------- //////
vec2 texcoord = gl_FragCoord.xy*texelSize;
float z = texture2D(depthtex0,texcoord).x;
float z2 = texture2D(depthtex1,texcoord).x;
float z = texture2D(depthtex0, texcoord).x;
float z2 = texture2D(depthtex1, texcoord).x;
float frDepth = ld(z);
float swappedDepth = z;
@ -258,19 +466,13 @@ void main() {
float DH_depth0 = 0.0;
#endif
vec3 fragpos = toScreenSpace_DH(texcoord/RENDER_SCALE-vec2(TAA_Offset)*texelSize*0.5, z, DH_depth0);
// vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(TAA_Offset)*texelSize*0.5,z));
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 np3 = normVec(p3);
float linearDistance = length(p3);
float linearDistance_cylinder = length(p3.xz);
// vec3 fragpos_NODH = toScreenSpace(texcoord/RENDER_SCALE-vec2(TAA_Offset)*texelSize*0.5, z);
// float linearDistance_NODH = length(p3);
vec3 viewPos = toScreenSpace_DH(texcoord/RENDER_SCALE, z, DH_depth0);
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 playerPos_normalized = normVec(playerPos);
vec3 playerPos222 = mat3(gbufferModelViewInverse) * toScreenSpace_DH(texcoord/RENDER_SCALE, 1.0,1.0) + gbufferModelViewInverse[3].xyz ;
float linearDistance = length(playerPos);
float linearDistance_cylinder = length(playerPos.xz);
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);
float lightleakfixfast = clamp(eyeBrightness.y/240.,0.0,1.0);
@ -280,7 +482,7 @@ void main() {
// bool isOpaque_entity = abs(opaqueMasks-0.45) < 0.01;
////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- //////
vec4 data = texture2D(colortex11,texcoord).rgba;
vec4 data = texelFetch2D(colortex11,ivec2(texcoord/texelSize),0).rgba;
vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)) ;
vec4 unpack1 = vec4(decodeVec2(data.b),0,0) ;
@ -288,7 +490,6 @@ void main() {
vec2 tangentNormals = unpack0.xy*2.0-1.0;
if(albedo.a < 0.01) tangentNormals = vec2(0.0);
vec4 TranslucentShader = texture2D(colortex2, texcoord);
////// --------------- UNPACK MISC --------------- //////
// 1.0 = water mask
@ -310,25 +511,36 @@ void main() {
#else
float cloudAlpha = 1.0;
#endif
float DEBUG = 0.0;
vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos, z >= 1.0,DEBUG);
gl_FragData[2] = temporallyFilteredVL;
// #ifdef DISTANT_HORIZONS
// vec4 vl = BilateralUpscale(colortex0, colortex14, colortex12, gl_FragCoord.xy - 1.5, sqrt(texture2D(colortex12,texcoord).a/65000.0), cloudAlpha);
// #else
// vec4 vl = BilateralUpscale(colortex0, colortex14, depthtex0, gl_FragCoord.xy - 1.5, frDepth,cloudAlpha);
// #endif
// vec4 temporallyFilteredVL = vl;
// vec4 temporallyFilteredVL = texture2D(colortex10, texcoord*VL_RENDER_RESOLUTION);
#ifdef DISTANT_HORIZONS
vec4 vl = BilateralUpscale(colortex0, colortex14, colortex12, gl_FragCoord.xy - 1.5, sqrt(texture2D(colortex12,texcoord).a/65000.0), cloudAlpha);
#else
vec4 vl = BilateralUpscale(colortex0, colortex14, depthtex0, gl_FragCoord.xy - 1.5, frDepth,cloudAlpha);
#endif
float bloomyFogMult = 1.0;
////// --------------- distort texcoords as a refraction effect
vec2 refractedCoord = texcoord;
#ifdef Refraction
ApplyDistortion(refractedCoord, tangentNormals, linearDistance, isEntity);
#endif
////// --------------- MAIN COLOR BUFFER
vec3 color = texture2D(colortex3, refractedCoord).rgb;
#ifdef FAKE_REFRACTION_EFFECT
// ApplyDistortion(refractedCoord, tangentNormals, linearDistance, isEntity);
// vec3 color = texture2D(colortex3, refractedCoord).rgb;
vec3 color = doRefractionEffect(refractedCoord, tangentNormals.xy, linearDistance);
#else
// vec3 color = texture2D(colortex3, refractedCoord).rgb;
vec3 color = texelFetch2D(colortex3, ivec2(refractedCoord/texelSize),0).rgb;
#endif
vec4 TranslucentShader = texture2D(colortex2, texcoord);
// color = vec3(texcoord-0.5,0.0) * mat3(gbufferModelViewInverse);
// apply block breaking effect.
if(albedo.a > 0.01 && !isWater && TranslucentShader.a <= 0.0 && !isEntity) color = mix(color*6.0, color, luma(albedo.rgb)) * albedo.rgb;
@ -342,7 +554,7 @@ void main() {
float fog = smoothstep(1.0, 0.0, min(max(1.0 - linearDistance_cylinder / far,0.0)*3.0,1.0) );
#endif
fog *= exp(-10.0 * pow(clamp(np3.y,0.0,1.0)*4.0,2.0));
fog *= exp(-10.0 * pow(clamp(playerPos_normalized.y,0.0,1.0)*4.0,2.0));
fog *= (1.0-caveDetection);
@ -351,7 +563,7 @@ void main() {
#ifdef SKY_GROUND
vec3 borderFogColor = skyGroundColor;
#else
vec3 borderFogColor = skyFromTex(np3, colortex4)/30.0;
vec3 borderFogColor = skyFromTex(playerPos_normalized, colortex4)/30.0;
#endif
color.rgb = mix(color.rgb, borderFogColor, fog);
@ -361,7 +573,7 @@ void main() {
if (TranslucentShader.a > 0.0){
#ifdef Glass_Tint
if(!isWater) color *= mix(normalize(albedo.rgb+0.0001)*0.9+0.1, vec3(1.0), max(fog, min(max(0.1-albedo.a,0.0) * 1000.0,1.0))) ;
if(!isWater) color *= mix(normalize(albedo.rgb+1e-7), vec3(1.0), max(fog, min(max(0.1-albedo.a,0.0) * 10.0,1.0))) ;
#endif
#ifdef BorderFog
@ -385,58 +597,50 @@ void main() {
#endif
cavefogCol *= 1.0-pow(1.0-pow(1.0 - max(1.0 - linearDistance/far,0.0),2.0),CaveFogFallOff);
cavefogCol *= exp(-7.0*clamp(normalize(np3).y*0.5+0.5,0.0,1.0)) * 0.999 + 0.001;
cavefogCol *= exp(-7.0*clamp(normalize(playerPos_normalized).y*0.5+0.5,0.0,1.0)) * 0.999 + 0.001;
float skyhole = pow(clamp(1.0-pow(max(np3.y - 0.6,0.0)*5.0,2.0),0.0,1.0),2);
cavefogCol *= 0.3;
float skyhole = pow(clamp(1.0-pow(max(playerPos_normalized.y - 0.6,0.0)*5.0,2.0),0.0,1.0),2);
color.rgb = mix(color.rgb + cavefogCol * caveDetection, cavefogCol, z >= 1.0 ? skyhole * caveDetection : 0.0);
}
#endif
#ifdef END_SHADER
// create a point that "glows" but in worldspace.
// this is not correct but whatever
float CenterdotV = dot(normalize(vec3(0.0,400.0,0.0) - cameraPosition), normalize(p3 + cameraPosition));
float distanceFadeOff = pow(min(max(length(cameraPosition)-300.0,0.0)/100.0,1.0),2.0);
color.rgb += vec3(0.1,0.5,1.0) * (exp2(-10.0 * max(-CenterdotV*0.5+0.5,0.0)) + exp(-150.0 * max(-CenterdotV*0.5+0.5,0.0))) * distanceFadeOff;
#endif
////// --------------- underwater fog
if (isEyeInWater == 1){
float dirtAmount = Dirt_Amount + 0.01;
float dirtAmount = Dirt_Amount;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 absorbColor = exp(-totEpsilon*linearDistance);
vec3 maxAbsorb = exp(-8.0 * totEpsilon);
vec3 absorption = exp(-2.0 * totEpsilon * linearDistance);
vec3 fixedAbsorption = exp(-30.0 * totEpsilon) ;
vec3 finalAbsorption = (absorption + fixedAbsorption * 5.0 * (1.0 + nightVision*10));
// vec3 finalAbsorption = absorption;
linearDistance = length(vec3(playerPos.x,max(-playerPos.y,0.0),playerPos.z));
// in vanilla, the water fog has a max distance of ~7 chunks
float fogfade = max(1.0 - linearDistance / min(far, 16.0*7.0), 0.0);
fogfade *= fogfade;
// fogfade = exp(-5.0* (1.0-fogfade));
color.rgb = mix(fixedAbsorption, color.rgb * finalAbsorption, fogfade);
// color.rgb = color.rgb * finalAbsorption;
#ifdef OVERWORLD_SHADER
linearDistance = length(vec3(p3.x,max(-p3.y,0.0),p3.z));
float fogfade = exp(-0.001*(linearDistance*linearDistance));
vec3 thresholdAbsorbedColor = mix(maxAbsorb, absorbColor, clamp(dot(absorbColor,vec3(0.33333)),0.0,1.0));
color.rgb = mix(vec3(1.0) * clamp(WsunVec.y,0,1) * pow(normalize(np3).y*0.3+0.7,1.5) * maxAbsorb, color.rgb * thresholdAbsorbedColor, clamp(fogfade,0.0,1.0));
#else
color.rgb *= absorbColor;
#endif
bloomyFogMult *= 0.4;
}
////// --------------- BLEND FOG INTO SCENE
//////////// apply VL fog over opaque and translucents
color *= vl.a*cloudAlpha ;
color += vl.rgb;
bloomyFogMult *= mix(vl.a,vl.a*0.5 + 0.5, rainStrength);
bloomyFogMult *= temporallyFilteredVL.a;
color *= temporallyFilteredVL.a;
color += temporallyFilteredVL.rgb;
////// --------------- VARIOUS FOG EFFECTS (in front of volumetric fog)
//////////// blindness, nightvision, liquid fogs and misc fogs
@ -449,12 +653,13 @@ void main() {
////// --------------- lava.
if (isEyeInWater == 2){
color.rgb = vec3(4.0,0.5,0.1);
color.rgb = mix(color.rgb, vec3(0.1,0.0,0.0), 1.0-exp(-10.0*clamp(linearDistance*0.5,0.,1.))*0.5 );
bloomyFogMult = 0.0;
}
///////// --------------- powdered snow
if (isEyeInWater == 3){
color.rgb = mix(color.rgb,vec3(10,15,20),clamp(linearDistance*0.5,0.,1.));
color.rgb = mix(color.rgb,vec3(0.5,0.75,1.0),clamp(linearDistance*0.5,0.,1.));
bloomyFogMult = 0.0;
}
@ -462,23 +667,30 @@ void main() {
color.rgb *= mix(1.0,clamp( exp(pow(linearDistance*(blindness*0.2),2) * -5),0.,1.) , blindness);
//////// --------------- darkness effect
color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor);
color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(viewPos)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor);
////// --------------- FINALIZE
#ifdef display_LUT
vec3 thingy = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb / 30;
if(luma(thingy) > 0.0){
color.rgb = thingy;
vl.a = 1.0;
}
// if(hideGUI == 0){
vec3 thingy = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy/150),0).rgb /1200.0;
if(luma(thingy) > 0.0){
color.rgb = thingy;
// // vl.a = 1.0;
}
// }
#if defined OVERWORLD_SHADER
if( hideGUI == 1) color.rgb = skyCloudsFromTex(playerPos_normalized, colortex4).rgb/1200.0;
#else
if( hideGUI == 1) color.rgb = volumetricsFromTex(playerPos_normalized, colortex4, 0.0).rgb/1200.0;
#endif
#endif
// if(texcoord.x > 0.5 )color.rgb = skyCloudsFromTex(np3, colortex4).rgb/30.0;
// color.rgb = vec3(DEBUG);
gl_FragData[0].r = bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[1].rgb = clamp(color.rgb, 0.0,68000.0);
// gl_FragData[1].rgb = vec3(tangentNormals.xy,0.0) ;
// gl_FragData[1].rgb = vec3(tangentNormals.xy,0.0) * 0.1 ;
// gl_FragData[1].rgb = vec3(1.0) * ld( (data.a > 0.0 ? data.a : texture2D(depthtex0, texcoord).x ) ) ;
// gl_FragData[1].rgb = gl_FragData[1].rgb * (1.0-TranslucentShader.a) + TranslucentShader.rgb*10.0;
// gl_FragData[1].rgb = 1-(texcoord.x > 0.5 ? vec3(TranslucentShader.a) : vec3(data.a));

View File

@ -37,7 +37,7 @@ void main() {
#ifdef OVERWORLD_SHADER
#ifdef BorderFog
skyGroundColor = texelFetch2D(colortex4,ivec2(1,37),0).rgb / 30.0 * Sky_Brightness;
skyGroundColor = texelFetch2D(colortex4,ivec2(1,37),0).rgb / 1200.0 * Sky_Brightness;
#endif
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
#endif

View File

@ -11,7 +11,7 @@ const int colortex6Format = R11F_G11F_B10F; // additionnal buffer for bloom (c
const int colortex7Format = RGBA8; // Final output, transparencies id (gbuffer->composite4)
const int colortex8Format = RGBA8; // Specular Texture
const int colortex9Format = RGBA8; // rain in alpha
const int colortex10Format = RGBA16; // resourcepack Skies
const int colortex10Format = RGBA16F; // resourcepack Skies
const int colortex11Format = RGBA16; // unchanged translucents albedo, alpha and tangent normals
const int colortex12Format = RGBA16F; // DISTANT HORIZONS + VANILLA MIXED DEPTHs
@ -31,7 +31,7 @@ const bool colortex6Clear = false;
const bool colortex7Clear = false;
const bool colortex8Clear = false;
const bool colortex9Clear = true;
const bool colortex10Clear = true;
const bool colortex10Clear = false;
const bool colortex11Clear = true;
const bool colortex12Clear = false;
const bool colortex13Clear = false;
@ -41,11 +41,11 @@ const bool colortex15Clear = false;
#ifdef SCREENSHOT_MODE
/*
const int colortex5Format = RGBA32F;// TAA buffer (everything)
const int colortex5Format = RGBA32F; //TAA buffer (everything)
*/
#else
/*
const int colortex5Format = R11F_G11F_B10F; // TAA buffer (everything)
const int colortex5Format = RGBA16F; //TAA buffer (everything)
*/
#endif
@ -67,6 +67,7 @@ uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform float viewHeight;
uniform float viewWidth;
uniform vec3 previousCameraPosition;
uniform mat4 gbufferPreviousModelView;
@ -213,6 +214,24 @@ vec4 smoothfilter(in sampler2D tex, in vec2 uv)
return texture2D(tex, uv);
}
vec2 smoothfilterUV(in vec2 uv)
{
vec2 textureResolution = vec2(viewWidth,viewHeight);
uv = uv*textureResolution + 0.5;
vec2 iuv = floor( uv );
vec2 fuv = fract( uv );
#ifndef SMOOTHESTSTEP_INTERPOLATION
uv = iuv + (fuv*fuv)*(3.0-2.0*fuv);
#endif
#ifdef SMOOTHESTSTEP_INTERPOLATION
uv = iuv + fuv*fuv*fuv*(fuv*(fuv*6.0-15.0)+10.0);
#endif
uv = (uv - 0.5)/textureResolution;
return uv;
}
//approximation from SMAA presentation from siggraph 2016
vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float sharpenAmount)
{
@ -231,15 +250,14 @@ vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float shar
vec2 w12 = w1 + w2;
vec2 tc12 = rtMetrics.xy * (centerPosition + w2 / w12);
vec3 centerColor = texture2D(colorTex, vec2(tc12.x, tc12.y)).rgb;
vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0);
vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0);
vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) +
vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) +
vec4(texture2D(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) +
vec4(centerColor, 1.0) * (w12.x * w12.y) +
vec4(texture2D(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) +
vec4(texture2D(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y );
return color.rgb/color.a;
}
@ -314,6 +332,24 @@ vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth,
return dmin;
}
vec3 RGB2YCoCg(vec3 RGB)
{
vec3 o;
o.x = 0.25*RGB.r + 0.5*RGB.g + 0.25*RGB.b;
o.y = 0.5*RGB.r - 0.5*RGB.b;
o.z = -0.25*RGB.r + 0.5*RGB.g - 0.25*RGB.b;
return o;
}
vec3 YCoCg2RGB(vec3 YCoCg)
{
vec3 o;
o.r = YCoCg.x + YCoCg.y - YCoCg.z;
o.g = YCoCg.x + YCoCg.z;
o.b = YCoCg.x - YCoCg.y - YCoCg.z;
return o;
}
vec4 computeTAA(vec2 texcoord, bool hand){
vec2 jitter = offsets[framemod8]*texelSize*0.5;
@ -340,9 +376,9 @@ vec4 computeTAA(vec2 texcoord, bool hand){
vec2 velocity = previousPosition.xy - closestToCamera.xy;
previousPosition.xy = texcoord + velocity;
// sample current frame, and make sure it is de-jittered
vec3 currentFrame = smoothfilter(colortex3, adjTC + jitter).rgb;
// vec3 currentFrame = smoothfilter(colortex3, adjTC + jitter).rgb;
vec3 currentFrame = texelFetch2D(colortex3, ivec2((adjTC + jitter)/texelSize), 0).rgb;
//reject history if off-screen and early exit
if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return vec4(currentFrame, 1.0);
@ -366,14 +402,13 @@ vec4 computeTAA(vec2 texcoord, bool hand){
vec3 colMax = max(col0,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8))))))));
vec3 colMin = min(col0,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8))))))));
vec3 colMax5 = max(col0,max(col5,max(col6,max(col7,col8))));
vec3 colMin5 = min(col0,min(col5,min(col6,min(col7,col8))));
colMin = 0.5 * (colMin + min(col0,min(col5,min(col6,min(col7,col8)))));
colMax = 0.5 * (colMax + max(col0,max(col5,max(col6,max(col7,col8)))));
colMin = 0.5 * (colMin + colMin5);
colMax = 0.5 * (colMax + colMax5);
#endif
#ifdef DAMAGE_TAKEN_EFFECT
// when this triggers, use current frame UV to sample history, for a funny trailing effect.
////// when this triggers, use current frame UV to sample history, for a funny trailing effect.
if(CriticalDamageTaken > 0.01) previousPosition.xy = texcoord;
#endif
@ -383,14 +418,17 @@ vec4 computeTAA(vec2 texcoord, bool hand){
float blendingFactor = BLEND_FACTOR;
if(hand) blendingFactor = clamp(length(velocity/texelSize),blendingFactor,1.0);
//Increases blending factor when far from AABB, reduces ghosting
blendingFactor = min(blendingFactor + luma(min(max(clampedframeHistory - frameHistory,0.0) / frameHistory, 1.0)),1.0);
////// Increases blending factor when far from AABB, reduces ghosting
// blendingFactor = min(blendingFactor + luma(min(max(clampedframeHistory-frameHistory,0.0) / frameHistory, 1.0)),1.0);
// blendingFactor = min(blendingFactor + luma(abs(clampedframeHistory - frameHistory)/clampedframeHistory) ,1.0);
// Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering
// if(luma(abs(clampedframeHistory - frameHistory)) > 0.01) blendingFactor = 1.0;
////// Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering
vec3 finalResult = invTonemap(mix(tonemap(clampedframeHistory), tonemap(currentFrame), blendingFactor));
#ifdef DAMAGE_TAKEN_EFFECT
// when this triggers, do a funny trailing effect.
////// when this triggers, do a funny trailing effect.
if(CriticalDamageTaken > 0.01) finalResult = mix(finalResult, frameHistory, sqrt(CriticalDamageTaken)*0.8);
#endif
#ifdef SCREENSHOT_MODE
@ -418,14 +456,10 @@ void main() {
// vec4 color = TAA_hq(hand);
vec4 color = computeTAA(texcoord, hand);
vec4 color = computeTAA(smoothfilterUV(texcoord), hand);
// gl_FragData[0] = clamp(color, 0.0, 65000.0);
#if DEBUG_VIEW == debug_TEMPORAL_REPROJECTION
color.rgb = texture2D(colortex3, taauTC).rgb;
#endif
#ifdef SCREENSHOT_MODE
gl_FragData[0] = clamp(color, 0.0, 65000.0);
#else

View File

@ -64,11 +64,18 @@ vec3 toShadowSpaceProjected(vec3 p3){
return p3;
}
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y) + 1.0/1.6180339887 * frameCounter);
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+frameCounter/1.6180339887);
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
@ -123,6 +130,7 @@ float invLinZ (float lindepth){
}
#ifdef OVERWORLD_SHADER
uniform sampler2D colortex4;
// uniform sampler2D colortex12;
// const bool shadowHardwareFiltering = true;
uniform sampler2DShadow shadow;
@ -135,11 +143,27 @@ float invLinZ (float lindepth){
uniform sampler2DShadow shadowtex1;
#endif
#define TEST
// #define TEST
#define TIMEOFDAYFOG
#include "/lib/lightning_stuff.glsl"
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#else
vec4 dailyWeatherParams0 = vec4(CloudLayer0_coverage, CloudLayer1_coverage, CloudLayer2_coverage, 0.0);
vec4 dailyWeatherParams1 = vec4(CloudLayer0_density, CloudLayer1_density, CloudLayer2_density, 0.0);
#endif
flat varying vec4 CurrentFrame_dailyWeatherParams0;
flat varying vec4 CurrentFrame_dailyWeatherParams1;
#define VL_CLOUDS_DEFERRED
#include "/lib/volumetricClouds.glsl"
#include "/lib/climate_settings.glsl"
#include "/lib/overworld_fog.glsl"
#endif
@ -165,23 +189,16 @@ vec2 R2_samples(float n){
return fract(alpha * n);
}
uniform float dayChangeSmooth;
uniform bool worldTimeChangeCheck;
void main() {
/* DRAWBUFFERS:4 */
gl_FragData[0] = vec4(0.0);
float mixhistory = 0.06;
float accumuteSpeed = texelFetch2D(colortex4, ivec2(5,5), 0).r/150.0;
vec2 pixelPos6 = vec2(5,5);
if (gl_FragCoord.x > pixelPos6.x && gl_FragCoord.x < pixelPos6.x + 1 && gl_FragCoord.y > pixelPos6.y && gl_FragCoord.y < pixelPos6.y + 1){
mixhistory = 0.1;
gl_FragData[0] = vec4(1,0,0,1);
}
#ifdef OVERWORLD_SHADER
@ -194,12 +211,12 @@ if (gl_FragCoord.x > pixelPos6.x && gl_FragCoord.x < pixelPos6.x + 1 && gl_FragC
#ifdef Daily_Weather
ivec2 pixelPos = ivec2(0,0);
if (gl_FragCoord.x > 1 && gl_FragCoord.x < 4 && gl_FragCoord.y > 1 && gl_FragCoord.y < 2){
mixhistory = clamp(dayChangeSmooth*dayChangeSmooth*dayChangeSmooth*0.1, frameTime*0.1, 1.0);
mixhistory = 0.005;
if(gl_FragCoord.x < 2) gl_FragData[0] = vec4(dailyWeatherParams0.rgb * 2.0,1.0);
if(gl_FragCoord.x > 2) gl_FragData[0] = vec4(dailyWeatherParams1.rgb * 2.0,1.0);
if(gl_FragCoord.x > 3) gl_FragData[0] = vec4(dailyWeatherParams0.a * 2.0, dailyWeatherParams1.a * 2.0, 0.0, 1.0);
if(gl_FragCoord.x < 2) gl_FragData[0] = vec4(CurrentFrame_dailyWeatherParams0.rgb * 10.0,1.0);
if(gl_FragCoord.x > 2) gl_FragData[0] = vec4(CurrentFrame_dailyWeatherParams1.rgb * 10.0,1.0);
if(gl_FragCoord.x > 3) gl_FragData[0] = vec4(CurrentFrame_dailyWeatherParams0.a * 10.0, CurrentFrame_dailyWeatherParams1.a * 10.0, 0.0, 1.0);
}
#endif
@ -267,7 +284,9 @@ if (gl_FragCoord.x > 18. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257){
sky *= vec3(0.0, 0.18, 0.35);
#endif
gl_FragData[0] = vec4(sky / 4000.0, 1.0);
gl_FragData[0] = vec4(sky / 4000.0 , 1.0);
if(worldTimeChangeCheck) mixhistory = 1.0;
}
/// --- Sky + clouds + fog
@ -275,27 +294,31 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+
vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0);
vec3 viewVector = cartToSphere(p);
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition) ;// * ( float(sunElevation > 1e-5)*2.0-1.0 );
vec3 viewPos = mat3(gbufferModelView)*viewVector*1024.0;
float noise = interleaved_gradientNoise_temporal();
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition + gbufferModelViewInverse[3].xyz) ;// * ( float(sunElevation > 1e-5)*2.0-1.0 );
vec3 sky = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy)-ivec2(257,0),0).rgb/150.0;
sky = mix(dot(sky, vec3(0.333)) * vec3(0.5), sky, pow(clamp(viewVector.y+1.0,0.0,1.0),5));
sky = mix(averageSkyCol_Clouds * AmbientLightTint * 0.25, sky, pow(clamp(viewVector.y+1.0,0.0,1.0),5.0));
vec3 suncol = lightSourceColor;
#ifdef ambientLight_only
suncol = vec3(0.0);
#endif
vec3 cloudDepth = vec3(0.0);
vec4 clouds = renderClouds(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*2.0, skyGroundCol/30.0, cloudDepth);
float atmosphereAlpha = 1.0;
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*2.0, skyGroundCol/30.0, averageSkyCol_Clouds*5.0, atmosphereAlpha);
float rejection = 1.0;
vec4 volumetricClouds = GetVolumetricClouds(viewPos, vec2(noise, 1.0-noise), WsunVec, suncol*2.5, skyGroundCol/30.0);
sky = sky*clouds.a + clouds.rgb / 5.0;
sky *= atmosphereAlpha;
sky = sky * VL_Fog.a + VL_Fog.rgb / 5.0;
float atmosphereAlpha = 1.0;
vec4 volumetricFog = GetVolumetricFog(viewPos, vec2(noise, 1.0-noise), suncol*2.5, skyGroundCol/30.0, averageSkyCol_Clouds*5.0, atmosphereAlpha, volumetricClouds.rgb);
sky = sky * volumetricClouds.a + volumetricClouds.rgb / 5.0;
sky = sky * volumetricFog.a + volumetricFog.rgb / 5.0;
gl_FragData[0] = vec4(sky,1.0);
if(worldTimeChangeCheck) mixhistory = 1.0;
}
#endif
@ -306,14 +329,15 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+
if (gl_FragCoord.x > (fogPos.x - fogPos.x*0.22) && gl_FragCoord.y > 0.4 && gl_FragCoord.x < 535){
vec2 p = clamp(floor(gl_FragCoord.xy-fogPos)/256.+tempOffsets/256.,-0.2,1.2);
vec3 viewVector = cartToSphere(p);
float noise = interleaved_gradientNoise_temporal();
vec3 BackgroundColor = vec3(0.0);
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*256., fract(frameCounter/1.6180339887), fract(frameCounter/2.6180339887));
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*256., noise, 1.0-noise);
BackgroundColor += VL_Fog.rgb/5.0;
BackgroundColor += VL_Fog.rgb;
gl_FragData[0] = vec4(BackgroundColor, 1.0);
gl_FragData[0] = vec4(BackgroundColor*8.0, 1.0);
}
#endif
@ -371,12 +395,11 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+
//Temporally accumulate sky and light values
vec3 temp = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb;
vec3 curr = gl_FragData[0].rgb*150.;
vec3 frameHistory = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb;
vec3 currentFrame = gl_FragData[0].rgb*150.;
if(accumuteSpeed < 1.0) mixhistory = 1.0;
gl_FragData[0].rgb = clamp(mix(temp, curr, mixhistory),0.0,65000.);
gl_FragData[0].rgb = clamp(mix(frameHistory, currentFrame, mixhistory),0.0,65000.);
//Exposure values
if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )

View File

@ -23,8 +23,13 @@ flat varying float rodExposure;
flat varying float avgL2;
flat varying float centerDepth;
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
uniform int hideGUI;
flat varying vec4 CurrentFrame_dailyWeatherParams0;
flat varying vec4 CurrentFrame_dailyWeatherParams1;
uniform sampler2D colortex4;
uniform sampler2D colortex6;
@ -146,10 +151,13 @@ void main() {
}
// maximum control of color and luminance
vec3 minimumlight = vec3(0.5,0.75,1.0) * (min(MIN_LIGHT_AMOUNT,0.0025) + nightVision);
// vec3 minimumlight = vec3(0.5,0.75,1.0) * nightVision;
averageSkyCol_Clouds = max( normalize(averageSkyCol_Clouds) * min(luma(averageSkyCol_Clouds) * 3.0,2.5) * (1.0-rainStrength*0.7), minimumlight);
averageSkyCol = max(averageSkyCol * PLANET_GROUND_BRIGHTNESS, minimumlight);
// averageSkyCol_Clouds = max( normalize(averageSkyCol_Clouds) * min(luma(averageSkyCol_Clouds) * 3.0,2.5) * (1.0-rainStrength*0.7), minimumlight);
vec3 minimumlight = vec3(0.02) * 0.2 * MIN_LIGHT_AMOUNT + nightVision * 0.05;
averageSkyCol_Clouds = max(normalize(averageSkyCol_Clouds + 1e-6) * min(luma(averageSkyCol_Clouds) * 3.0,2.5),0.0);
averageSkyCol = max(averageSkyCol * PLANET_GROUND_BRIGHTNESS,0.0) + max(minimumlight, 0.02 * 0.2);
////////////////////////////////////////
/// --- SUNLIGHT/MOONLIGHT STUFF --- ///
@ -165,7 +173,8 @@ void main() {
sunColor = sunColorBase/4000.0 * skyAbsorb;
moonColor = moonColorBase/4000.0;
lightSourceColor = (sunVis >= 1e-5 ? sunColor * sunVis : moonColor * moonVis) ;
// lightSourceColor = sunVis >= 1e-5 ? sunColor * sunVis : moonColor * moonVis;
lightSourceColor = sunColor * sunVis + moonColor * moonVis;
#endif
@ -213,8 +222,39 @@ void main() {
vec4(DAY9_l0_density, DAY9_l1_density, DAY9_l2_density, DAY9_cfog_density)
);
dailyWeatherParams0 = weatherParameters_A[dayCounter];
dailyWeatherParams1 = weatherParameters_B[dayCounter];
CurrentFrame_dailyWeatherParams0 = weatherParameters_A[dayCounter];
CurrentFrame_dailyWeatherParams1 = weatherParameters_B[dayCounter];
vec4 rainyWeatherParameters_A[3] = vec4[](
// vec4(DAY0_l0_coverage, DAY0_l1_coverage, DAY0_l2_coverage, DAY0_ufog_density),
vec4(1.3,0.0,0.0,0.0),
vec4(0.5,0.0,0.0,0.0),
vec4(0.0,0.0,0.0,0.0)
);
vec4 rainyWeatherParameters_B[3] = vec4[](
// vec4(DAY7_l0_density, DAY7_l1_density, DAY7_l2_density, DAY7_cfog_density),
vec4(0.1,0.0,0.0,0.0),
vec4(0.1,0.0,0.0,0.0),
vec4(0.0,0.0,0.0,0.0)
);
// if(hideGUI == 1){
// CurrentFrame_dailyWeatherParams0 = rainyWeatherParameters_A[worldDay%2];
// CurrentFrame_dailyWeatherParams1 = rainyWeatherParameters_B[worldDay%2];
// } else {
// CurrentFrame_dailyWeatherParams0 = vec4(0.5,0.0,0.0,0.0);
// CurrentFrame_dailyWeatherParams1 = vec4(0.1,0.5,0.0,0.0);
// }
#if defined Daily_Weather
dailyWeatherParams0 = vec4(sqrt(texelFetch2D(colortex4,ivec2(1,1),0).rgb/ 1500.0), 0.0);
dailyWeatherParams1 = vec4(texelFetch2D(colortex4,ivec2(2,1),0).rgb / 1500.0, 0.0);
dailyWeatherParams0.a = texelFetch2D(colortex4,ivec2(3,1),0).x/1500.0;
dailyWeatherParams1.a = texelFetch2D(colortex4,ivec2(3,1),0).y/1500.0;
#endif
#endif
@ -235,7 +275,7 @@ void main() {
vec2 ij = R2_samples((frameCounter%2000)*maxITexp+i);
vec2 tc = 0.5 + (ij-0.5) * 0.7;
vec3 sp = texture2D(colortex6, tc/16. * resScale+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb;
avgExp += log(luma(sp));
avgExp += log(sqrt(luma(sp)));
avgB += log(min(dot(sp,vec3(0.07,0.22,0.71)),8e-2));
}
@ -247,13 +287,16 @@ void main() {
float L = max(avgBrightness,1e-8);
float keyVal = 1.03-2.0/(log(L*4000/150.*8./3.0+1.0)/log(10.0)+2.0);
float expFunc = 0.5+0.5*tanh(log(L));
float targetExposure = 0.18/log2(L*2.5+1.045)*0.62;
float targetExposure = 1.0/log(L+1.05);
// float targetExposure = 0.35/log(L+1.05);
// float targetExposure = 0.18/log2(L*2.5+1.045)*0.62;
avgL2 = clamp(mix(avgB,texelFetch2D(colortex4,ivec2(10,37),0).b,0.985),0.00003051757,65000.0);
float targetrodExposure = max(0.012/log2(avgL2+1.002)-0.1,0.0)*1.2;
exposure = max(targetExposure*EXPOSURE_MULTIPLIER, 0.0);
exposure = max(targetExposure, 0.0);
// exposure = mix(0.0, 1.0, min(targetExposure,1.0));
// exposure = 1;

View File

@ -100,6 +100,17 @@ uniform int dhRenderDistance;
#define CLOUDS_INTERSECT_TERRAIN
uniform float eyeAltitude;
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#else
vec4 dailyWeatherParams0 = vec4(CloudLayer0_coverage, CloudLayer1_coverage, CloudLayer2_coverage, 0.0);
vec4 dailyWeatherParams1 = vec4(CloudLayer0_density, CloudLayer1_density, CloudLayer2_density, 0.0);
#endif
#include "/lib/volumetricClouds.glsl"
@ -116,7 +127,6 @@ uniform float eyeAltitude;
void main() {
/* DRAWBUFFERS:0 */

View File

@ -1,10 +1,12 @@
#include "/lib/settings.glsl"
// uniform int dhRenderDistance;
#if defined Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
flat varying vec3 averageSkyCol;
flat varying vec3 sunColor;
@ -32,8 +34,8 @@ void main() {
gl_Position.xy = (gl_Position.xy*0.5+0.5)*clamp(CLOUDS_QUALITY+0.01,0.0,1.0)*2.0-1.0;
#if defined Daily_Weather
dailyWeatherParams0 = vec4((texelFetch2D(colortex4,ivec2(1,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams1 = vec4((texelFetch2D(colortex4,ivec2(2,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams0 = vec4(texelFetch2D(colortex4,ivec2(1,1),0).rgb / 1500.0, 0.0);
dailyWeatherParams1 = vec4(texelFetch2D(colortex4,ivec2(2,1),0).rgb / 1500.0, 0.0);
#endif
averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb;

View File

@ -1,14 +1,18 @@
#include "/lib/settings.glsl"
uniform sampler2D colortex7;
uniform sampler2D colortex5;
uniform sampler2D colortex6;
uniform sampler2D colortex14;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D depthtex2;
uniform sampler2D noisetex;
varying vec2 texcoord;
uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform float viewHeight;
uniform float viewWidth;
uniform float aspectRatio;
@ -19,12 +23,19 @@ uniform int hideGUI;
#include "/lib/color_dither.glsl"
#include "/lib/res_params.glsl"
uniform float near;
uniform float far;
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
#include "/lib/gameplay_effects.glsl"
@ -53,14 +64,20 @@ uniform mat4 gbufferPreviousModelView;
#include "/lib/util.glsl"
#include "/lib/projections.glsl"
vec3 tonemap(vec3 col){
return col/(1+luma(col));
}
vec3 invTonemap(vec3 col){
return col/(1-luma(col));
}
vec3 doMotionBlur(vec2 texcoord, float depth, float noise){
vec3 doMotionBlur(vec2 texcoord, float depth, float noise, bool hand){
float samples = 4.0;
vec3 color = vec3(0.0);
float blurMult = 1.0;
if(depth < 0.56) blurMult = 0.0;
if(hand) blurMult = 0.0;
vec3 viewPos = toScreenSpace(vec3(texcoord, depth));
viewPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
@ -71,8 +88,9 @@ vec3 doMotionBlur(vec2 texcoord, float depth, float noise){
vec2 velocity = texcoord - previousPosition.xy;
// thank you Capt Tatsu for letting me use these
velocity = (velocity / (1.0 + length(velocity))) * 0.05 * blurMult * MOTION_BLUR_STRENGTH;
velocity = (velocity / (1.0 + length(velocity)) ) * 0.05 * blurMult * MOTION_BLUR_STRENGTH;
texcoord = texcoord - velocity*(samples*0.5 + noise);
vec2 screenEdges = 2.0/vec2(viewWidth, viewHeight);
for (int i = 0; i < int(samples); i++) {
@ -81,23 +99,53 @@ vec3 doMotionBlur(vec2 texcoord, float depth, float noise){
color += texture2D(colortex7, clamp(texcoord, screenEdges, 1.0-screenEdges)).rgb;
}
// return vec3(texcoord,0.0);
return color / samples;
}
float convertHandDepth_2(in float depth, bool hand) {
if(!hand) return depth;
float ndcDepth = depth * 2.0 - 1.0;
ndcDepth /= MC_HAND_DEPTH;
return ndcDepth * 0.5 + 0.5;
}
uniform sampler2D shadowcolor1;
float doVignette( in vec2 texcoord, in float noise){
float vignette = 1.0-clamp(1.0-length(texcoord-0.5),0.0,1.0);
// vignette = pow(1.0-pow(1.0-vignette,3),5);
vignette *= vignette*vignette;
vignette = 1.0-vignette;
vignette *= vignette*vignette*vignette*vignette;
// stop banding
vignette = vignette + vignette*(noise-0.5)*0.01;
return mix(1.0, vignette, VIGNETTE_STRENGTH);
}
void main() {
float depth = texture2D(depthtex0,texcoord*RENDER_SCALE).r;
float noise = interleaved_gradientNoise();
float noise = blueNoise();
#ifdef MOTION_BLUR
vec3 COLOR = doMotionBlur(texcoord, depth, noise);
float depth = texture2D(depthtex0, texcoord*RENDER_SCALE).r;
bool hand = depth < 0.56;
float depth2 = convertHandDepth_2(depth, hand);
vec3 COLOR = doMotionBlur(texcoord, depth2, noise, hand);
#else
vec3 COLOR = texture2D(colortex7,texcoord).rgb;
#endif
#ifdef VIGNETTE
COLOR *= doVignette(texcoord, noise);
#endif
#if defined LOW_HEALTH_EFFECT || defined DAMAGE_TAKEN_EFFECT || defined WATER_ON_CAMERA_EFFECT
// for making the fun, more fun
applyGameplayEffects(COLOR, texcoord, noise);
@ -108,10 +156,19 @@ void main() {
#endif
#if DEBUG_VIEW == debug_SHADOWMAP
vec2 shadowUV = texcoord * vec2(2.0, 1.0) ;
vec2 shadowUV = texcoord * vec2(2.0, 1.0);
// shadowUV -= vec2(0.5,0.0);
// float zoom = 0.1;
// shadowUV = ((shadowUV-0.5) - (shadowUV-0.5)*zoom) + 0.5;
if(shadowUV.x < 1.0 && shadowUV.y < 1.0 && hideGUI == 1)COLOR = texture2D(shadowcolor1,shadowUV).rgb;
if(shadowUV.x < 1.0 && shadowUV.y < 1.0 && hideGUI == 1) COLOR = texture2D(shadowcolor1,shadowUV).rgb;
#endif
#if DEBUG_VIEW == debug_DEPTHTEX0
COLOR = vec3(ld(texture2D(depthtex0, texcoord*RENDER_SCALE).r));
#endif
#if DEBUG_VIEW == debug_DEPTHTEX1
COLOR = vec3(ld(texture2D(depthtex1, texcoord*RENDER_SCALE).r));
#endif

View File

@ -2,9 +2,7 @@
// #if defined END_SHADER || defined NETHER_SHADER
#undef IS_LPV_ENABLED
// #endif
#ifndef OVERWORLD_SHADER
uniform float nightVision;
#endif
flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
@ -90,14 +88,33 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
flat varying vec3 refractedSunVec;
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#else
vec4 dailyWeatherParams0 = vec4(CloudLayer0_coverage, CloudLayer1_coverage, CloudLayer2_coverage, 0.0);
vec4 dailyWeatherParams1 = vec4(CloudLayer0_density, CloudLayer1_density, CloudLayer2_density, 0.0);
#endif
#define TIMEOFDAYFOG
#include "/lib/lightning_stuff.glsl"
#define CLOUDS_INTERSECT_TERRAIN
// #define CLOUDSHADOWSONLY
#include "/lib/volumetricClouds.glsl"
#include "/lib/climate_settings.glsl"
#include "/lib/overworld_fog.glsl"
// float fogPhase(float lightPoint){
// float linear = 1.0 - clamp(lightPoint*0.5+0.5,0.0,1.0);
// float linear2 = 1.0 - clamp(lightPoint,0.0,1.0);
// float exponential = exp2(pow(linear,0.3) * -15.0 ) * 1.5;
// exponential += sqrt(exp2(sqrt(linear) * -12.5));
// return exponential;
// }
#endif
#ifdef NETHER_SHADER
uniform sampler2D colortex4;
@ -190,7 +207,7 @@ float fogPhase2(float lightPoint){
return exponential;
}
vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL, float lightleakFix){
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
@ -207,8 +224,12 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos - gbufferModelViewInverse[3].xyz);
// vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
vec3 newabsorbance = exp(-rayLength * waterCoefs); // No need to take the integrated value
// vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
#ifdef OVERWORLD_SHADER
float phase = fogPhase(VdotL) * 5.0;
#else
@ -218,13 +239,14 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float
vec3 vL = vec3(0.0);
ambient = max(ambient * (normalize(wpos).y*0.3+0.7),0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 progressW = start.xyz+cameraPosition+dVWorld;
// progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
vec3 progressW = gbufferModelViewInverse[3].xyz + cameraPosition + d*dVWorld;
vec3 sh = vec3(1.0);
#ifdef OVERWORLD_SHADER
@ -255,24 +277,67 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float
}
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
sh *= GetCloudShadow(progressW, WsunVec);
#endif
#endif
vec3 sunMul = exp(-estSunDepth * d * waterCoefs * 1.1);
vec3 ambientMul = exp(-estEndDepth * d * waterCoefs );
vec3 sunAbsorbance = exp(-waterCoefs * estSunDepth * d);
vec3 ambientAbsorbance = exp(-waterCoefs * estEndDepth * d);
vec3 Directlight = ((lightSource * sh) * phase * sunMul) ;
vec3 Indirectlight = max(ambient * ambientMul, vec3(0.01,0.2,0.4) * ambientMul * MIN_LIGHT_AMOUNT * 0.03) ;
vec3 Directlight = lightSource * sh * phase * sunAbsorbance;
vec3 Indirectlight = ambient * ambientAbsorbance;
vec3 light = (Indirectlight + Directlight) * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-waterCoefs * dd * rayLength);
vec3 volumeCoeff = exp(-waterCoefs * dd * rayLength);
vL += (light - light * volumeCoeff) / waterCoefs * absorbance;
absorbance *= volumeCoeff;
}
// inColor += vL;
return vec4( vL, dot(newabsorbance,vec3(0.335)));
return vec4(vL, dot(absorbance,vec3(0.335)));
}
/*
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,32.0)/(1e-8+rayLength);
dV *= maxZ;
vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
rayLength *= maxZ;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float phase = phaseg(VdotL, Dirt_Mie_Phase);
float expFactor = 11.0;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
//project into biased shadowmap space
float distortFactor = calcDistort(spPos.xy);
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
vec3 ambientMul = exp(-estEndDepth * d * waterCoefs * 1.1);
vec3 sunMul = exp(-estSunDepth * d * waterCoefs);
vec3 light = (sh * lightSource*8./150./3.0 * phase * sunMul + ambientMul * ambient)*scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs *absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
*/
vec2 decodeVec2(float a){
const vec2 constant1 = 65535. / vec2( 256., 65536.);
const float constant2 = 256. / 255.;
@ -293,13 +358,16 @@ void main() {
vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize;
bool iswater = texture2D(colortex7,tc).a > 0.99;
float alpha = texture2D(colortex7,tc).a ;
float blendedAlpha = texture2D(colortex2, tc).a;
bool iswater = alpha > 0.99;
//////////////////////////////////////////////////////////
///////////////// BEHIND OF TRANSLUCENTS /////////////////
//////////////////////////////////////////////////////////
if(texture2D(colortex2, tc).a > 0.0 || iswater){
if(blendedAlpha > 0.0 || iswater){
float noise_1 = R2_dither();
float noise_2 = blueNoise();
@ -322,78 +390,106 @@ void main() {
// vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
float dirtAmount = Dirt_Amount + 0.1;
float dirtAmount = Dirt_Amount ;
// float dirtAmount = Dirt_Amount + 0.01;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 totEpsilon = dirtEpsilon * dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
#ifdef BIOME_TINT_WATER
// yoink the biome tint written in this buffer for water only.
if(iswater){
vec2 translucentdata = texture2D(colortex11,tc).gb;
vec2 translucentdata = texelFetch2D(colortex11,ivec2(tc/texelSize),0).gb;
vec3 wateralbedo = normalize(vec3(decodeVec2(translucentdata.x),decodeVec2(translucentdata.y).x)+0.00001) * 0.5 + 0.5;
scatterCoef = dirtAmount * wateralbedo / 3.14;
}
#endif
vec3 directLightColor = lightCol.rgb/80.0;
vec3 indirectLightColor = averageSkyCol/30.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds/30.0;
// vec3 directLightColor = lightCol.rgb / 2400.0;
// vec3 indirectLightColor = averageSkyCol / 1500.0;
// vec3 indirectLightColor_dynamic = averageSkyCol_Clouds / 900.0;
vec3 directLightColor = lightCol.rgb / 2400.0;
vec3 indirectLightColor = averageSkyCol / 1200.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds / 900.0;
vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
vec3 playerPos = normalize(mat3(gbufferModelViewInverse) * viewPos1);
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos1;
vec3 playerPos0 = mat3(gbufferModelViewInverse) * viewPos0;
#ifdef OVERWORLD_SHADER
// vec2 lightmap = decodeVec2(texture2D(colortex14, tc).a);
vec2 lightmap = vec2(0.0,texture2D(colortex14, tc).a);
// vec2 lightmap = vec2(0.0,texture2D(colortex14, tc).a);
vec2 lightmap = decodeVec2(texelFetch2D(colortex14,ivec2(tc/texelSize),0).x);
#ifdef DISTANT_HORIZONS
if(z >= 1.0) lightmap.y = 0.99;
#endif
#else
vec2 lightmap = decodeVec2(texture2D(colortex14, tc).a);
vec2 lightmap = decodeVec2(texelFetch2D(colortex14,ivec2(tc/texelSize),0).a);
lightmap.y = 1.0;
#endif
float Vdiff = distance(viewPos1, viewPos0) * 2.0;
float VdotU = playerPos.y;
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
float estimatedSunDepth = estimatedDepth / abs(WsunVec.y); //assuming water plane
// float Vdiff = distance(viewPos1, viewPos0) * 2.0;
// float VdotU = playerPos.y;
// float estimatedDepth = Vdiff * abs(VdotU); //assuming water plane
indirectLightColor_dynamic *= ambient_brightness * pow(1.0-pow(1.0-lightmap.y,0.5),3.0) ;
// float TorchBrightness_autoAdjust = mix(1.0, 30.0, clamp(exp(-10.0*exposure),0.0,1.0)) ;
// indirectLightColor_dynamic += vec3(TORCH_R,TORCH_G,TORCH_B) * TorchBrightness_autoAdjust * pow(1.0-sqrt(1.0-clamp(lightmap.x,0.0,1.0)),2.0) * 2.0;
vec3 cloudDepth = vec3(0.0);
vec4 VolumetricFog2 = vec4(0,0,0,1);
vec4 VolumetricClouds = vec4(0,0,0,1);
float Vdiff = distance(viewPos1, viewPos0);
float estimatedDepth = Vdiff * abs(normalize(playerPos).y);
float estimatedSunDepth = (Vdiff * 0.5) / abs(WsunVec.y); //assuming water plane
Vdiff *= 2.0;
#ifdef OVERWORLD_SHADER
if(!iswater){
// Vdiff = Vdiff * (1.0 - clamp(exp(-Vdiff),0.0,1.0)) + max(estimatedDepth - 1.0,0.0);
// estimatedDepth = max(estimatedDepth - 1.0,0.0);
indirectLightColor_dynamic *= ambient_brightness * lightmap.y*lightmap.y;
#if defined CLOUDS_INTERSECT_TERRAIN
VolumetricClouds = renderClouds(viewPos1, vec2(noise_1,noise_2), directLightColor, indirectLightColor, cloudDepth);
#endif
indirectLightColor_dynamic += MIN_LIGHT_AMOUNT * 0.02 * 0.2 + nightVision*0.02;
indirectLightColor_dynamic += vec3(TORCH_R,TORCH_G,TORCH_B) * pow(1.0-sqrt(1.0-clamp(lightmap.x,0.0,1.0)),2.0) ;
vec4 finalVolumetrics = vec4(0.0,0.0,0.0,1.0);
if(!iswater){
#ifdef OVERWORLD_SHADER
vec4 VolumetricClouds = GetVolumetricClouds(viewPos1, vec2(noise_1, noise_2), WsunVec, directLightColor, indirectLightColor);
float atmosphereAlpha = 1.0;
VolumetricFog2 = GetVolumetricFog(viewPos1, vec2(noise_1, noise_2), directLightColor, indirectLightColor,indirectLightColor_dynamic, atmosphereAlpha);
VolumetricClouds.a *= atmosphereAlpha;
vec4 VolumetricFog = GetVolumetricFog(viewPos1, vec2(noise_1, noise_2), directLightColor, indirectLightColor, indirectLightColor_dynamic, atmosphereAlpha, VolumetricClouds.rgb);
finalVolumetrics = VolumetricClouds;
// VolumetricClouds.a *= atmosphereAlpha;
#endif
#if defined CLOUDS_INTERSECT_TERRAIN
VolumetricFog2 = vec4(VolumetricClouds.rgb * VolumetricFog2.a * atmosphereAlpha + VolumetricFog2.rgb, VolumetricFog2.a*VolumetricClouds.a);
#endif
}
#endif
#if defined NETHER_SHADER || defined END_SHADER
vec4 VolumetricFog = GetVolumetricFog(viewPos1, noise_1, noise_2);
#endif
// #if defined OVERWORLD_SHADER
// vec4 VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a*VolumetricClouds.a);
// #endif
finalVolumetrics.rgb = finalVolumetrics.rgb * VolumetricFog.a + VolumetricFog.rgb;
finalVolumetrics.a *= VolumetricFog.a;
}
vec4 underwaterVlFog = vec4(0,0,0,1);
if(iswater) underwaterVlFog = waterVolumetrics_test(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor* (1.0-caveDetection), dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) );
vec4 fogFinal = vec4(underwaterVlFog.rgb * VolumetricFog2.a + VolumetricFog2.rgb, VolumetricFog2.a * underwaterVlFog.a);
float lightleakfix = clamp(lightmap.y + (1-caveDetection),0.0,1.0);
if(iswater && isEyeInWater != 1) underwaterVlFog = waterVolumetrics_test(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor, dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) ,lightleakfix);
finalVolumetrics.rgb += underwaterVlFog.rgb;
gl_FragData[0] = clamp(fogFinal, 0.0, 65000.0);
gl_FragData[0] = clamp(finalVolumetrics, 0.0, 65000.0);
}
}

View File

@ -6,10 +6,11 @@ flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
flat varying vec3 averageSkyCol_Clouds;
#if defined Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
flat varying vec3 WsunVec;
flat varying vec3 refractedSunVec;
@ -56,11 +57,11 @@ void main() {
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
#if defined Daily_Weather
dailyWeatherParams0 = vec4((texelFetch2D(colortex4,ivec2(1,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams1 = vec4((texelFetch2D(colortex4,ivec2(2,1),0).rgb/150.0)/2.0, 0.0);
dailyWeatherParams0 = vec4(texelFetch2D(colortex4,ivec2(1,1),0).rgb / 1500.0, 0.0);
dailyWeatherParams1 = vec4(texelFetch2D(colortex4,ivec2(2,1),0).rgb / 1500.0, 0.0);
dailyWeatherParams0.a = (texelFetch2D(colortex4,ivec2(3,1),0).x/150.0)/2.0;
dailyWeatherParams1.a = (texelFetch2D(colortex4,ivec2(3,1),0).y/150.0)/2.0;
dailyWeatherParams0.a = texelFetch2D(colortex4,ivec2(3,1),0).x/1500.0;
dailyWeatherParams1.a = texelFetch2D(colortex4,ivec2(3,1),0).y/1500.0;
#endif
#endif
@ -68,7 +69,7 @@ void main() {
#ifdef NETHER_SHADER
lightCol.rgb = vec3(0.0);
averageSkyCol = vec3(0.0);
averageSkyCol_Clouds = vec3(2.0, 1.0, 0.5) * 5.0;
averageSkyCol_Clouds = volumetricsFromTex(vec3(0.0,1.0,0.0), colortex4, 6).rgb;
#endif
#ifdef END_SHADER