summaryrefslogtreecommitdiff
path: root/assets/final/shaders/render
AgeCommit message (Collapse)Author
7 hoursfix(shaders): Resolve WGSL validation errors and add shader compilation testsskal
Fixed three critical WGSL shader issues causing demo64k and test_3d_render to crash: 1. **renderer_3d.wgsl**: Removed dead code using non-existent `inverse()` function - WGSL doesn't have `inverse()` for matrices - Dead code was unreachable but still validated by shader compiler - Also removed reference to undefined `in.normal` vertex input 2. **sdf_utils.wgsl & lighting.wgsl**: Fixed `get_normal_basic()` signature mismatch - Changed parameter from `obj_type: f32` to `obj_params: vec4<f32>` - Now correctly matches `get_dist()` function signature 3. **scene_query_linear.wgsl**: Fixed incorrect BVH binding declaration - Linear mode was incorrectly declaring binding 2 (BVH buffer) - Replaced BVH traversal with simple linear object loop - Root cause: Both BVH and Linear shaders were identical (copy-paste error) Added comprehensive shader compilation test (test_shader_compilation.cc): - Tests all production shaders compile successfully through WebGPU - Validates both BVH and Linear composition modes - Catches WGSL syntax errors, binding mismatches, and type errors - Would have caught all three bugs fixed in this commit Why tests didn't catch this: - Existing test_shader_assets only checked for keywords, not compilation - No test actually created WebGPU shader modules from composed code - New test fills this gap with real GPU validation Results: - demo64k runs without WebGPU errors - test_3d_render no longer crashes - All 22/23 tests pass (FftTest unrelated issue from FFT Phase 1) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
11 hoursRevert "fix(shaders): Correct plane distance scaling for non-uniform transforms"skal
This reverts commit a5229022b0e500ac86560e585081f45293e587d2.
11 hoursfix(shaders): Correct plane distance scaling for non-uniform transformsskal
When a plane has non-uniform scaling (e.g., floor with scale 20,0.01,20), transforming points to local space distorts SDF distances. For a horizontal plane with Y-scale of 0.01, distances become 100x too large in local space. Fix: Multiply plane distances by the scale factor along the normal direction (Y component for horizontal planes). This corrects shadow calculations while maintaining the large floor area needed for visualization. Reverted incorrect uniform scale fix (c23f3b9) that made floor too small.
11 hoursfix(shaders): Exclude meshes from SDF scaling factor in shadow calculationsskal
Fixed incorrect mesh shadow rendering caused by applying scale factor to mesh AABBs which already have correct local-space extents. ROOT CAUSE: The 's' scale factor (line 44) is meant for UNIT primitives (sphere, box, torus) that are scaled by the model matrix. Meshes (type 5.0) already store their correct AABB extents in obj_params.yzw, so applying 's' caused incorrect shadow sizes. ISSUE: let s = min(length(obj.model[0].xyz), ...); if (obj.params.x != 4.0) { // Excluded planes only d = min(d, get_dist(q, obj.params) * s); // ❌ WRONG for meshes! } FIX: if (obj.params.x != 4.0 && obj.params.x != 5.0) { // Exclude planes AND meshes d = min(d, get_dist(q, obj.params) * s); } else { d = min(d, get_dist(q, obj.params)); // No scaling } EXPLANATION: - Type 1.0 (Sphere): Unit sphere, scaled by 's' ✓ - Type 2.0 (Box): Unit box, scaled by 's' ✓ - Type 3.0 (Torus): Unit torus, scaled by 's' ✓ - Type 4.0 (Plane): Special case, no scaling ✓ - Type 5.0 (Mesh): AABB already has correct size, no scaling needed ✓ FILES FIXED: - assets/final/shaders/render/scene_query_linear.wgsl - assets/final/shaders/render/scene_query_bvh.wgsl PARTIAL FIX: This fixes mesh shadow sizing issues. Shadow rotation limitation remains (AABBs are axis-aligned, don't rotate with mesh - this is a fundamental AABB limitation, not a bug). handoff(Claude): Mesh shadows now correctly sized. Investigating floor shadow stretching issue next (likely related to plane scaling).
12 hoursfix: Correct mesh normal transformation and floor shadow renderingskal
19 hourschore: Update documentation, generated assets, and cleanupskal
Removed obsolete scene_query.wgsl (replaced by variants). Updated TODO.md. Committed generated asset files reflecting new shader snippets.
19 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.