FIX stochastic shadows on IRIS. add filter option for SSAO and all SSS types. imrpove fog upsampling (even when DH is being used). ambient light is more consistent across all types of weather. tweak cloud lighting.

This commit is contained in:
Xonk
2024-02-16 21:28:13 -05:00
parent f99a3c33b5
commit 088b8206c1
19 changed files with 696 additions and 241 deletions

View File

@ -165,13 +165,16 @@ vec4 GetVolumetricFog(
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 directMultiScattering = LightSourceColor * mieDayMulti * 3.14;
vec3 sunIndirectScattering = LightSourceColor * phaseg(dot(mat3(gbufferModelView)*vec3(0,1,0),normalize(viewPosition)), 0.5) * 3.14;
#endif
float RLmult = 3.0;
#ifdef DISTANT_HORIZONS
RLmult = 1.0;
float atmosphereMult = 1.0;
#else
float atmosphereMult = 2.0;
#endif
float expFactor = 11.0;
@ -181,6 +184,8 @@ vec4 GetVolumetricFog(
progress = start.xyz + d*dV;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
// float curvature = 1-exp(-25*pow(clamp(1.0 - length(progressW - cameraPosition)/(32*80),0.0,1.0),2));
//project into biased shadowmap space
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(progress.xy);
@ -198,6 +203,7 @@ vec4 GetVolumetricFog(
float sh2 = sh;
#ifdef VL_CLOUDS_SHADOWS
// if(clamp(progressW.y - CloudLayer1_height,0.0,1.0) < 1.0 && clamp(progressW.y-50,0.0,1.0) > 0.0)
sh *= GetCloudShadow_VLFOG(progressW, WsunVec);
#endif
@ -214,18 +220,18 @@ vec4 GetVolumetricFog(
///// ----- main fog lighting
//Just air
vec2 airCoef = exp(-max(progressW.y - SEA_LEVEL, 0.0) / vec2(8.0e3, 1.2e3) * vec2(6.,7.0)) * 24.0 * Haze_amount * clamp(CloudLayer0_height - progressW.y + max(eyeAltitude-(CloudLayer0_height-50),0),0.0,1.0);
vec2 airCoef = exp(-max(progressW.y - SEA_LEVEL, 0.0) / vec2(8.0e3, 1.2e3) * vec2(6.,7.0)) * (atmosphereMult * 24.0) * Haze_amount * clamp(CloudLayer0_height - progressW.y + max(eyeAltitude-(CloudLayer0_height-50),0),0.0,1.0);
//Pbr for air, yolo mix between mie and rayleigh for water droplets
vec3 rL = rC*airCoef.x;
vec3 m = (airCoef.y+density) * mC;
#ifdef PER_BIOME_ENVIRONMENT
vec3 Atmosphere = mix(skyLightPhased, biomeDirect, maxDistance) * (rL*RLmult + m); // not pbr so just make the atmosphere also dense fog heh
vec3 DirectLight = mix(LightSourcePhased, biomeIndirect, maxDistance) * sh * ((rL*RLmult)*rayL + m);
vec3 Atmosphere = mix(skyLightPhased, biomeDirect, maxDistance) * (rL + m); // not pbr so just make the atmosphere also dense fog heh
vec3 DirectLight = mix(LightSourcePhased, biomeIndirect, maxDistance) * sh * (rL*rayL + m);
#else
vec3 Atmosphere = skyLightPhased * (rL*RLmult + m); // not pbr so just make the atmosphere also dense fog heh
vec3 DirectLight = LightSourcePhased * sh * ((rL*RLmult)*rayL + m);
vec3 Atmosphere = skyLightPhased * (rL + m); // not pbr so just make the atmosphere also dense fog heh
vec3 DirectLight = LightSourcePhased * sh * (rL*rayL + m);
#endif
vec3 Lightning = Iris_Lightningflash_VLfog(progressW-cameraPosition, lightningBoltPosition.xyz) * (rL + m);
@ -240,51 +246,57 @@ vec4 GetVolumetricFog(
//////////////////////////////////////////
///// ----- cloud part
//////////////////////////////////////////
// curvature = clamp(1.0 - length(progressW - cameraPosition)/(32*128),0.0,1.0);
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;
float DUAL_DENSITY = otherlayer > 0.0 ? CloudLayer0_density : CloudLayer1_density;
float Density = otherlayer > 0.0 ? CloudLayer0_density : CloudLayer1_density;
float cumulus = GetCumulusDensity(-1, progressW, 1, DUAL_MIN_HEIGHT, DUAL_MAX_HEIGHT);
if(clamp(progressW.y - DUAL_MAX_HEIGHT,0.0,1.0) < 1.0 && clamp(progressW.y - DUAL_MIN_HEIGHT,0.0,1.0) > 0.0){
float BASE_FADE = Density * clamp(exp( (progressW.y - (DUAL_MAX_HEIGHT - 75)) / 9.0 ),0.0,1.0);
float DUAL_MIN_HEIGHT_2 = otherlayer > 0.0 ? CloudLayer0_height : CloudLayer1_height;
float DUAL_MAX_HEIGHT_2 = DUAL_MIN_HEIGHT + 100.0;
if(cumulus > 1e-5){
float muE = cumulus * BASE_FADE ;
float directLight = 0.0;
for (int j=0; j < 3; j++){
float cumulus = GetCumulusDensity(-1, progressW, 1, CloudLayer0_height, CloudLayer1_height);
float fadedDensity = DUAL_DENSITY * clamp(exp( (progressW.y - (DUAL_MAX_HEIGHT - 75)) / 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;
float muE = cumulus*fadedDensity;
float directLight = 0.0;
for (int j=0; j < 3; j++){
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) * DUAL_DENSITY;
directLight += shadow;
}
#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
#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
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*sh2, directMultiScattering*sh2, 1.0);
#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);
directLight += shadow;
}
/// shadows cast from one layer to another
/// large cumulus -> small cumulus
#if defined CloudLayer1 && defined CloudLayer0
if(otherlayer > 0.0) directLight += LAYER1_DENSITY * 2.0 * GetCumulusDensity(1, progressW + dV_Sun/abs(dV_Sun.y) * max((LAYER1_minHEIGHT+70*dither.y) - progressW.y,0.0), 0, LAYER1_minHEIGHT, LAYER1_maxHEIGHT);
#endif
// // altostratus -> cumulus
// #ifdef CloudLayer2
// vec3 HighAlt_shadowPos = rayProgress + dV_Sun/abs(dV_Sun.y) * max(LAYER2_HEIGHT - rayProgress.y,0.0);
// float HighAlt_shadow = GetAltostratusDensity(HighAlt_shadowPos) * CloudLayer2_density;
// directLight += HighAlt_shadow;
// #endif
float skyScatter = clamp(((DUAL_MAX_HEIGHT - 20 - progressW.y) / 275.0) * (0.5+DUAL_DENSITY),0.0,1.0);
float distantfade = 1- exp( -10*pow(clamp(1.0 - length(progressW - cameraPosition)/(32*65),0.0,1.0),2));
vec3 cloudlighting = DoCloudLighting(muE, cumulus, SkyLightColor, skyScatter, directLight, directScattering*sh2, directMultiScattering*sh2, 1);
color += max(cloudlighting - cloudlighting*exp(-muE*dd*dL),0.0) * absorbance;
absorbance *= max(exp(-muE*dd*dL),0.0);
}
#endif
if (min(dot(absorbance,vec3(0.335)),1.0) < 1e-5) break;
}
return vec4(color, min(dot(absorbance,vec3(0.335)),1.0));
}