summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclayjohn <claynjohn@gmail.com>2023-04-18 17:26:17 -0700
committerclayjohn <claynjohn@gmail.com>2023-04-18 17:26:17 -0700
commitab603e347f057737fdc0bdf47e2437ad32924cad (patch)
tree7028bafeabd88c3d9d4ab4ae9676faf5db418fa2
parenta7276f1ce0c2911216a2c4718efddab98ddffd8f (diff)
downloadredot-engine-ab603e347f057737fdc0bdf47e2437ad32924cad.tar.gz
Clamp normal when calculating 2D lighting to avoid artifacts
-rw-r--r--drivers/gles3/shaders/canvas.glsl2
-rw-r--r--servers/rendering/renderer_rd/shaders/canvas.glsl2
2 files changed, 2 insertions, 2 deletions
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl
index ea0a0b660d..ae3892fb61 100644
--- a/drivers/gles3/shaders/canvas.glsl
+++ b/drivers/gles3/shaders/canvas.glsl
@@ -589,7 +589,7 @@ void main() {
if (bool(read_draw_data_flags & FLAGS_FLIP_V)) {
normal.y = -normal.y;
}
- normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
+ normal.z = sqrt(max(0.0, 1.0 - dot(normal.xy, normal.xy)));
normal_used = true;
} else {
normal = vec3(0.0, 0.0, 1.0);
diff --git a/servers/rendering/renderer_rd/shaders/canvas.glsl b/servers/rendering/renderer_rd/shaders/canvas.glsl
index 1fb8b28b15..c96524b5c9 100644
--- a/servers/rendering/renderer_rd/shaders/canvas.glsl
+++ b/servers/rendering/renderer_rd/shaders/canvas.glsl
@@ -508,7 +508,7 @@ void main() {
if (bool(draw_data.flags & FLAGS_FLIP_V)) {
normal.y = -normal.y;
}
- normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
+ normal.z = sqrt(max(0.0, 1.0 - dot(normal.xy, normal.xy)));
normal_used = true;
} else {
normal = vec3(0.0, 0.0, 1.0);