diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-03 19:06:41 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-03 19:06:41 +0100 |
| commit | 3108fb0065a51dfc3548836ea16b287e92cd8881 (patch) | |
| tree | b20d3ffd904b65596ce9dd2df15a527b91a6539f /assets/final/shaders/renderer_3d.wgsl | |
| parent | c3714939897af2541c655c03bcdd61108fff46ea (diff) | |
feat: side-quest - Perlin noise sky and ProcGenFunc error handling
- 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.
Diffstat (limited to 'assets/final/shaders/renderer_3d.wgsl')
| -rw-r--r-- | assets/final/shaders/renderer_3d.wgsl | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/assets/final/shaders/renderer_3d.wgsl b/assets/final/shaders/renderer_3d.wgsl index 0b2c38b..3ce078d 100644 --- a/assets/final/shaders/renderer_3d.wgsl +++ b/assets/final/shaders/renderer_3d.wgsl @@ -2,6 +2,7 @@ @group(0) @binding(1) var<storage, read> object_data: ObjectsBuffer; @group(0) @binding(2) var noise_tex: texture_2d<f32>; @group(0) @binding(3) var noise_sampler: sampler; +@group(0) @binding(4) var sky_tex: texture_2d<f32>; struct VertexOutput { @builtin(position) position: vec4<f32>, @@ -120,7 +121,10 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { let bounds = ray_box_intersection(ro_local, rd_local, extent); - if (!bounds.hit) { discard; } + if (!bounds.hit) { + let uv_sky = vec2<f32>(atan2(rd_world.x, rd_world.z) / 6.28318 + 0.5, acos(clamp(rd_world.y, -1.0, 1.0)) / 3.14159); + return vec4<f32>(textureSample(sky_tex, noise_sampler, uv_sky).rgb, 1.0); + } var t = bounds.t_entry; var hit = false; @@ -131,7 +135,10 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { t = t + d_local; if (t > bounds.t_exit) { break; } } - if (!hit) { discard; } + if (!hit) { + let uv_sky = vec2<f32>(atan2(rd_world.x, rd_world.z) / 6.28318 + 0.5, acos(clamp(rd_world.y, -1.0, 1.0)) / 3.14159); + return vec4<f32>(textureSample(sky_tex, noise_sampler, uv_sky).rgb, 1.0); + } let q_hit = ro_local + rd_local * t; p = (obj.model * vec4<f32>(q_hit, 1.0)).xyz; // Correct world position |
