summaryrefslogtreecommitdiff
path: root/assets/final/shaders/renderer_3d.wgsl
AgeCommit message (Collapse)Author
12 hoursfix(shaders): Correct mesh normal transformation - remove double transposeskal
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).
13 hoursfix: Correct mesh normal transformation and floor shadow renderingskal
15 hoursfeat(3d): Implement basic OBJ mesh asset pipelineskal
Added support for loading and rendering OBJ meshes. - Updated asset_packer to parse .obj files into a binary format. - Added MeshAsset and GetMeshAsset helper to asset_manager. - Extended Object3D with mesh_asset_id and ObjectType::MESH. - Implemented mesh rasterization pipeline in Renderer3D. - Added a sample cube mesh and verified in test_3d_render.
20 hoursrefactor(gpu): Implement compile-time BVH toggle via shader compositionskal
Completed Task #18-B optimization and refactoring. - Replaced runtime branching in shader with compile-time snippet substitution in ShaderComposer. - Added 'scene_query_bvh.wgsl' and 'scene_query_linear.wgsl' as distinct snippets. - Refactored Renderer3D to manage two separate pipelines (with and without BVH). - Updated ShaderComposer to support snippet substitution during composition. - Verified both paths with test_3d_render (default and --no-bvh). - Removed temporary shader hacks and cleaned up renderer_3d.wgsl.
20 hoursfeat(perf): Add toggle for GPU BVH and fix fallbackskal
Completed Task #18-B. - Implemented GPU-side BVH traversal for scene queries, improving performance. - Added a --no-bvh command-line flag to disable the feature for debugging and performance comparison. - Fixed a shader compilation issue where the non-BVH fallback path failed to render objects.
2 daysfeat(gpu): Implement recursive WGSL composition and modularize shaders (Task ↵skal
#50) - Updated ShaderComposer to support recursive #include "snippet_name" with cycle detection. - Extracted granular WGSL snippets: math/sdf_shapes, math/sdf_utils, render/shadows, render/scene_query, render/lighting_utils. - Refactored Renderer3D to use #include in shaders, simplifying C++ dependency lists. - Fixed WGPUShaderSourceWGSL usage on macOS to correctly handle composed shader strings. - Added comprehensive unit tests for recursive composition in test_shader_composer. - Verified system stability with test_3d_render and full test suite. - Marked Task #50 as recurrent for future code hygiene.
3 daysfix: Implement proper skybox rendering with Perlin noiseskal
- Added ObjectType::SKYBOX for dedicated skybox rendering. - Created assets/final/shaders/skybox.wgsl for background rendering. - Implemented a two-pass rendering strategy in Renderer3D::render: - First pass renders the skybox without depth writes. - Second pass renders scene objects with depth testing. - Corrected GlobalUniforms struct in common_uniforms.wgsl and src/3d/renderer.h to include and explicit padding for 112-byte alignment. - Updated Renderer3D::update_uniforms to set the new and zero-initialize padding. - Reverted sky sampling logic in renderer_3d.wgsl to for SDF misses, preventing background bleed-through. - Updated test_3d_render.cc to include a SKYBOX object with Perlin noise. handoff(Gemini): The skybox is now correctly rendered with Perlin noise as a dedicated background pass. Objects render correctly without transparency to the sky. All necessary C++ and WGSL shader changes are implemented and verified.
3 daysfeat: side-quest - Perlin noise sky and ProcGenFunc error handlingskal
- Updated ProcGenFunc signature to return bool for error reporting. - Implemented gen_perlin (Fractional Brownian Motion) in procedural/generator.cc. - Added support for sky texture in Renderer3D and its shader. - Integrated Perlin noise sky texture in test_3d_render.cc. - Caught and handled memory/generation errors in AssetManager and TextureManager. - Assigned reference numbers to all remaining tasks in documentation. handoff(Gemini): Side-quest complete. ProcGenFunc now returns bool. Perlin noise added and used for sky in 3D test. Windows build remains stable. All tasks numbered.
4 daysrefactor: Shader Asset Integration (Task #24)skal
Extracted all hardcoded WGSL shaders into external assets. Updated AssetManager to handle shader snippets. Refactored Renderer3D, VisualDebug, and Effects to load shaders via the AssetManager, enabling better shader management and composition.