re-implement "render clouds as fog" setting. still has no curvature fix but its better than before...

This commit is contained in:
Xonk 2024-01-09 20:53:17 -05:00
parent 841ca3559f
commit 3eb81ec185
6 changed files with 140 additions and 117 deletions

View File

@ -660,7 +660,7 @@ void main() {
Background += Sky;
#ifdef VOLUMETRIC_CLOUDS
vec4 Clouds = texture2D_bicubic_offset(colortex0, texcoord*CLOUDS_QUALITY, noise_2);
vec4 Clouds = texture2D_bicubic_offset(colortex0, texcoord*CLOUDS_QUALITY, noise, RENDER_SCALE.x);
Background = Background * Clouds.a + Clouds.rgb;
#endif

View File

@ -95,7 +95,7 @@ vec3 sky_transmittance(vec3 position, vec3 direction, const float steps) {
vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 sunVector, vec3 moonVector, out vec2 pid, out vec3 transmittance, const int iSteps, float noise) {
const int jSteps = 4;
float planetGround = exp(-100 * pow(max(-viewVector.y*5,0.0),2)); // darken the ground in the sky.
float planetGround = exp(-100 * pow(max(-viewVector.y*5 + 0.1,0.0),2)); // darken the ground in the sky.
float GroundDarkening = max(planetGround * 0.7+0.3,clamp(sunVector.y*2.0,0.0,1.0));
vec3 viewPos = (sky_planetRadius + eyeAltitude) * upVector;

View File

@ -133,33 +133,26 @@ vec4 GetVolumetricFog(
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);
// #ifdef RAYMARCH_CLOUDS_WITH_FOG
// // first cloud layer
// float MinHeight_0 = Cumulus_height;
// float MaxHeight_0 = 100 + MinHeight_0;
#ifdef RAYMARCH_CLOUDS_WITH_FOG
vec3 SkyLightColor = AmbientColor;
vec3 LightSourceColor = LightColor;
#ifdef ambientLight_only
LightSourceColor = vec3(0.0);
#endif
// // second cloud layer
// float MinHeight_1 = MaxHeight_0 + 50;
// float MaxHeight_1 = 100 + MinHeight_1;
float shadowStep = 200.0;
// vec3 SkyLightColor = AmbientColor;
// vec3 LightSourceColor = LightColor;
// #ifdef ambientLight_only
// LightSourceColor = vec3(0.0);
// #endif
vec3 dV_Sun = WsunVec*shadowStep;
// float shadowStep = 200.0;
float mieDay = phaseg(SdotV, 0.75);
float mieDayMulti = (phaseg(SdotV, 0.35) + phaseg(-SdotV, 0.35) * 0.5) ;
// vec3 dV_Sun = WsunVec*shadowStep;
vec3 directScattering = LightSourceColor * mieDay * 3.14;
vec3 directMultiScattering = LightSourceColor * mieDayMulti * 4.0;
// float mieDay = phaseg(SdotV, 0.75);
// float mieDayMulti = (phaseg(SdotV, 0.35) + phaseg(-SdotV, 0.35) * 0.5) ;
// vec3 directScattering = LightSourceColor * mieDay * 3.14;
// vec3 directMultiScattering = LightSourceColor * mieDayMulti * 4.0;
// vec3 sunIndirectScattering = LightSourceColor * phaseg(dot(mat3(gbufferModelView)*vec3(0,1,0),normalize(viewPosition)), 0.5) * 3.14;
// #endif
vec3 sunIndirectScattering = LightSourceColor * phaseg(dot(mat3(gbufferModelView)*vec3(0,1,0),normalize(viewPosition)), 0.5) * 3.14;
#endif
float expFactor = 11.0;
for (int i=0;i<VL_SAMPLES;i++) {
@ -205,48 +198,55 @@ vec4 GetVolumetricFog(
color += (foglighting - foglighting * exp(-(rL+m)*dd*dL)) / ((rL+m)+0.00000001)*absorbance;
absorbance *= clamp(exp(-(rL+m)*dd*dL),0.0,1.0);
#ifdef RAYMARCH_CLOUDS_WITH_FOG
//////////////////////////////////////////
///// ----- cloud part
//////////////////////////////////////////
float otherlayer = max(progressW.y - (CloudLayer0_height+99.5), 0.0) > 0.0 ? 0.0 : 1.0;
float DUAL_MIN_HEIGHT = otherlayer > 0.0 ? CloudLayer0_height : CloudLayer1_height;
float DUAL_MAX_HEIGHT = DUAL_MIN_HEIGHT + 100.0;
// #ifdef RAYMARCH_CLOUDS_WITH_FOG
// //////////////////////////////////////////
// ///// ----- cloud part
// //////////////////////////////////////////
float Density = otherlayer > 0.0 ? CloudLayer0_density : CloudLayer1_density;
// float curvature = pow(clamp(1.0 - length(progressW)/far,0,1),2) * 50;
float cumulus = GetCumulusDensity(-1, progressW, 1, DUAL_MIN_HEIGHT, DUAL_MAX_HEIGHT);
float BASE_FADE = Density * clamp(exp( (progressW.y - (DUAL_MAX_HEIGHT - 75)) / 9.0 ),0.0,1.0);
// // determine the base of each cloud layer
// bool isUpperLayer = max(progressW.y - MinHeight_1,0.0) > 0.0;
// float CloudBaseHeights = isUpperLayer ? 200.0 + MaxHeight_0 : MaxHeight_0;
if(cumulus > 1e-5){
float muE = cumulus * BASE_FADE ;
float directLight = 0.0;
for (int j=0; j < 3; j++){
// float cumulus = GetCumulusDensity(progressW, 1, MinHeight_0, MaxHeight_0);
// float fadedDensity = Cumulus_density * clamp(exp( (progressW.y - (CloudBaseHeights - 70)) / 9.0 ),0.0,1.0);
vec3 shadowSamplePos = progressW + dV_Sun * (0.1 + j * (0.1 + dither.y*0.05));
float shadow = GetCumulusDensity(-1, shadowSamplePos, 0, DUAL_MIN_HEIGHT, DUAL_MAX_HEIGHT) * Density;
// if(cumulus > 1e-5){
// float muE = cumulus*fadedDensity;
directLight += shadow;
}
// float directLight = 0.0;
// for (int j=0; j < 3; j++){
#if defined CloudLayer1 && defined CloudLayer0
if(otherlayer > 0) directLight += CloudLayer1_density * 2.0 * GetCumulusDensity(1, progressW + dV_Sun/abs(dV_Sun.y) * max(((CloudLayer1_height+100)-70) - progressW.y,0.0), 0, CloudLayer1_height, CloudLayer1_height+100);
#endif
// vec3 shadowSamplePos = progressW + dV_Sun * (0.1 + j * (0.1 + dither.y*0.05));
// float shadow = GetCumulusDensity(shadowSamplePos, 0, MinHeight_0, MaxHeight_0) * Cumulus_density;
#if defined CloudLayer1 && defined CloudLayer0
float upperLayerOcclusion = otherlayer < 1 ? CloudLayer1_density * 2.0 * GetCumulusDensity(1, progressW + vec3(0.0,1.0,0.0) * max(((CloudLayer1_height+100)-70) - progressW.y,0.0), 0, CloudLayer1_height, CloudLayer1_height+100) : 0.0;
float skylightOcclusion = max(exp2((upperLayerOcclusion*upperLayerOcclusion) * -5), 0.75);
#else
float skylightOcclusion = 1.0;
#endif
// directLight += shadow;
// }
// if(max(progressW.y - MaxHeight_1 + 50,0.0) < 1.0) directLight += Cumulus_density * 2.0 * GetCumulusDensity(progressW + dV_Sun/abs(dV_Sun.y) * max((MaxHeight_1 - 30.0) - progressW.y,0.0), 0, MinHeight_0, MaxHeight_0);
// float upperLayerOcclusion = !isUpperLayer ? Cumulus_density * 2.0 * GetCumulusDensity(progressW + vec3(0.0,1.0,0.0) * max((MaxHeight_1 - 30.0) - progressW.y,0.0), 0, MinHeight_0, MaxHeight_0) : 0.0;
// float skylightOcclusion = max(exp2((upperLayerOcclusion*upperLayerOcclusion) * -5), 0.75);
float skyScatter = clamp((DUAL_MAX_HEIGHT - 20 - progressW.y) / 275.0,0.0,1.0);
vec3 cloudlighting = DoCloudLighting(muE, cumulus, AmbientColor*skylightOcclusion, skyScatter, directLight, directScattering, directMultiScattering, 1.0);
// float skyScatter = clamp((CloudBaseHeights - 20 - progressW.y) / 275.0,0.0,1.0);
// vec3 cloudlighting = DoCloudLighting(muE, cumulus, SkyLightColor*skylightOcclusion, skyScatter, directLight, directScattering*sh2, directMultiScattering*sh2, 1.0);
// // a horrible approximation of direct light indirectly hitting the lower layer of clouds after scattering through/bouncing off the upper layer.
// cloudlighting += sunIndirectScattering * exp((skyScatter*skyScatter) * cumulus * -35.0) * upperLayerOcclusion * exp(-20.0 * pow(abs(upperLayerOcclusion - 0.3),2));
// color += max(cloudlighting - cloudlighting*exp(-muE*dd*dL),0.0) * absorbance;
// absorbance *= max(exp(-muE*dd*dL),0.0);
// }
// #endif /// VL CLOUDS
#if defined CloudLayer1 && defined CloudLayer0
// a horrible approximation of direct light indirectly hitting the lower layer of clouds after scattering through/bouncing off the upper layer.
cloudlighting += sunIndirectScattering * exp((skyScatter*skyScatter) * cumulus * -35.0) * upperLayerOcclusion * exp(-20.0 * pow(abs(upperLayerOcclusion - 0.3),2));
#endif
color += max(cloudlighting - cloudlighting*exp(-muE*dd*dL),0.0) * absorbance;
absorbance *= max(exp(-muE*dd*dL),0.0);
}
#endif
}
return vec4(color, min(dot(absorbance,vec3(0.335)),1.0));
}

View File

@ -344,17 +344,17 @@ uniform int moonPhase;
#define CloudLayer0
#define CloudLayer0_coverage 0.7 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define CloudLayer0_density 0.5 // [0.01 0.F02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00]
#define CloudLayer0_density 0.5 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00]
#define CloudLayer0_height 250 // [-300 -290 -280 -270 -260 -250 -240 -230 -220 -210 -200 -190 -180 -170 -160 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 700 800 900 1000]
#define CloudLayer1
#define CloudLayer1_coverage 0.7 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define CloudLayer1_density 0.5 // [0.01 0.F02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00]
#define CloudLayer1_density 0.5 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00]
#define CloudLayer1_height 500 // [-300 -290 -280 -270 -260 -250 -240 -230 -220 -210 -200 -190 -180 -170 -160 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 700 800 900 1000]
#define CloudLayer2
#define CloudLayer2_coverage 0.3 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0]
#define CloudLayer2_density 0.1 // [0.01 0.F02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00]
#define CloudLayer2_density 0.1 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00]
#define CloudLayer2_height 2000 // [-300 -290 -280 -270 -260 -250 -240 -230 -220 -210 -200 -190 -180 -170 -160 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 700 800 900 1000]
#if (defined CloudLayer0 || defined CloudLayer1) && defined VOLUMETRIC_CLOUDS

View File

@ -99,13 +99,15 @@ vec4 texture2D_bicubic(sampler2D tex, vec2 uv)
g1(fuv.y) * (g0x * texture2D(tex, p2) +
g1x * texture2D(tex, p3));
}
vec4 texture2D_bicubic_offset(sampler2D tex, vec2 uv, float noise)
vec4 texture2D_bicubic_offset(sampler2D tex, vec2 uv, float noise, float scale)
{
float offsets = noise * (2.0 * 3.141592653589793238462643383279502884197169);
vec2 circleOffsets = vec2(sin(offsets), cos(offsets));
vec2 circleOffsets = vec2(sin(offsets), cos(offsets)) * scale;
#ifdef SCREENSHOT_MODE
circleOffsets = vec2(0.0);
#endif
// circleOffsets = vec2(0.0);
vec4 texelSize = vec4(texelSize,1.0/texelSize);
uv = uv*texelSize.zw;

View File

@ -65,6 +65,17 @@ float cloudCov(int layer, in vec3 pos, vec3 samplePos, float minHeight, float ma
SampleCoords1 = -( (samplePos.zx - cloud_movement*2) / 1500);
}
if(layer == -1){
float otherlayer = max(pos.y - (CloudLayer0_height+99.5), 0.0) > 0 ? 0.0 : 1.0;
if(otherlayer > 0.0){
SampleCoords0 = (samplePos.xz + cloud_movement) / 5000;
SampleCoords1 = (samplePos.xz - cloud_movement) / 500;
}else{
SampleCoords0 = -( (samplePos.zx + cloud_movement*2) / 15000);
SampleCoords1 = -( (samplePos.zx - cloud_movement*2) / 1500);
}
}
float CloudSmall = texture2D(noisetex, SampleCoords1 ).r;
float CloudLarge = texture2D(noisetex, SampleCoords0 ).b;
@ -77,10 +88,10 @@ float cloudCov(int layer, in vec3 pos, vec3 samplePos, float minHeight, float ma
float layer0 = min(min(coverage + CloudLayer0_coverage, clamp(maxHeight - pos.y,0,1)), 1.0 - clamp(minHeight - pos.y,0,1));
float Topshape = max(pos.y - (maxHeight - 75),0.0) / 200.0;
Topshape = max(pos.y - (maxHeight - 75),0.0) / 200.0;
Topshape += max(pos.y - (maxHeight - 10),0.0) / 50.0;
float Baseshape = max(minHeight + 12.5 - pos.y, 0.0) / 50.0;
Baseshape = max(minHeight + 12.5 - pos.y, 0.0) / 50.0;
FinalCloudCoverage = max(layer0 - Topshape - Baseshape,0.0);
}
@ -95,25 +106,33 @@ float cloudCov(int layer, in vec3 pos, vec3 samplePos, float minHeight, float ma
FinalCloudCoverage = max(layer1 - Topshape - Baseshape, 0.0);
}
if(layer == -1){
// float FirstLayerCoverage = DailyWeather_Cumulus(coverage);
float LAYER0_minHEIGHT_FOG = CloudLayer0_height;
float LAYER0_maxHEIGHT_FOG = 100 + LAYER0_minHEIGHT_FOG;
float layer0 = min(min(coverage + CloudLayer0_coverage, clamp(LAYER0_maxHEIGHT - pos.y,0,1)), 1.0 - clamp(LAYER0_minHEIGHT - pos.y,0,1));
float LAYER1_minHEIGHT_FOG = max(CloudLayer1_height,LAYER0_maxHEIGHT);
float LAYER1_maxHEIGHT_FOG = 100 + LAYER1_minHEIGHT_FOG;
float Topshape = max(pos.y - (LAYER0_maxHEIGHT - 75),0.0) / 200.0;
Topshape += max(pos.y - (LAYER0_maxHEIGHT - 10),0.0) / 50.0;
#ifdef CloudLayer0
float layer0 = min(min(coverage + CloudLayer0_coverage, clamp(LAYER0_maxHEIGHT_FOG - pos.y,0,1)), 1.0 - clamp(LAYER0_minHEIGHT_FOG - pos.y,0,1));
float Baseshape = max(LAYER0_minHEIGHT + 12.5 - pos.y, 0.0) / 50.0;
Topshape = max(pos.y - (LAYER0_maxHEIGHT_FOG - 75),0.0) / 200.0;
Topshape += max(pos.y - (LAYER0_maxHEIGHT_FOG - 10),0.0) / 50.0;
Baseshape = max(LAYER0_minHEIGHT_FOG + 12.5 - pos.y, 0.0) / 50.0;
FinalCloudCoverage += max(layer0 - Topshape - Baseshape,0.0);
FinalCloudCoverage += max(layer0 - Topshape - Baseshape,0.0);
#endif
#ifdef CloudLayer1
float layer1 = min(min(coverage + CloudLayer1_coverage, clamp(LAYER1_maxHEIGHT - pos.y,0,1)), 1.0 - clamp(LAYER1_minHEIGHT_FOG - pos.y,0,1));
float layer1 = min(min(coverage + CloudLayer1_coverage, clamp(LAYER1_maxHEIGHT - pos.y,0,1)), 1.0 - clamp(LAYER1_minHEIGHT - pos.y,0,1));
Topshape = max(pos.y - (LAYER1_maxHEIGHT_FOG - 75), 0.0) / 200;
Topshape += max(pos.y - (LAYER1_maxHEIGHT_FOG - 10 ), 0.0) / 50;
Baseshape = max(LAYER1_minHEIGHT_FOG + 12.5 - pos.y, 0.0) / 50.0;
Topshape = max(pos.y - (LAYER1_maxHEIGHT - 75), 0.0) / 200;
Topshape += max(pos.y - (LAYER1_maxHEIGHT - 10 ), 0.0) / 50;
Baseshape = max(LAYER1_minHEIGHT + 12.5 - pos.y, 0.0) / 50.0;
FinalCloudCoverage += max(layer1 - Topshape - Baseshape, 0.0);
FinalCloudCoverage += max(layer1 - Topshape - Baseshape, 0.0);
#endif
}
return FinalCloudCoverage;
@ -121,7 +140,7 @@ float cloudCov(int layer, in vec3 pos, vec3 samplePos, float minHeight, float ma
//Erode cloud with 3d Perlin-worley noise, actual cloud value
float cloudVol(int layer, in vec3 pos,in vec3 samplePos,in float cov, in int LoD, float minHeight, float maxHeight){
float otherlayer = layer == 0 ? 1.0 : 0.0;
float otherlayer = max(pos.y - (CloudLayer0_height+99.5), 0.0) > 0 ? 0.0 : 1.0;
float upperPlane = otherlayer;
float noise = 0.0 ;
@ -369,7 +388,8 @@ vec4 renderClouds(
float total_extinction = 1.0;
vec3 color = vec3(0.0);
float heightRelativeToClouds = clamp(1.0 - max(cameraPosition.y - LAYER0_minHEIGHT,0.0) / 200.0 ,0.0,1.0);
float heightRelativeToClouds = clamp(1.0 - max(cameraPosition.y - LAYER0_minHEIGHT,0.0) / 100.0 ,0.0,1.0);
// heightRelativeToClouds*=heightRelativeToClouds;
//////////////////////////////////////////
////// Raymarching stuff
@ -384,7 +404,7 @@ vec4 renderClouds(
vec3 dV_view = normalize(viewPos.xyz);
// this is the cloud curvature.
dV_view.y += 0.05 * heightRelativeToClouds;
dV_view.y += 0.025 * heightRelativeToClouds;
vec3 dV_view_Alto = dV_view;
dV_view_Alto *= 100/abs(dV_view_Alto.y)/15;
@ -414,19 +434,19 @@ vec4 renderClouds(
// use this to blend into the atmosphere's ground.
vec3 approxdistance = normalize(dV_view);
float distantfog = max(1.0 - clamp(exp2(pow(abs(approxdistance.y),1.5) * -35.0),0.0,1.0),0.0);
float distantfog = mix(1.0, max(1.0 - clamp(exp2(pow(abs(approxdistance.y),1.5) * -35.0),0.0,1.0),0.0), heightRelativeToClouds);
// distantfog = 1;
// terrible fake rayleigh scattering
vec3 rC = vec3(sky_coefficientRayleighR*1e-6, sky_coefficientRayleighG*1e-5, sky_coefficientRayleighB*1e-5)*3;
float atmosphere = exp(abs(approxdistance.y) * -5.0);
vec3 scatter = mix(vec3(1.0), exp(-10000.0 * rC * atmosphere) * distantfog, heightRelativeToClouds);
vec3 scatter = exp(-10000.0 * rC * atmosphere) * distantfog;
directScattering *= scatter;
directMultiScattering *= scatter;
sunIndirectScattering *= scatter;
//////////////////////////////////////////
////// Cloud layer Positions
////// render Cloud layers and do blending orders
//////////////////////////////////////////
// first cloud layer
@ -483,42 +503,43 @@ vec4 renderClouds(
total_extinction *= layer2.a;
#endif
/// i know this looks confusing
/// it is changing blending order based on the players position relative to the clouds.
/// to keep it simple for myself, it all revolves around layer0, the lowest cloud layer.
/// for layer1, swap between back to front and front to back blending if you are above or below layer0
/// for layer2, swap between back to front and front to back blending if you are above or below layer1
// order DOES matter here.
// if(layer1_below_layer0){
/// blend the altostratus clouds first, so it is BEHIND all the cumulus clouds, if the player postion is below the cumulus clouds.
/// handle the case if one of the cloud layers is disabled.
#if !defined CloudLayer1 && defined CloudLayer2
if(below_Layer2) color = color * layer2.a + layer2.rgb;
#endif
#if defined CloudLayer1 && defined CloudLayer2
if(below_Layer2) layer1.rgb = layer2.rgb * layer1.a + layer1.rgb;
#endif
// color = mix(layer1.rgb, layer0.rgb, float(above_Layer1));
// color = mix(color * layer0.a + layer0.rgb, color * layer1.a + layer1.rgb, float(above_Layer1)); ;
// } else {
#if defined CloudLayer1 && defined CloudLayer2
if(below_Layer2) layer1.rgb = layer2.rgb * layer1.a + layer1.rgb;
#endif
/// blend the cumulus clouds together. swap the blending order from (BACK TO FRONT -> FRONT TO BACK) depending on the player position relative to the lowest cloud layer.
#if defined CloudLayer0 && defined CloudLayer1
color = mix(layer0.rgb, layer1.rgb, float(below_Layer0));
color = mix(color * layer1.a + layer1.rgb, color * layer0.a + layer0.rgb, float(below_Layer0));
#endif
#if !defined CloudLayer1 && defined CloudLayer2
if(below_Layer2) color = color * layer2.a + layer2.rgb;
#endif
/// handle the case of one of the cloud layers being disabled.
#if defined CloudLayer0 && !defined CloudLayer1
color = color * layer0.a + layer0.rgb;
#endif
#if !defined CloudLayer0 && defined CloudLayer1
color = color * layer1.a + layer1.rgb;
#endif
#if defined CloudLayer0 && defined CloudLayer1
color = mix(layer0.rgb, layer1.rgb, float(below_Layer0));
color = mix(color * layer1.a + layer1.rgb, color * layer0.a + layer0.rgb, float(below_Layer0));
#endif
#if defined CloudLayer0 && !defined CloudLayer1
color = color * layer0.a + layer0.rgb;
#endif
#if !defined CloudLayer0 && defined CloudLayer1
color = color * layer1.a + layer1.rgb;
#endif
#ifdef CloudLayer2
if(!below_Layer2) color = color * layer2.a + layer2.rgb;
#endif
// }
/// blend the altostratus clouds last, so it is IN FRONT of all the cumulus clouds when the player position is above them.
#ifdef CloudLayer2
if(!below_Layer2) color = color * layer2.a + layer2.rgb;
#endif
return vec4(color, total_extinction);
// return mix(vec4(color, total_extinction),vec4(0.0,0.0,0.0,1.0),exp(abs(approxdistance.y) * -1) * (1-clamp(1.0-max(cameraPosition.y - LAYER2_HEIGHT,0.0) / 1000.0 ,0.0,1.0)));
}
#endif
@ -562,11 +583,11 @@ float GetCloudShadow_VLFOG(vec3 WorldPos, vec3 WorldSpace_sunVec){
float shadow = 0.0;
#ifdef CloudLayer0
vec3 lowShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.2)) * max((CloudLayer0_height) - WorldPos.y,0.0) ;
vec3 lowShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.2)) * max((CloudLayer0_height+ 30) - WorldPos.y,0.0) ;
shadow += GetCumulusDensity(0, lowShadowStart, 0, CloudLayer0_height,CloudLayer0_height+100)*CloudLayer0_density;
#endif
#ifdef CloudLayer1
vec3 higherShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.2)) * max((CloudLayer1_height) - WorldPos.y,0.0) ;
vec3 higherShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.2)) * max((CloudLayer1_height+ 30) - WorldPos.y,0.0) ;
shadow += GetCumulusDensity(1,higherShadowStart, 0, CloudLayer1_height,CloudLayer1_height+100)*CloudLayer1_density;
#endif
#ifdef CloudLayer2