DOUBLE LAYER CLOUDS TEST 5. ALOT OF END SHADER WORK DONE. fix a few tiny issues and some tweaks here and there.

This commit is contained in:
Xonk
2023-12-17 22:25:26 -05:00
parent d0c2712da0
commit 08d97f20ff
19 changed files with 299 additions and 339 deletions

View File

@ -1,3 +0,0 @@
#if Cumulus_coverage == 1.0
variable.float.VariableCoverage = 1.0
#endif

View File

@ -1,16 +0,0 @@
vec3 cloud2D(vec3 viewPos,vec3 col){
vec3 wpos = viewPos;
float wind = frameTimeCounter/200.;
vec2 intersection = ((2000.0-cameraPosition.y)*wpos.xz*inversesqrt(wpos.y+cameraPosition.y/512.-50./512.) + cameraPosition.xz+wind)/40000.;
float phase = pow(clamp(dot(viewPos,sunVec),0.,1.),2.)*0.5+0.5;
float fbm = clamp((texture2D(noisetex,intersection*vec2(1.,1.5)).a + texture2D(noisetex,intersection*vec2(2.,7.)+wind*0.4).a/2.)-0.5*(1.0-rainStrength),0.,1.) ;
return mix(col,6.*(vec3(0.9,1.2,1.5)*skyIntensityNight*0.02*(1.0-rainStrength*0.9)+17.*phase*nsunColor*skyIntensity*0.7*(1.0-rainStrength*0.9)),0.0*(fbm*fbm)*(fbm*fbm)*(fbm*clamp(wpos.y*0.9,0.,1.)));
}

View File

@ -63,35 +63,33 @@ SOFTWARE.*/
//----------------------------------------------------------------------------------------
// vec3 RandomPosition = hash31(frameTimeCounter);
float vortexBoundRange = 300.0;
vec3 ManualLightPos = vec3(ORB_X, ORB_Y, ORB_Z);
// int switcher = frameCounter % 2 == 0 ? 0 : 1;
vec3 LightSourcePosition(vec3 worldPos, vec3 cameraPos, float vortexBounds){
// float OneOrZero = int(mod(gl_FragCoord.x*gl_FragCoord.y + switcher, 2));
// this is static so it can just sit in one place
vec3 vortexPos = worldPos - vec3(0.0,200.0,0.0);
void LightSourcePosition(vec3 WorldPos, vec3 CameraPos, inout vec3 Pos1, inout vec3 Pos2){
vec3 lightningPos = worldPos - cameraPos - ManualLightPos;
// snap-to coordinates in worldspace.
float cellSize = 200.0;
lightningPos += fract(cameraPos/cellSize)*cellSize - cellSize*0.5;
Pos1 = WorldPos - vec3(0,200,0);
// Pos2 = WorldPos - vec3(-50,100,0);
// Pos1 = mix(Pos1, Pos2, OneOrZero);
// make the position offset to random places (RNG.xyz from non-clearing buffer).
vec3 randomOffset = (texelFetch2D(colortex4,ivec2(2,1),0).xyz / 150.0) * 2.0 - 1.0;
lightningPos -= randomOffset * 2.5;
#ifdef THE_ORB
cellSize = 200.0;
vec3 orbpos = worldPos - cameraPos - ManualLightPos;// - vec3(sin(frameTimeCounter), cos(frameTimeCounter), cos(frameTimeCounter))*100;
orbpos += fract(cameraPos/cellSize)*cellSize - cellSize*0.5;
vec3 Origin = WorldPos - CameraPos - ManualLightPos;
float cellSize = 200;
vec3 cellPos = CameraPos ;
Origin += fract(cellPos/cellSize)*cellSize - cellSize*0.5;
// Origin -= vec3(sin(frameTimeCounter),0,-cos(frameTimeCounter)) * 20;
vec3 randomPos = texelFetch2D(colortex4,ivec2(2,1),0).xyz / 150.0;
Origin -= (randomPos * 2.0 - 1.0);
// Pos1 = mix(Pos1, Origin, OneOrZero);
Pos2 = Origin;
return orbpos;
#else
return mix(lightningPos, vortexPos, vortexBounds);
#endif
}
float densityAtPosFog(in vec3 pos){
@ -134,39 +132,41 @@ void VolumeBounds(inout float Volume, vec3 Origin){
float thickness = 50.0 * radius;
float Torus = (thickness - clamp( pow( length( vec2(length(Origin.xz) - radius, Origin2.y) ),2.0) - radius, 0.0, thickness) ) / thickness;
Origin2.xz *= 0.3;
Origin2.xz *= 0.5;
Origin2.y -= 100;
float orb = clamp((1.0 - length(Origin2) / 15.0) * 1.5,0.0,1.0);
Volume = max(Volume - Bounds - Torus, orb);
float orb = clamp((1.0 - length(Origin2) / 15.0) * 1.0,0.0,1.0);
Volume = max(Volume - Bounds - Torus, 0);
}
// create the volume shape
float cloudVol(in vec3 pos){
float fogShape(in vec3 pos){
float vortexBounds = clamp(vortexBoundRange - length(pos), 0.0,1.0);
vec3 samplePos = pos*vec3(1.0,1.0/48.0,1.0);
float fogYstart = -60;
float Output = 0.0;
vec3 samplePos = pos*vec3(1.0,1./48.,1.0);
// this is below down where you fall to your death.
float voidZone = max(exp2(-1.0 * sqrt(max(pos.y - -60,0.0))) ,0.0) ;
// swirly swirly :DDDDDDDDDDD
// swirly swirly :DDDDDDDDDDD
SwirlAroundOrigin(samplePos, pos);
float NoisePlane = texture2D(noisetex, samplePos.xz/1024 ).b;
float MainShape = clamp(max(0.5 - densityAtPosFog(samplePos * 16),0.0) * 2,0.0,1.0);
float Erosion = abs(0.6 - densityAtPosFog(samplePos * (160. - MainShape*50) - vec3(0,frameTimeCounter*3,0) ));
float noise = densityAtPosFog(samplePos * 12.0);
float erosion = 1.0-densityAtPosFog((samplePos - frameTimeCounter/20) * (124 + (1-noise)*7));
Output = MainShape;
Output = max(Output - Erosion*0.5,0.0);
// apply limts
VolumeBounds(Output, pos);
float clumpyFog = max(exp(noise * -mix(10,4,vortexBounds))*mix(2,1,vortexBounds) - erosion*0.3, 0.0);
// apply limts
VolumeBounds(clumpyFog, pos);
// Output = max(max(100 - pos.y,0.0) - NoisePlane * 50 ,0.0);
return Output;
return clumpyFog + voidZone;
}
float EndLightMie(vec3 LightPos){
float endFogPhase(vec3 LightPos){
float mie = exp(length(LightPos) / -150);
mie *= mie;
@ -176,49 +176,50 @@ float EndLightMie(vec3 LightPos){
return mie;
}
void LightSourceColors(inout vec3 Color1, inout vec3 Color2){
// Color1 = vec3(0.7,0.88,1.0);
// Color2 = vec3(ORB_R,ORB_G,ORB_B);
Color1 = vec3(1.0,0.5,1.0);
Color2 = vec3(0.0,0.5,1.0);
vec3 LightSourceColors(float vortexBounds, float lightningflash){
// Color1 = mix(Color1, Color2, OneOrZero);
// vec3 vortexColor = vec3(0.7,0.88,1.0);
// vec3 lightningColor = vec3(ORB_R,ORB_G,ORB_B);
vec3 vortexColor = vec3(0.5,0.68,1.0);
vec3 lightningColor = vec3(1.0,0.3,0.2) * lightningflash;
#ifdef THE_ORB
return vec3(ORB_R, ORB_G, ORB_B) * ORB_ColMult;
#else
return mix(lightningColor, vortexColor, vortexBounds);
#endif
}
vec3 LightSourceLighting( vec3 WorldPos, vec3 LightPos, float Dither, float VolumeDensity, vec3 LightColor, float Phase ){
vec3 LightSourceLighting(vec3 startPos, vec3 lightPos, float noise, float density, vec3 lightColor, float vortexBound){
float Mie = EndLightMie(LightPos);
float Shadow = 0.0;
float phase = endFogPhase(lightPos);
float shadow = 0.0;
// vec3 shadowSamplePos = WorldPos - LightPos * 0.05;
for (int j=0; j < 3; j++){
// shadowSamplePos -= LightPos * 0.25 * Dither * min(j,1);
vec3 shadowSamplePos = WorldPos - LightPos * (0.05 + j * (0.25 + Dither*0.15));
Shadow += cloudVol(shadowSamplePos);
for (int j = 0; j < 3; j++){
vec3 shadowSamplePos = startPos - lightPos * (0.05 + j * (0.25 + noise*0.15));
shadow += fogShape(shadowSamplePos);
}
vec3 FinalLighting = LightColor * Mie * exp(Shadow * -5.0) ;
vec3 finalLighting = lightColor * phase * exp(shadow * -10.0);
FinalLighting += LightColor * exp2(-5 * max(2.5-Shadow,0.0) * vec3(1.2,1.0,0.8+VolumeDensity*0.4)) * (Mie*Mie) * clamp((1.0 - length(LightPos) / 100.0),0.0,1.0);
finalLighting += lightColor * phase*phase * (1.0-exp((shadow*shadow*shadow) * vec3(0.6,2.0,2) * -1)) * (1.0 - exp(-density*density));
return FinalLighting;
return finalLighting;
}
#define lightsourceCount 2 // [1 2]
vec4 GetVolumetricFog(
vec3 viewPos,
vec3 viewPosition,
float dither,
float dither2
){
int SAMPLES = 16;
vec3 vL = vec3(0.0);
float absorbance = 1.0;
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
/// ------------- RAYMARCHING STUFF ------------- \\\
int SAMPLES = 16;
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * viewPosition + gbufferModelViewInverse[3].xyz;
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
@ -228,91 +229,67 @@ vec4 GetVolumetricFog(
//rayvector into projected shadow map space
//we can use a projected vector because its orthographic projection
//however we still have to send it to curved shadow map space every step
vec3 dV = fragposition-start;
vec3 dV = fragposition - start;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
float maxLength = min(length(dVWorld),32.0 * 12.0)/length(dVWorld);
dV *= maxLength;
dVWorld *= maxLength;
float dL = length(dVWorld);
vec3 progressW = gbufferModelViewInverse[3].xyz + cameraPosition;
/// ------------- COLOR/LIGHTING STUFF ------------- \\\
vec3 color = vec3(0.0);
vec3 absorbance = vec3(1.0);
vec3 fogcolor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.05)) ;
vec3 LightCol1 = vec3(0); vec3 LightCol2 = vec3(0);
LightSourceColors(LightCol1, LightCol2);
float Flashing = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
// LightCol1 *= Flashing;
LightCol2 *= Flashing;
vec3 LightPos1 = vec3(0); vec3 LightPos2 = vec3(0);
LightSourcePosition(cameraPosition, cameraPosition, LightPos1, LightPos2);
float Phase1 = sqrt(1.0 - clamp( dot(normalize(dVWorld), normalize(-LightPos1)),0.0,1.0));
Phase1 = exp(Phase1 * -5.0) * 10;
float Phase2 = sqrt(1.0 - clamp( dot(normalize(dVWorld), normalize(-LightPos2)),0.0,1.0));
Phase2 = exp(Phase2 * -5.0) * 10;
float lightningflash = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
float expFactor = 11.0;
for (int i=0;i<SAMPLES;i++) {
float d = (pow(expFactor, float(i+dither)/float(SAMPLES))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(SAMPLES)) * log(expFactor) / float(SAMPLES)/(expFactor-1.0);
vec3 progress = start.xyz + d*dV;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
// determine where the vortex area ends and chaotic lightning area begins.
float vortexBounds = clamp(vortexBoundRange - length(progressW), 0.0,1.0);
// vec3 LightPos1 = vec3(0); vec3 LightPos2 = vec3(0);
LightSourcePosition(progressW, cameraPosition, LightPos1, LightPos2);
vec3 lightPosition = LightSourcePosition(progressW, cameraPosition, vortexBounds);
vec3 lightColors = LightSourceColors(vortexBounds, lightningflash);
float VolumeDensity = max(cloudVol(progressW),0.0);
// float VolumeDensity = 0.0;
float Density = max(VolumeDensity,0.0);
float volumeDensity = fogShape(progressW);
// volumeDensity += max(1.0 - length(vec3(lightPosition.x,lightPosition.y*2,lightPosition.z))/50,0.0) * vortexBounds;
float clearArea = 1.0-min(max(1.0 - length(progressW - cameraPosition) / 100,0.0),1.0);
float density = min(volumeDensity * clearArea, END_STORM_DENSTIY);
///// ----- air lighting, the haze
float distanceFog = max(1.0 - length(progressW - cameraPosition) / max(far, 32.0 * 13.0),0.0);
float hazeDensity = min(exp2(distanceFog * -25)+0.0005,1.0);
vec3 hazeColor = vec3(0.3,0.75,1.0) * 0.3;
color += (hazeColor - hazeColor*exp(-hazeDensity*dd*dL)) * absorbance;
////////////////////////////////////////////////////////////////
///////////////////////// AMBIENT LIGHT ////////////////////////
////////////////////////////////////////////////////////////////
///// ----- main lighting
vec3 voidLighting = vec3(1.0,0.0,0.8) * 0.1 * (1-exp(volumeDensity * -25)) * max(exp2(-1 * sqrt(max(progressW.y - -60,0.0))),0.0) ;
vec3 vL0 = fogcolor * exp2(VolumeDensity * -25) * 0.1 ;
vec3 ambient = vec3(0.5,0.75,1.0) * 0.2 * (exp((volumeDensity*volumeDensity) * -50) * 0.9 + 0.1);
float shadows = 0;
vec3 lightsources = LightSourceLighting(progressW, lightPosition, dither2, volumeDensity, lightColors, vortexBounds);
vec3 lighting = lightsources + ambient + voidLighting;
////////////////////////////////////////////////////////////////
/////////////////////// MAIN LIGHTSOURCE ///////////////////////
////////////////////////////////////////////////////////////////
vec3 Light1 = vec3(0); vec3 Light2 = vec3(0);
#ifdef THE_ORB
density += min(50.0*max(1.0 - length(lightPosition)/10,0.0),1.0);
#endif
Density += clamp((1.0 - length(LightPos1) / 10.0) * 10 ,0.0,1.0); // THE ORRRRRRRRRRRRRRRRRRRRRRRRRRB
Light1 = LightSourceLighting(progressW, LightPos1, dither2, VolumeDensity, LightCol1, Phase1);
#if lightsourceCount == 2
Density += clamp((1.0 - length(LightPos2) / 10.0) * 10 ,0.0,1.0); // THE ORRRRRRRRRRRRRRRRRRRRRRRRRRB
Light2 += LightSourceLighting(progressW, LightPos2, dither2, VolumeDensity, LightCol2, Phase2);
#endif
vL0 += Light1 + Light2;
////////////////////////////////////////////////////////////////
/////////////////////////// FINALIZE ///////////////////////////
////////////////////////////////////////////////////////////////
float AirDensity = 0.002;
// AirDensity = 0.0;
vec3 vL1 = vec3(0.5,0.75,1.0) * 0.5;
// vL1 += Light1 + Light2;
vL += (vL1 - vL1*exp2(-AirDensity*dd*dL)) * absorbance;
vL += (vL0 - vL0*exp(-Density*dd*dL)) * absorbance;
absorbance *= exp2(-(AirDensity+Density)*dd*dL);
if (absorbance < 1e-5) break;
///// ----- blend
color += (lighting - lighting*exp(-(density)*dd*dL)) * absorbance;
absorbance *= exp(-max(density,hazeDensity)*dd*dL);
}
return vec4(vL, absorbance);
return vec4(color, absorbance);
}
float GetCloudShadow(vec3 WorldPos, vec3 LightPos){
@ -320,11 +297,10 @@ float GetCloudShadow(vec3 WorldPos, vec3 LightPos){
for (int i=0; i < 3; i++){
vec3 shadowSamplePos = WorldPos - LightPos * (0.1 + pow(i,0.75)*0.25);
// vec3 shadowSamplePos = WorldPos - LightPos * i * 0.5;
float Cast = cloudVol(shadowSamplePos);
vec3 shadowSamplePos = WorldPos - LightPos * (pow(i,0.75)*0.25);
float Cast = fogShape(shadowSamplePos)*END_STORM_DENSTIY;
Shadow += Cast;
}
return clamp(exp(-Shadow*5.0),0.0,1.0);
return clamp(exp(Shadow * -5.0),0.0,1.0);
}

View File

@ -1,54 +0,0 @@
vec4 GetVolumetricFog(
vec3 viewPos,
float dither,
float dither2
){
int SAMPLES = 16;
vec3 vL = vec3(0.0);
float absorbance = 1.0;
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
//project view origin into projected shadowmap space
vec3 start = toShadowSpaceProjected(vec3(0.));
//rayvector into projected shadow map space
//we can use a projected vector because its orthographic projection
//however we still have to send it to curved shadow map space every step
vec3 dV = fragposition-start;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
float maxLength = min(length(dVWorld),far)/length(dVWorld);
dV *= maxLength;
dVWorld *= maxLength;
float dL = length(dVWorld);
float expFactor = 11.0;
for (int i=0;i<SAMPLES;i++) {
float d = (pow(expFactor, float(i+dither)/float(SAMPLES))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(SAMPLES)) * log(expFactor) / float(SAMPLES)/(expFactor-1.0);
vec3 progress = start.xyz + d*dV;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
// do main lighting
float Density = 0.05;
Density *= pow(normalize(-wpos).y*0.5+0.5,3.0);
// vec3 vL0 = vec3(0.8,0.5,1) * 0.05 * pow(normalize(wpos).y*0.5+0.5,2.0)*2.0;
vec3 vL0 = vec3(0.8,1.0,0.5) * 0.05 ;
vL += (vL0 - vL0*exp(-Density*dd*dL)) * absorbance;
absorbance *= exp(-(Density)*dd*dL);
if (absorbance < 1e-5) break;
}
return vec4(vL, absorbance);
}

View File

@ -343,7 +343,7 @@ uniform int moonPhase;
#define Cumulus_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 Cumulus_height 250 // [-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 Cumulus2_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 Cumulus2_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 Altostratus
@ -462,7 +462,7 @@ uniform int moonPhase;
// ----- END RELATED SETTINGS ----- //
//////////////////////////////////////
#define END_STORM_DENSTIY 1.0 // [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 END_STORM_DENSTIY 1.0 // [0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]
// #define DEBUG_endfog
// #define THE_ORB
@ -492,6 +492,8 @@ uniform int moonPhase;
// #define PhysicsMod_support // WARNING: this may or may not visually mess up the whole shader on AMD devices. if you dont see any weirdness then it's fine
#define PLANET_GROUND_BRIGHTNESS 1.0 // [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 CompSky_R 0.0 // [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 CompSky_G 0.0 // [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 CompSky_B 0.0 // [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 ]

View File

@ -53,16 +53,22 @@ float cloudCov(in vec3 pos, vec3 samplePos, float minHeight, float maxHeight){
float thedistance = 1.0-clamp(1.0-length((pos-cameraPosition).xz)/15000,0,1);
float heightRelativeToClouds = clamp(1.0 - max(cameraPosition.y - maxHeight,0.0) / 200.0 ,0.0,1.0);
thedistance = mix(0.0, thedistance, heightRelativeToClouds);
/// when the coordinates reach a certain height, alter the sample coordinates
if(max(pos.y - (maxHeight + 80),0.0) > 0.0){
SampleCoords0 = -( (samplePos.zx + cloud_movement*2) / 15000);
SampleCoords1 = -( (samplePos.zx - cloud_movement*2) / 1500);
}
float CloudLarge = texture2D(noisetex, SampleCoords0 ).b+thedistance;
float CloudSmall = texture2D(noisetex, SampleCoords1 ).r+thedistance;
float CloudSmall = texture2D(noisetex, SampleCoords1 ).r + thedistance;
float CloudLarge = texture2D(noisetex, SampleCoords0 ).b + thedistance;
float coverage = abs(pow(CloudLarge,1)*2.0 - 1.2)*0.5 - (1.0-CloudSmall);
float FirstLayerCoverage = DailyWeather_Cumulus(coverage);
/////// FIRST LAYER
@ -91,14 +97,14 @@ float cloudCov(in vec3 pos, vec3 samplePos, float minHeight, float maxHeight){
float cloudVol(in vec3 pos,in vec3 samplePos,in float cov, in int LoD, float minHeight, float maxHeight){
float upperPlane = 1.0 - clamp(pos.y - (maxHeight + 80),0.0,1.0);
float noise = 0.0 ;
float totalWeights = 0.0;
float pw = log(fbmPower1);
float pw2 = log(fbmPower2);
samplePos.xz -= cloud_movement/4;
// WIND
samplePos.xz += pow( max(pos.y - (minHeight+20), 0.0) / 20.0,1.50) * upperPlane;
noise += (1.0-densityAtPos(samplePos * mix(100.0,200.0,upperPlane)) ) * mix(2.0,1.0,upperPlane);
@ -147,9 +153,7 @@ float GetAltostratusDensity(vec3 pos){
}
#ifndef CLOUDSHADOWSONLY
uniform sampler2D colortex4;//Skybox
uniform sampler2D colortex4; //Skybox
//Mie phase function
@ -172,8 +176,6 @@ vec3 DoCloudLighting(
vec3 sunMultiScatter,
float distantfog
// float moonShadows,
// vec3 moonScatter
){
// float powder = 1.0 - exp((CloudShape*CloudShape) * -800);
float powder = 1.0 - exp(densityFaded * -10);
@ -194,8 +196,7 @@ vec3 DoCloudLighting(
vec4 renderClouds(
vec3 FragPosition,
vec2 Dither,
vec3 SunColor,
vec3 MoonColor,
vec3 LightColor,
vec3 SkyColor
){
@ -205,21 +206,24 @@ vec4 renderClouds(
float total_extinction = 1.0;
vec3 color = vec3(0.0);
float heightRelativeToClouds = clamp(1.0 - max(cameraPosition.y - (Cumulus_height+150),0.0) / 200.0 ,0.0,1.0);
//////////////////////////////////////////
////// lighting stuff
//////////////////////////////////////////
float shadowStep = 200.0;
vec3 dV_Sun = WsunVec*shadowStep;
float SdotV = dot(mat3(gbufferModelView)*WsunVec,normalize(FragPosition));
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) ;
vec3 sunScattering = SunColor * mieDay * 3.14;
vec3 sunMultiScattering = SunColor * mieDayMulti * 4.0;
vec3 directScattering = LightColor * mieDay * 3.14;
vec3 directMultiScattering = LightColor * mieDayMulti * 4.0;
vec3 sunIndirectScattering = SunColor * phaseg(dot(mat3(gbufferModelView)*vec3(0,1,0),normalize(FragPosition)), 0.5);
vec3 sunIndirectScattering = LightColor * phaseg(dot(mat3(gbufferModelView)*vec3(0,1,0),normalize(FragPosition)), 0.5);
//////////////////////////////////////////
@ -234,7 +238,8 @@ vec4 renderClouds(
vec3 dV_view = normalize(viewPos.xyz);
dV_view.y += 0.05;
dV_view.y += 0.05 * heightRelativeToClouds;
dV_view *= 300/abs(dV_view.y)/maxIT_clouds;
@ -252,51 +257,41 @@ vec4 renderClouds(
float startFlip = mix(max(cameraPosition.y - MaxHeight_0 - 200,0.0), max(MinHeight_0 - cameraPosition.y,0), clamp(dV_view.y,0,1));
vec3 progress_view = dV_view*Dither.y + cameraPosition + dV_view/abs(dV_view.y) * startFlip;
float allDensities = Cumulus_density;
vec3 forg = normalize(dV_view);
float distantfog = max(1.0 - clamp(exp2(pow(abs(forg.y),1.5) * -35.0),0.0,1.0),0.0);
// sunScattering *= distantfog;
// sunMultiScattering *= distantfog;
#ifdef Cumulus
for(int i = 0; i < maxIT_clouds; i++) {
// determine the base of each cloud layer
bool isUpperLayer = max(progress_view.y - MinHeight_1,0.0) > 0.0;
float CloudBaseHeights = isUpperLayer ? 200.0 + MaxHeight_0 : MaxHeight_0;
// if(isUpperLayer) allDensities = 0.25;
float cumulus = GetCumulusDensity(progress_view, 1, MinHeight_0, MaxHeight_0);
float fadedDensity = allDensities * clamp(exp( (progress_view.y - (CloudBaseHeights - 70)) / 9.0 ),0.0,1.0);
float fadedDensity = Cumulus_density * clamp(exp( (progress_view.y - (CloudBaseHeights - 70)) / 9.0 ),0.0,1.0);
if(cumulus > 1e-5){
float muE = cumulus*fadedDensity;
float sunLight = 0.0;
// float MoonLight = 0.0;
float directLight = 0.0;
for (int j=0; j < 3; j++){
vec3 shadowSamplePos = progress_view + dV_Sun * (0.1 + j * (0.1 + Dither.x*0.05));
float shadow = GetCumulusDensity(shadowSamplePos, 0, MinHeight_0, MaxHeight_0) * allDensities;
float shadow = GetCumulusDensity(shadowSamplePos, 0, MinHeight_0, MaxHeight_0) * Cumulus_density;
sunLight += shadow;
// MoonLight += shadow;
directLight += shadow;
}
if(max(progress_view.y - MaxHeight_1 + 50,0.0) < 1.0) sunLight += allDensities * 2.0 * GetCumulusDensity(progress_view + dV_Sun/abs(dV_Sun.y) * max((MaxHeight_1 - 30.0) - progress_view.y,0.0), 0, MinHeight_0, MaxHeight_0);
if(max(progress_view.y - MaxHeight_1 + 50,0.0) < 1.0) directLight += Cumulus_density * 2.0 * GetCumulusDensity(progress_view + dV_Sun/abs(dV_Sun.y) * max((MaxHeight_1 - 30.0) - progress_view.y,0.0), 0, MinHeight_0, MaxHeight_0);
float upperLayerOcclusion = !isUpperLayer ? allDensities * 2.0 * GetCumulusDensity(progress_view + vec3(0.0,1.0,0.0) * max((MaxHeight_1 - 30.0) - progress_view.y,0.0), 0, MinHeight_0, MaxHeight_0) : 0.0;
float skylightOcclusion = max(exp2((upperLayerOcclusion*upperLayerOcclusion) * -5), 0.5 + (1.0-distantfog)*0.5);
float upperLayerOcclusion = !isUpperLayer ? Cumulus_density * 2.0 * GetCumulusDensity(progress_view + vec3(0.0,1.0,0.0) * max((MaxHeight_1 - 30.0) - progress_view.y,0.0), 0, MinHeight_0, MaxHeight_0) : 0.0;
float skylightOcclusion = max(exp2((upperLayerOcclusion*upperLayerOcclusion) * -5), 0.75 + (1.0-distantfog)*0.25);
float skyScatter = clamp((CloudBaseHeights - 20 - progress_view.y) / 275.0,0.0,1.0);
vec3 Lighting = DoCloudLighting(muE, cumulus, SkyColor * skylightOcclusion, skyScatter, sunLight, sunScattering, sunMultiScattering, distantfog);
// vec3 indirectSunlight = sunIndirectScattering * skylightOcclusion * exp(-20.0 * pow(abs(upperLayerOcclusion - 0.3),2)) * exp((cumulus*cumulus) * -10.0) ;
// Lighting += indirectSunlight ;
vec3 Lighting = DoCloudLighting(muE, cumulus, SkyColor, skyScatter, directLight, directScattering, directMultiScattering, distantfog);
// a horrible approximation of direct light indirectly hitting the lower layer of clouds after scattering through/bouncing off the upper layer.
Lighting += sunIndirectScattering * skylightOcclusion * exp(-20.0 * pow(abs(upperLayerOcclusion - 0.3),2)) * exp((cumulus*cumulus) * -10.0) ; ;
color += max(Lighting - Lighting*exp(-mult*muE),0.0) * total_extinction;
@ -307,7 +302,6 @@ vec4 renderClouds(
progress_view += dV_view;
}
#endif
return vec4(color, total_extinction);
}
@ -351,6 +345,7 @@ float GetCloudShadow(vec3 feetPlayerPos){
return 1.0;
#endif
}
float GetCloudShadow_VLFOG(vec3 WorldPos, vec3 WorldSpace_sunVec){
#ifdef CLOUDS_SHADOWS
float MinHeight_0 = Cumulus_height;
@ -383,4 +378,4 @@ float GetCloudShadow_VLFOG(vec3 WorldPos, vec3 WorldSpace_sunVec){
#else
return 1.0;
#endif
}
}

View File

@ -1,5 +1,5 @@
float getWaterHeightmap(vec2 posxz, float waveM, float waveZ, float iswater) { // water waves
vec2 movement = vec2(frameTimeCounter*0.05);// *0;
vec2 movement = vec2(frameTimeCounter*0.05);
vec2 pos = posxz ;
float caustic = 1.0;
float weightSum = 0.0;