From ca1b9eb85eff949ba24853e3711755a2dbda6304 Mon Sep 17 00:00:00 2001 From: Xonk Date: Sat, 8 Jul 2023 21:16:51 -0400 Subject: [PATCH] Shadow and SSS fixes and tweaks. tiny lightmap tweaks. add toggle for basic shadow filter. --- shaders/composite.fsh | 11 +- shaders/composite1.fsh | 284 ++++++++++++++------------- shaders/composite1.vsh | 22 ++- shaders/composite11.fsh | 13 -- shaders/composite2.fsh | 3 +- shaders/composite5.fsh | 17 +- shaders/entity.properties | 4 +- shaders/final.fsh | 2 +- shaders/gbuffers_all_solid.fsh | 13 +- shaders/gbuffers_all_solid.vsh | 1 + shaders/gbuffers_all_translucent.fsh | 2 +- shaders/lib/settings.glsl | 1 + shaders/lib/specular.glsl | 1 + shaders/shaders.properties | 2 +- shaders/shadow.vsh | 54 +++-- shaders/world-1/composite2.fsh | 4 +- shaders/world1/composite.fsh | 4 +- 17 files changed, 227 insertions(+), 211 deletions(-) diff --git a/shaders/composite.fsh b/shaders/composite.fsh index 891bb98..dafdee4 100644 --- a/shaders/composite.fsh +++ b/shaders/composite.fsh @@ -180,34 +180,31 @@ void main() { float minshadowfilt = Min_Shadow_Filter_Radius; float maxshadowfilt = Max_Shadow_Filter_Radius; + float NdotL = clamp(dot(normal,WsunVec),0.0,1.0); + float vanillAO = clamp(texture2D(colortex15,texcoord).a,0.0,1.0) ; if(lightmap.y < 0.1 && !entities){ // minshadowfilt *= vanillAO; - maxshadowfilt = mix(minshadowfilt ,maxshadowfilt, vanillAO); + maxshadowfilt = mix(minshadowfilt, maxshadowfilt, vanillAO); } float SpecularTex = texture2D(colortex8,texcoord).z; float LabSSS = clamp((-65.0 + SpecularTex * 255.0) / 190.0 ,0.0,1.0); - #ifndef Variable_Penumbra_Shadows - if (translucent && !hand) minshadowfilt += 25; + if (LabSSS > 0.0 && !hand && NdotL < 0.001) minshadowfilt += 50; #endif - gl_FragData[0] = vec4(minshadowfilt, 0.1, 0.0, 0.0); - - if (z < 1.0){ // if( translucent || translucent2) if (!hand){ - float NdotL = clamp(dot(normal,WsunVec),0.0,1.0); vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z)); diff --git a/shaders/composite1.fsh b/shaders/composite1.fsh index a87f509..fb3c286 100644 --- a/shaders/composite1.fsh +++ b/shaders/composite1.fsh @@ -15,7 +15,6 @@ flat varying vec4 lightCol; flat varying vec3 WsunVec; flat varying vec2 TAA_Offset; -flat varying float tempOffsets; uniform float eyeAltitude; @@ -595,13 +594,11 @@ void rtGI(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightm vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, float lightPos){ - - float labcurve = pow(Density,LabSSS_Curve); float density = sqrt(30 - labcurve*15); - vec3 absorbed = max(1.0 - albedo,0.0) * density; - vec3 scatter = exp(-sqrt(Scattering * absorbed)) * exp(Scattering * -density); + vec3 absorbed = max(1.0 - albedo,0.0); + vec3 scatter = exp(absorbed * -sqrt(Scattering * 5)) * exp(Scattering * -density); scatter *= labcurve; scatter *= 0.5 + CustomPhase(lightPos, 1.0,30.0)*20; @@ -612,9 +609,8 @@ vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, floa vec3 SubsurfaceScattering_sky(vec3 albedo, float Scattering, float Density){ vec3 absorbed = max(luma(albedo) - albedo,0.0); + vec3 scatter = sqrt(exp(-(absorbed * Scattering * 15)) * (1.0 - Scattering)); - // vec3 scatter = exp(-sqrt(max(Scattering+0.05,0.0) * absorbed * 25)) * exp(Scattering * -5); - vec3 scatter = exp(-sqrt(Scattering * absorbed * 5)) * pow((-Scattering+1.0)*1.25,2.0); scatter *= pow(Density,LabSSS_Curve); return scatter; @@ -687,18 +683,21 @@ void GriAndEminShadowFix( float SkyLightmap, bool Entities ){ + float DistanceOffset = clamp(0.1 + length(WorldPos) / (shadowMapResolution*0.20), 0.0,1.0) ; vec3 Bias = FlatNormal * DistanceOffset; // adjust the bias thingy's strength as it gets farther away. + vec3 finalBias = Bias; + // stop lightleaking - if(SkyLightmap < 0.1 && !Entities) { - WorldPos += mix(Bias, 0.5 * (0.5 - fract(WorldPos + cameraPosition + FlatNormal*0.01 ) ), VanillaAO) ; - }else{ - WorldPos += Bias; - } + vec2 scale = vec2(0.5); scale.y *= 0.5; + vec3 zoomShadow = scale.y - scale.x * fract(WorldPos + cameraPosition + Bias*scale.y); + if(SkyLightmap < 0.1 && !Entities) finalBias = mix(Bias, zoomShadow, clamp(VanillaAO*5,0,1)); + + WorldPos += finalBias; } -void LabEmission( +void Emission( inout vec3 Lighting, vec3 Albedo, float Emission @@ -750,10 +749,10 @@ void main() { float z0 = texture2D(depthtex0,texcoord).x; float z = texture2D(depthtex1,texcoord).x; - float TranslucentDepth = clamp( ld(z0)-ld(z0) ,0.0,1.0); + float TranslucentDepth = clamp( ld(z0)-ld(z0),0.0,1.0); vec2 tempOffset=TAA_Offset; - vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z)); + vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z)); vec3 fragpos_rtshadow = toScreenSpace(vec3(texcoord/RENDER_SCALE,z)); vec3 fragpos_handfix = fragpos; @@ -778,8 +777,8 @@ void main() { scatterCoef *= 0.1; #endif - float noise = blueNoise(); + float noise = blueNoise(); float iswaterstuff = texture2D(colortex7,texcoord).a ; bool iswater = iswaterstuff > 0.99; @@ -816,10 +815,6 @@ void main() { #endif float vanilla_AO = normalAndAO.a; - normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1); - - - bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01; bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01; @@ -837,7 +832,6 @@ void main() { vec3 ambientCoefs = normal/dot(abs(normal),vec3(1.)); - float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2) ,0.0,1.0); vec3 DirectLightColor = (lightCol.rgb/80.0); @@ -849,13 +843,21 @@ void main() { vec3 AmbientLightColor = averageSkyCol_Clouds; + + int shadowmapindicator = 0; float cloudShadow = 1.0; - if ( z >= 1.) { //sky - #ifdef Compositing_Sky - gl_FragData[0].rgb = vec3(CompSky_R, CompSky_G, CompSky_B); - #else + if ( z >= 1.) {//sky + + //////////////////////////////// //////////////////////////////// + //////////////////////////////// SKY STUFF //////////////////////////////// + //////////////////////////////// //////////////////////////////// + #ifdef Compositing_Sky + + gl_FragData[0].rgb = vec3(CompSky_R, CompSky_G, CompSky_B); + + #else vec3 background = vec3(0.0); vec3 orbitstar = vec3(np3.x,abs(np3.y),np3.z); @@ -872,102 +874,113 @@ void main() { vec3 skyTEX = skyFromTex(np3,colortex4)/150.0 * 5.0; background += skyTEX; - // eclipse - // color *=max(1.0 - drawSun(dot(lightCol.a * WsunVec, (np3-0.0002)*1.001),0, vec3(1),vec3(0.0)),0.0); - vec4 cloud = texture2D_bicubic(colortex0,texcoord*CLOUDS_QUALITY); if(eyeAltitude < 25000) background = background*cloud.a + cloud.rgb; gl_FragData[0].rgb = clamp(fp10Dither(background ,triangularize(noise)),0.0,65000.); + #endif + }else{//land - ////// ----- direct ----- ////// + //////////////////////////////// //////////////////////////////// + //////////////////////////////// DIRECT LIGHTING //////////////////////////////// + //////////////////////////////// //////////////////////////////// vec3 Direct_lighting = vec3(1.0); float Shadows = clamp(1.0 - filtered.b,0.0,1.0); + float SHADOWBLOCKERDEPTBH = filtered.y; + float NdotL = dot(slopednormal,WsunVec); NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0); - if (abs(filtered.y-0.1) < 0.0004 && !iswater) Shadows = clamp((lightmap.y-0.85)*25,0,1); - float SHADOWBLOCKERDEPTBH = filtered.y; - //if (abs(filtered.y-0.1) < 0.0004 && !iswater) SHADOWBLOCKERDEPTBH = 1.0-clamp((lightmap.y-0.85)*25,0,1); + + float shadowNDOTL = NdotL; + #ifndef Variable_Penumbra_Shadows + shadowNDOTL += LabSSS; + #endif - vec3 SSS = vec3(0.0); + vec3 p3_shadow = mat3(gbufferModelViewInverse) * fragpos_handfix + gbufferModelViewInverse[3].xyz; - if (NdotL > 0.001) { - - vec3 p3_shadow = mat3(gbufferModelViewInverse) * fragpos_handfix + gbufferModelViewInverse[3].xyz; - - GriAndEminShadowFix(p3_shadow, viewToWorld(FlatNormals), normalAndAO.a, lightmap.y, entities); - - - 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; - // Shadows = 0.0; - vec3 shadew = projectedShadowPosition.xyz; - //do shadows only if on shadow map - if (abs(shadew.x) < 1.0-1.5/shadowMapResolution && abs(shadew.y) < 1.0-1.5/shadowMapResolution && abs(shadew.z) < 6.0){ + if(!hand) GriAndEminShadowFix(p3_shadow, viewToWorld(FlatNormals), vanilla_AO, lightmap.y, entities); - float diffthresh = 0.0; - // if(hand && eyeBrightness.y/240. > 0.0) diffthresh = 0.0003; + vec3 projectedShadowPosition = mat3(shadowModelView) * p3_shadow + shadowModelView[3].xyz; + projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz; - projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5); + //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 && abs(projectedShadowPosition.z) < 6.0){ + if (shadowNDOTL > 0.001){ Shadows = 0.0; - float rdMul = filtered.x*distortFactor*d0*k/shadowMapResolution; + projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5); - for(int i = 0; i < SHADOW_FILTER_SAMPLE_COUNT; i++){ - // if(hand) noise = 0.0; - vec2 offsetS = tapLocation(i,SHADOW_FILTER_SAMPLE_COUNT,1.618,noise,0.0); - float weight = 1.0+(i+noise)*rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution; - float isShadow = shadow2D(shadow,vec3(projectedShadowPosition + vec3(rdMul*offsetS,-diffthresh*weight))).x; - Shadows += isShadow/SHADOW_FILTER_SAMPLE_COUNT; - } + #ifdef BASIC_SHADOW_FILTER + float rdMul = filtered.x*distortFactor*d0*k/shadowMapResolution; + + for(int i = 0; i < SHADOW_FILTER_SAMPLE_COUNT; i++){ + vec2 offsetS = tapLocation(i,SHADOW_FILTER_SAMPLE_COUNT,1.618,noise,0.0); + + float isShadow = shadow2D(shadow,projectedShadowPosition + vec3(rdMul*offsetS, 0.0) ).x; + Shadows += isShadow/SHADOW_FILTER_SAMPLE_COUNT; + } + #else + Shadows = shadow2D(shadow, projectedShadowPosition).x; + #endif } + shadowmapindicator = 1; } - #ifdef Variable_Penumbra_Shadows + bool outsideShadowMap = shadowmapindicator < 1; + + if(outsideShadowMap && !iswater) Shadows = clamp((lightmap.y-0.8) * 5,0,1); - float sunSSS_density = LabSSS; - - #ifndef RENDER_ENTITY_SHADOWS - if(entities) sunSSS_density = 0.0; - #endif + //////////////////////////////// SUN SSS //////////////////////////////// + vec3 SSS = vec3(0.0); - SSS = SubsurfaceScattering_sun(albedo, SHADOWBLOCKERDEPTBH, sunSSS_density, clamp(dot(np3, WsunVec),0.0,1.0)) ; - SSS *= DirectLightColor; - if (isEyeInWater == 0) SSS *= lightleakfix; // light leak fix - #endif - - if (!hand){ - - if (abs(filtered.y-0.1) < 0.0004 && LabSSS < 0.0 ) SSS = vec3(0.0); - - #ifdef SCREENSPACE_CONTACT_SHADOWS - - vec3 vec = lightCol.a*sunVec; - float screenShadow = rayTraceShadow(vec, fragpos_rtshadow, interleaved_gradientNoise()); - screenShadow *= screenShadow ; - - #ifdef Variable_Penumbra_Shadows - Shadows = min(screenShadow, Shadows + luma(SSS)); - if (abs(filtered.y-0.1) < 0.0004 ) SSS *= vec3(Shadows); - #endif - - #endif + #ifndef Variable_Penumbra_Shadows + if(LabSSS > 0 ) { + SHADOWBLOCKERDEPTBH = pow(1.0 - Shadows,2); } + #endif - #ifdef Variable_Penumbra_Shadows - SSS *= 1.0-NdotL*Shadows; + #if SSS_TYPE != 0 + + if (outsideShadowMap) SHADOWBLOCKERDEPTBH = 0.0; + + float sunSSS_density = LabSSS; + + #ifndef RENDER_ENTITY_SHADOWS + if(entities) sunSSS_density = 0.0; #endif + + SSS = SubsurfaceScattering_sun(albedo, SHADOWBLOCKERDEPTBH, sunSSS_density, clamp(dot(np3, WsunVec),0.0,1.0)) ; + SSS *= DirectLightColor; + + if (isEyeInWater == 0) SSS *= lightleakfix; // light leak fix + #endif + + if (!hand){ + #ifdef SCREENSPACE_CONTACT_SHADOWS + float screenShadow = rayTraceShadow(lightCol.a*sunVec, fragpos_rtshadow, interleaved_gradientNoise()); + screenShadow *= screenShadow; + + Shadows = min(screenShadow, Shadows); + + if (outsideShadowMap) SSS *= Shadows; + #endif + } + + #if SSS_TYPE != 0 + SSS *= 1.0-clamp(NdotL*Shadows,0,1); + #endif + #ifdef VOLUMETRIC_CLOUDS #ifdef CLOUDS_SHADOWS cloudShadow = GetCloudShadow(p3); @@ -976,14 +989,14 @@ void main() { #endif #endif - ////// ----- indirect ----- ////// + //////////////////////////////// //////////////////////////////// + //////////////////////////////// INDIRECT LIGHTING //////////////////////////////// + //////////////////////////////// //////////////////////////////// vec3 Indirect_lighting = vec3(1.0); - // float cloudOcclusion = GetCloudShadow_occluson(p3 + cameraPosition); - // AmbientLightColor *= cloudOcclusion*0.5+.5; - - float skylight = clamp(abs(ambientCoefs.y + 1.0),0.35,2.0); + // float skylight = clamp(abs(ambientCoefs.y + 1.0),0.35,2.0); + float skylight = clamp(ambientCoefs.y + 0.5,0.25,2.0); #if indirect_effect == 2 || indirect_effect == 3 || indirect_effect == 4 if (!hand) skylight = 1.0; @@ -991,39 +1004,31 @@ void main() { // do this to make underwater shading easier. vec2 newLightmap = lightmap.xy; - if((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)) newLightmap.y = clamp(newLightmap.y,0,1); - - #ifndef ambientSSS_view Indirect_lighting = DoAmbientLighting(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), newLightmap.xy, skylight); #endif - vec3 AO = vec3(1.0); vec3 debug = vec3(0.0); // vanilla AO #if indirect_effect == 0 - // AO = vec3(mix(1.0 - exp2(-5 * pow(1-vanilla_AO,3)), 1.0, pow(newLightmap.x,4))) ; AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ; #endif // SSAO + vanilla AO #if indirect_effect == 1 - // AO *= mix(1.0 - exp2(-5 * pow(1-vanilla_AO,3)),1.0, pow(newLightmap.x,4)); - AO = vec3( exp( (vanilla_AO*vanilla_AO) * -3) ) ; if (!hand) ssAO(AO, SkySSS, fragpos, 1.0, blueNoise(gl_FragCoord.xy).rg, FlatNormals , texcoord, ambientCoefs, newLightmap.xy, isLeaf); - #endif // GTAO #if indirect_effect == 2 int seed = (frameCounter%40000); vec2 r2 = fract(R2_samples(seed) + blueNoise(gl_FragCoord.xy).rg); - if (!hand) AO = ambient_occlusion(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z), fragpos, worldToView(slopednormal), r2, debug) * vec3(1.0); + if (!hand) AO = ambient_occlusion(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z), fragpos, worldToView(slopednormal), r2, debug) * vec3(1.0); #endif // RTAO @@ -1040,36 +1045,47 @@ void main() { AO = mix(AO,vec3(1.0), min(NdotL*Shadows,1.0)); #endif - Indirect_lighting *= AO; - - - vec3 SSS_forSky = vec3(0.0); + //////////////////////////////// SKY SSS //////////////////////////////// #ifdef Ambient_SSS if (!hand){ + vec3 SSS_forSky = vec3(0.0); + #if indirect_effect != 1 ScreenSpace_SSS(SkySSS, fragpos, blueNoise(gl_FragCoord.xy).rg, FlatNormals, isLeaf); #endif + + vec3 ambientColor = ((AmbientLightColor * 2.0 * ambient_brightness) * 8./150./3.) * 1.25; + float lightmap = pow(newLightmap.y,3); + float uplimit = clamp(1.0-pow(clamp(ambientCoefs.y + 0.5,0.0,1.0),2),0,1); + SSS_forSky = SubsurfaceScattering_sky(albedo, SkySSS, LabSSS); - SSS_forSky *= (AmbientLightColor* 2.0 * ambient_brightness) * 8./150.; - SSS_forSky *= pow(newLightmap.y,3); - // SSS_forSky *= pow(1.0-clamp(abs(ambientCoefs.y+0.5),0.0,1.0),0.1); - - SSS += SSS_forSky * pow(1.0-clamp(abs(ambientCoefs.y+0.5),0.0,1.0),0.1); // Indirect_lighting += SubsurfaceScattering_sky(albedo, SkySSS, LabSSS) * ((AmbientLightColor* 2.0 * ambient_brightness)* 8./150.) * pow(newLightmap.y,3); + SSS_forSky *= ambientColor; + SSS_forSky *= lightmap; + SSS_forSky *= uplimit; + + // Combine with the other SSS + SSS += SSS_forSky; + + SSS_forSky = vec3((1.0 - SkySSS) * LabSSS); + SSS_forSky *= ambientColor; + SSS_forSky *= lightmap; + + ////light up dark parts so its more visible + Indirect_lighting = max(Indirect_lighting, SSS_forSky); } #endif - // Indirect_lighting = max(Indirect_lighting, SSS_forSky); - + Indirect_lighting *= AO; - - - ////// ----- Under Water Shading ----- ////// + //////////////////////////////// //////////////////////////////// + //////////////////////////////// UNDER WATER SHADING //////////////////////////////// + //////////////////////////////// //////////////////////////////// vec3 waterabsorb_speculars = vec3(1); if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)){ - vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z0)); + vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0)); float Vdiff = distance(fragpos,fragpos0); float VdotU = np3.y; float estimatedDepth = Vdiff * abs(VdotU); //assuming water plane @@ -1101,8 +1117,9 @@ void main() { } - - ////// ----- Finalize ----- ////// + //////////////////////////////// //////////////////////////////// + //////////////////////////////// FINALIZE //////////////////////////////// + //////////////////////////////// //////////////////////////////// #ifdef Seasons #ifdef Snowy_Winter @@ -1131,8 +1148,7 @@ void main() { Direct_lighting = DoDirectLighting(DirectLightColor, Shadows, NdotL, 0.0); - - //combine all light sources + vec3 FINAL_COLOR = Indirect_lighting + Direct_lighting + SSS; #ifndef ambientSSS_view @@ -1143,29 +1159,29 @@ void main() { MaterialReflections(FINAL_COLOR, SpecularTex.r, SpecularTex.ggg, albedo, WsunVec, (Shadows*NdotL)*DirectLightColor, lightmap.y, slopednormal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg, interleaved_gradientNoise()), hand, entities); #endif - LabEmission(FINAL_COLOR, albedo, SpecularTex.a); + Emission(FINAL_COLOR, albedo, SpecularTex.a); - if(lightningBolt) FINAL_COLOR.rgb += vec3(Lightning_R,Lightning_G,Lightning_B) * 255.0; - - - gl_FragData[0].rgb = FINAL_COLOR ; - // if(LabSSS > 0.0) gl_FragData[0].rgb = vec3(0,25,0); + gl_FragData[0].rgb = FINAL_COLOR; } - ////// ----- Under Water Fog ----- ////// + + //////////////////////////////// //////////////////////////////// + //////////////////////////////// UNDERWATER FOG //////////////////////////////// + //////////////////////////////// //////////////////////////////// + if (iswater){ - vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z0)); + vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0)); float Vdiff = distance(fragpos,fragpos0); float VdotU = np3.y; float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane float estimatedSunDepth = estimatedDepth/abs(WsunVec.y); //assuming water plane - float custom_lightmap_T = pow(texture2D(colortex14, texcoord).a,1.5); + float custom_lightmap_T = pow(texture2D(colortex14, texcoord).a,3.0); - vec3 ambientColVol = (averageSkyCol_Clouds*8./150./1.5) * max(custom_lightmap_T,MIN_LIGHT_AMOUNT*0.0015); - vec3 lightColVol = (lightCol.rgb / 80.); + vec3 ambientColVol = (averageSkyCol_Clouds*8./150./2.) * max(custom_lightmap_T,MIN_LIGHT_AMOUNT*0.0015); + vec3 lightColVol = DirectLightColor; if (isEyeInWater == 0) waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedSunDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol, lightColVol, dot(np3, WsunVec)); } diff --git a/shaders/composite1.vsh b/shaders/composite1.vsh index 43f40c1..c24c659 100644 --- a/shaders/composite1.vsh +++ b/shaders/composite1.vsh @@ -54,15 +54,7 @@ flat varying float WinterTimeForSnow; void main() { gl_Position = ftransform(); - #ifdef TAA_UPSCALING - gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; - #endif - tempOffsets = HaltonSeq2(frameCounter%10000); - TAA_Offset = offsets[frameCounter%8]; - #ifndef TAA - TAA_Offset = vec2(0.0); - #endif averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb; // averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb; @@ -87,4 +79,18 @@ void main() { YearCycleColor(color1, color2, WinterTimeForSnow); #endif #endif + + + + + + TAA_Offset = offsets[frameCounter%8]; + + #ifndef TAA + TAA_Offset = vec2(0.0); + #endif + + #ifdef TAA_UPSCALING + gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; + #endif } diff --git a/shaders/composite11.fsh b/shaders/composite11.fsh index b0587a2..84bef77 100644 --- a/shaders/composite11.fsh +++ b/shaders/composite11.fsh @@ -17,7 +17,6 @@ uniform sampler2D colortex5; uniform sampler2D colortex3; // uniform sampler2D colortex6; uniform sampler2D colortex7; -// uniform sampler2D colortex10; // uniform sampler2D colortex8; // specular // uniform sampler2D colortex9; // specular uniform sampler2D depthtex0; @@ -67,10 +66,6 @@ float ld(float depth) { return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near } -// blindness fogs -uniform float blindness; -uniform float darknessFactor; - void main() { /* DRAWBUFFERS:7 */ float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.); @@ -127,14 +122,6 @@ void main() { float rodCurve = mix(1.0, rodLum/(2.5+rodLum), purkinje); col = mix(clamp(lum,0.0,0.05)*Purkinje_Multiplier*vec3(Purkinje_R, Purkinje_G, Purkinje_B)+1.5e-3, col, rodCurve); -// #ifdef display_LUT -// vec2 movedTC = texcoord ; -// if(movedTC.x < 0.4 ) col.rgb = texture2D(colortex4,movedTC/2).rgb * 0.001; -// #endif - - - - #ifndef USE_ACES_COLORSPACE_APPROXIMATION col = LinearTosRGB(TONEMAP(col)); #else diff --git a/shaders/composite2.fsh b/shaders/composite2.fsh index 9d07dec..fd6dae9 100644 --- a/shaders/composite2.fsh +++ b/shaders/composite2.fsh @@ -310,7 +310,8 @@ void main() { float estEyeDepth = clamp((14.0-eyeBrightnessSmooth.y/255.0*16.0)/14.0,0.,1.0); estEyeDepth *= estEyeDepth*estEyeDepth*34.0; - vec3 ambientColVol = averageSkyCol_Clouds*8./150./1.5; + + vec3 ambientColVol = averageSkyCol_Clouds*8./150./2.0; vec3 lightColVol = (lightCol.rgb / 80.); estEyeDepth = max(Water_Top_Layer - cameraPosition.y,0.0); diff --git a/shaders/composite5.fsh b/shaders/composite5.fsh index 10cf4d1..a0b6e00 100644 --- a/shaders/composite5.fsh +++ b/shaders/composite5.fsh @@ -22,18 +22,19 @@ const int colortex4Format = RGBA16F; //light values and skyboxes (everything) const int colortex6Format = R11F_G11F_B10F; //additionnal buffer for bloom (composite3->final) -const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) -const int colortex8Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) -const int colortex9Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) -const int colortex10Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) +const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) +const int colortex8Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) +const int colortex9Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) +const int colortex10Format = RGBA16F; //FREE BUFFER -const int colortex11Format = RGBA16; //Final output, transparencies id (gbuffer->composite4) -const int colortex13Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) -const int colortex14Format = RGBA8; // Final output, transparencies id (gbuffer->composite4) -const int colortex15Format = RGBA8; // flat normals and vanilla AO +const int colortex11Format = RGBA16; +const int colortex13Format = RGBA8; +const int colortex14Format = RGBA8; +const int colortex15Format = RGBA8; // flat normals and vanilla AO */ //no need to clear the buffers, saves a few fps + /* const bool colortex0Clear = false; const bool colortex1Clear = false; diff --git a/shaders/entity.properties b/shaders/entity.properties index 5010876..ae99a3c 100644 --- a/shaders/entity.properties +++ b/shaders/entity.properties @@ -3,10 +3,10 @@ ### all the different strengths of subsurface scattering and what entities to put them on. #medium sss (same as strong sss for blocks) -entity.1100 = slime giant ender_dragon ghast sheep +entity.1100 = slime giant ghast #weak sss (same as weak sss for blocks) -entity.1200 = player frog chicken snow_golem polar_bear zombie_horse armor_stand arrow squid bat cat cod cow donkey fox horse mooshroom mule ocelot parrot pig piglin polar_bear pufferfish rabbit salmon strider tropical_fish turtle villager wandering_trader bee cave_spider dolphin enderman llama panda spider wolf zombified_piglin blaze creeper drowned endermite evoker guardian hoglin husk magma_cube phantom piglin_brute pillager ravager silverfish stray vex vindicator witch zoglin zombie zombie_villager wither trader_llama +entity.1200 = ender_dragon player sheep frog chicken snow_golem polar_bear zombie_horse armor_stand arrow squid bat cat cod cow donkey fox horse mooshroom mule ocelot parrot pig piglin polar_bear pufferfish rabbit salmon strider tropical_fish turtle villager wandering_trader bee cave_spider dolphin enderman llama panda spider wolf zombified_piglin blaze creeper drowned endermite evoker guardian hoglin husk magma_cube phantom piglin_brute pillager ravager silverfish stray vex vindicator witch zoglin zombie zombie_villager wither trader_llama # various stuff diff --git a/shaders/final.fsh b/shaders/final.fsh index b8e751a..60dd0a6 100644 --- a/shaders/final.fsh +++ b/shaders/final.fsh @@ -128,5 +128,5 @@ void main() { applyContrast(FINAL_COLOR, CONTRAST); // for fun - gl_FragColor.rgb = FINAL_COLOR; + gl_FragColor.rgb = FINAL_COLOR ; } diff --git a/shaders/gbuffers_all_solid.fsh b/shaders/gbuffers_all_solid.fsh index ca0a3f4..48972d0 100644 --- a/shaders/gbuffers_all_solid.fsh +++ b/shaders/gbuffers_all_solid.fsh @@ -541,7 +541,16 @@ void main() { if(SpecularTex.g < 229.5/255.0) Albedo.rgb = mix(Albedo.rgb, vec3(0), Puddle_shape*porosity); #endif - vec4 data1 = clamp( encode(viewToWorld(normal), (blueNoise()*vec2(torchlightmap,lmtexcoord.w) / (30.0 * (1+ (1-RENDER_SCALE.x))) ) + vec2(torchlightmap,lmtexcoord.w)), 0.0, 1.0); + // apply noise to lightmaps to reduce banding. + vec2 PackLightmaps = vec2(torchlightmap,lmtexcoord.w); + + #ifndef ENTITIES + #ifndef HAND + PackLightmaps = max(PackLightmaps*blueNoise()*0.05 + PackLightmaps,0.0); + #endif + #endif + + vec4 data1 = clamp( encode(viewToWorld(normal),PackLightmaps), 0.0, 1.0); gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w)); @@ -556,6 +565,6 @@ void main() { // gl_FragData[5].xyz = velocity *0.5+0.5; // #endif - gl_FragData[3] = vec4(FlatNormals * 0.5 + 0.5,VanillaAO); + gl_FragData[3] = vec4(FlatNormals * 0.5 + 0.5, VanillaAO); #endif } \ No newline at end of file diff --git a/shaders/gbuffers_all_solid.vsh b/shaders/gbuffers_all_solid.vsh index d2af865..c7739cb 100644 --- a/shaders/gbuffers_all_solid.vsh +++ b/shaders/gbuffers_all_solid.vsh @@ -86,6 +86,7 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), vec2(-7.,-1.)/8., vec2(3,7.)/8., vec2(7.,-7.)/8.); + #define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) #define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) vec4 toClipSpace3(vec3 viewSpacePosition) { diff --git a/shaders/gbuffers_all_translucent.fsh b/shaders/gbuffers_all_translucent.fsh index 21b58ab..9ad2581 100644 --- a/shaders/gbuffers_all_translucent.fsh +++ b/shaders/gbuffers_all_translucent.fsh @@ -505,6 +505,6 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize gl_FragData[1] = vec4(Albedo,iswater); #endif - gl_FragData[3].a = lmtexcoord.w; + gl_FragData[3].a = max(lmtexcoord.w*blueNoise()*0.05 + lmtexcoord.w,0.0); } } \ No newline at end of file diff --git a/shaders/lib/settings.glsl b/shaders/lib/settings.glsl index 2784518..d810fcf 100644 --- a/shaders/lib/settings.glsl +++ b/shaders/lib/settings.glsl @@ -120,6 +120,7 @@ const float shadowDistanceRenderMul = -1.0; // [-1.0 1.0] #define Max_Shadow_Filter_Radius 30.0 // [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 43.0 44.0 45.0 46.0 47.0 48.0 49.0 50.0 51.0 52.0 53.0 54.0 55.0 56.0 57.0 58.0 59.0 60.0 61.0 62.0 63.0 64.0 65.0 66.0 67.0 68.0 69.0 70.0 71.0 72.0 73.0 74.0 75.0 76.0 77.0 78.0 79.0 80.0 81.0 82.0 83.0 84.0 85.0 86.0 87.0 88.0 89.0 90.0 91.0 92.0 93.0 94.0 95.0 96.0 97.0 98.0 99.0 100.0 101.0 102.0 103.0 104.0 105.0 106.0 107.0 108.0 109.0 110.0 111.0 112.0 113.0 114.0 115.0 116.0 117.0 118.0 119.0 ] #define Max_Filter_Depth 20.0 // [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 43.0 44.0 45.0 46.0 47.0 48.0 49.0 50.0 51.0 52.0 53.0 54.0 55.0 56.0 57.0 58.0 59.0 60.0 61.0 62.0 63.0 64.0 65.0 66.0 67.0 68.0 69.0 70.0 71.0 72.0 73.0 74.0 75.0 76.0 77.0 78.0 79.0 80.0 81.0 82.0 83.0 84.0 85.0 86.0 87.0 88.0 89.0 90.0 91.0 92.0 93.0 94.0 95.0 96.0 97.0 98.0 99.0 100.0 101.0 102.0 103.0 104.0 105.0 106.0 107.0 108.0 109.0 110.0 111.0 112.0 113.0 114.0 115.0 116.0 117.0 118.0 119.0 ] +#define BASIC_SHADOW_FILTER #define SHADOW_FILTER_SAMPLE_COUNT 13 // [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 44 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 ] #define SHADOW_DISABLE_ALPHA_MIPMAPS #define Stochastic_Transparent_Shadows diff --git a/shaders/lib/specular.glsl b/shaders/lib/specular.glsl index 53bcda6..223097f 100644 --- a/shaders/lib/specular.glsl +++ b/shaders/lib/specular.glsl @@ -192,6 +192,7 @@ vec3 SampleVNDFGGX( // This gives the normal on the hemisphere // xonk note, i added those magic numbers huhuhuh vec3 halfway = reflected*0.5 + viewerDirection*1.5; + // vec3 halfway = reflected + viewerDirection; // Transform the halfway direction back to hemiellispoid configuation // This gives the final sampled normal diff --git a/shaders/shaders.properties b/shaders/shaders.properties index aac84a0..5eaa3b0 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -69,7 +69,7 @@ screen = [Direct_Light] [World] [Ambient_light] [Fog] [Post_Processing] [Clouds] screen.Subsurface_Scattering = SSS_TYPE LabSSS_Curve MISC_BLOCK_SSS MOB_SSS Ambient_SSS ambientsss_brightness screen.Filtering.columns=1 - screen.Filtering = SHADOW_FILTER_SAMPLE_COUNT Min_Shadow_Filter_Radius Variable_Penumbra_Shadows VPS_Search_Samples Max_Shadow_Filter_Radius Max_Filter_Depth + screen.Filtering = BASIC_SHADOW_FILTER SHADOW_FILTER_SAMPLE_COUNT Min_Shadow_Filter_Radius Variable_Penumbra_Shadows VPS_Search_Samples Max_Shadow_Filter_Radius Max_Filter_Depth ### AMBIENT LIGHT screen.Ambient_light.columns=1 diff --git a/shaders/shadow.vsh b/shaders/shadow.vsh index d1bdc17..2790014 100644 --- a/shaders/shadow.vsh +++ b/shaders/shadow.vsh @@ -26,16 +26,20 @@ uniform float frameTimeCounter; uniform vec3 sunVec; uniform float aspectRatio; uniform float sunElevation; +uniform vec3 sunPosition; uniform float lightSign; uniform float cosFov; uniform vec3 shadowViewDir; uniform vec3 shadowCamera; uniform vec3 shadowLightVec; uniform float shadowMaxProj; -attribute vec4 mc_Entity; attribute vec4 mc_midTexCoord; varying vec4 glcolor; +attribute vec4 mc_Entity; +uniform int blockEntityId; +uniform int entityId; + const float PI48 = 150.796447372*WAVY_SPEED; float pi2wt = PI48*frameTimeCounter; @@ -91,47 +95,39 @@ vec4 toClipSpace3(vec3 viewSpacePosition) { } void main() { - vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz; - - //Check if the vertice is going to cast shadows - // #ifdef SHADOW_FRUSTRUM_CULLING - // if (intersectCone(cosFov, shadowCamera, shadowViewDir, position, -shadowLightVec, shadowMaxProj)) { - // #endif - // #ifdef WAVY_PLANTS - // bool istopv = gl_MultiTexCoord0.t < mc_midTexCoord.t; - // if ((mc_Entity.x == 10001&&istopv) && length(position.xy) < 24.0) { - // vec3 worldpos = mat3(shadowModelViewInverse) * position + shadowModelViewInverse[3].xyz; - // worldpos.xyz += calcMovePlants(worldpos.xyz + cameraPosition)*gl_MultiTexCoord1.y; - // position = mat3(shadowModelView) * worldpos + shadowModelView[3].xyz ; - // } + #ifdef WAVY_PLANTS + bool istopv = gl_MultiTexCoord0.t < mc_midTexCoord.t; + if ((mc_Entity.x == 10001&&istopv) && length(position.xy) < 24.0) { + vec3 worldpos = mat3(shadowModelViewInverse) * position + shadowModelViewInverse[3].xyz; + worldpos.xyz += calcMovePlants(worldpos.xyz + cameraPosition)*gl_MultiTexCoord1.y; + position = mat3(shadowModelView) * worldpos + shadowModelView[3].xyz ; + } - // if ((mc_Entity.x == 10003) && length(position.xy) < 24.0) { - // vec3 worldpos = mat3(shadowModelViewInverse) * position + shadowModelViewInverse[3].xyz; - // worldpos.xyz += calcMoveLeaves(worldpos.xyz + cameraPosition, 0.0040, 0.0064, 0.0043, 0.0035, 0.0037, 0.0041, vec3(1.0,0.2,1.0), vec3(0.5,0.1,0.5))*gl_MultiTexCoord1.y; - // position = mat3(shadowModelView) * worldpos + shadowModelView[3].xyz ; - // } - // #endif + if ((mc_Entity.x == 10003) && length(position.xy) < 24.0) { + vec3 worldpos = mat3(shadowModelViewInverse) * position + shadowModelViewInverse[3].xyz; + worldpos.xyz += calcMoveLeaves(worldpos.xyz + cameraPosition, 0.0040, 0.0064, 0.0043, 0.0035, 0.0037, 0.0041, vec3(1.0,0.2,1.0), vec3(0.5,0.1,0.5))*gl_MultiTexCoord1.y; + position = mat3(shadowModelView) * worldpos + shadowModelView[3].xyz ; + } + #endif // gl_Position = BiasShadowProjection_altered(toClipSpace3(position),mat3(shadowProjection),mat3(shadowModelView), gl_NormalMatrix * gl_Normal); gl_Position = BiasShadowProjection(toClipSpace3(position)); - - gl_Position.z /= 6.0; + float bias = 6.0; + + vec3 FlatNormals = normalize(gl_NormalMatrix *gl_Normal); + vec3 WsunVec = (float(sunElevation > 1e-5)*2-1.)*normalize(mat3(shadowModelViewInverse) * sunPosition); + if(entityId == 1100) bias = 6.0 + (1-clamp(dot(WsunVec,FlatNormals),0,1))*0.3; + + gl_Position.z /= bias; texcoord.xy = gl_MultiTexCoord0.xy; - if(mc_Entity.x == 8 || mc_Entity.x == 9) gl_Position.w = -1.0; - - #ifdef SHADOW_FRUSTRUM_CULLING - } - else - gl_Position.xyzw = vec4(0.0,0.0,1e30,0.0); //Degenerates the triangle - #endif } diff --git a/shaders/world-1/composite2.fsh b/shaders/world-1/composite2.fsh index b702613..7e55fda 100644 --- a/shaders/world-1/composite2.fsh +++ b/shaders/world-1/composite2.fsh @@ -305,7 +305,7 @@ vec4 blueNoise(vec2 coord){ return texelFetch2D(colortex6, ivec2(coord )%512 , 0); } -void LabEmission( +void Emission( inout vec3 Lighting, vec3 Albedo, float Emission @@ -467,7 +467,7 @@ void main() { MaterialReflections_N(gl_FragData[0].rgb, SpecularTex.r, SpecularTex.ggg, albedo, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,noise), hand); #endif - LabEmission(gl_FragData[0].rgb, albedo, SpecularTex.a); + Emission(gl_FragData[0].rgb, albedo, SpecularTex.a); if(lightningBolt) gl_FragData[0].rgb += vec3(Lightning_R,Lightning_G,Lightning_B) ; diff --git a/shaders/world1/composite.fsh b/shaders/world1/composite.fsh index 297c570..89820c4 100644 --- a/shaders/world1/composite.fsh +++ b/shaders/world1/composite.fsh @@ -303,7 +303,7 @@ vec4 blueNoise(vec2 coord){ return texelFetch2D(colortex6, ivec2(coord )%512 , 0); } -void LabEmission( +void Emission( inout vec3 Lighting, vec3 Albedo, float Emission @@ -459,7 +459,7 @@ void main() { if(!hand) gl_FragData[0].rgb *= ssao(fragpos,noise,FlatNormals) * AO; - LabEmission(gl_FragData[0].rgb, albedo, SpecularTex.a); + Emission(gl_FragData[0].rgb, albedo, SpecularTex.a); if(lightningBolt) gl_FragData[0].rgb = LightColor * 10 ;