From 92e766e85394a06474644ae248d1cf6caf9e1845 Mon Sep 17 00:00:00 2001 From: Xonk Date: Sat, 30 Mar 2024 23:20:34 -0400 Subject: [PATCH] FIX block breaking effect on iris. FIX glowing water in some scenarios,. FIX clouds blipping at the end of a day. IMPROVE hand lighting (better specular and diffuse) --- shaders/dimensions/all_particles.fsh | 25 +++++- shaders/dimensions/all_particles.vsh | 2 +- shaders/dimensions/all_solid.fsh | 12 +-- shaders/dimensions/all_solid.vsh | 3 +- shaders/dimensions/all_translucent.fsh | 22 +++++- shaders/dimensions/all_translucent.vsh | 2 +- shaders/dimensions/composite1.fsh | 78 +++++++++++++----- shaders/dimensions/composite3.fsh | 14 +++- shaders/dimensions/composite5.fsh | 79 ++++++++++++++----- .../dimensions/fogBehindTranslucent_pass.fsh | 13 +-- shaders/lib/specular.glsl | 18 ++--- shaders/lib/volumetricClouds.glsl | 4 +- shaders/shaders.properties | 3 +- shaders/world-1/gbuffers_damagedblock.fsh | 2 +- shaders/world-1/gbuffers_damagedblock.vsh | 2 +- shaders/world0/gbuffers_damagedblock.fsh | 2 +- shaders/world0/gbuffers_damagedblock.vsh | 2 +- shaders/world1/gbuffers_damagedblock.fsh | 2 +- shaders/world1/gbuffers_damagedblock.vsh | 2 +- 19 files changed, 205 insertions(+), 82 deletions(-) diff --git a/shaders/dimensions/all_particles.fsh b/shaders/dimensions/all_particles.fsh index 0fd32b4..5326e26 100644 --- a/shaders/dimensions/all_particles.fsh +++ b/shaders/dimensions/all_particles.fsh @@ -89,13 +89,28 @@ float phaseg(float x, float g){ return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) / 3.14; } +//encoding by jodie +float encodeVec2(vec2 a){ + const vec2 constant1 = vec2( 1., 256.) / 65535.; + vec2 temp = floor( a * 255. ); + return temp.x*constant1.x+temp.y*constant1.y; +} +float encodeVec2(float x,float y){ + return encodeVec2(vec2(x,y)); +} + + //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// -/* DRAWBUFFERS:29 */ +#ifdef DAMAGE_BLOCK_EFFECT + /* RENDERTARGETS:11 */ +#else + /* DRAWBUFFERS:29 */ +#endif void main() { @@ -111,6 +126,9 @@ void main() { vec3 feetPlayerPos_normalized = normalize(feetPlayerPos); vec4 TEXTURE = texture2D(texture, lmtexcoord.xy)*color; + + + vec3 Albedo = toLinear(TEXTURE.rgb); @@ -215,6 +233,11 @@ void main() { #else gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * Albedo; #endif + + #ifdef DAMAGE_BLOCK_EFFECT + + gl_FragData[0] = vec4(0.0, encodeVec2(TEXTURE.rg), encodeVec2(vec2(TEXTURE.b,0.0)), TEXTURE.a); + #endif // distance fade targeting the world border... if(TEXTURE.a < 0.7 && TEXTURE.a > 0.2) gl_FragData[0] *= clamp(1.0 - length(feetPlayerPos) / 100.0 ,0.0,1.0); diff --git a/shaders/dimensions/all_particles.vsh b/shaders/dimensions/all_particles.vsh index 4855a64..a04de5b 100644 --- a/shaders/dimensions/all_particles.vsh +++ b/shaders/dimensions/all_particles.vsh @@ -62,7 +62,7 @@ vec4 toClipSpace3(vec3 viewSpacePosition) { void main() { lmtexcoord.xy = (gl_MultiTexCoord0).xy; - vec2 lmcoord = gl_MultiTexCoord1.xy / 255.0; // is this even correct? lol' + vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0; // is this even correct? lol' lmtexcoord.zw = lmcoord; diff --git a/shaders/dimensions/all_solid.fsh b/shaders/dimensions/all_solid.fsh index db2ca98..4fab275 100644 --- a/shaders/dimensions/all_solid.fsh +++ b/shaders/dimensions/all_solid.fsh @@ -75,6 +75,7 @@ uniform float rainStrength; uniform sampler2D noisetex;//depth uniform sampler2D depthtex0; + uniform vec4 entityColor; // in vec3 velocity; @@ -289,7 +290,6 @@ varying vec3 pos; void main() { - bool ifPOM = false; #ifdef POM @@ -365,7 +365,7 @@ void main() { float used_POM_DEPTH = 1.0; if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) { - // float noise = interleaved_gradientNoise_temp(); + float noise = blueNoise(); #ifdef Adaptive_Step_length vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0); used_POM_DEPTH = 1.0; @@ -374,12 +374,12 @@ void main() { #endif vec3 coord = vec3(vtexcoord.st , 1.0); - coord += interval * used_POM_DEPTH; + coord += interval * noise * used_POM_DEPTH; - float sumVec = 0.5; + float sumVec = noise; for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - POM_DEPTH + POM_DEPTH * readNormal(coord.st).a ) < coord.p && coord.p >= 0.0; ++loopCount) { coord = coord + interval * used_POM_DEPTH; - sumVec += 1.0 * used_POM_DEPTH; + sumVec += used_POM_DEPTH; } if (coord.t < mincoord) { @@ -408,6 +408,7 @@ void main() { float textureLOD = bias(); vec4 Albedo = texture2D_POMSwitch(texture, adjustedTexCoord.xy, vec4(dcdx,dcdy), ifPOM, textureLOD) * color; + #if defined HAND if (Albedo.a < 0.1) discard; #endif @@ -488,6 +489,7 @@ void main() { normal = applyBump(tbnMatrix, NormalTex.xyz, mix(1.0,1-Puddle_shape,rainfall) ); + // normal = applyBump(tbnMatrix, NormalTex.xyz, 0.0); #endif //////////////////////////////// //////////////////////////////// diff --git a/shaders/dimensions/all_solid.vsh b/shaders/dimensions/all_solid.vsh index b017794..d4a4f85 100644 --- a/shaders/dimensions/all_solid.vsh +++ b/shaders/dimensions/all_solid.vsh @@ -190,8 +190,9 @@ void main() { vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz; - + pos = position; + /////// ----- COLOR STUFF ----- /////// color = gl_Color; diff --git a/shaders/dimensions/all_translucent.fsh b/shaders/dimensions/all_translucent.fsh index e442493..1e8a449 100644 --- a/shaders/dimensions/all_translucent.fsh +++ b/shaders/dimensions/all_translucent.fsh @@ -312,6 +312,20 @@ uniform float dhFarPlane; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// +float darkSpecularHighlight(vec3 playerPos, vec3 normal, float roughness, float f0){ + + roughness = max(pow(1.0 - roughness, 2.0),0.002); + + float distanceFalloff = clamp( exp(-7.0 * (length(playerPos) / 16.0)) ,0.0,1.0); + + float NdotP = clamp(1.0 + dot(normal, normalize(playerPos)),0.0,1.0); + + float specularHighlight = exp( -(1.0 / roughness) * NdotP ) * f0; + + return specularHighlight * distanceFalloff; +} + + uniform vec4 entityColor; /* RENDERTARGETS:2,7,11,14 */ void main() { @@ -586,7 +600,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) float f0 = SpecularTex.g; // roughness = 0.1; - // f0 = 1.0; + // f0 = 0.1; if (iswater > 0.0 && gl_FragData[0].a < 0.9999999){ vec3 Reflections_Final = vec3(0.0); @@ -641,9 +655,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) #ifdef OVERWORLD_SHADER if(isEyeInWater == 1 && iswater > 0.9){ - SkyReflection.rgb = exp(-8.0 * vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B)) * clamp(WsunVec.y*lightCol.a,0,1) ; + SkyReflection.rgb = exp(-8.0 * vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B)) * clamp(WsunVec.y*lightCol.a,0,1); } + + // if(iswater > 0.9) SkyReflection.rgb = mix(vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B)*0.1, SkyReflection.rgb*indoors, clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0),0.0,1.0)); #endif + float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1); #ifdef ENTITIES @@ -655,6 +672,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) Reflections_Final += SunReflection * Metals; + // Reflections_Final += vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B)*0.1 * darkSpecularHighlight(feetPlayerPos, viewToWorld(normal), 0.9, 0.1); gl_FragData[0].rgb = Reflections_Final ; diff --git a/shaders/dimensions/all_translucent.vsh b/shaders/dimensions/all_translucent.vsh index 3fed393..729b430 100644 --- a/shaders/dimensions/all_translucent.vsh +++ b/shaders/dimensions/all_translucent.vsh @@ -82,7 +82,7 @@ varying vec4 pos; void main() { lmtexcoord.xy = (gl_MultiTexCoord0).xy; - vec2 lmcoord = gl_MultiTexCoord1.xy / 255.0; // is this even correct? lol + vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0; // is this even correct? lol lmtexcoord.zw = lmcoord; vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz; diff --git a/shaders/dimensions/composite1.fsh b/shaders/dimensions/composite1.fsh index a390dc4..cfb441f 100644 --- a/shaders/dimensions/composite1.fsh +++ b/shaders/dimensions/composite1.fsh @@ -57,7 +57,7 @@ uniform int hideGUI; uniform sampler2D noisetex; //noise uniform sampler2D depthtex0; uniform sampler2D depthtex1; -// uniform sampler2D depthtex2; +uniform sampler2D depthtex2; // #ifdef DISTANT_HORIZONS uniform sampler2D dhDepthTex; @@ -132,6 +132,13 @@ void convertHandDepth(inout float depth) { ndcDepth /= MC_HAND_DEPTH; depth = ndcDepth * 0.5 + 0.5; } +float convertHandDepth_2(in float depth, bool hand) { + if(!hand) return depth; + + float ndcDepth = depth * 2.0 - 1.0; + ndcDepth /= MC_HAND_DEPTH; + return ndcDepth * 0.5 + 0.5; +} vec3 toScreenSpace(vec3 p) { vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); @@ -228,7 +235,7 @@ vec2 decodeVec2(float a){ vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort) { - float alpha0 = sampleNumber/nb; + float alpha0 = sampleNumber/nb; float alpha = (sampleNumber+jitter)/nb; float angle = jitter*6.28 + alpha * 4.0 * 6.28; @@ -427,9 +434,11 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE #endif -vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, bool isSSS){ +vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, bool isSSS, bool hand){ + + float handSwitch = hand ? 1.0 : 0.0; + float steps = 16.0; - float Shadow = 1.0; float SSS = 0.0; @@ -439,8 +448,8 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo _near = dhNearPlane; _far = dhFarPlane; } - - vec3 clipPosition = toClipSpace3_DH(viewPos, depthCheck); + + vec3 clipPosition = toClipSpace3_DH(viewPos, depthCheck); //prevents the ray from going behind the camera float rayLength = ((viewPos.z + lightDir.z * _far*sqrt(3.)) > -_near) ? @@ -451,7 +460,7 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo float Stepmult = depthCheck ? (isSSS ? 0.5 : 6.0) : (isSSS ? 1.0 : 3.0); - vec3 rayDir = direction * Stepmult * vec3(RENDER_SCALE,1.0); + vec3 rayDir = direction * Stepmult * vec3(RENDER_SCALE,1.0); vec3 screenPos = clipPosition * vec3(RENDER_SCALE,1.0) + rayDir*noise; if(isSSS) screenPos -= rayDir*0.9; @@ -460,7 +469,7 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo screenPos += rayDir; - float samplePos = texture2D(depthtex1, screenPos.xy).x; + float samplePos = convertHandDepth_2(texture2D(depthtex1, screenPos.xy).x, hand); #ifdef DISTANT_HORIZONS if(depthCheck) samplePos = texture2D(dhDepthTex1, screenPos.xy).x; @@ -470,7 +479,7 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo vec2 linearZ = vec2(linearizeDepthFast(screenPos.z, _near, _far), linearizeDepthFast(samplePos, _near, _far)); float calcthreshold = abs(linearZ.x - linearZ.y) / linearZ.x; - bool depthThreshold1 = calcthreshold < 0.015; + bool depthThreshold1 = calcthreshold < mix(0.015, 0.035, handSwitch); bool depthThreshold2 = calcthreshold < 0.05; if (depthThreshold1) Shadow = 0.0; @@ -737,6 +746,23 @@ vec3 ColorBoost(vec3 COLOR, float saturation){ return COLOR + difference*(-luminance + saturation); } + +float darkSpecularHighlight(vec3 playerPos, vec3 normal, float roughness, float f0){ + + roughness = max(pow(1.0 - roughness, 2.0),0.002); + + float distanceFalloff = clamp( exp(-7.0 * (length(playerPos) / 16.0)) ,0.0,1.0); + + float NdotP = clamp(1.0 + dot(normal, normalize(playerPos)),0.0,1.0); + + float specularHighlight = exp( -(1.0 / roughness) * NdotP ) * f0; + + return specularHighlight * distanceFalloff; +} + + + + void main() { vec3 DEBUG = vec3(1.0); @@ -834,11 +860,14 @@ void main() { bool entities = abs(dataUnpacked1.w-0.45) < 0.01; // bool isBoss = abs(dataUnpacked1.w-0.60) < 0.01; bool isGrass = abs(dataUnpacked1.w-0.60) < 0.01; - bool hand = abs(dataUnpacked1.w-0.75) < 0.01 && z0 < 1.0; + bool hand = abs(dataUnpacked1.w-0.75) < 0.01 && z < 1.0; // bool blocklights = abs(dataUnpacked1.w-0.8) <0.01; - if(hand) convertHandDepth(z); + if(hand){ + convertHandDepth(z); + convertHandDepth(z0); + } #ifdef DISTANT_HORIZONS vec3 viewPos = toScreenSpace_DH(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z, DH_depth1); @@ -997,7 +1026,7 @@ void main() { vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz; // if(!entities) if(!hand) - GriAndEminShadowFix(shadowPlayerPos, viewToWorld(FlatNormals), vanilla_AO, lightmap.y); + if(!hand) GriAndEminShadowFix(shadowPlayerPos, viewToWorld(FlatNormals), vanilla_AO, lightmap.y); vec3 projectedShadowPosition = mat3(shadowModelView) * shadowPlayerPos + shadowModelView[3].xyz; projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz; @@ -1093,7 +1122,7 @@ void main() { vec3 viewPos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0)); #endif - float Vdiff = distance(viewPos, viewPos0)*2.0; + float Vdiff = distance(viewPos, viewPos0)*mix(5.0,2.0,clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0)); float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y); //assuming water plane // make it such that the estimated depth flips to be correct when entering water. @@ -1109,7 +1138,6 @@ void main() { Absorbtion = mix(exp(-2.0 * totEpsilon * estimatedDepth), exp(-8.0 * totEpsilon), depthfalloff); DirectLightColor *= Absorbtion; - AmbientLightColor *= Absorbtion; // apply caustics to the lighting, and make sure they dont look weird DirectLightColor *= mix(1.0, waterCaustics(feetPlayerPos + cameraPosition, WsunVec)*WATER_CAUSTICS_BRIGHTNESS + 0.25, clamp(estimatedDepth,0,1)); @@ -1136,14 +1164,15 @@ void main() { float sunSSS_density = LabSSS; + #ifndef RENDER_ENTITY_SHADOWS if(entities) sunSSS_density = 0.0; #endif - if (!hand){ + // if (!hand){ #ifdef SCREENSPACE_CONTACT_SHADOWS - vec2 SS_directLight = SSRT_Shadows(toScreenSpace_DH(texcoord/RENDER_SCALE, z, DH_depth1), isDHrange, normalize(WsunVec*mat3(gbufferModelViewInverse)), interleaved_gradientNoise(), sunSSS_density > 0.0); + vec2 SS_directLight = SSRT_Shadows(toScreenSpace_DH(texcoord/RENDER_SCALE, z, DH_depth1), isDHrange, normalize(WsunVec*mat3(gbufferModelViewInverse)), interleaved_gradientNoise(), sunSSS_density > 0.0, hand); Shadows = min(Shadows, SS_directLight.r); ShadowBlockerDepth = mix(SS_directLight.g, ShadowBlockerDepth, shadowMapFalloff); @@ -1156,7 +1185,7 @@ void main() { Direct_SSS *= mix(LM_shadowMapFallback, 1.0, shadowMapFalloff); if (isEyeInWater == 0) Direct_SSS *= clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); // light leak fix - } + // } #endif #ifdef CLOUDS_SHADOWS @@ -1217,8 +1246,7 @@ void main() { // Indirect_lighting += up + down; Indirect_lighting = vec3(0.1); - - Indirect_lighting *= Absorbtion; + #endif #ifdef END_SHADER @@ -1226,11 +1254,11 @@ void main() { Indirect_lighting *= clamp(1.5 + dot(normal, feetPlayerPos_normalized)*0.5,0,2); - Indirect_lighting *= Absorbtion; #endif Indirect_lighting = DoAmbientLightColor(Indirect_lighting, MinimumLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy); + Indirect_lighting *= Absorbtion; #ifdef OVERWORLD_SHADER Indirect_lighting += LightningFlashLighting; #endif @@ -1326,12 +1354,16 @@ void main() { vec2 specularNoises = vec2(noise, R2_dither()); DoSpecularReflections(gl_FragData[0].rgb, viewPos, feetPlayerPos_normalized, WsunVec, specularNoises, normal, SpecularTex.r, SpecularTex.g, albedo, DirectLightColor*Shadows*NdotL, lightmap.y, hand); #endif - + + // gl_FragData[0].rgb += vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B)*0.1 * darkSpecularHighlight(feetPlayerPos, normal, SpecularTex.r, SpecularTex.g); + Emission(gl_FragData[0].rgb, albedo, SpecularTex.a); if(lightningBolt) gl_FragData[0].rgb = vec3(77.0, 153.0, 255.0); } + + if(translucent_alpha > 0.0 ){ #ifdef DISTANT_HORIZONS @@ -1371,6 +1403,10 @@ void main() { gl_FragData[0].rgb = FilteredDebug; #endif + + + + #ifdef CLOUDS_INFRONT_OF_WORLD gl_FragData[1] = texture2D(colortex2, texcoord); if(heightRelativeToClouds > 0.0 && !hand){ diff --git a/shaders/dimensions/composite3.fsh b/shaders/dimensions/composite3.fsh index 023b52d..3c1e6f9 100644 --- a/shaders/dimensions/composite3.fsh +++ b/shaders/dimensions/composite3.fsh @@ -269,7 +269,7 @@ void main() { vec4 TranslucentShader = texture2D(colortex2, texcoord); ////// --------------- UNPACK MISC --------------- ////// - float trpData = texture2D(colortex7,texcoord).a; + float trpData = texture2D(colortex7, texcoord).a; ////// --------------- MASKS/BOOLEANS --------------- ////// bool iswater = trpData > 0.99; @@ -325,12 +325,17 @@ void main() { color.rgb = mix(color.rgb, borderFogColor, fog); #endif + + + if (albedo.a > 0.0 || TranslucentShader.a > 0.0){ - if (TranslucentShader.a > 0.0){ - #ifdef Glass_Tint - if(!iswater) color *= normalize(albedo.rgb+0.0001)*0.9+0.1; + #ifdef Glass_Tint + if(!iswater && TranslucentShader.a > 0.0) color *= normalize(albedo.rgb+0.0001)*0.9+0.1; #endif + // block breaking effect. + if(!iswater && TranslucentShader.a <= 0.0) color *= albedo.rgb; + color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb; #ifdef BorderFog @@ -438,6 +443,7 @@ void main() { } #endif // color.rgb = vec3(1) * sqrt(texture2D(colortex12,texcoord).a/65000.0); + gl_FragData[0].r = bloomyFogMult; // pass fog alpha so bloom can do bloomy fog gl_FragData[1].rgb = clamp(color.rgb, 0.0,68000.0); diff --git a/shaders/dimensions/composite5.fsh b/shaders/dimensions/composite5.fsh index eb795f9..00e1a12 100644 --- a/shaders/dimensions/composite5.fsh +++ b/shaders/dimensions/composite5.fsh @@ -53,12 +53,14 @@ const bool colortex15Clear = false; varying vec2 texcoord; flat varying float tempOffsets; uniform sampler2D colortex0; +uniform sampler2D colortex1; uniform sampler2D colortex3; uniform sampler2D colortex5; uniform sampler2D colortex6; uniform sampler2D colortex10; uniform sampler2D colortex12; uniform sampler2D depthtex0; +uniform sampler2D depthtex1; uniform vec2 texelSize; uniform float frameTimeCounter; @@ -170,23 +172,36 @@ vec3 tonemap(vec3 col){ vec3 invTonemap(vec3 col){ return col/(1-luma(col)); } +void convertHandDepth(inout float depth) { + float ndcDepth = depth * 2.0 - 1.0; + ndcDepth /= MC_HAND_DEPTH; + depth = ndcDepth * 0.5 + 0.5; +} -vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth) +vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth, bool hand) { vec2 du = vec2(texelSize.x*2., 0.0); vec2 dv = vec2(0.0, texelSize.y*2.); - vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x); - vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x); - vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x); - vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x); - vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x); + vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x); + vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x); + vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x); + vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x); + vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x); + + if(hand){ + convertHandDepth(dtl.z); + convertHandDepth(dtr.z); + convertHandDepth(dmc.z); + convertHandDepth(dbl.z); + convertHandDepth(dbr.z); + } vec3 dmin = dmc; - dmin = dmin.z > dtr.z? dtr : dmin; - dmin = dmin.z > dtl.z? dtl : dmin; - dmin = dmin.z > dbl.z? dbl : dmin; - dmin = dmin.z > dbr.z? dbr : dmin; + dmin = dmin.z > dtr.z ? dtr : dmin; + dmin = dmin.z > dtl.z ? dtl : dmin; + dmin = dmin.z > dbl.z ? dbl : dmin; + dmin = dmin.z > dbr.z ? dbr : dmin; #ifdef TAA_UPSCALING dmin.xy = dmin.xy/RENDER_SCALE; @@ -195,9 +210,7 @@ vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth) return dmin; } - - -vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth, bool depthCheck) +vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth, bool depthCheck, bool hand) { vec2 du = vec2(texelSize.x*2., 0.0); vec2 dv = vec2(0.0, texelSize.y*2.); @@ -214,11 +227,19 @@ vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth, dbl += vec3(-texelSize.x, texelSize.y, depthCheck ? texture2D(dhDepth, texcoord + dv - du).x : texture2D(depth, texcoord + dv - du).x); dbr += vec3( texelSize.x, texelSize.y, depthCheck ? texture2D(dhDepth, texcoord + dv + du).x : texture2D(depth, texcoord + dv + du).x); + if(hand){ + convertHandDepth(dtl.z); + convertHandDepth(dtr.z); + convertHandDepth(dmc.z); + convertHandDepth(dbl.z); + convertHandDepth(dbr.z); + } + vec3 dmin = dmc; - dmin = dmin.z > dtr.z? dtr : dmin; - dmin = dmin.z > dtl.z? dtl : dmin; - dmin = dmin.z > dbl.z? dbl : dmin; - dmin = dmin.z > dbr.z? dbr : dmin; + dmin = dmin.z > dtr.z ? dtr : dmin; + dmin = dmin.z > dtl.z ? dtl : dmin; + dmin = dmin.z > dbl.z ? dbl : dmin; + dmin = dmin.z > dbr.z ? dbr : dmin; #ifdef TAA_UPSCALING dmin.xy = dmin.xy/RENDER_SCALE; @@ -298,7 +319,7 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), -vec4 TAA_hq(){ +vec4 TAA_hq(bool hand){ #ifdef TAA_UPSCALING vec2 adjTC = clamp(texcoord*RENDER_SCALE, vec2(0.0), RENDER_SCALE - texelSize*2.0); @@ -311,9 +332,9 @@ vec4 TAA_hq(){ //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion #ifdef CLOSEST_VELOCITY #ifdef DISTANT_HORIZONS - vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhDepthTex, depthCheck); + vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhDepthTex, depthCheck, hand); #else - vec3 closestToCamera = closestToCamera5taps(adjTC,depthtex0); + vec3 closestToCamera = closestToCamera5taps(adjTC,depthtex0, hand); #endif #endif @@ -368,8 +389,11 @@ vec4 TAA_hq(){ //Increases blending factor when far from AABB and in motion, reduces ghosting float isclamped = distance(albedoPrev,finalcAcc)/luma(albedoPrev) * 0.5; + float movementRejection = (0.12+isclamped)*clamp(length(velocity/texelSize),0.0,1.0); + if(hand) movementRejection *= 5.0; + //Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering vec4 supersampled = vec4(invTonemap(mix(tonemap(finalcAcc), tonemap(albedoCurrent0), clamp(BLEND_FACTOR + movementRejection, 0.0,1.0))), 1.0); @@ -386,13 +410,26 @@ vec4 TAA_hq(){ #endif } + +vec2 decodeVec2(float a){ + const vec2 constant1 = 65535. / vec2( 256., 65536.); + const float constant2 = 256. / 255.; + return fract( a * constant1 ) * constant2 ; +} + void main() { /* DRAWBUFFERS:5 */ gl_FragData[0].a = 1.0; + #ifdef TAA - vec4 color = TAA_hq(); + + + float dataUnpacked = decodeVec2(texture2D(colortex1,texcoord).w).y; + bool hand = abs(dataUnpacked-0.75) < 0.01 && texture2D(depthtex1,texcoord).x < 1.0; + + vec4 color = TAA_hq(hand); #ifdef SCREENSHOT_MODE gl_FragData[0] = clamp(color, 0.0, 65000.0); diff --git a/shaders/dimensions/fogBehindTranslucent_pass.fsh b/shaders/dimensions/fogBehindTranslucent_pass.fsh index ff53dcb..5672ffa 100644 --- a/shaders/dimensions/fogBehindTranslucent_pass.fsh +++ b/shaders/dimensions/fogBehindTranslucent_pass.fsh @@ -197,7 +197,8 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float #endif vec3 absorbance = vec3(1.0); vec3 vL = vec3(0.0); - + + ambient = max(ambient* (normalize(wpos).y*0.3+0.7),0.0); float expFactor = 11.0; for (int i=0;i= 1.0 ) lightmap = 1.0; + if(z >= 1.0) lightmap = 1.0; #else float lightmap = 1.0; #endif - float Vdiff = distance(viewPos1, viewPos0); + float Vdiff = distance(viewPos1, viewPos0) * 2.0; float VdotU = playerPos.y; float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane - float estimatedSunDepth = estimatedDepth/abs(WsunVec.y); //assuming water plane + float estimatedSunDepth = estimatedDepth / abs(WsunVec.y); //assuming water plane vec4 VolumetricFog2 = vec4(0,0,0,1); #ifdef OVERWORLD_SHADER @@ -325,7 +326,7 @@ void main() { #endif vec4 underwaterVlFog = vec4(0,0,0,1); - if(iswater)underwaterVlFog = waterVolumetrics_test(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic * max(lightmap,0.0), directLightColor, dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) ); + if(iswater) underwaterVlFog = waterVolumetrics_test(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic * max(lightmap,0.0), directLightColor, dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) ); vec4 fogFinal = vec4(underwaterVlFog.rgb * VolumetricFog2.a + VolumetricFog2.rgb, VolumetricFog2.a * underwaterVlFog.a); diff --git a/shaders/lib/specular.glsl b/shaders/lib/specular.glsl index df8fa16..1ec0f69 100644 --- a/shaders/lib/specular.glsl +++ b/shaders/lib/specular.glsl @@ -86,19 +86,17 @@ vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, boo float dist = 1.0 + clamp(position.z*position.z/50.0,0.0,2.0); // shrink sample size as distance increases for (int i = 0; i <= int(quality); i++) { - vec2 scaleUV = hand ? spos.xy*texelSize : spos.xy/texelSize/4.0; // fix for ssr on hand - float sp = sqrt(texelFetch2D(colortex4,ivec2(scaleUV),0).a/65000.0); - - - sp = invLinZ(sp); + float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0)); if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ) ) return vec3(spos.xy/RENDER_SCALE,sp); + spos += stepv; //small bias float biasamount = (0.0002 + 0.0015*pow(depthcancleoffset,5) ) / dist; - // float biasamount = 0.0002 / dist; - if(hand) biasamount = 0.01; + + if(hand) biasamount = 0.00035; + minZ = maxZ-biasamount / ld(spos.z); maxZ += stepv.z; @@ -193,7 +191,7 @@ void DoSpecularReflections( Roughness = 1.0 - Roughness; Roughness *= Roughness; F0 = F0 == 0.0 ? 0.02 : F0; - // Roughness = 0.1; + // Roughness = 0.0; // F0 = 0.9; mat3 Basis = CoordBase(Normal); @@ -201,7 +199,7 @@ void DoSpecularReflections( #ifdef Rough_reflections vec3 SamplePoints = SampleVNDFGGX(ViewDir, vec2(Roughness), Noise.x); - if(Hand) SamplePoints = normalize(vec3(0.0,0.0,1.0)); + if(Hand) SamplePoints = vec3(0.0,0.0,1.0); #else vec3 SamplePoints = vec3(0.0,0.0,1.0); #endif @@ -214,7 +212,7 @@ void DoSpecularReflections( float RayContribution = lerp(F0, 1.0, Fresnel); // ensure that when the angle is 0 that the correct F0 is used. #ifdef Rough_reflections - if(Hand) RayContribution = RayContribution * pow(1.0-Roughness,3.0); + if(Hand) RayContribution = RayContribution * pow(1.0-Roughness,F0 > 229.5/255.0 ? 1.0 : 3.0); #else RayContribution = RayContribution * pow(1.0-Roughness,3.0); #endif diff --git a/shaders/lib/volumetricClouds.glsl b/shaders/lib/volumetricClouds.glsl index e30ea34..047fe2d 100644 --- a/shaders/lib/volumetricClouds.glsl +++ b/shaders/lib/volumetricClouds.glsl @@ -52,7 +52,9 @@ float LAYER2_DENSITY = dailyWeatherParams1.z; float rainCloudwetness = rainStrength; // float cloud_movement = frameTimeCounter * Cloud_Speed ; // float cloud_movement = abs((12000 - worldTime) * Cloud_Speed ) * 0.05; -float cloud_movement = (worldTime / 24.0) * Cloud_Speed; +// float cloud_movement = (worldTime / 24.0) * Cloud_Speed; +uniform int worldDay; +float cloud_movement = (worldTime + worldDay*24000.0) / 24.0 * Cloud_Speed; //3D noise from 2d texture float densityAtPos(in vec3 pos){ diff --git a/shaders/shaders.properties b/shaders/shaders.properties index f93d067..fa38741 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -62,7 +62,6 @@ program.composite5.enabled = TAA_UPSCALING # terrible blending for shadows on purpose blend.shadow = SRC_COLOR ZERO ONE ZERO - blend.gbuffers_water = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE blend.gbuffers_hand_water = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE blend.gbuffers_textured = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE @@ -72,7 +71,7 @@ blend.gbuffers_basic = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE blend.gbuffers_weather = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE blend.gbuffers_armor_glint = ONE ONE ONE ZERO blend.gbuffers_skytextured = ONE ONE ONE ZERO -blend.gbuffers_damagedblock = ONE ONE ONE ZERO +blend.gbuffers_damagedblock = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE # Disable blending blend.gbuffers_terrain = off diff --git a/shaders/world-1/gbuffers_damagedblock.fsh b/shaders/world-1/gbuffers_damagedblock.fsh index bae444a..ac2bc09 100644 --- a/shaders/world-1/gbuffers_damagedblock.fsh +++ b/shaders/world-1/gbuffers_damagedblock.fsh @@ -3,4 +3,4 @@ #define DAMAGE_BLOCK_EFFECT #define NETHER_SHADER -#include "/dimensions/all_translucent.fsh" \ No newline at end of file +#include "/dimensions/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_damagedblock.vsh b/shaders/world-1/gbuffers_damagedblock.vsh index 1cf93e3..f09b952 100644 --- a/shaders/world-1/gbuffers_damagedblock.vsh +++ b/shaders/world-1/gbuffers_damagedblock.vsh @@ -3,4 +3,4 @@ #define DAMAGE_BLOCK_EFFECT #define NETHER_SHADER -#include "/dimensions/all_translucent.vsh" \ No newline at end of file +#include "/dimensions/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world0/gbuffers_damagedblock.fsh b/shaders/world0/gbuffers_damagedblock.fsh index 49c7bb0..7c7bfb3 100644 --- a/shaders/world0/gbuffers_damagedblock.fsh +++ b/shaders/world0/gbuffers_damagedblock.fsh @@ -3,4 +3,4 @@ #define OVERWORLD_SHADER #define DAMAGE_BLOCK_EFFECT -#include "/dimensions/all_translucent.fsh" \ No newline at end of file +#include "/dimensions/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world0/gbuffers_damagedblock.vsh b/shaders/world0/gbuffers_damagedblock.vsh index f063bd6..e24e3e7 100644 --- a/shaders/world0/gbuffers_damagedblock.vsh +++ b/shaders/world0/gbuffers_damagedblock.vsh @@ -3,4 +3,4 @@ #define OVERWORLD_SHADER #define DAMAGE_BLOCK_EFFECT -#include "/dimensions/all_translucent.vsh" \ No newline at end of file +#include "/dimensions/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_damagedblock.fsh b/shaders/world1/gbuffers_damagedblock.fsh index 117d0f4..d72bc9f 100644 --- a/shaders/world1/gbuffers_damagedblock.fsh +++ b/shaders/world1/gbuffers_damagedblock.fsh @@ -3,4 +3,4 @@ #define END_SHADER #define DAMAGE_BLOCK_EFFECT -#include "/dimensions/all_translucent.fsh" \ No newline at end of file +#include "/dimensions/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_damagedblock.vsh b/shaders/world1/gbuffers_damagedblock.vsh index 5b3e965..d72bc9f 100644 --- a/shaders/world1/gbuffers_damagedblock.vsh +++ b/shaders/world1/gbuffers_damagedblock.vsh @@ -3,4 +3,4 @@ #define END_SHADER #define DAMAGE_BLOCK_EFFECT -#include "/dimensions/all_translucent.vsh" \ No newline at end of file +#include "/dimensions/all_particles.fsh" \ No newline at end of file