#version 120 //Volumetric fog rendering #extension GL_EXT_gpu_shader4 : enable #define VL_SAMPLES 8 //[4 6 8 10 12 14 16 20 24 30 40 50] #define Ambient_Mult 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0 5.0 6.0 10.0] #define SEA_LEVEL 70 //[0 10 20 30 40 50 60 70 80 90 100 110 120 130 150 170 190] //The volumetric light uses an altitude-based fog density, this is where fog density is the highest, adjust this value according to your world. #define ATMOSPHERIC_DENSITY 1.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 4.0 5.0 7.5 10.0 12.5 15.0 20.] #define fog_mieg1 0.40 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0] #define fog_mieg2 0.10 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0] #define fog_coefficientRayleighR 5.8 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0] #define fog_coefficientRayleighG 1.35 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0] #define fog_coefficientRayleighB 3.31 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0] #define fog_coefficientMieR 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0] #define fog_coefficientMieG 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0] #define fog_coefficientMieB 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0] #define Underwater_Fog_Density 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0] 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 float tempOffsets; flat varying float fogAmount; flat varying float VFAmount; uniform sampler2D noisetex; uniform sampler2D depthtex0; uniform sampler2D colortex2; uniform sampler2D colortex3; // uniform sampler2D colortex4; uniform vec3 sunVec; uniform float far; uniform int frameCounter; uniform float rainStrength; uniform float sunElevation; uniform ivec2 eyeBrightnessSmooth; uniform float frameTimeCounter; uniform int isEyeInWater; uniform vec2 texelSize; uniform float isWastes; uniform float isWarpedForest; uniform float isCrimsonForest; uniform float isSoulValley; uniform float isBasaltDelta; #include "lib/waterOptions.glsl" #include "lib/color_transforms.glsl" #include "lib/color_dither.glsl" #include "lib/projections.glsl" #include "lib/sky_gradient.glsl" #include "lib/volumetricClouds.glsl" #define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) float interleaved_gradientNoise(){ return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets); } 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){ vec3 samplePos = pos*vec3(1.0,1./24.,1.0) ; vec3 samplePos2 = pos*vec3(1.0,1./48.,1.0) + vec3(frameTimeCounter,0,frameTimeCounter); float fog_shape = 1-densityAtPosFog(samplePos * 16.0 ); float fog_eroded = densityAtPosFog( samplePos2 * 255.0 ); return max( (fog_shape*2.0 - fog_eroded*0.2) - 1.5, 0.0) * 255*255 ; } 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 } mat2x3 getVolumetricRays(float dither,vec3 fragpos, vec3 fragpos_ALT) { //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*4)/length(dVWorld); dV *= maxLength; dVWorld *= maxLength; //apply dither vec3 progress = start.xyz; vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; vec3 vL = vec3(0.); float dL = length(dVWorld); vec3 lightSource = normalize(WsunVec); vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource; float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpos)); float mie = phaseg(SdotV,0.8); float rayL = phaseRayleigh(SdotV); float mu = 1.0; vec3 absorbance = vec3(1.0); float expFactor = 11.0; vec3 fogColor = gl_Fog.color.rgb * 0.5 ; vec3 lightning = SunCol ; vec3 rC = vec3(fogColor.r*1e-6, fogColor.g*1e-5, fogColor.b*1e-5); vec3 mC = vec3(fogColor.r*1e-6, fogColor.g*1e-6, fogColor.b*1e-6); for (int i=0;i