2023-01-12 15:00:14 -05:00
#ifdef HQ_CLOUDS
2023-01-12 15:28:19 -05:00
int maxIT_clouds = minRayMarchSteps;
int maxIT = maxRayMarchSteps;
2023-01-12 15:00:14 -05:00
#else
2023-01-12 15:28:19 -05:00
int maxIT_clouds = minRayMarchStepsLQ;
int maxIT = maxRayMarchStepsLQ;
2023-01-12 15:00:14 -05:00
#endif
#ifdef HQ_CLOUDS
const int cloudLoD = cloud_LevelOfDetail;
const int cloudShadowLoD = cloud_ShadowLevelOfDetail;
#else
const int cloudLoD = cloud_LevelOfDetailLQ;
const int cloudShadowLoD = cloud_ShadowLevelOfDetailLQ;
#endif
2023-10-07 22:18:20 -04:00
// uniform float viewHeight;
// uniform float viewWidth;
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
uniform int worldTime;
2023-01-12 15:00:14 -05:00
#define WEATHERCLOUDS
#include "/lib/climate_settings.glsl"
2023-10-22 15:57:26 -04:00
2023-06-01 17:41:06 -04:00
float CumulusHeight = Cumulus_height;
2023-04-16 16:18:26 -04:00
float MaxCumulusHeight = CumulusHeight + 100;
float AltostratusHeight = 2000;
2023-01-12 15:00:14 -05:00
2023-06-16 00:01:03 -04:00
2023-04-16 16:18:26 -04:00
float rainCloudwetness = rainStrength;
2023-06-18 19:10:13 -04:00
// float cloud_movement = frameTimeCounter * Cloud_Speed ;
float cloud_movement = (worldTime / 24.0) * Cloud_Speed ;
2023-01-12 15:00:14 -05:00
//3D noise from 2d texture
float densityAtPos(in vec3 pos){
pos /= 18.;
pos.xz *= 0.5;
vec3 p = floor(pos);
vec3 f = fract(pos);
vec2 uv = p.xz + f.xz + p.y * vec2(0.0,193.0);
vec2 coord = uv / 512.0;
//The y channel has an offset to avoid using two textures fetches
vec2 xy = texture2D(noisetex, coord).yx;
return mix(xy.r,xy.g, f.y);
}
float cloudCov(in vec3 pos,vec3 samplePos){
2023-01-12 15:28:19 -05:00
2023-04-27 15:09:58 -04:00
float CloudLarge = texture2D(noisetex, (samplePos.xz + cloud_movement) / 5000 ).b;
float CloudSmall = texture2D(noisetex, (samplePos.xz - cloud_movement) / 500 ).r;
2023-01-12 15:28:19 -05:00
2023-10-07 22:18:20 -04:00
2023-06-01 17:41:06 -04:00
float Topshape = max(pos.y - (MaxCumulusHeight - 75), 0.0) / 200;
2023-04-16 16:18:26 -04:00
Topshape += max(exp((pos.y - MaxCumulusHeight) / 10.0 ), 0.0) ;
2023-01-12 15:28:19 -05:00
2023-05-09 19:08:34 -04:00
float coverage = abs(pow(CloudLarge,1)*2.0 - 1.2)*0.5 - (1.0-CloudSmall);
float FinalShape = DailyWeather_Cumulus(coverage) - Topshape;
2023-01-12 15:28:19 -05:00
2023-04-16 16:18:26 -04:00
// cap the top and bottom for reasons
2023-10-07 22:18:20 -04:00
float capbase = sqrt(max((CumulusHeight+12.5) - pos.y, 0.0)/50) * (1-rainStrength);
2023-04-16 16:18:26 -04:00
float captop = max(pos.y - MaxCumulusHeight, 0.0);
2023-10-07 22:18:20 -04:00
FinalShape = max(FinalShape - capbase - captop , 0.0);
2023-01-12 15:28:19 -05:00
2023-05-09 19:08:34 -04:00
return FinalShape;
2023-01-12 15:00:14 -05:00
}
2023-04-16 16:18:26 -04:00
2023-01-12 15:00:14 -05:00
//Erode cloud with 3d Perlin-worley noise, actual cloud value
float cloudVol(in vec3 pos,in vec3 samplePos,in float cov, in int LoD){
float noise = 0.0 ;
float totalWeights = 0.0;
float pw = log(fbmPower1);
float pw2 = log(fbmPower2);
2023-04-16 16:18:26 -04:00
samplePos.xz -= cloud_movement/4;
2023-07-21 20:18:12 -04:00
2023-04-27 15:09:58 -04:00
samplePos.xz += pow( max(pos.y - (CumulusHeight+20), 0.0) / 20.0,1.50);
2023-04-16 16:18:26 -04:00
noise += 1.0-densityAtPos(samplePos * 200.) ;
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
float smallnoise = densityAtPos(samplePos * 600.);
if (LoD > 0) noise += ((1-smallnoise) - max(0.15 - abs(smallnoise * 2.0 - 0.55) * 0.5,0.0)*1.5) * 0.6 * sqrt(noise);
2023-04-16 16:18:26 -04:00
noise *= 1.0-cov;
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
2023-01-12 15:00:14 -05:00
noise = noise*noise;
2023-04-16 16:18:26 -04:00
float cloud = max(cov - noise*noise*fbmAmount,0.0);
2023-01-12 15:00:14 -05:00
return cloud;
}
2023-04-16 16:18:26 -04:00
float GetCumulusDensity(in vec3 pos, in int LoD){
2023-01-12 15:00:14 -05:00
2023-01-12 15:28:19 -05:00
vec3 samplePos = pos*vec3(1.0,1./48.,1.0)/4;
2023-10-07 22:18:20 -04:00
2023-01-12 15:00:14 -05:00
float coverageSP = cloudCov(pos,samplePos);
if (coverageSP > 0.001) {
if (LoD < 0) return max(coverageSP - 0.27*fbmAmount,0.0);
2023-04-16 16:18:26 -04:00
return cloudVol(pos,samplePos,coverageSP,LoD);
2023-01-12 15:00:14 -05:00
} else return 0.0;
}
2023-04-16 16:18:26 -04:00
float GetAltostratusDensity(vec3 pos){
2023-01-12 15:00:14 -05:00
2023-04-27 15:09:58 -04:00
float large = texture2D(noisetex, (pos.xz + cloud_movement)/100000. ).b;
float small = texture2D(noisetex, (pos.xz - cloud_movement)/10000. - vec2(-large,1-large)/5).b;
2023-10-07 22:18:20 -04:00
2023-04-16 16:18:26 -04:00
float shape = (small + pow((1.0-large),2.0))/2.0;
2023-05-09 19:08:34 -04:00
2023-10-07 22:18:20 -04:00
// float erode = 1-texture2D(noisetex, (pos.xz / ((1-small)*0.5+1.0) - cloud_movement)/1000. + vec2(-small,1-small)/5).b;
// float shape = max((small + pow((1.0-large),2.0))/2.0 - erode*0.05,0.0);
2023-05-09 19:08:34 -04:00
float Coverage; float Density;
2023-06-11 17:28:54 -04:00
DailyWeather_Alto(Coverage, Density);
2023-01-12 15:00:14 -05:00
2023-05-09 19:08:34 -04:00
shape = pow(max(shape + Coverage - 0.5,0.0),2.0);
shape *= Density;
2023-01-12 15:00:14 -05:00
2023-04-16 16:18:26 -04:00
return shape;
2023-01-12 15:00:14 -05:00
}
2023-10-07 22:18:20 -04:00
#ifndef CLOUDSHADOWSONLY
uniform sampler2D colortex4;//Skybox
//Mie phase function
float phaseg(float x, float g){
float gg = g * g;
return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) / 3.14;
}
2023-04-16 16:18:26 -04:00
2023-01-12 15:00:14 -05:00
// random magic number bullshit go!
vec3 Cloud_lighting(
float CloudShape,
float SkyShadowing,
float SunShadowing,
float MoonShadowing,
vec3 SkyColors,
vec3 sunContribution,
vec3 sunContributionMulti,
vec3 moonContribution,
2023-04-16 16:18:26 -04:00
float AmbientShadow,
2023-05-03 21:29:53 -04:00
int cloudType,
2023-06-10 16:49:06 -04:00
vec3 pos,
float time
2023-01-12 15:00:14 -05:00
){
2023-04-16 16:18:26 -04:00
// float powder = 1.0 - exp((CloudShape*CloudShape) * -800);
2023-10-07 22:18:20 -04:00
float powder = 1.0 - exp(CloudShape * -10);
2023-04-16 16:18:26 -04:00
float lesspowder = powder*0.4+0.6;
2023-01-12 15:28:19 -05:00
2023-06-27 00:18:41 -04:00
vec3 skyLighting = SkyColors;
2023-05-09 19:08:34 -04:00
2023-05-03 21:29:53 -04:00
#ifdef Altostratus
2023-06-11 17:28:54 -04:00
/// a special conditon where scattered light exiting altocumulus clouds come down onto the cumulus clouds below.
float cov = 0.0;
float den = 0.0;
DailyWeather_Alto(cov, den);
2023-05-03 21:29:53 -04:00
2023-10-07 22:18:20 -04:00
skyLighting += sunContributionMulti * 0.3 * exp2(AmbientShadow * SkyShadowing * -20) * clamp( 1.0 - pow( abs(den - 0.35) * 4.0 , 5.0) ,0.0,1.0) * cov;
#endif
2023-01-12 15:28:19 -05:00
2023-10-07 22:18:20 -04:00
// skyLighting *= (1.0 - sqrt(exp2((1.0-SkyShadowing) * AmbientShadow * -10))) * lesspowder ;
skyLighting *= exp2((AmbientShadow*AmbientShadow) * SkyShadowing * -35) * lesspowder;
2023-01-12 15:28:19 -05:00
2023-01-12 15:00:14 -05:00
2023-06-01 17:41:06 -04:00
2023-10-07 22:18:20 -04:00
vec3 sunLighting = exp(SunShadowing * -15 + powder ) * sunContribution ;
sunLighting += exp(SunShadowing * -4) * sunContributionMulti * (powder*0.7+0.3);
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
vec3 moonLighting = exp(MoonShadowing * -7 + powder) * moonContribution;
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
if(cloudType == 1){
skyLighting = SkyColors * exp(-sqrt(SkyShadowing)) * lesspowder;
sunLighting = exp(SunShadowing * -5 ) * sunContribution;
sunLighting += exp(SunShadowing * -1) * sunContributionMulti * powder;
}
2023-01-12 15:28:19 -05:00
2023-10-07 22:18:20 -04:00
return skyLighting + moonLighting + sunLighting ;
2023-01-12 15:00:14 -05:00
}
vec4 renderClouds(
2023-04-16 16:18:26 -04:00
vec3 FragPosition,
vec2 Dither,
vec3 SunColor,
vec3 MoonColor,
vec3 SkyColor
2023-01-12 15:00:14 -05:00
){
#ifndef VOLUMETRIC_CLOUDS
return vec4(0.0,0.0,0.0,1.0);
#endif
2023-10-07 22:18:20 -04:00
2023-01-12 15:00:14 -05:00
float total_extinction = 1.0;
2023-04-16 16:18:26 -04:00
vec3 color = vec3(0.0);
2023-01-12 15:00:14 -05:00
//project pixel position into projected shadowmap space
2023-10-07 22:18:20 -04:00
vec4 viewPos = normalize(gbufferModelViewInverse*vec4(FragPosition,1.0));
vec3 eyeplayepos = normalize(mat3(gbufferModelViewInverse) * FragPosition.xyz);
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
maxIT_clouds = int(clamp(maxIT_clouds / sqrt(exp2(viewPos.y)),0.0, maxIT));
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
vec3 dV_view = normalize(viewPos.xyz);
vec3 dV_view2 = dV_view;
2023-01-12 15:00:14 -05:00
2023-06-14 18:45:54 -04:00
dV_view.y += 0.05;
2023-01-12 15:00:14 -05:00
//setup ray to start at the start of the cloud plane and end at the end of the cloud plane
2023-04-16 16:18:26 -04:00
dV_view *= max(MaxCumulusHeight - CumulusHeight, 0.0)/abs(dV_view.y)/maxIT_clouds;
2023-10-07 22:18:20 -04:00
2023-04-16 16:18:26 -04:00
float mult = length(dV_view);
2023-01-12 15:28:19 -05:00
2023-04-16 16:18:26 -04:00
// i want the samples to stay at one point in the world, but as the height coordinates go negative everything goes insideout, so this is a work around....
float startFlip = mix(max(cameraPosition.y - MaxCumulusHeight,0.0), max(CumulusHeight-cameraPosition.y,0), clamp(dV_view.y,0,1));
2023-10-07 22:18:20 -04:00
vec3 progress_view = dV_view*Dither.x + cameraPosition + (dV_view/abs(dV_view.y))*startFlip ;
2023-01-12 15:00:14 -05:00
2023-04-16 16:18:26 -04:00
// thank you emin for this world interseciton thing
// float lViewPosM = length(FragPosition) < far * 1.5 ? length(FragPosition) - 1.0 : 1000000000.0;
// bool IntersecTerrain = false;
2023-10-07 22:18:20 -04:00
////// lighting stuff
2023-01-12 15:00:14 -05:00
float shadowStep = 200.;
2023-10-07 22:18:20 -04:00
// vec3 dV_Sun = normalize(mat3(gbufferModelViewInverse)*sunVec)*shadowStep;
vec3 dV_Sun = WsunVec*shadowStep;
// vec3 dV_Sun_small = dV_Sun/shadowStep;
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
float SdotV = dot(mat3(gbufferModelView)*WsunVec,normalize(FragPosition));
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
SkyColor *= clamp(abs(dV_Sun.y)/100.,0.5,1.0);
2023-04-16 16:18:26 -04:00
SunColor = SunColor * clamp(dV_Sun.y ,0.0,1.0);
MoonColor *= clamp(-dV_Sun.y,0.0,1.0);
2023-01-12 15:00:14 -05:00
2023-10-20 21:24:50 -04:00
#ifdef ambientLight_only
SunColor = vec3(0.0);
MoonColor = vec3(0.0);
#endif
2023-04-16 16:18:26 -04:00
if(dV_Sun.y/shadowStep < -0.1) dV_Sun = -dV_Sun;
2023-06-01 17:41:06 -04:00
2023-10-07 22:18:20 -04:00
float mieDay = phaseg(SdotV, 0.75);
float mieDayMulti = (phaseg(SdotV, 0.35) + phaseg(-SdotV, 0.35) * 0.5) ;
2023-01-12 15:28:19 -05:00
2023-10-07 22:18:20 -04:00
vec3 sunContribution = SunColor * mieDay * 3.14;
vec3 sunContributionMulti = SunColor * mieDayMulti * 4.0;
2023-01-12 15:00:14 -05:00
2023-06-10 16:49:06 -04:00
float mieNight = (phaseg(-SdotV,0.8) + phaseg(-SdotV, 0.35)*4);
2023-04-16 16:18:26 -04:00
vec3 moonContribution = MoonColor * mieNight;
2023-06-01 17:41:06 -04:00
2023-06-10 16:49:06 -04:00
float timing = 1.0 - clamp(pow(abs(dV_Sun.y)/150.0,2.0),0.0,1.0);
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
2023-06-22 21:00:42 -04:00
2023-04-16 16:18:26 -04:00
#ifdef Cumulus
2023-10-07 22:18:20 -04:00
// float shadowStepSize[3] = float[](
// 0.05,
// 0.25 + Dither.y*0.1,
// 0.50 + Dither.y*0.1
// );
2023-04-16 16:18:26 -04:00
for(int i=0;i<maxIT_clouds;i++) {
2023-10-07 22:18:20 -04:00
2023-04-16 16:18:26 -04:00
// IntersecTerrain = length(progress_view - cameraPosition) > lViewPosM;
// if(IntersecTerrain) break;
2023-10-07 22:18:20 -04:00
float cumulus = GetCumulusDensity(progress_view, 1) ;
// cumulus = max(cumulus - (1-texture2D(noisetex, (eyeplayepos + cameraPosition / 500).xz*10).b)*0.1, 0.0 );
2023-06-01 17:41:06 -04:00
float alteredDensity = Cumulus_density * clamp(exp( (progress_view.y - (MaxCumulusHeight - 75)) / 9.0 ),0.0,1.0);
2023-01-12 15:00:14 -05:00
2023-04-16 16:18:26 -04:00
if(cumulus > 1e-5){
float muE = cumulus*alteredDensity;
2023-01-12 15:00:14 -05:00
2023-04-16 16:18:26 -04:00
float Sunlight = 0.0;
float MoonLight = 0.0;
2023-05-03 21:29:53 -04:00
for (int j=0; j < 3; j++){
2023-10-07 22:18:20 -04:00
// vec3 shadowSamplePos = progress_view + dV_Sun * (shadowStepSize[j] + Dither.y*shadowdither[j]);
// float shadow = GetCumulusDensity(shadowSamplePos, max(1-j,0)) * Cumulus_density;
2023-05-03 21:29:53 -04:00
2023-10-07 22:18:20 -04:00
vec3 shadowSamplePos = progress_view + dV_Sun * (0.1 + j * (0.1 + Dither.y*0.05));
2023-04-16 16:18:26 -04:00
float shadow = GetCumulusDensity(shadowSamplePos, 0) * Cumulus_density;
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
Sunlight += shadow;
2023-04-16 16:18:26 -04:00
MoonLight += shadow;
2023-01-12 15:00:14 -05:00
}
2023-04-16 16:18:26 -04:00
#ifdef Altostratus
// cast a shadow from higher clouds onto lower clouds
vec3 HighAlt_shadowPos = progress_view + dV_Sun/abs(dV_Sun.y) * max(AltostratusHeight - progress_view.y,0.0);
2023-05-09 19:08:34 -04:00
float HighAlt_shadow = GetAltostratusDensity(HighAlt_shadowPos);
2023-04-16 16:18:26 -04:00
Sunlight += HighAlt_shadow;
#endif
2023-06-01 17:41:06 -04:00
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
// float ambientlightshadow = 1.0 - clamp(exp((progress_view.y - (MaxCumulusHeight - 50)) / 100.0),0.0,1.0) ;
float ambientlightshadow = clamp((MaxCumulusHeight - progress_view.y - 50) / 100.0, 0.0,1.0);
vec3 S = Cloud_lighting(muE, cumulus*Cumulus_density, Sunlight, MoonLight, SkyColor, sunContribution, sunContributionMulti, moonContribution, ambientlightshadow, 0, progress_view, WsunVec.y);
#ifndef TEST
S += Iris_Lightningflash_VLcloud(progress_view - cameraPosition, lightningBoltPosition.xyz) * ambientlightshadow * exp(muE * -10.0) ;
#endif
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
vec3 Sint = (S - S * exp(-mult*muE)) / max(muE,1e-5);
2023-04-16 16:18:26 -04:00
color += max(muE*Sint*total_extinction,0.0);
2023-10-07 22:18:20 -04:00
total_extinction *= max(exp(-mult*muE),0.0);
2023-01-12 15:00:14 -05:00
if (total_extinction < 1e-5) break;
2023-04-16 16:18:26 -04:00
}
progress_view += dV_view;
2023-01-12 15:00:14 -05:00
}
2023-04-16 16:18:26 -04:00
#endif
#ifdef Altostratus
if (max(AltostratusHeight-cameraPosition.y,0.0)/max(normalize(dV_view).y,0.0) / 100000.0 < AltostratusHeight) {
vec3 progress_view_high = dV_view2 + cameraPosition + dV_view2/dV_view2.y * max(AltostratusHeight-cameraPosition.y,0.0);
2023-05-09 19:08:34 -04:00
float altostratus = GetAltostratusDensity(progress_view_high);
2023-01-12 15:00:14 -05:00
2023-04-16 16:18:26 -04:00
float Sunlight = 0.0;
float MoonLight = 0.0;
2023-01-12 15:00:14 -05:00
2023-04-16 16:18:26 -04:00
if(altostratus > 1e-5){
for (int j = 0; j < 2; j++){
2023-10-07 22:18:20 -04:00
vec3 shadowSamplePos_high = progress_view_high + (dV_Sun * (1.0 - abs(WsunVec.y))) * (1 + j + Dither.y);
2023-05-09 19:08:34 -04:00
float shadow = GetAltostratusDensity(shadowSamplePos_high);
2023-10-07 22:18:20 -04:00
Sunlight += shadow / (1 + j);
// vec3 shadowSamplePos_high = progress_view_high + dV_Sun * float(j+Dither.y);
// float shadow = GetAltostratusDensity(shadowSamplePos_high);
// Sunlight += shadow;
2023-04-16 16:18:26 -04:00
}
2023-06-10 16:49:06 -04:00
vec3 S = Cloud_lighting(altostratus, altostratus, Sunlight, MoonLight, SkyColor, sunContribution, sunContributionMulti, moonContribution, 1, 1, progress_view_high, timing);
2023-01-12 15:00:14 -05:00
2023-10-07 22:18:20 -04:00
vec3 Sint = (S - S * exp(-mult*altostratus)) / max(altostratus,1e-5);
2023-04-16 16:18:26 -04:00
color += max(altostratus*Sint*total_extinction,0.0);
2023-10-07 22:18:20 -04:00
total_extinction *= max(exp(-mult*altostratus),0.0);
2023-04-16 16:18:26 -04:00
}
2023-01-12 15:00:14 -05:00
}
#endif
2023-04-16 16:18:26 -04:00
vec3 normView = normalize(dV_view);
2023-10-07 22:18:20 -04:00
2023-01-12 15:00:14 -05:00
// Assume fog color = sky gradient at long distance
2023-10-07 22:18:20 -04:00
vec4 fogColor = vec4(skyFromTex(normView, colortex4)/30.0, 0.0);
float fog = clamp(abs(max(cameraPosition.y, 255.0) + MaxCumulusHeight) / max(abs(CumulusHeight-cameraPosition.y),0.00001) * abs(normView.y/1.5),0,1);
// fog = pow(1.0 - exp(fog * -(5 - rainStrength*3)),2.0);
fog = 1.0 - clamp(exp((fog*fog) * -5.0),0.0,1.0);
// fog = 1.0;
// if(IntersecTerrain) fog = 1.0;
// return vec4(vec3(fog),0.0);
return mix(fogColor, vec4(color, total_extinction), clamp(fog,0.0,1.0));
2023-01-12 15:00:14 -05:00
}
2023-04-16 16:18:26 -04:00
2023-10-07 22:18:20 -04:00
#endif
2023-06-01 17:41:06 -04:00
2023-10-07 22:18:20 -04:00
float GetCloudShadow(vec3 feetPlayerPos){
#ifdef CLOUDS_SHADOWS
vec3 playerPos = feetPlayerPos + cameraPosition;
2023-06-01 17:41:06 -04:00
2023-06-05 23:34:26 -04:00
float shadow = 0.0;
2023-04-16 16:18:26 -04:00
// assume a flat layer of cloud, and stretch the sampled density along the sunvector, starting from some vertical layer in the cloud.
#ifdef Cumulus
2023-06-01 17:41:06 -04:00
vec3 lowShadowStart = playerPos + WsunVec/abs(WsunVec.y) * max((MaxCumulusHeight - 70) - playerPos.y,0.0) ;
2023-10-07 22:18:20 -04:00
shadow += GetCumulusDensity(lowShadowStart, 1)*Cumulus_density;
2023-04-16 16:18:26 -04:00
#endif
#ifdef Altostratus
vec3 highShadowStart = playerPos + WsunVec/abs(WsunVec.y) * max(AltostratusHeight - playerPos.y,0.0);
2023-10-07 22:18:20 -04:00
shadow += GetAltostratusDensity(highShadowStart) * 0.5;
2023-04-16 16:18:26 -04:00
#endif
2023-10-07 22:18:20 -04:00
shadow = clamp(shadow,0.0,1.0);
shadow *= shadow;
shadow = exp2(shadow * -100.0);
2023-04-16 16:18:26 -04:00
return shadow;
2023-10-07 22:18:20 -04:00
#else
return 1.0;
#endif
2023-04-16 16:18:26 -04:00
}
2023-06-22 14:58:16 -04:00
float GetCloudShadow_VLFOG(vec3 WorldPos, vec3 WorldSpace_sunVec){
2023-10-07 22:18:20 -04:00
#ifdef CLOUDS_SHADOWS
2023-06-05 23:34:26 -04:00
float shadow = 0.0;
2023-04-16 16:18:26 -04:00
// assume a flat layer of cloud, and stretch the sampled density along the sunvector, starting from some vertical layer in the cloud.
2023-06-11 17:28:54 -04:00
#ifdef Cumulus
2023-06-22 14:58:16 -04:00
vec3 lowShadowStart = WorldPos + WorldSpace_sunVec/abs(WorldSpace_sunVec.y) * max((MaxCumulusHeight - 60) - WorldPos.y,0.0) ;
2023-10-07 22:18:20 -04:00
shadow += max(GetCumulusDensity(lowShadowStart, 0) , 0.0)*Cumulus_density;
2023-06-11 17:28:54 -04:00
#endif
2023-04-16 16:18:26 -04:00
#ifdef Altostratus
2023-06-22 14:58:16 -04:00
vec3 highShadowStart = WorldPos + WorldSpace_sunVec/abs(WorldSpace_sunVec.y) * max(AltostratusHeight - WorldPos.y,0.0);
2023-10-07 22:18:20 -04:00
shadow += GetAltostratusDensity(highShadowStart)*0.5;
2023-04-16 16:18:26 -04:00
#endif
2023-10-07 22:18:20 -04:00
shadow = clamp(shadow,0.0,1.0);
shadow *= shadow;
2023-04-16 16:18:26 -04:00
2023-10-07 22:18:20 -04:00
shadow = exp2(shadow * -150.0);
2023-04-16 16:18:26 -04:00
2023-06-15 17:25:01 -04:00
return shadow;
2023-10-07 22:18:20 -04:00
#else
return 1.0;
#endif
2023-06-15 17:25:01 -04:00
}
float GetCloudSkyOcclusion(vec3 WorldPos){
2023-10-07 22:18:20 -04:00
#ifdef CLOUDS_SHADOWS
2023-06-15 17:25:01 -04:00
float shadow = 0.0;
vec3 shadowDir = vec3(0,1,0);
// assume a flat layer of cloud, and stretch the sampled density along the sunvector, starting from some vertical layer in the cloud.
#ifdef Cumulus
vec3 lowShadowStart = WorldPos + shadowDir/abs(shadowDir.y) * max((MaxCumulusHeight - 60) - WorldPos.y,0.0) ;
shadow += GetCumulusDensity(lowShadowStart,0)*Cumulus_density;
#endif
shadow = clamp(exp(-shadow*25.0) ,0.0,1.0);
2023-06-10 23:30:29 -04:00
return shadow;
2023-10-07 22:18:20 -04:00
#else
return 1.0;
#endif
2023-04-16 16:18:26 -04:00
}