From e13040b3734640abf33873031877ca9b762b14d6 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Fri, 11 Dec 2020 10:18:12 +0000 Subject: [PATCH] Fix bug in normal map decompression Not clamping the range here leads to dithering artifacts. --- drivers/gles2/shaders/canvas.glsl | 2 +- drivers/gles3/shaders/canvas.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index 444839ff9ba..b6371980cda 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -455,7 +455,7 @@ void main() { if (use_default_normal) { normal.xy = texture2D(normal_texture, uv).xy * 2.0 - 1.0; - 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/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 9a1122c9206..620968cd143 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -549,7 +549,7 @@ void main() { if (use_default_normal) { normal.xy = textureLod(normal_texture, uv, 0.0).xy * 2.0 - 1.0; - 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);