Bliss-Shader/shaders/lib/Shadows.glsl

29 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-10-07 22:18:20 -04:00
// Emin's and Gri's combined ideas to stop peter panning and light leaking, also has little shadowacne so thats nice
// https://www.complementary.dev/reimagined
// https://github.com/gri573
void GriAndEminShadowFix(
inout vec3 WorldPos,
vec3 FlatNormal,
float VanillaAO,
float SkyLightmap
2023-10-07 22:18:20 -04:00
){
float MinimumValue = 0.05;
// give a tiny boost to the distance mulitplier when shadowmap resolution is below 2048.0
2024-11-15 17:54:18 -05:00
// float ResMultiplier = 1.0 + (shadowDistance/8.0)*(1.0 - min(shadowMapResolution,2048)/2048.0)*0.3;
2024-11-15 17:54:18 -05:00
// float DistanceMultiplier = max(1.0 - max(1.0 - length(WorldPos) / shadowDistance, 0.0), MinimumValue) * ResMultiplier;
float theDistance = max(1.0 - length(WorldPos) / shadowDistance,0.0);
float DistanceMultiplier = mix(0.5, 0.05, theDistance);
float DistanceMultiplier2 = mix(1.0, 0.02, theDistance);
vec3 Bias = (FlatNormal * DistanceMultiplier + WsunVec * DistanceMultiplier2);
2023-10-07 22:18:20 -04:00
// stop lightleaking by zooming up, centered on blocks
2023-10-07 22:18:20 -04:00
vec2 scale = vec2(0.5); scale.y *= 0.5;
2024-11-15 17:54:18 -05:00
vec3 zoomShadow = scale.y - scale.x * fract(WorldPos + cameraPosition + Bias*scale.y*0.1);
if(SkyLightmap < 0.1 && isEyeInWater != 1 && VanillaAO > 0.0) Bias = zoomShadow;
2023-10-07 22:18:20 -04:00
WorldPos += Bias;
2023-10-07 22:18:20 -04:00
}