Fix Shadow Texture Border Sampling on Web

Fix Shadow Texture Border Sampling on Web, by doing a manual check of the uvs in the shader. This probably slows down other versions, but it is not feasible to have two versions of the shader just for this reason.
main
andrewjhaman 10 months ago
parent f58d50f7ab
commit fab5c86841

@ -3848,6 +3848,8 @@ extern bool profiling;
#else
bool profiling;
#endif
#else
const bool show_devtools = false;
#endif
Color debug_color = {1,0,0,1};

@ -48,6 +48,13 @@ float decodeDepth(vec4 rgba) {
}
float do_shadow_sample(sampler2D shadowMap, vec2 uv, float scene_depth) {
{
//WebGL does not support GL_CLAMP_TO_BORDER, or border colors at all it seems, so we have to check explicitly.
//This will probably slow down other versions which do support texture borders, but the current system does
// not provide a non-overly complex way to include/not-include this code based on the backend. So here it is.
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0)
return 1.0;
}
float map_depth = decodeDepth(texture(shadowMap, uv));
map_depth += 0.001;//bias to counter self-shadowing
return step(scene_depth, map_depth);

@ -0,0 +1,5 @@
@block clamp_to_border
//WebGL does not support GL_CLAMP_TO_BORDER, or border colors at all it seems, so we have to check explicitly.
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0)
return 1.0;
@end
Loading…
Cancel
Save