#version 120 //Volumetric fog rendering #extension GL_EXT_gpu_shader4 : enable #include "lib/settings.glsl" flat varying vec3 sunColor; flat varying vec3 moonColor; flat varying vec3 avgAmbient2; 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 colortex3; // // uniform sampler2D colortex0; // uniform sampler2D colortex7; // uniform sampler2D colortex13; // 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 waterCaustics(vec3 wPos, vec3 lightSource) { // water waves vec2 pos = wPos.xz + (lightSource.xz/lightSource.y*wPos.y); if(isEyeInWater==1) pos = wPos.xz - (lightSource.xz/lightSource.y*wPos.y); // fix the fucky vec2 movement = vec2(-0.035*frameTimeCounter); float caustic = 0.0; float weightSum = 0.0; float radiance = 2.39996; mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance))); const vec2 wave_size[4] = vec2[]( vec2(64.), vec2(32.,16.), vec2(16.,32.), vec2(48.) ); for (int i = 0; i < 4; i++){ pos = rotationMatrix * pos; vec2 speed = movement; float waveStrength = 1.0; if( i == 0) { speed *= 0.15; waveStrength = 2.0; } float small_wave = texture2D(noisetex, pos / wave_size[i] + speed ).b * waveStrength; caustic += max( 1.0-sin( 1.0-pow( 0.5+sin( small_wave*3.0 )*0.5, 25.0) ), 0); weightSum -= exp2(caustic*0.1); } return caustic / weightSum; } vec3 normVec (vec3 vec){ return vec*inversesqrt(dot(vec,vec)); } void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){ int spCount = 8; vec3 start = toShadowSpaceProjected(rayStart); vec3 end = toShadowSpaceProjected(rayEnd); vec3 dV = (end-start); //limit ray length at 32 blocks for performance and reducing integration error //you can't see above this anyway float maxZ = min(rayLength,48.0)/(1e-8+rayLength); dV *= maxZ; vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; rayLength *= maxZ; float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; // dVWorld *= maxZ vec3 progressW = (gbufferModelViewInverse[3].xyz+cameraPosition); vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a; // vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz; // vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz); vec3 absorbance = vec3(1.0); vec3 vL = vec3(0.0); float phase = phaseg(VdotL,0.5) * 1.5 + 0.1; lightSource *= clamp(abs(WsunVec.y)*5,0.,1.); float cloudShadow = 1; float expFactor = 11.0; for (int i=0;i