From ea2b188b64fb89ff51bd9bdf3c958757296afb4c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 2 May 2017 17:07:50 -0700 Subject: [PATCH] Recompute Y from X/Z for normal maps --- libraries/render-utils/src/MaterialTextures.slh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/MaterialTextures.slh b/libraries/render-utils/src/MaterialTextures.slh index 7b73896cc5..a530f4faf2 100644 --- a/libraries/render-utils/src/MaterialTextures.slh +++ b/libraries/render-utils/src/MaterialTextures.slh @@ -64,7 +64,9 @@ float fetchRoughnessMap(vec2 uv) { uniform sampler2D normalMap; vec3 fetchNormalMap(vec2 uv) { // unpack normal, swizzle to get into hifi tangent space with Y axis pointing out - return normalize(texture(normalMap, uv).rbg -vec3(0.5, 0.5, 0.5)); + vec2 t = 2.0 * (texture(normalMap, uv).rg - vec2(0.5, 0.5)); + vec2 t2 = t*t; + return normalize(vec3(t.x, sqrt(1 - t2.x - t2.y), t.y)); } <@endif@>