fix cloud horizon line when sky ground is off

This commit is contained in:
Xonk 2024-06-28 16:31:31 -04:00
parent dd35c0cb9d
commit 0ccec1e817
5 changed files with 20 additions and 11 deletions

View File

@ -28,6 +28,7 @@ uniform vec3 sunVec;
uniform float sunElevation; uniform float sunElevation;
// uniform float far; // uniform float far;
uniform float near;
uniform float dhFarPlane; uniform float dhFarPlane;
uniform float dhNearPlane; uniform float dhNearPlane;
@ -126,7 +127,9 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
} }
#endif #endif
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
#ifdef OVERWORLD_SHADER #ifdef OVERWORLD_SHADER
const bool shadowHardwareFiltering = true; const bool shadowHardwareFiltering = true;
uniform sampler2DShadow shadow; uniform sampler2DShadow shadow;

View File

@ -84,6 +84,7 @@ vec3 toScreenSpace(vec3 p) {
return viewPos.xyz / viewPos.w; return viewPos.xyz / viewPos.w;
} }
uniform float near;
uniform float dhFarPlane; uniform float dhFarPlane;
uniform float dhNearPlane; 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) { float linearizeDepthFast(const in float depth, const in float near, const in float far) {
return (near * far) / (depth * (near - far) + far); return (near * far) / (depth * (near - far) + far);
} }
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
#ifdef OVERWORLD_SHADER #ifdef OVERWORLD_SHADER
// uniform sampler2D colortex12; // uniform sampler2D colortex12;

View File

@ -35,6 +35,7 @@ uniform float sunElevation;
// uniform float far; // uniform float far;
uniform float dhFarPlane; uniform float dhFarPlane;
uniform float dhNearPlane; uniform float dhNearPlane;
uniform float near;
uniform int frameCounter; uniform int frameCounter;
uniform float frameTimeCounter; uniform float frameTimeCounter;
@ -64,7 +65,7 @@ uniform float caveDetection;
#include "/lib/DistantHorizons_projections.glsl" #include "/lib/DistantHorizons_projections.glsl"
float DH_ld(float dist) { 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){ float DH_inv_ld (float lindepth){
return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane); return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane);

View File

@ -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) #define saturate(x) clamp(x,0.0,1.0)

View File

@ -282,7 +282,6 @@ vec4 renderLayer(
){ ){
vec3 COLOR = vec3(0.0); vec3 COLOR = vec3(0.0);
float TOTAL_EXTINCTION = 1.0; float TOTAL_EXTINCTION = 1.0;
bool IntersecTerrain = false; bool IntersecTerrain = false;
#ifdef CLOUDS_INTERSECT_TERRAIN #ifdef CLOUDS_INTERSECT_TERRAIN
@ -384,16 +383,16 @@ if(layer == 2){
COLOR += max(lighting - lighting*exp(-mult*muE),0.0) * TOTAL_EXTINCTION; COLOR += max(lighting - lighting*exp(-mult*muE),0.0) * TOTAL_EXTINCTION;
TOTAL_EXTINCTION *= max(exp(-mult*muE),0.0); TOTAL_EXTINCTION *= max(exp(-mult*muE),0.0);
if (TOTAL_EXTINCTION < 1e-5) break; if (TOTAL_EXTINCTION < 1e-5) break;
} }
} }
rayProgress += dV_view; rayProgress += dV_view;
} }
return vec4(COLOR, TOTAL_EXTINCTION); return vec4(COLOR, TOTAL_EXTINCTION);
} }
} }
@ -414,6 +413,9 @@ vec3 layerStartingPosition(
return position; return position;
} }
float invLinZ_cloud (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
vec4 renderClouds( vec4 renderClouds(
vec3 FragPosition, vec3 FragPosition,
vec2 Dither, vec2 Dither,
@ -549,7 +551,7 @@ vec4 renderClouds(
total_extinction *= layer1.a; total_extinction *= layer1.a;
// stop overdraw. // stop overdraw.
altoNotVisible = (layer1.a < 1e-5 || notVisible)&& below_Layer1; altoNotVisible = (layer1.a < 1e-5 || notVisible) && below_Layer1;
#endif #endif
#ifdef CloudLayer2 #ifdef CloudLayer2
@ -593,10 +595,9 @@ vec4 renderClouds(
#endif #endif
#ifndef SKY_GROUND #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 #else
return vec4(color, total_extinction); return vec4(color, total_extinction);
#endif #endif