diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-08-15 08:40:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-15 08:40:16 +0200 |
commit | 4c6cf97257343a95dd9042f9441dfe5de5f39cc7 (patch) | |
tree | dd9210eff39fe58c658e27df251fe9cdd001be42 | |
parent | da157744cd40c5052bc1ebdc66bed972c0a3e7a6 (diff) | |
parent | 66eba18969587762044825922e4a761c393583a6 (diff) |
Merge pull request #20941 from codingHahn/fix-normals-on-shader
Fix handling of normals that approach 1
-rw-r--r-- | drivers/gles2/shaders/scene.glsl | 2 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl index 9251e21080..3e64c92e96 100644 --- a/drivers/gles2/shaders/scene.glsl +++ b/drivers/gles2/shaders/scene.glsl @@ -526,7 +526,7 @@ FRAGMENT_SHADER_CODE #if defined(ENABLE_NORMALMAP) normalmap.xy = normalmap.xy * 2.0 - 1.0; - normalmap.z = sqrt(1.0 - dot(normalmap.xy, normalmap.xy)); + normalmap.z = sqrt(max(0.0, 1.0 - dot(normalmap.xy, normalmap.xy))); // normal = normalize(mix(normal_interp, tangent * normalmap.x + binormal * normalmap.y + normal * normalmap.z, normaldepth)) * side; normal = normalmap; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index dee8bcbc58..2d6f42679f 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -1700,7 +1700,7 @@ FRAGMENT_SHADER_CODE #if defined(ENABLE_NORMALMAP) normalmap.xy=normalmap.xy*2.0-1.0; - normalmap.z=sqrt(1.0-dot(normalmap.xy,normalmap.xy)); //always ignore Z, as it can be RG packed, Z may be pos/neg, etc. + normalmap.z=sqrt(max(0.0, 1.0-dot(normalmap.xy,normalmap.xy))); //always ignore Z, as it can be RG packed, Z may be pos/neg, etc. normal = normalize( mix(normal_interp,tangent * normalmap.x + binormal * normalmap.y + normal * normalmap.z,normaldepth) ) * side; |