#version 120 //Volumetric fog rendering #extension GL_EXT_gpu_shader4 : enable #include "lib/settings.glsl" flat varying vec4 lightCol; flat varying vec3 ambientUp; flat varying vec3 ambientLeft; flat varying vec3 ambientRight; flat varying vec3 ambientB; flat varying vec3 ambientF; flat varying vec3 ambientDown; flat varying vec3 avgAmbient; flat varying float tempOffsets; flat varying float fogAmount; flat varying float VFAmount; flat varying float FogSchedule; uniform sampler2D noisetex; uniform sampler2D depthtex0; uniform sampler2D depthtex1; uniform sampler2DShadow shadow; flat varying vec3 refractedSunVec; flat varying vec3 WsunVec; uniform sampler2D colortex1; uniform sampler2D colortex2; uniform sampler2D colortex3; // uniform sampler2D colortex4; uniform vec3 sunVec; uniform float far; uniform float near; uniform int frameCounter; uniform float rainStrength; uniform float sunElevation; uniform ivec2 eyeBrightnessSmooth; uniform float frameTimeCounter; uniform int isEyeInWater; uniform vec2 texelSize; #include "lib/Shadow_Params.glsl" #include "lib/color_transforms.glsl" #include "lib/color_dither.glsl" #include "lib/projections.glsl" #include "lib/sky_gradient.glsl" #include "/lib/res_params.glsl" // #include "lib/biome_specifics.glsl" #define TIMEOFDAYFOG #include "lib/volumetricClouds.glsl" float blueNoise(){ return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); } float R2_dither(){ vec2 alpha = vec2(0.75487765, 0.56984026); return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ; } float R2_dither2(){ vec2 alpha = vec2(0.75487765, 0.56984026); return fract(alpha.x *(1- gl_FragCoord.x) + alpha.y * (1-gl_FragCoord.y) + 1.0/1.6180339887 * frameCounter) ; } float interleaved_gradientNoise(){ vec2 alpha = vec2(0.75487765, 0.56984026); vec2 coord = vec2(alpha.x * gl_FragCoord.x,alpha.y * gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter; float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); return noise; } float phaseRayleigh(float cosTheta) { const vec2 mul_add = vec2(0.1, 0.28) /acos(-1.0); return cosTheta * mul_add.x + mul_add.y; // optimized version from [Elek09], divided by 4 pi for energy conservation } float GetCloudShadow(vec3 eyePlayerPos){ vec3 worldPos = (eyePlayerPos + cameraPosition) - Cloud_Height; vec3 cloudPos = worldPos*Cloud_Size + WsunVec/abs(WsunVec.y) * ((3250 - 3250*0.35) - worldPos.y*Cloud_Size) ; float shadow = getCloudDensity(cloudPos, 1); shadow = clamp(exp(-shadow*5),0.0,1.0); return shadow ; } 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 fog_densities_atmospheric = 24 * Haze_amount; // this is seperate from the cloudy and uniform fog. float cloudVol(in vec3 pos){ vec3 samplePos = pos*vec3(1.0,1./24.,1.0); vec3 samplePos2 = pos*vec3(1.0,1./48.,1.0); float mult = exp( -max((pos.y - SEA_LEVEL) / 35.,0.0)); float fog_shape = 1-densityAtPosFog(samplePos * 24.0); float fog_eroded = 1-densityAtPosFog( samplePos2 * 200.0); float CloudyFog = max( (fog_shape*2.0 - fog_eroded*0.5) - 1.2, 0.0) * mult; float UniformFog = exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0)); float RainFog = max(fog_shape*10. - 7.,0.5) * exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0)) * 5. * rainStrength; TimeOfDayFog(UniformFog, CloudyFog); return CloudyFog + UniformFog + RainFog; } mat2x3 getVolumetricRays( float dither, vec3 fragpos, float dither2 ){ //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; //apply dither vec3 progress = start.xyz; vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; vec3 vL = vec3(0.); float SdotV = dot(sunVec,normalize(fragpos))*lightCol.a; float dL = length(dVWorld); //Mie phase + somewhat simulates multiple scattering (Horizon zero down cloud approx) float mie = phaseg(SdotV,0.7)*5.0 + 1.0; float rayL = phaseRayleigh(SdotV); // Makes fog more white idk how to simulate it correctly vec3 sunColor = lightCol.rgb / 127.0; vec3 skyCol0 = (ambientUp / 150. * 5.); // * max(abs(WsunVec.y)/150.0,0.); vec3 rC = vec3(fog_coefficientRayleighR*1e-6, fog_coefficientRayleighG*1e-5, fog_coefficientRayleighB*1e-5); vec3 mC = vec3(fog_coefficientMieR*1e-6, fog_coefficientMieG*1e-6, fog_coefficientMieB*1e-6); float mu = 1.0; float muS = mu; vec3 absorbance = vec3(1.0); float expFactor = 11.0; vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a; float cloudShadow = 1.0; for (int i=0;i