summaryrefslogtreecommitdiff
path: root/assets/final/shaders/compute/gen_perlin.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-09 13:59:07 +0100
committerskal <pascal.massimino@gmail.com>2026-02-09 13:59:07 +0100
commit744bcadfe8f4bb1b2d4f1daf9f880fa511d65405 (patch)
tree49ec05f0b4d6f04d04ab7904164fb602bcd7bee7 /assets/final/shaders/compute/gen_perlin.wgsl
parentc712874ece1ca7073904f5fb84cc866d28084de0 (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_perlin.wgsl')
-rw-r--r--assets/final/shaders/compute/gen_perlin.wgsl44
1 files changed, 44 insertions, 0 deletions
diff --git a/assets/final/shaders/compute/gen_perlin.wgsl b/assets/final/shaders/compute/gen_perlin.wgsl
new file mode 100644
index 0000000..73816d6
--- /dev/null
+++ b/assets/final/shaders/compute/gen_perlin.wgsl
@@ -0,0 +1,44 @@
+// GPU procedural Perlin noise texture generator.
+// Fractional Brownian Motion using value noise.
+
+#include "math/noise"
+
+struct PerlinParams {
+ width: u32,
+ height: u32,
+ seed: f32,
+ frequency: f32,
+ amplitude: f32,
+ amplitude_decay: f32,
+ octaves: u32,
+ _pad0: f32, // Padding for alignment
+}
+
+@group(0) @binding(0) var output_tex: texture_storage_2d<rgba8unorm, write>;
+@group(0) @binding(1) var<uniform> params: PerlinParams;
+
+@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 uv = vec2<f32>(f32(id.x) / f32(params.width),
+ f32(id.y) / f32(params.height));
+
+ var value = 0.0;
+ var amplitude = params.amplitude;
+ var frequency = params.frequency;
+ var total_amp = 0.0;
+
+ for (var o: u32 = 0u; o < params.octaves; o++) {
+ let p = uv * frequency + params.seed;
+ value += noise_2d(p) * amplitude;
+ total_amp += amplitude;
+ frequency *= 2.0;
+ amplitude *= params.amplitude_decay;
+ }
+
+ value /= total_amp;
+ let clamped = clamp(value, 0.0, 1.0);
+
+ textureStore(output_tex, id.xy, vec4<f32>(clamped, clamped, clamped, 1.0));
+}