Don't overcorrect parallax Y

This commit is contained in:
Alexei Kotov 2025-08-25 10:21:17 +03:00
parent 944925663d
commit b011b81d77
3 changed files with 5 additions and 7 deletions

View File

@ -126,13 +126,10 @@ void main()
#if @parallax || @diffuseParallax
#if @parallax
float height = texture2D(normalMap, normalMapUV).a;
float flipY = (passTangent.w > 0.0) ? -1.f : 1.f;
#else
float height = texture2D(diffuseMap, diffuseMapUV).a;
// FIXME: shouldn't be necessary, but in this path false-positives are common
float flipY = -1.f;
#endif
offset = getParallaxOffset(transpose(normalToViewMatrix) * normalize(-passViewPos), height, flipY);
offset = getParallaxOffset(transpose(normalToViewMatrix) * normalize(-passViewPos), height);
#endif
vec2 screenCoords = gl_FragCoord.xy / screenRes;

View File

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

View File

@ -4,9 +4,9 @@
#define PARALLAX_SCALE 0.04
#define PARALLAX_BIAS -0.02
vec2 getParallaxOffset(vec3 eyeDir, float height, float flipY)
vec2 getParallaxOffset(vec3 eyeDir, float height)
{
return vec2(eyeDir.x, eyeDir.y * flipY) * ( height * PARALLAX_SCALE + PARALLAX_BIAS );
return vec2(eyeDir.x, -eyeDir.y) * ( height * PARALLAX_SCALE + PARALLAX_BIAS );
}
#endif