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"
|
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float LAYER0_minHEIGHT = CloudLayer0_height;
|
|
|
|
float LAYER0_maxHEIGHT = 100 + LAYER0_minHEIGHT;
|
2023-10-22 15:57:26 -04:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float LAYER1_minHEIGHT = max(CloudLayer1_height,LAYER0_maxHEIGHT);
|
|
|
|
float LAYER1_maxHEIGHT = 100 + LAYER1_minHEIGHT;
|
|
|
|
|
|
|
|
float LAYER2_HEIGHT = max(CloudLayer2_height,LAYER1_maxHEIGHT);
|
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 ;
|
2023-12-27 15:04:36 -05:00
|
|
|
// float cloud_movement = abs((12000 - worldTime) * Cloud_Speed ) * 0.05;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float cloudCov(int layer, in vec3 pos, vec3 samplePos, float minHeight, float maxHeight){
|
2023-11-22 02:01:06 -05:00
|
|
|
float FinalCloudCoverage = 0.0;
|
2024-01-01 17:56:59 -05:00
|
|
|
|
|
|
|
vec2 SampleCoords0 = vec2(0.0); vec2 SampleCoords1 = vec2(0.0);
|
2023-11-22 02:01:06 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
if(layer == 0){
|
|
|
|
SampleCoords0 = (samplePos.xz + cloud_movement) / 5000;
|
|
|
|
SampleCoords1 = (samplePos.xz - cloud_movement) / 500;
|
|
|
|
}
|
2023-12-08 01:14:42 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
if(layer == 1){
|
2023-11-22 02:01:06 -05:00
|
|
|
SampleCoords0 = -( (samplePos.zx + cloud_movement*2) / 15000);
|
|
|
|
SampleCoords1 = -( (samplePos.zx - cloud_movement*2) / 1500);
|
|
|
|
}
|
2024-01-01 17:56:59 -05:00
|
|
|
|
2023-12-31 16:51:35 -05:00
|
|
|
float CloudSmall = texture2D(noisetex, SampleCoords1 ).r;
|
|
|
|
float CloudLarge = texture2D(noisetex, SampleCoords0 ).b;
|
2023-12-17 22:25:26 -05:00
|
|
|
|
2023-12-31 16:51:35 -05:00
|
|
|
float coverage = abs(CloudLarge*2.0 - 1.2)*0.5 - (1.0-CloudSmall);
|
2024-01-01 17:56:59 -05:00
|
|
|
float Topshape = 0.0;
|
|
|
|
float Baseshape = 0.0;
|
2023-12-17 22:25:26 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
if(layer == 0){
|
|
|
|
// float FirstLayerCoverage = DailyWeather_Cumulus(coverage);
|
2023-12-17 22:25:26 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float layer0 = min(min(coverage + CloudLayer0_coverage, clamp(maxHeight - pos.y,0,1)), 1.0 - clamp(minHeight - pos.y,0,1));
|
2023-10-07 22:18:20 -04:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float Topshape = max(pos.y - (maxHeight - 75),0.0) / 200.0;
|
|
|
|
Topshape += max(pos.y - (maxHeight - 10),0.0) / 50.0;
|
2023-01-12 15:28:19 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float Baseshape = max(minHeight + 12.5 - pos.y, 0.0) / 50.0;
|
2023-01-12 15:28:19 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
FinalCloudCoverage = max(layer0 - Topshape - Baseshape,0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(layer == 1){
|
|
|
|
float layer1 = min(min(coverage + CloudLayer1_coverage, clamp(maxHeight - pos.y,0,1)), 1.0 - clamp(minHeight - pos.y,0,1));
|
|
|
|
|
|
|
|
Topshape = max(pos.y - (maxHeight - 75), 0.0) / 200;
|
|
|
|
Topshape += max(pos.y - (maxHeight - 10 ), 0.0) / 50;
|
|
|
|
Baseshape = max(minHeight + 12.5 - pos.y, 0.0) / 50.0;
|
|
|
|
|
|
|
|
FinalCloudCoverage = max(layer1 - Topshape - Baseshape, 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(layer == -1){
|
|
|
|
// float FirstLayerCoverage = DailyWeather_Cumulus(coverage);
|
|
|
|
|
|
|
|
float layer0 = min(min(coverage + CloudLayer0_coverage, clamp(LAYER0_maxHEIGHT - pos.y,0,1)), 1.0 - clamp(LAYER0_minHEIGHT - pos.y,0,1));
|
|
|
|
|
|
|
|
float Topshape = max(pos.y - (LAYER0_maxHEIGHT - 75),0.0) / 200.0;
|
|
|
|
Topshape += max(pos.y - (LAYER0_maxHEIGHT - 10),0.0) / 50.0;
|
2023-11-22 02:01:06 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float Baseshape = max(LAYER0_minHEIGHT + 12.5 - pos.y, 0.0) / 50.0;
|
2023-01-12 15:28:19 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
FinalCloudCoverage += max(layer0 - Topshape - Baseshape,0.0);
|
|
|
|
|
|
|
|
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 - 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FinalCloudCoverage;
|
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
|
2024-01-01 17:56:59 -05:00
|
|
|
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 upperPlane = otherlayer;
|
2023-11-22 02:01:06 -05:00
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
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-12-17 22:25:26 -05:00
|
|
|
|
|
|
|
// WIND
|
2023-11-22 02:01:06 -05:00
|
|
|
samplePos.xz += pow( max(pos.y - (minHeight+20), 0.0) / 20.0,1.50) * upperPlane;
|
2023-04-27 15:09:58 -04:00
|
|
|
|
2023-11-22 02:01:06 -05:00
|
|
|
noise += (1.0-densityAtPos(samplePos * mix(100.0,200.0,upperPlane)) ) * mix(2.0,1.0,upperPlane);
|
|
|
|
|
|
|
|
if (LoD > 0) {
|
|
|
|
float smallnoise = densityAtPos(samplePos * mix(450.0,600.0,upperPlane));
|
|
|
|
noise += ((1-smallnoise) - max(0.15 - abs(smallnoise * 2.0 - 0.55) * 0.5,0.0)*1.5) * 0.6 * sqrt(noise);
|
|
|
|
}
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2023-12-05 22:06:47 -05:00
|
|
|
noise *= (1.0-cov);
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
|
2023-12-05 22:06:47 -05:00
|
|
|
noise = noise*noise * (upperPlane*0.7+0.3);
|
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;
|
|
|
|
}
|
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float GetCumulusDensity(int layer, in vec3 pos, in int LoD, float minHeight, float maxHeight){
|
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
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float coverageSP = cloudCov(layer, pos,samplePos, minHeight, maxHeight);
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2023-11-22 02:01:06 -05:00
|
|
|
// return coverageSP;
|
2023-01-12 15:00:14 -05:00
|
|
|
if (coverageSP > 0.001) {
|
|
|
|
if (LoD < 0) return max(coverageSP - 0.27*fbmAmount,0.0);
|
2024-01-01 17:56:59 -05:00
|
|
|
return cloudVol(layer, pos,samplePos,coverageSP,LoD ,minHeight, maxHeight) ;
|
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-12-31 20:22:31 -05:00
|
|
|
|
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
|
2023-12-17 22:25:26 -05:00
|
|
|
uniform sampler2D colortex4; //Skybox
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
//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!
|
2023-11-22 02:01:06 -05:00
|
|
|
vec3 DoCloudLighting(
|
|
|
|
float density,
|
|
|
|
float densityFaded,
|
|
|
|
|
|
|
|
vec3 skyLightCol,
|
|
|
|
float skyScatter,
|
|
|
|
|
|
|
|
float sunShadows,
|
|
|
|
vec3 sunScatter,
|
2023-12-08 01:14:42 -05:00
|
|
|
vec3 sunMultiScatter,
|
|
|
|
float distantfog
|
2023-11-22 02:01:06 -05:00
|
|
|
|
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-11-22 02:01:06 -05:00
|
|
|
float powder = 1.0 - exp(densityFaded * -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-11-22 02:01:06 -05:00
|
|
|
vec3 skyLight = skyLightCol;
|
2023-05-09 19:08:34 -04:00
|
|
|
|
2023-12-31 16:51:35 -05:00
|
|
|
float skyLightShading = exp2((skyScatter*skyScatter) * densityFaded * -35.0) * lesspowder;
|
|
|
|
|
|
|
|
skyLight *= mix(1.0, skyLightShading, distantfog);
|
2023-05-03 21:29:53 -04:00
|
|
|
|
2023-11-22 02:01:06 -05:00
|
|
|
vec3 sunLight = exp(sunShadows * -15 + powder ) * sunScatter;
|
2023-12-05 22:06:47 -05:00
|
|
|
sunLight += exp(sunShadows * -3) * sunMultiScatter * (powder*0.7+0.3);
|
2023-12-26 13:35:35 -05:00
|
|
|
|
2023-12-05 22:06:47 -05:00
|
|
|
// return skyLight;
|
|
|
|
// return sunLight;
|
2023-11-22 02:01:06 -05:00
|
|
|
return skyLight + sunLight;
|
2023-01-12 15:00:14 -05:00
|
|
|
}
|
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
vec3 layerStartingPosition(
|
|
|
|
vec3 dV_view,
|
|
|
|
vec3 cameraPos,
|
|
|
|
float dither,
|
|
|
|
|
|
|
|
float minHeight,
|
|
|
|
float maxHeight
|
|
|
|
){
|
|
|
|
// allow passing through/above/below the plane without limits
|
|
|
|
float flip = mix(max(cameraPos.y - maxHeight,0.0), max(minHeight - cameraPos.y,0), clamp(dV_view.y,0,1));
|
|
|
|
|
|
|
|
// orient the ray to be a flat plane facing up/down
|
|
|
|
vec3 position = dV_view*dither + cameraPos + dV_view/abs(dV_view.y) * flip;
|
|
|
|
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4 renderLayer(
|
|
|
|
int layer,
|
|
|
|
in vec3 rayProgress,
|
|
|
|
in vec3 dV_view,
|
|
|
|
in float mult,
|
|
|
|
in float dither,
|
|
|
|
|
|
|
|
int QUALITY,
|
|
|
|
|
|
|
|
float minHeight,
|
|
|
|
float maxHeight,
|
|
|
|
|
|
|
|
in vec3 dV_Sun,
|
|
|
|
|
|
|
|
float cloudDensity,
|
|
|
|
in vec3 skyLightCol,
|
|
|
|
in vec3 sunScatter,
|
|
|
|
in vec3 sunMultiScatter,
|
|
|
|
in float distantfog,
|
|
|
|
bool notVisible
|
|
|
|
){
|
|
|
|
vec3 COLOR = vec3(0.0);
|
|
|
|
float TOTAL_EXTINCTION = 1.0;
|
|
|
|
|
|
|
|
|
|
|
|
if(layer == 2){
|
|
|
|
if(notVisible) return vec4(COLOR, TOTAL_EXTINCTION);
|
|
|
|
|
|
|
|
float signFlip = mix(-1.0, 1.0, clamp(cameraPosition.y - minHeight,0.0,1.0));
|
|
|
|
|
|
|
|
if(max(signFlip * normalize(dV_view).y,0.0) <= 0.0){
|
|
|
|
float altostratus = GetAltostratusDensity(rayProgress);
|
|
|
|
|
|
|
|
if(altostratus > 1e-5){
|
|
|
|
float muE = altostratus;
|
|
|
|
|
|
|
|
float directLight = 0.0;
|
|
|
|
for (int j = 0; j < 2; j++){
|
|
|
|
vec3 shadowSamplePos_high = rayProgress + dV_Sun * (0.1 + j + dither);
|
|
|
|
float shadow = GetAltostratusDensity(shadowSamplePos_high);
|
|
|
|
directLight += shadow; /// (1+j);
|
|
|
|
}
|
|
|
|
|
|
|
|
float skyscatter_alto = sqrt(altostratus*0.05);
|
|
|
|
vec3 lighting = DoCloudLighting(altostratus, 1.0, skyLightCol, skyscatter_alto, directLight, sunScatter, sunMultiScatter, distantfog);
|
|
|
|
|
|
|
|
COLOR += max(lighting - lighting*exp(-mult*muE),0.0) * TOTAL_EXTINCTION;
|
|
|
|
TOTAL_EXTINCTION *= max(exp(-mult*muE),0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec4(COLOR, TOTAL_EXTINCTION);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
for(int i = 0; i < QUALITY; i++) {
|
|
|
|
/// avoid overdraw
|
|
|
|
if(notVisible) break;
|
|
|
|
|
|
|
|
float cumulus = GetCumulusDensity(layer, rayProgress, 1, minHeight, maxHeight);
|
|
|
|
|
|
|
|
float fadedDensity = cloudDensity * clamp(exp( (rayProgress.y - (maxHeight - 75)) / 9.0 ),0.0,1.0);
|
|
|
|
|
|
|
|
if(cumulus > 1e-5){
|
|
|
|
float muE = cumulus * fadedDensity;
|
|
|
|
|
|
|
|
float directLight = 0.0;
|
|
|
|
for (int j=0; j < 3; j++){
|
|
|
|
|
|
|
|
vec3 shadowSamplePos = rayProgress + dV_Sun * (0.1 + j * (0.1 + dither*0.05));
|
|
|
|
float shadow = GetCumulusDensity(layer, shadowSamplePos, 0, minHeight, maxHeight) * cloudDensity;
|
|
|
|
|
|
|
|
directLight += shadow;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined CloudLayer1 && defined CloudLayer0
|
|
|
|
if(layer == 0) directLight += CloudLayer1_density * 2.0 * GetCumulusDensity(1, rayProgress + dV_Sun/abs(dV_Sun.y) * max((LAYER1_maxHEIGHT-70) - rayProgress.y,0.0), 0, LAYER1_minHEIGHT, LAYER1_maxHEIGHT);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CloudLayer2
|
|
|
|
// cast a shadow from higher clouds onto lower clouds
|
|
|
|
vec3 HighAlt_shadowPos = rayProgress + dV_Sun/abs(dV_Sun.y) * max(LAYER2_HEIGHT - rayProgress.y,0.0);
|
|
|
|
float HighAlt_shadow = GetAltostratusDensity(HighAlt_shadowPos) ;
|
|
|
|
directLight += HighAlt_shadow;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined CloudLayer1 && defined CloudLayer0
|
|
|
|
float upperLayerOcclusion = layer == 0 ? CloudLayer1_density * 2.0 * GetCumulusDensity(1, rayProgress + vec3(0.0,1.0,0.0) * max((LAYER1_maxHEIGHT-70) - rayProgress.y,0.0), 0, LAYER1_minHEIGHT, LAYER1_maxHEIGHT) : 0.0;
|
|
|
|
float skylightOcclusion = max(exp2((upperLayerOcclusion*upperLayerOcclusion) * -5), 0.75 + (1.0-distantfog)*0.25);
|
|
|
|
#else
|
|
|
|
float skylightOcclusion = 1.0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
float skyScatter = clamp((maxHeight - 20 - rayProgress.y) / 275.0,0.0,1.0);
|
|
|
|
vec3 lighting = DoCloudLighting(muE, cumulus, skyLightCol*skylightOcclusion, skyScatter, directLight, sunScatter, sunMultiScatter, distantfog);
|
|
|
|
|
|
|
|
#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.
|
|
|
|
lighting += sunScatter * exp((skyScatter*skyScatter) * cumulus * -35.0) * upperLayerOcclusion * exp(-20.0 * pow(abs(upperLayerOcclusion - 0.3),2));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
COLOR += max(lighting - lighting*exp(-mult*muE),0.0) * TOTAL_EXTINCTION;
|
|
|
|
TOTAL_EXTINCTION *= max(exp(-mult*muE),0.0);
|
|
|
|
|
|
|
|
if (TOTAL_EXTINCTION < 1e-5) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rayProgress += dV_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec4(COLOR, TOTAL_EXTINCTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
vec4 renderClouds(
|
2023-04-16 16:18:26 -04:00
|
|
|
vec3 FragPosition,
|
|
|
|
vec2 Dither,
|
2023-12-17 22:25:26 -05:00
|
|
|
vec3 LightColor,
|
2023-04-16 16:18:26 -04:00
|
|
|
vec3 SkyColor
|
2023-11-22 02:01:06 -05:00
|
|
|
){
|
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
#ifndef VOLUMETRIC_CLOUDS
|
|
|
|
return vec4(0.0,0.0,0.0,1.0);
|
|
|
|
#endif
|
|
|
|
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
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float heightRelativeToClouds = clamp(1.0 - max(cameraPosition.y - LAYER0_minHEIGHT,0.0) / 200.0 ,0.0,1.0);
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2023-12-05 22:06:47 -05:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////// Raymarching stuff
|
|
|
|
//////////////////////////////////////////
|
2023-10-20 21:24:50 -04:00
|
|
|
|
2023-12-05 22:06:47 -05:00
|
|
|
//project pixel position into projected shadowmap space
|
|
|
|
vec4 viewPos = normalize(gbufferModelViewInverse * vec4(FragPosition,1.0) );
|
|
|
|
// maxIT_clouds = int(clamp(maxIT_clouds / sqrt(exp2(viewPos.y)),0.0, maxIT));
|
|
|
|
maxIT_clouds = int(clamp(maxIT_clouds / sqrt(exp2(viewPos.y)),0.0, maxIT));
|
2024-01-01 17:56:59 -05:00
|
|
|
// maxIT_clouds = 15;
|
2023-01-12 15:28:19 -05:00
|
|
|
|
2023-12-05 22:06:47 -05:00
|
|
|
vec3 dV_view = normalize(viewPos.xyz);
|
2023-12-31 18:02:53 -05:00
|
|
|
|
|
|
|
// this is the cloud curvature.
|
2023-12-31 18:06:37 -05:00
|
|
|
dV_view.y += 0.05 * heightRelativeToClouds;
|
2023-10-07 22:18:20 -04:00
|
|
|
|
2023-12-31 20:22:31 -05:00
|
|
|
vec3 dV_view_Alto = dV_view;
|
2024-01-01 17:56:59 -05:00
|
|
|
dV_view_Alto *= 100/abs(dV_view_Alto.y)/15;
|
|
|
|
float mult_alto = length(dV_view_Alto);
|
2023-12-31 20:22:31 -05:00
|
|
|
|
2024-01-01 18:30:43 -05:00
|
|
|
dV_view *= 90/abs(dV_view.y)/maxIT_clouds;
|
2023-12-08 01:14:42 -05:00
|
|
|
|
2023-12-05 22:06:47 -05:00
|
|
|
float mult = length(dV_view);
|
2024-01-01 17:56:59 -05:00
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
////// lighting stuff
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
float shadowStep = 200.0;
|
|
|
|
|
|
|
|
vec3 dV_Sun = WsunVec*shadowStep;
|
|
|
|
float SdotV = dot(mat3(gbufferModelView)*WsunVec, normalize(FragPosition));
|
|
|
|
|
|
|
|
float mieDay = phaseg(SdotV, 0.75);
|
|
|
|
float mieDayMulti = (phaseg(SdotV, 0.35) + phaseg(-SdotV, 0.35) * 0.5) ;
|
2023-12-05 22:06:47 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
vec3 directScattering = LightColor * mieDay * 3.14;
|
|
|
|
vec3 directMultiScattering = LightColor * mieDayMulti * 4.0;
|
2023-10-07 22:18:20 -04:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
vec3 sunIndirectScattering = LightColor * phaseg(dot(mat3(gbufferModelView)*vec3(0,1,0),normalize(FragPosition)), 0.5) * 3.14;
|
2023-06-22 21:00:42 -04:00
|
|
|
|
2023-12-05 22:06:47 -05:00
|
|
|
|
2023-12-31 16:51:35 -05:00
|
|
|
// use this to blend into the atmosphere's ground.
|
2024-01-01 17:56:59 -05:00
|
|
|
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);
|
2023-12-31 16:51:35 -05:00
|
|
|
|
|
|
|
// terrible fake rayleigh scattering
|
|
|
|
vec3 rC = vec3(sky_coefficientRayleighR*1e-6, sky_coefficientRayleighG*1e-5, sky_coefficientRayleighB*1e-5)*3;
|
2024-01-01 17:56:59 -05:00
|
|
|
float atmosphere = exp(abs(approxdistance.y) * -5.0);
|
2023-12-31 18:41:12 -05:00
|
|
|
vec3 scatter = mix(vec3(1.0), exp(-10000.0 * rC * atmosphere) * distantfog, heightRelativeToClouds);
|
2023-12-31 16:51:35 -05:00
|
|
|
|
2023-12-31 18:41:12 -05:00
|
|
|
directScattering *= scatter;
|
|
|
|
directMultiScattering *= scatter;
|
|
|
|
sunIndirectScattering *= scatter;
|
2023-12-31 16:51:35 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////// Cloud layer Positions
|
|
|
|
//////////////////////////////////////////
|
2023-12-31 20:22:31 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
// first cloud layer
|
|
|
|
float MinHeight = LAYER0_minHEIGHT;
|
|
|
|
float MaxHeight = LAYER0_maxHEIGHT;
|
2023-12-31 20:22:31 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float MinHeight1 = LAYER1_minHEIGHT;
|
|
|
|
float MaxHeight1 = LAYER1_maxHEIGHT;
|
2023-12-31 20:22:31 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
float Height2 = LAYER2_HEIGHT;
|
2023-12-31 20:22:31 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
// int above_Layer0 = int(clamp(cameraPosition.y - MaxHeight,0.0,1.0));
|
|
|
|
int below_Layer0 = int(clamp(MaxHeight - cameraPosition.y,0.0,1.0));
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
int above_Layer1 = int(clamp(MaxHeight1 - cameraPosition.y,0.0,1.0));
|
|
|
|
bool below_Layer1 = clamp(cameraPosition.y - MinHeight1,0.0,1.0) < 1.0;
|
|
|
|
bool below_Layer2 = clamp(cameraPosition.y - Height2,0.0,1.0) < 1.0;
|
|
|
|
// bool layer1_below_layer0 = MinHeight1 < MinHeight;
|
|
|
|
|
|
|
|
bool altoNotVisible = false;
|
|
|
|
|
|
|
|
#ifdef CloudLayer0
|
|
|
|
vec3 layer0_start = layerStartingPosition(dV_view, cameraPosition, Dither.y, MinHeight, MaxHeight);
|
|
|
|
#endif
|
|
|
|
#ifdef CloudLayer1
|
|
|
|
vec3 layer1_start = layerStartingPosition(dV_view, cameraPosition, Dither.y, MinHeight1, MaxHeight1);
|
|
|
|
#endif
|
|
|
|
#ifdef CloudLayer2
|
|
|
|
vec3 layer2_start = layerStartingPosition(dV_view_Alto, cameraPosition, Dither.y, Height2, Height2);
|
|
|
|
#endif
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
#ifdef CloudLayer0
|
|
|
|
vec4 layer0 = renderLayer(0, layer0_start, dV_view, mult, Dither.x, maxIT_clouds, MinHeight, MaxHeight, dV_Sun, CloudLayer0_density, SkyColor, directScattering, directMultiScattering, distantfog, false);
|
|
|
|
total_extinction *= layer0.a;
|
2023-05-03 21:29:53 -04:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
// stop overdraw.
|
|
|
|
bool notVisible = layer0.a < 1e-5 && below_Layer1;
|
|
|
|
altoNotVisible = notVisible;
|
|
|
|
#else
|
|
|
|
// stop overdraw.
|
|
|
|
bool notVisible = false;
|
|
|
|
#endif
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
#ifdef CloudLayer1
|
|
|
|
vec4 layer1 = renderLayer(1, layer1_start, dV_view, mult, Dither.x, maxIT_clouds, MinHeight1, MaxHeight1, dV_Sun, CloudLayer1_density, SkyColor, directScattering, directMultiScattering, distantfog, notVisible);
|
|
|
|
total_extinction *= layer1.a;
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
// stop overdraw.
|
|
|
|
altoNotVisible = (layer1.a < 1e-5 || notVisible)&& below_Layer1;
|
|
|
|
#endif
|
2023-12-05 22:06:47 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
#ifdef CloudLayer2
|
|
|
|
vec4 layer2 = renderLayer(2, layer2_start, dV_view_Alto, mult_alto, Dither.x, maxIT_clouds, Height2, Height2, dV_Sun, CloudLayer2_density, SkyColor, directScattering, directMultiScattering, distantfog, altoNotVisible);
|
|
|
|
total_extinction *= layer2.a;
|
|
|
|
#endif
|
|
|
|
|
2023-12-31 20:22:31 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
// order DOES matter here.
|
|
|
|
// if(layer1_below_layer0){
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
// 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
|
2023-12-26 13:35:35 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
#if !defined CloudLayer1 && defined CloudLayer2
|
|
|
|
if(below_Layer2) color = color * layer2.a + layer2.rgb;
|
|
|
|
#endif
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
#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
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
#if defined CloudLayer0 && !defined CloudLayer1
|
|
|
|
color = color * layer0.a + layer0.rgb;
|
|
|
|
#endif
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
#if !defined CloudLayer0 && defined CloudLayer1
|
|
|
|
color = color * layer1.a + layer1.rgb;
|
|
|
|
#endif
|
2023-12-31 20:22:31 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
#ifdef CloudLayer2
|
|
|
|
if(!below_Layer2) color = color * layer2.a + layer2.rgb;
|
|
|
|
#endif
|
|
|
|
// }
|
2023-12-31 20:22:31 -05:00
|
|
|
|
2023-12-08 01:14:42 -05:00
|
|
|
return vec4(color, total_extinction);
|
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
|
2023-11-22 02:01:06 -05:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
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.
|
2024-01-01 17:56:59 -05:00
|
|
|
#ifdef CloudLayer0
|
|
|
|
vec3 lowShadowStart = playerPos + (WsunVec / max(abs(WsunVec.y),0.2)) * max((CloudLayer0_height + 30) - playerPos.y,0.0) ;
|
|
|
|
shadow += GetCumulusDensity(0, lowShadowStart, 1, CloudLayer0_height, CloudLayer0_height+100)*CloudLayer0_density;
|
2023-04-16 16:18:26 -04:00
|
|
|
#endif
|
2024-01-01 17:56:59 -05:00
|
|
|
#ifdef CloudLayer1
|
|
|
|
vec3 higherShadowStart = playerPos + (WsunVec / max(abs(WsunVec.y),0.2)) * max((CloudLayer1_height + 30) - playerPos.y,0.0) ;
|
|
|
|
shadow += GetCumulusDensity(1, higherShadowStart, 0, CloudLayer1_height, CloudLayer1_height+100)*CloudLayer1_density;
|
|
|
|
#endif
|
|
|
|
#ifdef CloudLayer2
|
|
|
|
vec3 highShadowStart = playerPos + (WsunVec / max(abs(WsunVec.y),0.2)) * max(CloudLayer1_height - playerPos.y,0.0);
|
2023-12-31 20:22:31 -05:00
|
|
|
shadow += GetAltostratusDensity(highShadowStart) * 0.5;
|
|
|
|
#endif
|
2023-04-16 16:18:26 -04:00
|
|
|
|
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
|
|
|
|
2024-01-01 18:30:43 -05:00
|
|
|
return mix(1.0, shadow, CLOUD_SHADOW_STRENGTH);
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
#else
|
|
|
|
return 1.0;
|
|
|
|
#endif
|
2023-04-16 16:18:26 -04:00
|
|
|
}
|
2023-12-17 22:25:26 -05: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-11-22 02:01:06 -05:00
|
|
|
|
2023-06-05 23:34:26 -04:00
|
|
|
float shadow = 0.0;
|
2023-11-22 02:01:06 -05:00
|
|
|
|
2024-01-01 17:56:59 -05:00
|
|
|
#ifdef CloudLayer0
|
|
|
|
vec3 lowShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.2)) * max((CloudLayer0_height) - WorldPos.y,0.0) ;
|
|
|
|
shadow += GetCumulusDensity(0, lowShadowStart, 0, CloudLayer0_height,CloudLayer0_height+100)*CloudLayer0_density;
|
2023-06-11 17:28:54 -04:00
|
|
|
#endif
|
2024-01-01 17:56:59 -05:00
|
|
|
#ifdef CloudLayer1
|
|
|
|
vec3 higherShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.2)) * max((CloudLayer1_height) - WorldPos.y,0.0) ;
|
|
|
|
shadow += GetCumulusDensity(1,higherShadowStart, 0, CloudLayer1_height,CloudLayer1_height+100)*CloudLayer1_density;
|
|
|
|
#endif
|
|
|
|
#ifdef CloudLayer2
|
|
|
|
vec3 highShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.2)) * max(CloudLayer2_height - WorldPos.y,0.0);
|
2023-12-31 20:22:31 -05:00
|
|
|
shadow += GetAltostratusDensity(highShadowStart)*0.5;
|
|
|
|
#endif
|
2023-04-16 16:18:26 -04:00
|
|
|
|
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
|
|
|
|
2024-01-01 18:30:43 -05:00
|
|
|
return mix(1.0, shadow, CLOUD_SHADOW_STRENGTH);
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
#else
|
|
|
|
return 1.0;
|
|
|
|
#endif
|
2023-12-17 22:25:26 -05:00
|
|
|
}
|