| Age | Commit message (Collapse) | Author |
|
Adds two new functions for displacement-mapped normal calculation:
Functions added:
- get_normal_bump(): High-quality 6-sample central differences
- get_normal_bump_fast(): Optimized 4-sample tetrahedron pattern
Performance comparison:
- get_normal_bump: 6 SDF + 6 texture + 6 UV = 18 operations
- get_normal_bump_fast: 4 SDF + 4 texture + 4 UV = 12 operations
- Speed improvement: 33% faster with tetrahedron method
Parameters:
- p: Sample position (vec3)
- obj_params: Object parameters (vec4)
- noise_tex: Displacement texture (texture_2d)
- noise_sampler: Texture sampler
- disp_strength: Displacement strength multiplier
Requirements:
- spherical_uv() function must be available in calling context
- get_dist() function must be available in calling context
Use cases:
- get_normal_bump: Static scenes, high-quality renders
- get_normal_bump_fast: Real-time rendering, performance-critical paths
Location: assets/final/shaders/math/sdf_utils.wgsl
|
|
Adds get_normal_fast() variant using tetrahedral gradient approximation.
Performance improvement:
- 4 SDF evaluations (vs 6 in get_normal_basic)
- ~33% fewer distance field samples
- Tetrahedron pattern: k.xyy, k.yyx, k.yxy, k.xxx where k=(1,-1)
Trade-off:
- Slightly less accurate than central differences method
- Good for real-time rendering where performance matters
- Same sphere optimization (analytical normal for obj_type == 1.0)
Parameters:
- epsilon: 0.0001 (vs 0.001 in basic method)
- Same interface: takes position and object params
Use case: Fast lighting calculations, performance-critical shaders
|
|
Created math/common_utils.wgsl with reusable shader functions:
- transform_normal() - Normal matrix transform (2 call sites)
- spherical_uv() - Spherical UV mapping (7 call sites)
- spherical_uv_from_dir() - For direction vectors (1 call site)
- grid_pattern() - Procedural checkerboard (2 call sites)
- Constants: PI, TAU
Refactored shaders:
- renderer_3d.wgsl: 7 spherical_uv + 1 normal + 2 grid (~12 lines removed)
- mesh_render.wgsl: 1 normal transform (~3 lines removed)
- skybox.wgsl: 1 spherical UV (~2 lines removed)
Impact: ~200 bytes saved, 12 call sites deduplicated
Tests: 31/31 passing
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
|
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>
|
|
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.
|
|
#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.
|