make VL fog exist when clouds are turned off

This commit is contained in:
Xonk 2023-06-14 18:42:33 -04:00
parent 06a764f437
commit b19c03d6b8
5 changed files with 78 additions and 79 deletions

View File

@ -902,7 +902,7 @@ void main() {
SSS = SubsurfaceScattering_sun(albedo, SHADOWBLOCKERDEPTBH, LabSSS, clamp(dot(np3, WsunVec),0.0,1.0)) ; SSS = SubsurfaceScattering_sun(albedo, SHADOWBLOCKERDEPTBH, LabSSS, clamp(dot(np3, WsunVec),0.0,1.0)) ;
// if (isEyeInWater == 0) SSS *= lightleakfix; // light leak fix if (isEyeInWater == 0) SSS *= lightleakfix; // light leak fix
#endif #endif

View File

@ -220,6 +220,7 @@ void main() {
gl_FragData[0] = clamp(VL_Fog,0.0,65000.); gl_FragData[0] = clamp(VL_Fog,0.0,65000.);
#endif #endif
} else { } else {
float dirtAmount = Dirt_Amount; float dirtAmount = Dirt_Amount;

View File

@ -112,7 +112,9 @@
#define CaveFog_amount 1 // [0 1 2 3 4 5 6 7 8 9 10 15 20 25] #define CaveFog_amount 1 // [0 1 2 3 4 5 6 7 8 9 10 15 20 25]
#define Cloud_Fog // render the VL clouds a second time along with VL fog so you can fly through it and stuff. expect a noticeable performance hit.
// ----- TIME OF DAY FOG ----- // // ----- TIME OF DAY FOG ----- //
#define TOD_Fog_mult 1.0 // [0.0 0.25 0.5 0.75 1.0 2.0 3.0 4.0 5.0 10.0 15.0 20.0 25.0 50.0 75.0 100.0] #define TOD_Fog_mult 1.0 // [0.0 0.25 0.5 0.75 1.0 2.0 3.0 4.0 5.0 10.0 15.0 20.0 25.0 50.0 75.0 100.0]
@ -304,7 +306,10 @@ const float shadowDistanceRenderMul = -1.0; //[-1.0 1.0] THIS WILL BREAK SUBSURF
#define Daily_Weather // different skies and fog for different days. #define Daily_Weather // different skies and fog for different days.
#ifdef VOLUMETRIC_CLOUDS #ifdef VOLUMETRIC_CLOUDS
#define Cloud_Fog // render the VL clouds a second time along with VL fog so you can fly through it and stuff. expect a noticeable performance hit.
#define CLOUDS_SHADOWS // Casts shadows from clouds on the world #define CLOUDS_SHADOWS // Casts shadows from clouds on the world
#ifdef CLOUDS_SHADOWS #ifdef CLOUDS_SHADOWS
#define VL_CLOUDS_SHADOWS // Casts shadows from clouds on VL #define VL_CLOUDS_SHADOWS // Casts shadows from clouds on VL
#endif #endif

View File

@ -215,7 +215,7 @@ vec4 renderClouds(
vec3 dV_view = normalize(fragpos.xyz); vec3 dV_view = normalize(fragpos.xyz);
dV_view.y += 0.05; // dV_view.y += 0.05;
vec3 dV_view2 = dV_view; vec3 dV_view2 = dV_view;
float mult2 = length(dV_view2); float mult2 = length(dV_view2);
@ -337,7 +337,7 @@ vec4 renderClouds(
// Assume fog color = sky gradient at long distance // Assume fog color = sky gradient at long distance
vec3 fogColor = skyFromTex(normView, colortex4)/150. * 5.0; vec3 fogColor = skyFromTex(normView, colortex4)/150. * 5.0;
float dist = max(cameraPosition.y+CumulusHeight,max(CumulusHeight,150))/(abs(normView.y)+0.001); float dist = max(cameraPosition.y+CumulusHeight,max(CumulusHeight,150))/(abs(normView.y)+0.001);
float fog = exp(dist / -5000.0 * (1.0+rainCloudwetness*8.)); float fog = exp(dist / -15000.0 * (1.0+rainCloudwetness*8.));
// if(IntersecTerrain) fog = 1.0; // if(IntersecTerrain) fog = 1.0;

View File

@ -146,7 +146,7 @@ vec4 getVolumetricRays(
/// really dumb lmao
vec4 InsideACloudFog( vec4 InsideACloudFog(
vec3 fragpos, vec3 fragpos,
vec2 Dither, vec2 Dither,
@ -154,10 +154,6 @@ vec4 InsideACloudFog(
vec3 MoonColor, vec3 MoonColor,
vec3 SkyColor vec3 SkyColor
){ ){
// #ifndef VOLUMETRIC_CLOUDS
// return vec4(0.0,0.0,0.0,1.0);
// #endif
float total_extinction = 1.0; float total_extinction = 1.0;
vec3 color = vec3(0.0); vec3 color = vec3(0.0);
@ -184,13 +180,13 @@ vec4 InsideACloudFog(
vec3 progress = start.xyz; vec3 progress = start.xyz;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
vec3 progress_view = vec3(0.0); vec3 progress_view = vec3(0.0);
float expFactor = 11.0; float expFactor = 11.0;
////// lighitng stuff ////// lighitng stuff
float shadowStep = 200.; float shadowStep = 200.;
vec3 dV_Sun = normalize(mat3(gbufferModelViewInverse)*sunVec)*shadowStep; vec3 dV_Sun = normalize(mat3(gbufferModelViewInverse)*sunVec)*shadowStep;
vec3 dV_Sun_small = dV_Sun/shadowStep;
float SdotV = dot(sunVec,normalize(fragpos)); float SdotV = dot(sunVec,normalize(fragpos));
@ -201,22 +197,23 @@ vec4 InsideACloudFog(
vec3 Fog_SkyCol = SkyColor; vec3 Fog_SkyCol = SkyColor;
vec3 Fog_SunCol = SunColor; vec3 Fog_SunCol = SunColor;
// if(dV_Sun.y/shadowStep < -0.1) dV_Sun = -dV_Sun;
float mieDay = phaseg(SdotV, 0.75) * 3.14;
float mieDayMulti = phaseg(SdotV, 0.35) * 2;
vec3 sunContribution = SunColor * mieDay;
vec3 sunContributionMulti = SunColor * mieDayMulti ;
float mieNight = (phaseg(-SdotV,0.8) + phaseg(-SdotV, 0.35)*4);
vec3 moonContribution = MoonColor * mieNight;
float timing = 1.0 - clamp(pow(abs(dV_Sun.y)/150.0,2.0),0.0,1.0);
///////// fog part float mieDay = phaseg(SdotV, 0.75) * 3.14;
float mieDayMulti = phaseg(SdotV, 0.35) * 2;
vec3 sunContribution = SunColor * mieDay;
vec3 sunContributionMulti = SunColor * mieDayMulti ;
float mieNight = (phaseg(-SdotV,0.8) + phaseg(-SdotV, 0.35)*4);
vec3 moonContribution = MoonColor * mieNight;
float timing = 1.0 - clamp(pow(abs(dV_Sun.y)/150.0,2.0),0.0,1.0);
//Mie phase + somewhat simulates multiple scattering (Horizon zero down cloud approx) //Mie phase + somewhat simulates multiple scattering (Horizon zero down cloud approx)
float mie = phaseg(SdotV,0.7)*5.0 + 1.0; float mie = phaseg(SdotV,0.7)*5.0 + 1.0;
@ -234,54 +231,55 @@ vec4 InsideACloudFog(
float mu = 1.0; float mu = 1.0;
float muS = mu; float muS = mu;
#ifdef Cumulus float Shadows_for_Fog = 0.0;
for (int i=0;i<VL_SAMPLES;i++) {
float d = (pow(expFactor, float(i+Dither.x)/float(VL_SAMPLES))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+Dither.x)/float(VL_SAMPLES)) * log(expFactor) / float(VL_SAMPLES)/(expFactor-1.0);
progress = start.xyz + d*dV;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
//project into biased shadowmap space for (int i=0;i<VL_SAMPLES;i++) {
float distortFactor = calcDistort(progress.xy);
vec3 pos = vec3(progress.xy*distortFactor, progress.z);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){ float d = (pow(expFactor, float(i+Dither.x)/float(VL_SAMPLES))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5; float dd = pow(expFactor, float(i+Dither.x)/float(VL_SAMPLES)) * log(expFactor) / float(VL_SAMPLES)/(expFactor-1.0);
sh = shadow2D( shadow, pos).x; progress = start.xyz + d*dV;
} progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
//project into biased shadowmap space
float distortFactor = calcDistort(progress.xy);
vec3 pos = vec3(progress.xy*distortFactor, progress.z);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
float cloudhsadow = sh; Shadows_for_Fog = sh;
#ifdef VL_CLOUDS_SHADOWS #ifdef VL_CLOUDS_SHADOWS
cloudhsadow = sh * GetCloudShadow_VLFOG(progressW); Shadows_for_Fog = sh * GetCloudShadow_VLFOG(progressW);
#endif #endif
float densityVol = cloudVol(progressW); float densityVol = cloudVol(progressW);
//Water droplets(fog) //Water droplets(fog)
float density = densityVol*ATMOSPHERIC_DENSITY*mu*300.; float density = densityVol*ATMOSPHERIC_DENSITY*mu*300.;
//Just air //Just air
vec2 airCoef = exp(-max(progressW.y-SEA_LEVEL,0.0)/vec2(8.0e3, 1.2e3)*vec2(6.,7.0)) * 24 * Haze_amount; vec2 airCoef = exp(-max(progressW.y-SEA_LEVEL,0.0)/vec2(8.0e3, 1.2e3)*vec2(6.,7.0)) * 24 * Haze_amount;
//Pbr for air, yolo mix between mie and rayleigh for water droplets //Pbr for air, yolo mix between mie and rayleigh for water droplets
vec3 rL = rC*airCoef.x; vec3 rL = rC*airCoef.x;
vec3 m = (airCoef.y+density)*mC; vec3 m = (airCoef.y+density)*mC;
vec3 DirectLight = (Fog_SunCol*cloudhsadow) * (rayL*rL+m*mie); vec3 DirectLight = (Fog_SunCol*Shadows_for_Fog) * (rayL*rL+m*mie);
vec3 AmbientLight = Fog_SkyCol * m; vec3 AmbientLight = Fog_SkyCol * m;
vec3 AtmosphericFog = Fog_SkyCol * (rL+m) ; vec3 AtmosphericFog = Fog_SkyCol * (rL+m) ;
// extra fog effects // extra fog effects
vec3 rainRays = ((Fog_SunCol/5)*cloudhsadow) * (rayL*phaseg(SdotV,0.5)) * clamp(pow(WsunVec.y,5)*2,0.0,1.0) * rainStrength * RainFog_amount; vec3 rainRays = ((Fog_SunCol/5)*Shadows_for_Fog) * (rayL*phaseg(SdotV,0.5)) * clamp(pow(WsunVec.y,5)*2,0.0,1.0) * rainStrength * RainFog_amount;
vec3 CaveRays = (Fog_SunCol*cloudhsadow) * phaseg(SdotV,0.7) * 0.001 * (1.0 - max(eyeBrightnessSmooth.y,0)/240.); vec3 CaveRays = (Fog_SunCol*Shadows_for_Fog) * phaseg(SdotV,0.7) * 0.001 * (1.0 - max(eyeBrightnessSmooth.y,0)/240.);
vec3 vL0 = (DirectLight + AmbientLight + AtmosphericFog + rainRays ) * max(eyeBrightnessSmooth.y,0)/240. + CaveRays ; vec3 vL0 = (DirectLight + AmbientLight + AtmosphericFog + rainRays ) * max(eyeBrightnessSmooth.y,0)/240. + CaveRays ;
color += (vL0 - vL0 * exp(-(rL+m)*dd*dL)) / ((rL+m)+0.00000001)*total_extinction;
total_extinction *= dot(clamp(exp(-(rL+m)*dd*dL),0.0,1.0), vec3(0.333333));
color += (vL0 - vL0 * exp(-(rL+m)*dd*dL)) / ((rL+m)+0.00000001)*total_extinction;
total_extinction *= dot(clamp(exp(-(rL+m)*dd*dL),0.0,1.0), vec3(0.333333));
progress_view = progressW; progress_view = progressW;
@ -323,12 +321,7 @@ vec4 InsideACloudFog(
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;
}
#endif
return vec4(color, total_extinction); return vec4(color, total_extinction);
} }