From 396c9edba725f44b633244aa1e916746ce5f719a Mon Sep 17 00:00:00 2001 From: Xonk Date: Sun, 7 Jul 2024 16:29:14 -0400 Subject: [PATCH] fix atmosphere haze absorbance. fix small specular reflection issue --- shaders/dimensions/composite2.fsh | 6 ++++-- shaders/dimensions/composite3.fsh | 2 ++ shaders/dimensions/deferred.fsh | 18 ++++++++---------- .../dimensions/fogBehindTranslucent_pass.fsh | 6 ++++-- shaders/lib/overworld_fog.glsl | 4 +++- shaders/lib/settings.glsl | 2 +- shaders/lib/specular.glsl | 2 +- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/shaders/dimensions/composite2.fsh b/shaders/dimensions/composite2.fsh index e6eed28..0fad316 100644 --- a/shaders/dimensions/composite2.fsh +++ b/shaders/dimensions/composite2.fsh @@ -412,7 +412,9 @@ void main() { #endif #ifdef OVERWORLD_SHADER - vec4 VolumetricFog = GetVolumetricFog(viewPos0, vec2(noise_2,noise_1), directLightColor, indirectLightColor, averageSkyCol_Clouds/30.0, cloudDepth); + float atmosphereAlpha = 1.0; + vec4 VolumetricFog = GetVolumetricFog(viewPos0, vec2(noise_2,noise_1), directLightColor, indirectLightColor, averageSkyCol_Clouds/30.0, atmosphereAlpha); + VolumetricClouds.a *= atmosphereAlpha; #endif #if defined NETHER_SHADER || defined END_SHADER @@ -420,7 +422,7 @@ void main() { #endif #if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN - VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a); + VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a * atmosphereAlpha + VolumetricFog.rgb, VolumetricFog.a); #endif gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0); diff --git a/shaders/dimensions/composite3.fsh b/shaders/dimensions/composite3.fsh index 95e3617..b5bdc22 100644 --- a/shaders/dimensions/composite3.fsh +++ b/shaders/dimensions/composite3.fsh @@ -473,6 +473,8 @@ void main() { vl.a = 1.0; } #endif + + // if(texcoord.x > 0.5 )color.rgb = skyCloudsFromTex(np3, colortex4).rgb/30.0; 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); diff --git a/shaders/dimensions/deferred.fsh b/shaders/dimensions/deferred.fsh index 43ae5e6..84b8232 100644 --- a/shaders/dimensions/deferred.fsh +++ b/shaders/dimensions/deferred.fsh @@ -278,25 +278,23 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+ WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition) ;// * ( 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)); 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); - vec4 clouds = renderClouds(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*2.0, skyGroundCol/30.0,cloudDepth); - sky = sky*clouds.a + clouds.rgb / 5.0; - - sky = mix(dot(sky, vec3(0.333)) * vec3(0.5), sky, pow(clamp(viewVector.y+1.0,0.0,1.0),5)); - vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*1.75, skyGroundCol/30.0, averageSkyCol_Clouds/30.0,cloudDepth); - + sky = sky*clouds.a + clouds.rgb / 5.0; + sky *= atmosphereAlpha; sky = sky * VL_Fog.a + VL_Fog.rgb / 5.0; - - // if(p.y < 0.05) sky = averageSkyCol_Clouds; - gl_FragData[0] = vec4(sky,1.0); } #endif diff --git a/shaders/dimensions/fogBehindTranslucent_pass.fsh b/shaders/dimensions/fogBehindTranslucent_pass.fsh index d1fe1e1..87ceb60 100644 --- a/shaders/dimensions/fogBehindTranslucent_pass.fsh +++ b/shaders/dimensions/fogBehindTranslucent_pass.fsh @@ -379,10 +379,12 @@ void main() { VolumetricClouds = renderClouds(viewPos1, vec2(noise_1,noise_2), directLightColor, indirectLightColor, cloudDepth); #endif - VolumetricFog2 = GetVolumetricFog(viewPos1, vec2(noise_1, noise_2), directLightColor, indirectLightColor,indirectLightColor_dynamic,cloudDepth); + float atmosphereAlpha = 1.0; + VolumetricFog2 = GetVolumetricFog(viewPos1, vec2(noise_1, noise_2), directLightColor, indirectLightColor,indirectLightColor_dynamic, atmosphereAlpha); + VolumetricClouds.a *= atmosphereAlpha; #if defined CLOUDS_INTERSECT_TERRAIN - VolumetricFog2 = vec4(VolumetricClouds.rgb * VolumetricFog2.a + VolumetricFog2.rgb, VolumetricFog2.a*VolumetricClouds.a); + VolumetricFog2 = vec4(VolumetricClouds.rgb * VolumetricFog2.a * atmosphereAlpha + VolumetricFog2.rgb, VolumetricFog2.a*VolumetricClouds.a); #endif } #endif diff --git a/shaders/lib/overworld_fog.glsl b/shaders/lib/overworld_fog.glsl index 14200db..5a3159b 100644 --- a/shaders/lib/overworld_fog.glsl +++ b/shaders/lib/overworld_fog.glsl @@ -68,7 +68,7 @@ vec4 GetVolumetricFog( vec3 LightColor, vec3 AmbientColor, vec3 AveragedAmbientColor, - inout vec3 cloudDepth + inout float atmosphereAlpha ){ #ifndef TOGGLE_VL_FOG return vec4(0.0,0.0,0.0,1.0); @@ -266,6 +266,7 @@ vec4 GetVolumetricFog( vec3 Atmosphere = (LightSourcePhased * sh * (rayL*rL + sunPhase*m) + AveragedAmbientColor * (rL+m) * (lightLevelZero*0.99 + 0.01)) * inACave; color += (Atmosphere - Atmosphere * atmosphereVolumeCoeff) / (rL+m+1e-6) * atmosphereAbsorbance * totalAbsorbance; atmosphereAbsorbance *= dot(atmosphereVolumeCoeff, vec3(0.33333)); + //------------------------------------ //------ LPV FOG EFFECT //------------------------------------ @@ -335,6 +336,7 @@ vec4 GetVolumetricFog( if (totalAbsorbance < 1e-5) break; #endif } + atmosphereAlpha = atmosphereAbsorbance; return vec4(color, totalAbsorbance); } diff --git a/shaders/lib/settings.glsl b/shaders/lib/settings.glsl index 49dd31c..9670d32 100644 --- a/shaders/lib/settings.glsl +++ b/shaders/lib/settings.glsl @@ -1,4 +1,4 @@ -#define SHADER_VERSION_LABEL 477 // [477] +#define SHADER_VERSION_LABEL 478 // [478] #define saturate(x) clamp(x,0.0,1.0) diff --git a/shaders/lib/specular.glsl b/shaders/lib/specular.glsl index 2cbc01d..ee44e96 100644 --- a/shaders/lib/specular.glsl +++ b/shaders/lib/specular.glsl @@ -243,7 +243,7 @@ void DoSpecularReflections( #ifdef Sky_reflection #ifdef OVERWORLD_SHADER - if(hasReflections) Background_Reflection = (skyCloudsFromTexLOD(L, colortex4, sqrt(Roughness) * 9.0).rgb / 30.0) * Metals ; + if(hasReflections) Background_Reflection = (skyCloudsFromTex(L, colortex4).rgb / 30.0) * Metals ; #else if(hasReflections) Background_Reflection = (skyCloudsFromTexLOD2(L, colortex4, sqrt(Roughness) * 6.0).rgb / 30.0) * Metals; #endif