From 205413fa6050b879eb84944bda0ec64ced47a384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ralph=20K=C3=BCpper?= Date: Wed, 11 Nov 2026 15:30:03 +0100 Subject: [PATCH] Normal mapping without tangents: negate the derivative bitangent for glTF The screen-space tangent frame returns the direction of increasing v, but glTF's v runs down the image while its normal maps keep +Y up, so the frame inverted the normal map's green channel on every mesh without a TANGENT attribute. On low-poly meshes whose normal map carries the smoothing, each triangle showed as a facet. The vertex-tangent branch was already correct. --- native/shared/src/renderer/shaders/core.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/native/shared/src/renderer/shaders/core.rs b/native/shared/src/renderer/shaders/core.rs index a291ec32..5055890b 100644 --- a/native/shared/src/renderer/shaders/core.rs +++ b/native/shared/src/renderer/shaders/core.rs @@ -286,7 +286,13 @@ fn compute_tbn(dp1: vec3, dp2: vec3, duv1: vec2, duv2: vec2, let b = dp2perp * duv1.y + dp1perp * duv2.y; let denom = max(dot(t, t), dot(b, b)); let invmax = inverseSqrt(max(denom, 1e-20)); - return mat3x3(t * invmax, b * invmax, n); + // The bitangent is negated. This construction returns the direction of + // increasing v, but glTF's v runs down the image while its normal maps + // keep +Y up, so the glTF bitangent (cross(normal, tangent) * w, what the + // vertex-tangent branch builds) points along decreasing v. Unnegated, the + // fallback inverted the normal map's green channel: on a low-poly mesh + // whose normal map carries its smoothing, every triangle became a facet. + return mat3x3(t * invmax, -b * invmax, n); } // The 4x4 Bayer threshold (0.5..15.5)/16 at (x, y), from the bits of x ^ y and