|
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).
|