summaryrefslogtreecommitdiff
path: root/src/util/mini_math.h
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-06 09:38:10 +0100
committerskal <pascal.massimino@gmail.com>2026-02-06 09:38:10 +0100
commit4e10d1c0b7718509ba8197b869fc88a5f94b0630 (patch)
tree94c793ef716e3aaf5fbf3e59baabb7bcdfefb7ef /src/util/mini_math.h
parent7d60a8a9ece368e365b5c857600004298cb89526 (diff)
fix(shaders): Correct mesh normal transformation - remove double transpose
Fixed critical bug in normal matrix transformation causing mesh stretching and incorrect scaling during rotation. ROOT CAUSE: In WGSL, mat3x3(v0, v1, v2) creates a matrix where v0, v1, v2 are COLUMNS. When extracting rows from inv_model, the constructor already produces the transpose. Applying transpose() again cancels out, giving incorrect normals. ISSUE: let normal_matrix = mat3x3(inv_model[0].xyz, inv_model[1].xyz, inv_model[2].xyz); // This gives transpose(inv_model) already! out.normal = normalize(transpose(normal_matrix) * in.normal); // Double transpose = identity, wrong result FIX: let normal_matrix = mat3x3(inv_model[0].xyz, inv_model[1].xyz, inv_model[2].xyz); // Already transpose(inv_model), which is the correct normal matrix out.normal = normalize(normal_matrix * in.normal); // Correct transformation FILES FIXED: - assets/final/shaders/mesh_render.wgsl:38 (mesh vertex normals) - assets/final/shaders/renderer_3d.wgsl:185 (SDF bump-mapped normals) RESULT: Mesh normals now transform correctly under rotation and non-uniform scaling. Fixes Task A (test_mesh visualization stretching bug). handoff(Claude): Normal transformation bug fixed. Mesh should now render correctly without stretching. Shadow bug on floor plane still remains (separate WGSL shader issue for later investigation).
Diffstat (limited to 'src/util/mini_math.h')
0 files changed, 0 insertions, 0 deletions