From 01387e87205998c8176cbfd159b6be8a3393407f Mon Sep 17 00:00:00 2001 From: Xonk Date: Tue, 11 Mar 2025 18:50:00 -0400 Subject: [PATCH] smaller water fog tweaks. fix wrong normal usage in some parts of forward rendering --- shaders/dimensions/all_translucent.fsh | 13 +- shaders/dimensions/composite2.fsh | 1 - .../dimensions/fogBehindTranslucent_pass.fsh | 135 +++--------------- shaders/lib/specular.glsl | 2 +- 4 files changed, 29 insertions(+), 122 deletions(-) diff --git a/shaders/dimensions/all_translucent.fsh b/shaders/dimensions/all_translucent.fsh index 39296fc..cc1bced 100644 --- a/shaders/dimensions/all_translucent.fsh +++ b/shaders/dimensions/all_translucent.fsh @@ -517,6 +517,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) TangentNormal = NormalTex.xy; normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0); + worldSpaceNormal = normalize(viewToWorld(normal).xyz); // TangentNormal = clamp(TangentNormal + (blueNoise()*2.0-1.0)*0.005,-1.0,1.0); float nameTagMask = 0.0; @@ -605,7 +606,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) #endif #ifdef NETHER_SHADER - Indirect_lighting = volumetricsFromTex(normalize(worldSpaceNormal), colortex4, 0).rgb / 1200.0 / 1.5; + Indirect_lighting = volumetricsFromTex(worldSpaceNormal, colortex4, 0).rgb / 1200.0 / 1.5; #endif #ifdef END_SHADER @@ -634,12 +635,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) #ifdef IS_LPV_ENABLED vec3 normalOffset = vec3(0.0); - if (any(greaterThan(abs(worldSpaceNormal), vec3(1.0e-6)))) + if (any(greaterThan(abs(viewToWorld(normalMat.xyz).xyz), vec3(1.0e-6)))) normalOffset = 0.5*worldSpaceNormal; #if LPV_NORMAL_STRENGTH > 0 if (any(greaterThan(abs(normal), vec3(1.0e-6)))) { - vec3 texNormalOffset = -normalOffset + viewToWorld(normal); + vec3 texNormalOffset = -normalOffset + worldSpaceNormal; normalOffset = mix(normalOffset, texNormalOffset, (LPV_NORMAL_STRENGTH*0.01)); } #endif @@ -653,7 +654,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) vec4 flashLightSpecularData = vec4(0.0); #ifdef FLASHLIGHT - Indirect_lighting += calculateFlashlight(FragCoord.xy*texelSize/RENDER_SCALE, viewPos, vec3(0.0), viewToWorld(normalize(normal)), flashLightSpecularData, false); + Indirect_lighting += calculateFlashlight(FragCoord.xy*texelSize/RENDER_SCALE, viewPos, vec3(0.0), worldSpaceNormal, flashLightSpecularData, false); #endif vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo; @@ -708,7 +709,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) #endif - 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, isHand, reflectance, flashLightSpecularData); + vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), worldSpaceNormal, roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, isHand, reflectance, flashLightSpecularData); gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * reflectance; @@ -748,7 +749,7 @@ 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 = viewToWorld(normalize(normal.xyz)) * 0.1; + gl_FragData[0].rgb = worldSpaceNormal * 0.1; gl_FragData[0].a = 1; #endif #if DEBUG_VIEW == debug_INDIRECT diff --git a/shaders/dimensions/composite2.fsh b/shaders/dimensions/composite2.fsh index 59fa41b..489820e 100644 --- a/shaders/dimensions/composite2.fsh +++ b/shaders/dimensions/composite2.fsh @@ -286,7 +286,6 @@ vec4 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither, float phase = 0.0; #endif - // float thing = -normalize(dVWorld + (cameraPosition - vec3(cameraPosition.x, waterEnteredAltitude-1.0,cameraPosition.z))).y; float thing = -normalize(dVWorld).y; thing = clamp(thing + 0.333,0.0,1.0); thing = pow(1.0-pow(1.0-thing,2.0),2.0); diff --git a/shaders/dimensions/fogBehindTranslucent_pass.fsh b/shaders/dimensions/fogBehindTranslucent_pass.fsh index 905a4b1..247d61e 100644 --- a/shaders/dimensions/fogBehindTranslucent_pass.fsh +++ b/shaders/dimensions/fogBehindTranslucent_pass.fsh @@ -109,35 +109,32 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo #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; + uniform sampler2D colortex4; #include "/lib/nether_fog.glsl" #endif + #ifdef END_SHADER -uniform sampler2D colortex4; + uniform sampler2D colortex4; #include "/lib/end_fog.glsl" #endif - #define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) +vec4 blueNoise(vec2 coord){ + return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ; +} + +float blueNoise(){ + return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a+ 1.0/1.6180339887 * frameCounter ); +} + float interleaved_gradientNoise(){ return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*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 ); -} + float R2_dither(){ #ifdef TAA vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0; @@ -148,53 +145,6 @@ float R2_dither(){ return fract(alpha.x * coord.x + alpha.y * coord.y ) ; } -void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){ - 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,12.0)/(1e-8+rayLength); - dV *= maxZ; - - - rayLength *= maxZ; - - float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; - estEndDepth *= maxZ; - estSunDepth *= maxZ; - - vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz; - vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz); - - vec3 absorbance = vec3(1.0); - vec3 vL = vec3(0.0); - - float expFactor = 11.0; - for (int i=0;i