fix terrain normal map handedness

This commit is contained in:
wareya 2025-07-11 12:23:22 -04:00
parent c232ad55b4
commit 869881d227
2 changed files with 3 additions and 3 deletions

View File

@ -49,7 +49,7 @@ void main()
vec2 adjustedUV = (gl_TextureMatrix[0] * vec4(uv, 0.0, 1.0)).xy; vec2 adjustedUV = (gl_TextureMatrix[0] * vec4(uv, 0.0, 1.0)).xy;
#if @parallax #if @parallax
adjustedUV += getParallaxOffset(transpose(normalToViewMatrix) * normalize(-passViewPos), texture2D(normalMap, adjustedUV).a, 1.f); adjustedUV += getParallaxOffset(transpose(normalToViewMatrix) * normalize(-passViewPos), texture2D(normalMap, adjustedUV).a, -1.0f);
#endif #endif
vec4 diffuseTex = texture2D(diffuseMap, adjustedUV); vec4 diffuseTex = texture2D(diffuseMap, adjustedUV);
gl_FragData[0] = vec4(diffuseTex.xyz, 1.0); gl_FragData[0] = vec4(diffuseTex.xyz, 1.0);

View File

@ -46,8 +46,8 @@ void main(void)
normalToViewMatrix = gl_NormalMatrix; normalToViewMatrix = gl_NormalMatrix;
#if @normalMap #if @normalMap
mat3 tbnMatrix = generateTangentSpace(vec4(1.0, 0.0, 0.0, 1.0), passNormal); mat3 tbnMatrix = generateTangentSpace(vec4(1.0, 0.0, 0.0, -1.0), passNormal);
tbnMatrix[0] = normalize(cross(tbnMatrix[2], tbnMatrix[1])); // note, now we need to re-cross to derive tangent again because it wasn't orthonormal tbnMatrix[0] = -normalize(cross(tbnMatrix[2], tbnMatrix[1])); // our original tangent was not at a 90 degree angle to the normal, so we need to rederive it
normalToViewMatrix *= tbnMatrix; normalToViewMatrix *= tbnMatrix;
#endif #endif