From b2bd45885a77e8936ab1d2c2ed30a238d9f073a6 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 6 Feb 2026 09:46:57 +0100 Subject: fix(test_mesh): Use uniform floor scale to fix shadow artifacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed floor shadow stretching caused by extreme non-uniform scaling. ROOT CAUSE: Floor plane used scale(20.0, 0.01, 20.0) - a 2000:1 scale ratio! When transforming shadow ray points into local space: - Y coordinates scaled by 1/0.01 = 100x - sdPlane distance calculation returns distorted values - Shadow raymarching fails, causing stretching artifacts ISSUE: floor.scale = vec3(20.0f, 0.01f, 20.0f); // ❌ Extreme non-uniform scale // In local space: dot(p_local, (0,1,0)) + 0.0 // But p_local.y is 100x larger than world-space distance! FIX: floor.scale = vec3(1.0f, 1.0f, 1.0f); // ✓ Uniform scale floor.position = vec3(0, 0, 0); // Explicit ground level EXPLANATION: For PLANE objects, XZ scale doesn't matter (planes are infinite). Y scale distorts the SDF distance calculation. Uniform scale preserves correct world-space distances. RESULT: - Floor shadows now render correctly - No stretching toward center - Shadow distances accurate for soft shadow calculations COMBINED WITH PREVIOUS FIXES: 1. Shader normal transformation (double-transpose fix) 2. Quaternion axis normalization (rotation stretching fix) 3. Mesh shadow scaling exclusion (AABB size fix) 4. Floor uniform scale (this fix) Task A (test_mesh visualization) now FULLY RESOLVED. handoff(Claude): All mesh transformation and shadow bugs fixed. Meshes rotate correctly, normals transform properly, shadows render accurately. Remaining known limitation: mesh shadows use AABB (axis-aligned), so they don't rotate with the mesh - this is expected AABB behavior. --- src/tests/test_mesh.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/test_mesh.cc b/src/tests/test_mesh.cc index f29ec27..75b45ac 100644 --- a/src/tests/test_mesh.cc +++ b/src/tests/test_mesh.cc @@ -284,7 +284,8 @@ int main(int argc, char** argv) { // --- Create Scene --- Object3D floor(ObjectType::PLANE); - floor.scale = vec3(20.0f, 0.01f, 20.0f); // Very thin floor proxy + floor.position = vec3(0, 0, 0); // Floor at ground level + floor.scale = vec3(1.0f, 1.0f, 1.0f); // Uniform scale (planes are infinite anyway) floor.color = vec4(0.5f, 0.5f, 0.5f, 1.0f); g_scene.add_object(floor); -- cgit v1.2.3