From faeb60f2af9746b1460c421a0f468f1c9f6a56ca Mon Sep 17 00:00:00 2001 From: Xonk Date: Mon, 17 Mar 2025 23:39:48 -0400 Subject: [PATCH] slight improvements to cloud/fog intersections --- shaders/lib/overworld_fog.glsl | 8 +++++--- shaders/lib/volumetricClouds.glsl | 28 ++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/shaders/lib/overworld_fog.glsl b/shaders/lib/overworld_fog.glsl index ed24481..ebdc5d9 100644 --- a/shaders/lib/overworld_fog.glsl +++ b/shaders/lib/overworld_fog.glsl @@ -170,9 +170,11 @@ vec4 GetVolumetricFog( for (int i = 0; i < SAMPLECOUNT; i++) { float d = (pow(expFactor, float(i+dither.x)/float(SAMPLECOUNT))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); float dd = pow(expFactor, float(i+dither.y)/float(SAMPLECOUNT)) * log(expFactor) / float(SAMPLECOUNT)/(expFactor-1.0); - - // check if the fog intersects clouds - if(length(d*dVWorld) > cloudPlaneDistance) break; + + #ifdef VOLUMETRIC_CLOUDS + // check if the fog intersects clouds + if(length(d*dVWorld) > cloudPlaneDistance) break; + #endif progress = start.xyz + d*dV; progressW = gbufferModelViewInverse[3].xyz + cameraPosition + d*dVWorld; diff --git a/shaders/lib/volumetricClouds.glsl b/shaders/lib/volumetricClouds.glsl index d2138f7..b2e28f7 100644 --- a/shaders/lib/volumetricClouds.glsl +++ b/shaders/lib/volumetricClouds.glsl @@ -256,6 +256,13 @@ vec4 raymarchCloud( float distanceFactor = length(rayDirection); + float densityTresholdCheck = 0.0; + + if(LayerIndex == SMALLCUMULUS_LAYER) densityTresholdCheck = 0.06; + if(LayerIndex == LARGECUMULUS_LAYER) densityTresholdCheck = 0.02; + if(LayerIndex == ALTOSTRATUS_LAYER) densityTresholdCheck = 0.01; + + densityTresholdCheck = mix(1e-5, densityTresholdCheck, dither); if(LayerIndex == ALTOSTRATUS_LAYER){ float density = dailyWeatherParams1.z; @@ -273,10 +280,12 @@ vec4 raymarchCloud( float shape = getCloudShape(LayerIndex, 1, rayPosition, minHeight, maxHeight); float shapeWithDensity = shape*density; + if(shapeWithDensity > mix(1e-5, 0.06, dither)){ + cloudPlaneDistance.x = length(rayPosition - cameraPosition); cloudPlaneDistance.y = 0.0; + } + // check if the pixel has visible clouds before doing work. if(shapeWithDensity > 1e-5){ - - cloudPlaneDistance.x = length(rayPosition - cameraPosition); cloudPlaneDistance.y = 0.0; // can add the initial cloud shape sample for a free shadow starting step :D float sunShadowMask = (shapeWithDensity + getCloudScattering(LayerIndex, rayPosition, sunVector, dither, minHeight, maxHeight, density)) * (1.0-abs(WsunVec.y)); @@ -333,8 +342,7 @@ vec4 raymarchCloud( float shapeWithDensity = shape*density; float shapeWithDensityFaded = shape*density * pow(clamp((rayPosition.y - minHeight)/(max(maxHeight-minHeight,1.0)*0.25),0.0,1.0),2.0); - - if(shapeWithDensityFaded > mix(0.06, 1e-5, dither)){ + if(shapeWithDensityFaded > densityTresholdCheck){ cloudPlaneDistance.x = length(rayPosition - cameraPosition); cloudPlaneDistance.y = 0.0; } @@ -560,6 +568,16 @@ vec4 GetVolumetricClouds( cloudPlaneDistance = mix(cloudLayer2_Distance.x, cloudLayer1_Distance.x, cloudLayer2_Distance.y); cloudPlaneDistance = mix(cloudLayer0_Distance.x, cloudPlaneDistance, cloudLayer0_Distance.y); #endif + + #if defined CloudLayer0 && !defined CloudLayer1 && !defined CloudLayer2 + cloudPlaneDistance = cloudLayer0_Distance.x; + #endif + #if !defined CloudLayer0 && defined CloudLayer1 && !defined CloudLayer2 + cloudPlaneDistance = cloudLayer1_Distance.x; + #endif + #if !defined CloudLayer0 && !defined CloudLayer1 && defined CloudLayer2 + cloudPlaneDistance = cloudLayer2_Distance.x; + #endif #ifdef CloudLayer2 cloudColor = altoStratusClouds; @@ -568,8 +586,6 @@ vec4 GetVolumetricClouds( cloudColor.rgb *= largeCumulusClouds.a; cloudColor.rgb += largeCumulusClouds.rgb; cloudColor.a *= largeCumulusClouds.a; - - #endif #ifdef CloudLayer0 cloudColor.rgb *= smallCumulusClouds.a;