diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-09 13:59:07 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-09 13:59:07 +0100 |
| commit | 744bcadfe8f4bb1b2d4f1daf9f880fa511d65405 (patch) | |
| tree | 49ec05f0b4d6f04d04ab7904164fb602bcd7bee7 /assets/final/shaders/compute/gen_grid.wgsl | |
| parent | c712874ece1ca7073904f5fb84cc866d28084de0 (diff) | |
feat(gpu): Phase 2 - Add gen_perlin and gen_grid GPU compute shaders
Complete Phase 2 implementation:
- gen_perlin.wgsl: FBM with configurable octaves, amplitude decay
- gen_grid.wgsl: Grid pattern with configurable spacing/thickness
- TextureManager extensions: create_gpu_perlin_texture(), create_gpu_grid_texture()
- Asset packer now validates gen_noise, gen_perlin, gen_grid for PROC_GPU()
- 3 compute pipelines (lazy-init on first use)
Shader parameters:
- gen_perlin: seed, frequency, amplitude, amplitude_decay, octaves (32 bytes)
- gen_grid: width, height, grid_size, thickness (16 bytes)
test_3d_render migration:
- Replaced CPU sky texture (gen_perlin) with GPU version
- Replaced CPU noise texture (gen_noise) with GPU version
- Added new GPU grid texture (256x256, 32px grid, 2px lines)
Size impact:
- gen_perlin.wgsl: ~200 bytes (compressed)
- gen_grid.wgsl: ~100 bytes (compressed)
- Total Phase 2 code: ~300 bytes
- Cumulative (Phase 1+2): ~600 bytes
Testing:
- All 34 tests passing (100%)
- test_gpu_procedural validates all generators
- test_3d_render uses 3 GPU textures (noise, perlin, grid)
Next: Phase 3 - Variable dimensions, async generation, pipeline caching
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'assets/final/shaders/compute/gen_grid.wgsl')
| -rw-r--r-- | assets/final/shaders/compute/gen_grid.wgsl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/assets/final/shaders/compute/gen_grid.wgsl b/assets/final/shaders/compute/gen_grid.wgsl new file mode 100644 index 0000000..cc5e189 --- /dev/null +++ b/assets/final/shaders/compute/gen_grid.wgsl @@ -0,0 +1,24 @@ +// GPU procedural grid pattern generator. +// Simple grid lines with configurable spacing and thickness. + +struct GridParams { + width: u32, + height: u32, + grid_size: u32, + thickness: u32, +} + +@group(0) @binding(0) var output_tex: texture_storage_2d<rgba8unorm, write>; +@group(0) @binding(1) var<uniform> params: GridParams; + +@compute @workgroup_size(8, 8, 1) +fn main(@builtin(global_invocation_id) id: vec3<u32>) { + if (id.x >= params.width || id.y >= params.height) { return; } + + let on_line = (id.x % params.grid_size) < params.thickness || + (id.y % params.grid_size) < params.thickness; + + let val = select(0.0, 1.0, on_line); + + textureStore(output_tex, id.xy, vec4<f32>(val, val, val, 1.0)); +} |
