From 35ee91b5d0b4736c566c170d560b2f276c5b9d2f Mon Sep 17 00:00:00 2001 From: Xonk Date: Thu, 15 Jun 2023 17:25:01 -0400 Subject: [PATCH] Make seasonal snow only in winter - early spring, make rain less when not under a cloud --- shaders/composite1.fsh | 6 ++- shaders/composite1.vsh | 21 +++++++- shaders/composite3.fsh | 6 ++- shaders/gbuffers_all_particles.fsh | 77 ++++++++++++++++-------------- shaders/gbuffers_all_solid.fsh | 11 ----- shaders/gbuffers_all_solid.vsh | 4 +- shaders/lib/climate_settings.glsl | 12 ++++- shaders/lib/settings.glsl | 3 +- shaders/lib/volumetricClouds.glsl | 19 ++++++++ 9 files changed, 105 insertions(+), 54 deletions(-) diff --git a/shaders/composite1.fsh b/shaders/composite1.fsh index 5367e7e..35df800 100644 --- a/shaders/composite1.fsh +++ b/shaders/composite1.fsh @@ -72,6 +72,8 @@ uniform vec3 sunVec; uniform ivec2 eyeBrightnessSmooth; uniform ivec2 eyeBrightness; +flat varying float WinterTimeForSnow; + // uniform int worldTime; #define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) @@ -1064,6 +1066,8 @@ void main() { SnowPatches = 1.0 - clamp( exp(pow(SnowPatches,3.5) * -100.0) ,0,1); SnowPatches *= clamp(sqrt(normal.y),0,1) * clamp(pow(lightmap.y,25)*25,0,1); + SnowPatches = mix(0.0, SnowPatches, WinterTimeForSnow); + if(!hand && !iswater){ albedo = mix(albedo, vec3(0.8,0.9,1.0), SnowPatches); SpecularTex.rg = mix(SpecularTex.rg, vec2(1,0.05), SnowPatches); @@ -1119,7 +1123,7 @@ void main() { } - // gl_FragData[0].rgb = worldToView(normal); if(z >= 1) gl_FragData[0].rgb = vec3(0.5); + // gl_FragData[0].rgb *= GetCloudSkyOcclusion(p3 + cameraPosition); // if (abs(filtered.b-0.1) < 0.0004 ) gl_FragData[0].rgb = vec3(0,1,0); /* DRAWBUFFERS:3 */ diff --git a/shaders/composite1.vsh b/shaders/composite1.vsh index 523082f..5a2e718 100644 --- a/shaders/composite1.vsh +++ b/shaders/composite1.vsh @@ -33,6 +33,19 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), #include "/lib/util.glsl" #include "/lib/res_params.glsl" + + + + + +#define SEASONS_VSH +#include "/lib/climate_settings.glsl" + +flat varying float WinterTimeForSnow; + + + + void main() { gl_Position = ftransform(); @@ -57,5 +70,11 @@ void main() { zMults = vec3((far * near)*2.0,far+near,far-near); - + WinterTimeForSnow = 0.0; + + #ifdef Snowy_Winter + vec3 color1 = vec3(0.0); + vec3 color2 = color1; + YearCycleColor(color1, color2, WinterTimeForSnow); + #endif } diff --git a/shaders/composite3.fsh b/shaders/composite3.fsh index f78349b..2b1a5c0 100644 --- a/shaders/composite3.fsh +++ b/shaders/composite3.fsh @@ -276,7 +276,10 @@ void main() { color += vl.rgb; float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0); // bloomy rain effect - if(rainDrops > 0.0) vl.a *= clamp(exp2(-rainDrops*5),0.,1.); // bloomy rain effect + + + + if(rainDrops > 0.0) vl.a *= clamp(1.0 - rainDrops ,0.,1.); // bloomy rain effect gl_FragData[0].r = vl.a; /// lava. @@ -302,7 +305,6 @@ void main() { if(texcoord.x < 0.45 && luma(thingy) > 0.0 ) color.rgb = thingy; #endif - gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0); // gl_FragData[1].rgb = vec3(tangentNormals,0.0); diff --git a/shaders/gbuffers_all_particles.fsh b/shaders/gbuffers_all_particles.fsh index 567f691..826f573 100644 --- a/shaders/gbuffers_all_particles.fsh +++ b/shaders/gbuffers_all_particles.fsh @@ -96,50 +96,57 @@ vec3 normVec (vec3 vec){ void main() { vec4 TEXTURE = texture2D(texture, lmtexcoord.xy)*color; - - gl_FragData[1].a = TEXTURE.a; // for bloomy rain and stuff - - -#ifndef WEATHER - - gl_FragData[1].a = 1.0 - TEXTURE.a; // for bloomy rain and stuff - - vec3 Albedo = toLinear(TEXTURE.rgb); vec2 tempOffset = offsets[framemod8]; vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0)); vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; vec3 np3 = normVec(p3); + float cloudOcclusion = 0.0; - float Shadows = 1.0; - vec3 p3_shadow = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; - vec3 projectedShadowPosition = mat3(shadowModelView) * p3_shadow + shadowModelView[3].xyz; - projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz; + if(TEXTURE.a > 0.0) cloudOcclusion = 1.0 - GetCloudSkyOcclusion(p3 + cameraPosition)*0.9; + gl_FragData[1].a = TEXTURE.a * cloudOcclusion; // for bloomy rain and stuff - //apply distortion - float distortFactor = calcDistort(projectedShadowPosition.xy); - projectedShadowPosition.xy *= distortFactor; - //do shadows only if on shadow map - if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution){ - - float diffthresh = 0.0002; - projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5,0.5,0.5); - - Shadows = shadow2D_bicubic(shadow,vec3(projectedShadowPosition + vec3(0.0,0.0,-diffthresh*1.2))); - - } - #ifdef CLOUDS_SHADOWS - Shadows *= GetCloudShadow(p3); - #endif - - float lightleakfix = clamp(eyeBrightnessSmooth.y/240.0,0.0,1.0); - float phase = phaseg(clamp(dot(np3, WsunVec),0.0,1.0),(1.0-gl_FragData[0].a) * 0.8 + 0.1) + 1.0 ; - vec3 Direct_lighting = DoDirectLighting(lightCol.rgb/80., Shadows, 1.0, 0.0) * phase * lightleakfix; - - vec3 Indirect_lighting = DoAmbientLighting(avgAmbient, vec3(TORCH_R,TORCH_G,TORCH_B), lmtexcoord.zw, 5.0); +#ifndef WEATHER + gl_FragData[1].a = 1.0 - TEXTURE.a; gl_FragData[0].a = TEXTURE.a; - gl_FragData[0].rgb = (Direct_lighting + Indirect_lighting) * Albedo; + + vec3 Albedo = toLinear(TEXTURE.rgb); + + // do the maths only if the pixels exist.... + if(TEXTURE.a > 0.0){ + + float Shadows = 1.0; + vec3 p3_shadow = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; + vec3 projectedShadowPosition = mat3(shadowModelView) * p3_shadow + shadowModelView[3].xyz; + projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz; + + //apply distortion + float distortFactor = calcDistort(projectedShadowPosition.xy); + projectedShadowPosition.xy *= distortFactor; + //do shadows only if on shadow map + if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution){ + + float diffthresh = 0.0002; + projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5,0.5,0.5); + + Shadows = shadow2D_bicubic(shadow,vec3(projectedShadowPosition + vec3(0.0,0.0,-diffthresh*1.2))); + + } + #ifdef CLOUDS_SHADOWS + Shadows *= GetCloudShadow(p3); + #endif + + float lightleakfix = clamp(eyeBrightnessSmooth.y/240.0,0.0,1.0); + float phase = phaseg(clamp(dot(np3, WsunVec),0.0,1.0),(1.0-gl_FragData[0].a) * 0.8 + 0.1) + 1.0 ; + vec3 Direct_lighting = DoDirectLighting(lightCol.rgb/80., Shadows, 1.0, 0.0) * phase * lightleakfix; + + vec3 Indirect_lighting = DoAmbientLighting(avgAmbient, vec3(TORCH_R,TORCH_G,TORCH_B), lmtexcoord.zw, 5.0); + // gl_FragData[0].a = TEXTURE.a; + gl_FragData[0].rgb = (Direct_lighting + Indirect_lighting) * Albedo; + + } + #endif } \ No newline at end of file diff --git a/shaders/gbuffers_all_solid.fsh b/shaders/gbuffers_all_solid.fsh index ec34903..5e5ce22 100644 --- a/shaders/gbuffers_all_solid.fsh +++ b/shaders/gbuffers_all_solid.fsh @@ -229,17 +229,6 @@ vec3 blackbody2(float Temp) return srgbToLinear2(col); } -float densityAtPosSNOW(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); -} //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// diff --git a/shaders/gbuffers_all_solid.vsh b/shaders/gbuffers_all_solid.vsh index 956f6b3..664f7f4 100644 --- a/shaders/gbuffers_all_solid.vsh +++ b/shaders/gbuffers_all_solid.vsh @@ -53,7 +53,6 @@ flat varying int LIGHTNING; flat varying float SSSAMOUNT; flat varying float EMISSIVE; - flat varying int NameTags; in vec3 at_velocity; @@ -298,7 +297,8 @@ void main() { #ifndef BLOCKENTITIES #ifndef ENTITIES #ifndef HAND - YearCycleColor(color.rgb, gl_Color.rgb); + float blank = 0.0; + YearCycleColor(color.rgb, gl_Color.rgb, blank); #endif #endif #endif diff --git a/shaders/lib/climate_settings.glsl b/shaders/lib/climate_settings.glsl index 37f6779..13ad3ed 100644 --- a/shaders/lib/climate_settings.glsl +++ b/shaders/lib/climate_settings.glsl @@ -29,7 +29,8 @@ void YearCycleColor ( inout vec3 FinalColor, - vec3 glcolor + vec3 glcolor, + inout float SnowySeason ){ // colors for things that arent leaves and using the tint index. vec3 SummerCol = vec3(Summer_R, Summer_G, Summer_B); @@ -79,6 +80,15 @@ // multiply final color by the final lerped color, because it contains all the other colors. if(IsTintIndex) FinalColor = SpringToSummer; + + #ifdef Snowy_Winter + // this is to make snow only exist in winter + float FallToWinter_snowfall = mix(0.0, 1.0, AutumnTime); + float WinterToSpring_snowfall = mix(FallToWinter_snowfall, 0.0, WinterTime); + SnowySeason = WinterToSpring_snowfall; + #else + SnowySeason = 0.0; + #endif } #endif #endif diff --git a/shaders/lib/settings.glsl b/shaders/lib/settings.glsl index 6016f7f..f9df006 100644 --- a/shaders/lib/settings.glsl +++ b/shaders/lib/settings.glsl @@ -216,7 +216,8 @@ #define Seasons #define Season_Length 24 // how long each season lasts in minecraft days. 91 is roughly how long each season is in reality. 1 will make a year last 4 days [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91] -// #define Snowy_Winter // snow in the winter, yes or no? +#define Snowy_Winter // snow in the winter, yes or no? + #define Summer_R 1.0 // the color of the plants during this season [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0] #define Summer_G 1.0 // the color of the plants during this season [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0] #define Summer_B 1.0 // the color of the plants during this season [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0] diff --git a/shaders/lib/volumetricClouds.glsl b/shaders/lib/volumetricClouds.glsl index a243bcc..3fbf91c 100644 --- a/shaders/lib/volumetricClouds.glsl +++ b/shaders/lib/volumetricClouds.glsl @@ -391,5 +391,24 @@ float GetCloudShadow_VLFOG(vec3 WorldPos){ // do not allow it to exist above the lowest cloud plane // shadow *= clamp(((MaxCumulusHeight + CumulusHeight)*0.435 - WorldPos.y)/100,0.0,1.0) ; + return shadow; +} + +float GetCloudSkyOcclusion(vec3 WorldPos){ + + float shadow = 0.0; + + vec3 shadowDir = vec3(0,1,0); + + + // assume a flat layer of cloud, and stretch the sampled density along the sunvector, starting from some vertical layer in the cloud. + #ifdef Cumulus + vec3 lowShadowStart = WorldPos + shadowDir/abs(shadowDir.y) * max((MaxCumulusHeight - 60) - WorldPos.y,0.0) ; + shadow += GetCumulusDensity(lowShadowStart,0)*Cumulus_density; + #endif + + + shadow = clamp(exp(-shadow*25.0) ,0.0,1.0); + return shadow; } \ No newline at end of file