float densityAtPosFog(in vec3 pos){ pos /= 18.; pos.xz *= 0.5; vec3 p = floor(pos); vec3 f = fract(pos); f = (f*f) * (3.-2.*f); vec2 uv = p.xz + f.xz + p.y * vec2(0.0,193.0); vec2 coord = uv / 512.0; vec2 xy = texture2D(noisetex, coord).yx; return mix(xy.r,xy.g, f.y); } float cloudVol(in vec3 pos){ float Output = 0.0; vec3 samplePos = pos*vec3(1.0,1./48.,1.0); float Wind = pow(max(pos.y-30,0.0) / 15.0,2.1); float Plumes = texture2D(noisetex, (samplePos.xz + Wind)/256.0).b; float floorPlumes = clamp(0.3 - exp(Plumes * -6),0,1); Plumes *= Plumes; float Erosion = densityAtPosFog(samplePos * 400 - frameTimeCounter*10 - Wind*10) *0.7+0.3 ; // float maxdist = clamp((12 * 8) - length(pos - cameraPosition),0.0,1.0); float RoofToFloorDensityFalloff = exp(max(100-pos.y,0.0) / -15); float FloorDensityFalloff = pow(exp(max(pos.y-31,0.0) / -3.0),2); float RoofDensityFalloff = exp(max(120-pos.y,0.0) / -10); Output = max((RoofToFloorDensityFalloff - Plumes * (1.0-Erosion)) * 2.0, clamp((FloorDensityFalloff - floorPlumes*0.5) * Erosion ,0.0,1.0) ); return Output; } vec4 GetVolumetricFog( vec3 fragpos, 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) * fragpos + 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); vec3 fogcolor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.05)) ; float expFactor = 11.0; for (int i=0;i