summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-12-21 23:30:55 +0100
committerGitHub <noreply@github.com>2019-12-21 23:30:55 +0100
commit34ddb7ac59f4c7e548122fa4bea1e89803db2ec4 (patch)
tree4620963cc770350fbbf845f5ebd7146ead7cdd41
parent58c07f27fc0f6b6c706dc7e0ffb1e471ede165a5 (diff)
parentd7f9d71be23daac44c06c4f84993ceae43193b1e (diff)
Merge pull request #34519 from MadEqua/fix-contact-shadows
Fix contact shadow when light is outside of viewport.
-rw-r--r--drivers/gles3/shaders/scene.glsl24
1 files changed, 14 insertions, 10 deletions
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 549a36817e..f16f798ac5 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -897,18 +897,22 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
bias += incr * 2.0;
vec3 uv_depth = (source.xyz / source.w) * 0.5 + 0.5;
- float depth = texture(depth_buffer, uv_depth.xy).r;
-
- if (depth < uv_depth.z) {
- if (depth > (bias.z / bias.w) * 0.5 + 0.5) {
- return min(pow(ratio, 4.0), 1.0);
- } else {
- return 1.0;
+ if (uv_depth.x > 0.0 && uv_depth.x < 1.0 && uv_depth.y > 0.0 && uv_depth.y < 1.0) {
+ float depth = texture(depth_buffer, uv_depth.xy).r;
+
+ if (depth < uv_depth.z) {
+ if (depth > (bias.z / bias.w) * 0.5 + 0.5) {
+ return min(pow(ratio, 4.0), 1.0);
+ } else {
+ return 1.0;
+ }
}
- }
- ratio += ratio_incr;
- steps -= 1.0;
+ ratio += ratio_incr;
+ steps -= 1.0;
+ } else {
+ return 1.0;
+ }
}
return 1.0;