From 0ccec1e81783dbd062ffe669a2f52543852269cc Mon Sep 17 00:00:00 2001 From: Xonk Date: Fri, 28 Jun 2024 16:31:31 -0400 Subject: [PATCH] fix cloud horizon line when sky ground is off --- shaders/dimensions/composite2.fsh | 5 ++++- shaders/dimensions/deferred.fsh | 4 ++++ .../dimensions/fogBehindTranslucent_pass.fsh | 3 ++- shaders/lib/settings.glsl | 2 +- shaders/lib/volumetricClouds.glsl | 17 +++++++++-------- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/shaders/dimensions/composite2.fsh b/shaders/dimensions/composite2.fsh index 49dacf6..aa418cf 100644 --- a/shaders/dimensions/composite2.fsh +++ b/shaders/dimensions/composite2.fsh @@ -28,6 +28,7 @@ uniform vec3 sunVec; uniform float sunElevation; // uniform float far; +uniform float near; uniform float dhFarPlane; uniform float dhNearPlane; @@ -126,7 +127,9 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo } #endif - +float invLinZ (float lindepth){ + return -((2.0*near/lindepth)-far-near)/(far-near); +} #ifdef OVERWORLD_SHADER const bool shadowHardwareFiltering = true; uniform sampler2DShadow shadow; diff --git a/shaders/dimensions/deferred.fsh b/shaders/dimensions/deferred.fsh index 3009a88..92f7e8b 100644 --- a/shaders/dimensions/deferred.fsh +++ b/shaders/dimensions/deferred.fsh @@ -84,6 +84,7 @@ vec3 toScreenSpace(vec3 p) { return viewPos.xyz / viewPos.w; } +uniform float near; uniform float dhFarPlane; uniform float dhNearPlane; @@ -117,6 +118,9 @@ float DH_inv_ld (float lindepth){ float linearizeDepthFast(const in float depth, const in float near, const in float far) { return (near * far) / (depth * (near - far) + far); } +float invLinZ (float lindepth){ + return -((2.0*near/lindepth)-far-near)/(far-near); +} #ifdef OVERWORLD_SHADER // uniform sampler2D colortex12; diff --git a/shaders/dimensions/fogBehindTranslucent_pass.fsh b/shaders/dimensions/fogBehindTranslucent_pass.fsh index 3d0c9d7..fe46782 100644 --- a/shaders/dimensions/fogBehindTranslucent_pass.fsh +++ b/shaders/dimensions/fogBehindTranslucent_pass.fsh @@ -35,6 +35,7 @@ uniform float sunElevation; // uniform float far; uniform float dhFarPlane; uniform float dhNearPlane; +uniform float near; uniform int frameCounter; uniform float frameTimeCounter; @@ -64,7 +65,7 @@ uniform float caveDetection; #include "/lib/DistantHorizons_projections.glsl" float DH_ld(float dist) { - return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane)); + return (2.0 * near) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane)); } float DH_inv_ld (float lindepth){ return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane); diff --git a/shaders/lib/settings.glsl b/shaders/lib/settings.glsl index 076084f..59b15ae 100644 --- a/shaders/lib/settings.glsl +++ b/shaders/lib/settings.glsl @@ -1,4 +1,4 @@ -#define SHADER_VERSION_LABEL 473 // [473] +#define SHADER_VERSION_LABEL 474 // [474] #define saturate(x) clamp(x,0.0,1.0) diff --git a/shaders/lib/volumetricClouds.glsl b/shaders/lib/volumetricClouds.glsl index 350b652..116e5f8 100644 --- a/shaders/lib/volumetricClouds.glsl +++ b/shaders/lib/volumetricClouds.glsl @@ -282,7 +282,6 @@ vec4 renderLayer( ){ vec3 COLOR = vec3(0.0); float TOTAL_EXTINCTION = 1.0; - bool IntersecTerrain = false; #ifdef CLOUDS_INTERSECT_TERRAIN @@ -384,16 +383,16 @@ if(layer == 2){ COLOR += max(lighting - lighting*exp(-mult*muE),0.0) * TOTAL_EXTINCTION; TOTAL_EXTINCTION *= max(exp(-mult*muE),0.0); - + if (TOTAL_EXTINCTION < 1e-5) break; + } } rayProgress += dV_view; - - } + return vec4(COLOR, TOTAL_EXTINCTION); } } @@ -414,6 +413,9 @@ vec3 layerStartingPosition( return position; } +float invLinZ_cloud (float lindepth){ + return -((2.0*near/lindepth)-far-near)/(far-near); +} vec4 renderClouds( vec3 FragPosition, vec2 Dither, @@ -549,7 +551,7 @@ vec4 renderClouds( total_extinction *= layer1.a; // stop overdraw. - altoNotVisible = (layer1.a < 1e-5 || notVisible)&& below_Layer1; + altoNotVisible = (layer1.a < 1e-5 || notVisible) && below_Layer1; #endif #ifdef CloudLayer2 @@ -593,10 +595,9 @@ vec4 renderClouds( #endif #ifndef SKY_GROUND - vec3 normView = normalize(dV_viewTEST); - vec4 fogcolor = vec4(skyFromTex(normView, colortex4)/30.0, 0.0); - return mix(fogcolor, vec4(color, total_extinction), clamp(distantfog2,0.0,1.0)); + // return mix(fogcolor, vec4(color, total_extinction), clamp(distantfog2,0.0,1.0)); + return mix(vec4(vec3(0.0),1.0), vec4(color, total_extinction), clamp(distantfog2,0.0,1.0)); #else return vec4(color, total_extinction); #endif