Flip the parallax offset Y component based on tangent parity (Bug #3440)

coverity_scan^2
scrawl 9 years ago
parent 6f5b68859f
commit 8e23c37668

@ -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

@ -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

@ -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 );
}

@ -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);

Loading…
Cancel
Save