From 8e23c37668acafd072cbde6a8310be9680dda6e0 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 16 Jun 2016 18:07:10 +0200 Subject: [PATCH] Flip the parallax offset Y component based on tangent parity (Bug #3440) --- files/shaders/objects_fragment.glsl | 6 +++--- files/shaders/objects_vertex.glsl | 4 ++-- files/shaders/parallax.glsl | 4 ++-- files/shaders/terrain_fragment.glsl | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index 8f21e7247..ac8c2d591 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -28,7 +28,7 @@ varying vec2 emissiveMapUV; #if @normalMap uniform sampler2D normalMap; varying vec2 normalMapUV; -varying vec3 passTangent; +varying vec4 passTangent; #endif #if @envMap @@ -69,7 +69,7 @@ void main() vec4 normalTex = texture2D(normalMap, normalMapUV); vec3 normalizedNormal = normalize(passNormal); - vec3 normalizedTangent = normalize(passTangent); + vec3 normalizedTangent = normalize(passTangent.xyz); vec3 binormal = cross(normalizedTangent, normalizedNormal); mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal); @@ -82,7 +82,7 @@ void main() vec3 cameraPos = (gl_ModelViewMatrixInverse * vec4(0,0,0,1)).xyz; vec3 objectPos = (gl_ModelViewMatrixInverse * vec4(passViewPos, 1)).xyz; vec3 eyeDir = normalize(cameraPos - objectPos); - vec2 offset = getParallaxOffset(eyeDir, tbnTranspose, normalTex.a); + vec2 offset = getParallaxOffset(eyeDir, tbnTranspose, normalTex.a, (passTangent.w > 0) ? -1.f : 1.f); adjustedDiffuseUV += offset; // only offset diffuse for now, other textures are more likely to be using a completely different UV set // TODO: check not working as the same UV buffer is being bound to different targets diff --git a/files/shaders/objects_vertex.glsl b/files/shaders/objects_vertex.glsl index 9aabbe696..e140cd6ad 100644 --- a/files/shaders/objects_vertex.glsl +++ b/files/shaders/objects_vertex.glsl @@ -22,7 +22,7 @@ varying vec2 emissiveMapUV; #if @normalMap varying vec2 normalMapUV; -varying vec3 passTangent; +varying vec4 passTangent; #endif #if @envMap @@ -85,7 +85,7 @@ void main(void) #if @normalMap normalMapUV = (gl_TextureMatrix[@normalMapUV] * gl_MultiTexCoord@normalMapUV).xy; - passTangent = gl_MultiTexCoord7.xyz; + passTangent = gl_MultiTexCoord7.xyzw; #endif #if @specularMap diff --git a/files/shaders/parallax.glsl b/files/shaders/parallax.glsl index 097a59ed1..433dbcd3e 100644 --- a/files/shaders/parallax.glsl +++ b/files/shaders/parallax.glsl @@ -1,8 +1,8 @@ #define PARALLAX_SCALE 0.04 #define PARALLAX_BIAS -0.02 -vec2 getParallaxOffset(vec3 eyeDir, mat3 tbnTranspose, float height) +vec2 getParallaxOffset(vec3 eyeDir, mat3 tbnTranspose, float height, float flipY) { vec3 TSeyeDir = normalize(eyeDir * tbnTranspose); - return TSeyeDir.xy * ( height * PARALLAX_SCALE + PARALLAX_BIAS ); + return vec2(TSeyeDir.x, TSeyeDir.y * flipY) * ( height * PARALLAX_SCALE + PARALLAX_BIAS ); } diff --git a/files/shaders/terrain_fragment.glsl b/files/shaders/terrain_fragment.glsl index d05a94687..0995a2d44 100644 --- a/files/shaders/terrain_fragment.glsl +++ b/files/shaders/terrain_fragment.glsl @@ -53,7 +53,7 @@ void main() vec3 cameraPos = (gl_ModelViewMatrixInverse * vec4(0,0,0,1)).xyz; vec3 objectPos = (gl_ModelViewMatrixInverse * vec4(passViewPos, 1)).xyz; vec3 eyeDir = normalize(cameraPos - objectPos); - adjustedUV += getParallaxOffset(eyeDir, tbnTranspose, normalTex.a); + adjustedUV += getParallaxOffset(eyeDir, tbnTranspose, normalTex.a, 1.f); // update normal using new coordinates normalTex = texture2D(normalMap, adjustedUV);