Light bleeding improvement
This commit is contained in:
parent
2a661daf3e
commit
b4e0cefbe7
@ -59,6 +59,11 @@ vec2 get_parallax_offset_uv(vec2 uv, vec3 view_direction) {
|
||||
return current_uv;
|
||||
}
|
||||
|
||||
// Return a linear interpolation (0..1) of value between low and high, or 0.0 / 1.0 if value is below / above the bounds
|
||||
float linear_step(float low, float high, float value) {
|
||||
return clamp((value - low) / (high - low), 0.0, 1.0);
|
||||
}
|
||||
|
||||
float get_shadow(vec4 fragPosLightSpace, vec3 normal) {
|
||||
// perform perspective divide
|
||||
mediump vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||
@ -79,10 +84,12 @@ float get_shadow(vec4 fragPosLightSpace, vec3 normal) {
|
||||
float p = step(projCoords.z, moments.x);
|
||||
// We divide by this later, so make sure it's not exactly 0
|
||||
// It seems like it should always be 0.0, but due to interpolation it's not -- it increases with the deviation!
|
||||
float variance = max(moments.y - moments.x * moments.x, 0.00002);
|
||||
// A larger second parameter to max() means more blur (but also more light bleeding)
|
||||
float variance = max(moments.y - moments.x * moments.x, 0.0005);
|
||||
|
||||
float d = projCoords.z - moments.x * 1.0; // bias should be "compare", what is that?
|
||||
float p_max = variance / (variance + d * d);
|
||||
// Use linear_step to prevent light bleeding
|
||||
float p_max = linear_step(0.2, 1.0, variance / (variance + d * d));
|
||||
|
||||
// If this pixel is exactly in the light, p is 1, so make sure we return that in that case
|
||||
// min() to make sure that it doesn't get greater than 1.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user