From b91c1f796ff8011fba3ec536719ebe267b860125 Mon Sep 17 00:00:00 2001 From: Xonk Date: Mon, 12 Feb 2024 00:49:20 -0500 Subject: [PATCH] add max distance for biome effects. make border fog cylindrical. Fix compile error on optifine. --- shaders/dimensions/DH_solid.fsh | 27 ++++++++- shaders/dimensions/composite1.fsh | 14 +++-- shaders/dimensions/composite3.fsh | 5 +- shaders/dimensions/composite5.fsh | 12 ++-- shaders/dimensions/deferred.fsh | 4 +- shaders/dimensions/deferred2.fsh | 27 +-------- shaders/lib/DistantHorizons_projections.glsl | 8 ++- shaders/lib/climate_settings.glsl | 59 ++++++++++++++------ shaders/lib/overworld_fog.glsl | 30 +++++++--- 9 files changed, 119 insertions(+), 67 deletions(-) diff --git a/shaders/dimensions/DH_solid.fsh b/shaders/dimensions/DH_solid.fsh index f41afc9..ed7b76a 100644 --- a/shaders/dimensions/DH_solid.fsh +++ b/shaders/dimensions/DH_solid.fsh @@ -75,6 +75,22 @@ float R2_dither(){ return fract(alpha.x * coord.x + alpha.y * coord.y ) ; } +//3D noise from 2d texture +float densityAtPos(in vec3 pos){ + pos /= 18.; + pos.xz *= 0.5; + vec3 p = floor(pos); + vec3 f = fract(pos); + vec2 uv = p.xz + f.xz + p.y * vec2(0.0,193.0); + vec2 coord = uv / 512.0; + + //The y channel has an offset to avoid using two textures fetches + vec2 xy = texture2D(noisetex, coord).yx; + + return mix(xy.r,xy.g, f.y); +} +uniform vec3 cameraPosition; + /* RENDERTARGETS:1,7,8 */ void main() { // overdraw prevention @@ -90,7 +106,16 @@ void main() { // alpha is material masks, set it to 0.65 to make a DH LODs mask. vec4 Albedo = vec4(gcolor.rgb, 1.0); - + + // vec3 worldPos = mat3(gbufferModelViewInverse)*pos.xyz + cameraPosition; + // worldPos = (worldPos*vec3(1.0,1./48.,1.0)/4) ; + // worldPos = floor(worldPos * 4.0 + 0.001) / 32.0; + // float noiseTexture = densityAtPos(worldPos* 5000 ) +0.5; + + // float noiseFactor = max(1.0 - 0.3 * dot(Albedo.rgb, Albedo.rgb),0.0); + // Albedo.rgb *= pow(noiseTexture, 0.6 * noiseFactor); + // Albedo.rgb *= (noiseTexture*noiseTexture)*0.5 + 0.5; + #ifdef WhiteWorld Albedo.rgb = vec3(0.5); #endif diff --git a/shaders/dimensions/composite1.fsh b/shaders/dimensions/composite1.fsh index f3ac550..0be5e27 100644 --- a/shaders/dimensions/composite1.fsh +++ b/shaders/dimensions/composite1.fsh @@ -754,12 +754,18 @@ void main() { #ifdef OVERWORLD_SHADER DirectLightColor = lightCol.rgb/80.0; + AmbientLightColor = averageSkyCol_Clouds; #ifdef PER_BIOME_ENVIRONMENT - BiomeSunlightColor(DirectLightColor); + // BiomeSunlightColor(DirectLightColor); + vec3 biomeDirect = DirectLightColor; + vec3 biomeIndirect = AmbientLightColor; + float inBiome = BiomeVLFogColors(biomeDirect, biomeIndirect); + + float maxDistance = inBiome * min(max(1.0 - length(feetPlayerPos)/(32*8),0.0)*2.0,1.0); + DirectLightColor = mix(DirectLightColor, biomeDirect, maxDistance); #endif - - AmbientLightColor = averageSkyCol_Clouds; + vec3 filteredShadow = vec3(1.412,1.0,0.0); if (!hand) filteredShadow = texture2D(colortex3,texcoord).rgb; @@ -845,7 +851,7 @@ void main() { vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz; - + if(!hand || !entities) GriAndEminShadowFix(shadowPlayerPos, viewToWorld(FlatNormals), vanilla_AO, lightmap.y, entities); vec3 projectedShadowPosition = mat3(shadowModelView) * shadowPlayerPos + shadowModelView[3].xyz; diff --git a/shaders/dimensions/composite3.fsh b/shaders/dimensions/composite3.fsh index a69896b..aa95397 100644 --- a/shaders/dimensions/composite3.fsh +++ b/shaders/dimensions/composite3.fsh @@ -248,6 +248,7 @@ void main() { vec3 np3 = normVec(p3); float linearDistance = length(p3); + float linearDistance_cylinder = length(p3.xz); float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0); float lightleakfixfast = clamp(eyeBrightness.y/240.,0.0,1.0); @@ -292,9 +293,9 @@ void main() { #if defined BorderFog #ifdef DISTANT_HORIZONS - float fog = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - linearDistance / dhFarPlane,0.0)*3.0,1.0),2.0),2.0); + float fog = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - linearDistance_cylinder / dhFarPlane,0.0)*3.0,1.0),2.0),2.0); #else - float fog = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - linearDistance / far,0.0)*5.0,1.0),2.0),2.0); + float fog = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - linearDistance_cylinder / far,0.0)*5.0,1.0),2.0),2.0); #endif fog *= exp(-10.0 * pow(clamp(np3.y,0.0,1.0)*4.0,2.0)); diff --git a/shaders/dimensions/composite5.fsh b/shaders/dimensions/composite5.fsh index 7da7dae..6ebf431 100644 --- a/shaders/dimensions/composite5.fsh +++ b/shaders/dimensions/composite5.fsh @@ -229,6 +229,7 @@ vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth, uniform sampler2D dhDepthTex; +uniform float far; uniform float dhFarPlane; uniform float dhNearPlane; @@ -250,9 +251,12 @@ float invertlinearDepthFast(const in float depth, const in float near, const in vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) { - mat4 projectionMatrix = depthCheck ? dhPreviousProjection : gbufferPreviousProjection; - - return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + #ifdef DISTANT_HORIZONS + mat4 projectionMatrix = depthCheck ? dhPreviousProjection : gbufferPreviousProjection; + return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + #else + return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + #endif } vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) { @@ -309,7 +313,7 @@ vec4 TAA_hq(){ #ifdef DISTANT_HORIZONS vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhDepthTex, depthCheck); #else - vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0); + vec3 closestToCamera = closestToCamera5taps(adjTC,depthtex0); #endif #endif diff --git a/shaders/dimensions/deferred.fsh b/shaders/dimensions/deferred.fsh index 3a9f347..22fbeae 100644 --- a/shaders/dimensions/deferred.fsh +++ b/shaders/dimensions/deferred.fsh @@ -77,8 +77,8 @@ float blueNoise(){ } #define DHVLFOG -#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) -#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) +// #define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) +// #define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) vec3 toScreenSpace(vec3 p) { vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); diff --git a/shaders/dimensions/deferred2.fsh b/shaders/dimensions/deferred2.fsh index 32102f1..3bbdc50 100644 --- a/shaders/dimensions/deferred2.fsh +++ b/shaders/dimensions/deferred2.fsh @@ -43,6 +43,7 @@ vec3 toScreenSpace(vec3 p) { vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; return fragposition.xyz / fragposition.w; } + float R2_dither(){ vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0; vec2 alpha = vec2(0.75487765, 0.56984026); @@ -76,32 +77,6 @@ vec3 normVec (vec3 vec){ return vec*inversesqrt(dot(vec,vec)); } -#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) -#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) - uniform mat4 dhPreviousProjection; - uniform mat4 dhProjectionInverse; - uniform mat4 dhProjection; - - vec3 DH_toScreenSpace(vec3 p) { - vec4 iProjDiag = vec4(dhProjectionInverse[0].x, dhProjectionInverse[1].y, dhProjectionInverse[2].zw); - vec3 feetPlayerPos = p * 2. - 1.; - vec4 viewPos = iProjDiag * feetPlayerPos.xyzz + dhProjectionInverse[3]; - return viewPos.xyz / viewPos.w; - } - - vec3 DH_toClipSpace3(vec3 viewSpacePosition) { - return projMAD(dhProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; - } - - uniform float dhFarPlane; - uniform float dhNearPlane; - float DH_ld(float dist) { - return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane)); - } - float DH_inv_ld (float lindepth){ - return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane); - } - #include "/lib/lightning_stuff.glsl" #include "/lib/sky_gradient.glsl" diff --git a/shaders/lib/DistantHorizons_projections.glsl b/shaders/lib/DistantHorizons_projections.glsl index cb2594c..e8ba75c 100644 --- a/shaders/lib/DistantHorizons_projections.glsl +++ b/shaders/lib/DistantHorizons_projections.glsl @@ -33,9 +33,13 @@ vec3 toScreenSpace_DH( vec2 texcoord, float depth, float DHdepth ) { } vec3 toClipSpace3_DH( vec3 viewSpacePosition, bool depthCheck ) { - mat4 projectionMatrix = depthCheck ? dhProjection : gbufferProjection; + #ifdef DISTANT_HORIZONS + mat4 projectionMatrix = depthCheck ? dhProjection : gbufferProjection; + return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + #else + return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + #endif - return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; } mat4 DH_shadowProjectionTweak( in mat4 projection){ diff --git a/shaders/lib/climate_settings.glsl b/shaders/lib/climate_settings.glsl index 1bd986b..1307bca 100644 --- a/shaders/lib/climate_settings.glsl +++ b/shaders/lib/climate_settings.glsl @@ -175,25 +175,26 @@ FinalFogColor = mix(FinalFogColor, BiomeColors, Inbiome); } - void BiomeSunlightColor( - inout vec3 FinalSunlightColor - ){ - // this is a little complicated? lmao - vec3 BiomeColors = vec3(0.0); - BiomeColors.r = isSwamps*SWAMP_R + isJungles*JUNGLE_R + isDarkForests*DARKFOREST_R + sandStorm*1.0 + snowStorm*0.6; - BiomeColors.g = isSwamps*SWAMP_G + isJungles*JUNGLE_G + isDarkForests*DARKFOREST_G + sandStorm*0.5 + snowStorm*0.8; - BiomeColors.b = isSwamps*SWAMP_B + isJungles*JUNGLE_B + isDarkForests*DARKFOREST_B + sandStorm*0.3 + snowStorm*1.0; + // void BiomeSunlightColor( + // inout vec3 FinalSunlightColor + // ){ + // // this is a little complicated? lmao + // vec3 BiomeColors = vec3(0.0); + // BiomeColors.r = isSwamps*SWAMP_R + isJungles*JUNGLE_R + isDarkForests*DARKFOREST_R + sandStorm*1.0 + snowStorm*0.6; + // BiomeColors.g = isSwamps*SWAMP_G + isJungles*JUNGLE_G + isDarkForests*DARKFOREST_G + sandStorm*0.5 + snowStorm*0.8; + // BiomeColors.b = isSwamps*SWAMP_B + isJungles*JUNGLE_B + isDarkForests*DARKFOREST_B + sandStorm*0.3 + snowStorm*1.0; - // these range 0.0-1.0. they will never overlap. - float Inbiome = isJungles+isSwamps+isDarkForests+sandStorm+snowStorm; + // // these range 0.0-1.0. they will never overlap. + // float Inbiome = isJungles+isSwamps+isDarkForests+sandStorm+snowStorm; - // interpoloate between normal fog colors and biome colors. the transition speeds are conrolled by the biome uniforms. - FinalSunlightColor = mix(FinalSunlightColor, FinalSunlightColor * (BiomeColors*0.8+0.2), Inbiome); - } + // // interpoloate between normal fog colors and biome colors. the transition speeds are conrolled by the biome uniforms. + // FinalSunlightColor = mix(FinalSunlightColor, FinalSunlightColor * (BiomeColors*0.8+0.2), Inbiome); + // } void BiomeFogDensity( inout vec4 UniformDensity, - inout vec4 CloudyDensity + inout vec4 CloudyDensity, + float maxDistance ){ // these range 0.0-1.0. they will never overlap. float Inbiome = isJungles+isSwamps+isDarkForests+sandStorm+snowStorm; @@ -202,9 +203,29 @@ BiomeFogDensity.x = isSwamps*SWAMP_UNIFORM_DENSITY + isJungles*JUNGLE_UNIFORM_DENSITY + isDarkForests*DARKFOREST_UNIFORM_DENSITY + sandStorm*15 + snowStorm*150; BiomeFogDensity.y = isSwamps*SWAMP_CLOUDY_DENSITY + isJungles*JUNGLE_CLOUDY_DENSITY + isDarkForests*DARKFOREST_CLOUDY_DENSITY + sandStorm*255 + snowStorm*255; - UniformDensity = mix(UniformDensity, vec4(BiomeFogDensity.x), Inbiome); - CloudyDensity = mix(CloudyDensity, vec4(BiomeFogDensity.y), Inbiome); + UniformDensity = mix(UniformDensity, vec4(BiomeFogDensity.x), Inbiome*maxDistance); + CloudyDensity = mix(CloudyDensity, vec4(BiomeFogDensity.y), Inbiome*maxDistance); } + + float BiomeVLFogColors(inout vec3 DirectLightCol, inout vec3 IndirectLightCol){ + + // this is a little complicated? lmao + vec3 BiomeColors = vec3(0.0); + BiomeColors.r = isSwamps*SWAMP_R + isJungles*JUNGLE_R + isDarkForests*DARKFOREST_R + sandStorm*1.0 + snowStorm*0.6; + BiomeColors.g = isSwamps*SWAMP_G + isJungles*JUNGLE_G + isDarkForests*DARKFOREST_G + sandStorm*0.5 + snowStorm*0.8; + BiomeColors.b = isSwamps*SWAMP_B + isJungles*JUNGLE_B + isDarkForests*DARKFOREST_B + sandStorm*0.3 + snowStorm*1.0; + + // insure the biome colors are locked to the fog shape and lighting, but not its orignal color. + DirectLightCol = BiomeColors * max(dot(DirectLightCol,vec3(0.33333)), MIN_LIGHT_AMOUNT*0.025 + nightVision*0.2); + + IndirectLightCol = BiomeColors * max(dot(IndirectLightCol,vec3(0.33333)), MIN_LIGHT_AMOUNT*0.025 + nightVision*0.2); + + // these range 0.0-1.0. they will never overlap. + float Inbiome = isJungles+isSwamps+isDarkForests+sandStorm+snowStorm; + + return Inbiome; + } + #endif /////////////////////////////////////////////////////////////////////////////// @@ -213,7 +234,9 @@ #ifdef TIMEOFDAYFOG // uniform int worldTime; - void TimeOfDayFog(inout float Uniform, inout float Cloudy) { + void TimeOfDayFog( + inout float Uniform, inout float Cloudy, float maxDistance + ) { float Time = worldTime%24000; @@ -233,7 +256,7 @@ #endif #ifdef PER_BIOME_ENVIRONMENT - BiomeFogDensity(UniformDensity, CloudyDensity); // let biome fog hijack to control densities, and overrride any other density controller... + BiomeFogDensity(UniformDensity, CloudyDensity, maxDistance); // let biome fog hijack to control densities, and overrride any other density controller... #endif Uniform *= Morning*UniformDensity.r + Noon*UniformDensity.g + Evening*UniformDensity.b + Night*UniformDensity.a; diff --git a/shaders/lib/overworld_fog.glsl b/shaders/lib/overworld_fog.glsl index c8dd7ae..19034a0 100644 --- a/shaders/lib/overworld_fog.glsl +++ b/shaders/lib/overworld_fog.glsl @@ -14,7 +14,7 @@ float densityAtPosFog(in vec3 pos){ } -float cloudVol(in vec3 pos){ +float cloudVol(in vec3 pos, float maxDistance ){ vec3 samplePos = pos*vec3(1.0,1./24.,1.0); vec3 samplePos2 = pos*vec3(1.0,1./48.,1.0); @@ -40,7 +40,7 @@ float cloudVol(in vec3 pos){ if(sandStorm > 0 || snowStorm > 0) CloudyFog = mix(CloudyFog, max(densityAtPosFog((samplePos2 - vec3(frameTimeCounter,0,frameTimeCounter)*10) * 100.0 ) - 0.2,0.0) * heightlimit, sandStorm+snowStorm); #endif - TimeOfDayFog(UniformFog, CloudyFog); + TimeOfDayFog(UniformFog, CloudyFog, maxDistance); float noise = densityAtPosFog(samplePos * 12.0); float erosion = 1.0-densityAtPosFog(samplePos2 * (125 - (1-pow(1-noise,5))*25)); @@ -51,9 +51,9 @@ float cloudVol(in vec3 pos){ // float testfogshapes = clumpyFog*30; // return testfogshapes; + // return max(exp( max(pos.y - 90,0.0) / -1), 0.0) * 100; return CloudyFog + UniformFog + RainFog; - // float groundFog = max(exp( max(pos.y - 90,0.0) / -1), 0.0) * 100; } @@ -139,8 +139,9 @@ vec4 GetVolumetricFog( LightSourcePhased = vec3(0.0); #endif #ifdef PER_BIOME_ENVIRONMENT - BiomeFogColor(LightSourcePhased); - BiomeFogColor(skyLightPhased); + vec3 biomeDirect = LightSourcePhased; + vec3 biomeIndirect = skyLightPhased; + float inBiome = BiomeVLFogColors(biomeDirect, biomeIndirect); #endif skyLightPhased = max(skyLightPhased + skyLightPhased*(normalize(wpos).y*0.9+0.1),0.0); @@ -200,7 +201,13 @@ vec4 GetVolumetricFog( sh *= GetCloudShadow_VLFOG(progressW, WsunVec); #endif - float densityVol = cloudVol(progressW) * lightleakfix; + + #ifdef PER_BIOME_ENVIRONMENT + float maxDistance = inBiome * min(max(1.0 - length(d*dVWorld.xz)/(32*8),0.0)*2.0,1.0); + float densityVol = cloudVol(progressW, maxDistance) * lightleakfix; + #else + float densityVol = cloudVol(progressW, 0.0) * lightleakfix; + #endif //Water droplets(fog) float density = densityVol*300.0; @@ -213,11 +220,18 @@ vec4 GetVolumetricFog( vec3 rL = rC*airCoef.x; vec3 m = (airCoef.y+density) * mC; - vec3 Atmosphere = skyLightPhased * (rL*RLmult + m); // not pbr so just make the atmosphere also dense fog heh - vec3 DirectLight = LightSourcePhased * sh * ((rL*RLmult)*rayL + m); + #ifdef PER_BIOME_ENVIRONMENT + vec3 Atmosphere = mix(skyLightPhased, biomeDirect, maxDistance) * (rL*RLmult + m); // not pbr so just make the atmosphere also dense fog heh + vec3 DirectLight = mix(LightSourcePhased, biomeIndirect, maxDistance) * sh * ((rL*RLmult)*rayL + m); + #else + vec3 Atmosphere = skyLightPhased * (rL*RLmult + m); // not pbr so just make the atmosphere also dense fog heh + vec3 DirectLight = LightSourcePhased * sh * ((rL*RLmult)*rayL + m); + #endif vec3 Lightning = Iris_Lightningflash_VLfog(progressW-cameraPosition, lightningBoltPosition.xyz) * (rL + m); vec3 foglighting = (Atmosphere + DirectLight + Lightning) * lightleakfix; + + color += (foglighting - foglighting * exp(-(rL+m)*dd*dL)) / ((rL+m)+0.00000001)*absorbance; absorbance *= clamp(exp(-(rL+m)*dd*dL),0.0,1.0);