2023-07-07 13:56:38 +01:00
|
|
|
#include "/lib/settings.glsl"
|
2023-01-12 15:00:14 -05:00
|
|
|
//Computes volumetric clouds at variable resolution (default 1/4 res)
|
2023-01-12 15:28:19 -05:00
|
|
|
|
2023-06-26 00:33:31 -04:00
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
flat varying vec3 sunColor;
|
2024-03-12 17:16:30 -04:00
|
|
|
// flat varying vec3 moonColor;
|
2023-07-25 22:48:08 -04:00
|
|
|
flat varying vec3 averageSkyCol;
|
2023-06-26 00:33:31 -04:00
|
|
|
|
|
|
|
flat varying float tempOffsets;
|
2023-10-07 22:18:20 -04:00
|
|
|
// uniform float far;
|
2023-06-26 00:33:31 -04:00
|
|
|
uniform float near;
|
2023-01-12 15:00:14 -05:00
|
|
|
uniform sampler2D depthtex0;
|
2024-05-04 21:08:24 -04:00
|
|
|
|
|
|
|
#ifdef DISTANT_HORIZONS
|
2024-02-05 16:04:37 -05:00
|
|
|
uniform sampler2D dhDepthTex;
|
2024-05-16 19:56:32 -04:00
|
|
|
uniform sampler2D dhDepthTex1;
|
2024-05-04 21:08:24 -04:00
|
|
|
#endif
|
2024-05-16 19:56:32 -04:00
|
|
|
|
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
// uniform sampler2D colortex4;
|
|
|
|
uniform sampler2D noisetex;
|
|
|
|
|
2024-02-05 16:04:37 -05:00
|
|
|
uniform sampler2D colortex12;
|
|
|
|
|
2023-04-16 16:18:26 -04:00
|
|
|
flat varying vec3 WsunVec;
|
2024-06-10 23:26:19 -04:00
|
|
|
uniform float sunElevation;
|
2023-01-12 15:00:14 -05:00
|
|
|
uniform vec3 sunVec;
|
|
|
|
uniform vec2 texelSize;
|
|
|
|
uniform float frameTimeCounter;
|
|
|
|
uniform float rainStrength;
|
|
|
|
uniform int frameCounter;
|
|
|
|
uniform int framemod8;
|
|
|
|
uniform mat4 gbufferProjectionInverse;
|
|
|
|
uniform mat4 gbufferModelViewInverse;
|
|
|
|
uniform vec3 cameraPosition;
|
|
|
|
|
|
|
|
uniform mat4 gbufferModelView;
|
2024-05-16 19:56:32 -04:00
|
|
|
uniform mat4 gbufferProjection;
|
2023-01-12 15:00:14 -05:00
|
|
|
// flat varying vec2 TAA_Offset;
|
|
|
|
|
2024-05-16 19:56:32 -04:00
|
|
|
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
|
|
|
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
|
|
|
|
vec3 toScreenSpace(vec3 p) {
|
|
|
|
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
|
|
|
|
vec3 p3 = p * 2. - 1.;
|
|
|
|
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
|
|
|
|
return fragposition.xyz / fragposition.w;
|
|
|
|
}
|
2024-02-12 00:49:20 -05:00
|
|
|
|
2024-05-16 19:56:32 -04:00
|
|
|
|
|
|
|
#include "/lib/DistantHorizons_projections.glsl"
|
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
float R2_dither(){
|
2024-03-01 22:48:09 -05:00
|
|
|
#ifdef TAA
|
2023-10-18 17:43:29 -04:00
|
|
|
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
|
2024-03-01 22:48:09 -05:00
|
|
|
#else
|
|
|
|
|
|
|
|
vec2 coord = gl_FragCoord.xy;
|
|
|
|
#endif
|
2023-01-12 15:00:14 -05:00
|
|
|
vec2 alpha = vec2(0.75487765, 0.56984026);
|
2023-10-18 17:43:29 -04:00
|
|
|
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
|
2023-01-12 15:00:14 -05:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2023-10-07 22:18:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-06 21:03:31 -04:00
|
|
|
#include "/lib/TAA_jitter.glsl"
|
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
float blueNoise(){
|
2024-03-01 22:48:09 -05:00
|
|
|
#ifdef TAA
|
2024-03-12 17:16:30 -04:00
|
|
|
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
2024-03-01 22:48:09 -05:00
|
|
|
#else
|
2024-03-12 17:16:30 -04:00
|
|
|
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a);
|
2024-03-01 22:48:09 -05:00
|
|
|
#endif
|
2023-01-12 15:00:14 -05:00
|
|
|
}
|
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
vec3 normVec (vec3 vec){
|
|
|
|
return vec*inversesqrt(dot(vec,vec));
|
|
|
|
}
|
2024-05-16 19:56:32 -04:00
|
|
|
uniform float far;
|
2023-06-29 00:10:03 -04:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
|
2024-05-16 19:56:32 -04:00
|
|
|
float ld(float dist) {
|
|
|
|
return (2.0 * near) / (far + near - dist * (far - near));
|
|
|
|
}
|
|
|
|
|
|
|
|
uniform int dhRenderDistance;
|
|
|
|
|
|
|
|
#include "/lib/lightning_stuff.glsl"
|
2023-10-07 22:18:20 -04:00
|
|
|
#include "/lib/sky_gradient.glsl"
|
2024-05-22 00:01:17 -04:00
|
|
|
#include "/lib/res_params.glsl"
|
2024-05-16 19:56:32 -04:00
|
|
|
|
2024-06-27 15:53:27 -04:00
|
|
|
#define CLOUDS_INTERSECT_TERRAIN
|
2024-06-19 21:44:21 -04:00
|
|
|
uniform float eyeAltitude;
|
2023-10-07 22:18:20 -04:00
|
|
|
#include "/lib/volumetricClouds.glsl"
|
2024-05-22 00:01:17 -04:00
|
|
|
|
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
|
2024-02-05 16:04:37 -05:00
|
|
|
|
2024-05-16 19:56:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
|
|
|
//////////////////////////////VOID MAIN//////////////////////////////
|
|
|
|
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2023-01-12 15:00:14 -05:00
|
|
|
void main() {
|
|
|
|
/* DRAWBUFFERS:0 */
|
2024-06-19 21:44:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined OVERWORLD_SHADER && defined VOLUMETRIC_CLOUDS && !defined CLOUDS_INTERSECT_TERRAIN
|
2023-10-07 22:18:20 -04:00
|
|
|
vec2 halfResTC = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY/RENDER_SCALE+0.5+offsets[framemod8]*CLOUDS_QUALITY*RENDER_SCALE*0.5);
|
2024-05-16 19:56:32 -04:00
|
|
|
|
2024-06-10 23:26:19 -04:00
|
|
|
vec2 halfResTC2 = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY+0.5+offsets[framemod8]*CLOUDS_QUALITY*0.5);
|
2024-05-16 19:56:32 -04:00
|
|
|
|
2024-06-10 23:26:19 -04:00
|
|
|
#ifdef CLOUDS_INTERSECT_TERRAIN
|
|
|
|
float depth = texture2D(depthtex0, halfResTC2*texelSize).x;
|
|
|
|
|
|
|
|
#ifdef DISTANT_HORIZONS
|
|
|
|
float DH_depth = texture2D(dhDepthTex, halfResTC2*texelSize).x;
|
|
|
|
vec3 viewPos = toScreenSpace_DH(halfResTC*texelSize, depth, DH_depth);
|
|
|
|
#else
|
|
|
|
vec3 viewPos = toScreenSpace(vec3(halfResTC*texelSize, depth));
|
|
|
|
#endif
|
2024-05-16 19:56:32 -04:00
|
|
|
#else
|
2024-06-10 23:26:19 -04:00
|
|
|
vec3 viewPos = toScreenSpace(vec3(halfResTC*texelSize, 1.0));
|
2024-05-16 19:56:32 -04:00
|
|
|
#endif
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-06-19 21:44:21 -04:00
|
|
|
vec3 tesvar = vec3(0.0);
|
|
|
|
vec4 VolumetricClouds = renderClouds(viewPos, vec2(R2_dither(), blueNoise()), sunColor/80.0, averageSkyCol/30.0,tesvar);
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2023-10-07 22:18:20 -04:00
|
|
|
gl_FragData[0] = VolumetricClouds;
|
|
|
|
#else
|
|
|
|
gl_FragData[0] = vec4(0.0,0.0,0.0,1.0);
|
|
|
|
#endif
|
|
|
|
}
|