summaryrefslogtreecommitdiff
path: root/src/shader/particle.wgsl
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-20 23:20:21 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-20 23:20:21 -0700
commit533da47f2cc03a8b60a7c6c0bb5a938a7e523a03 (patch)
treee4709c9d56954c0a9b2bd3e21f64c036490ed070 /src/shader/particle.wgsl
parent29575e8592f5d6d566abb0ce9beaf794fb98a4e4 (diff)
particles
Diffstat (limited to 'src/shader/particle.wgsl')
-rw-r--r--src/shader/particle.wgsl46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/shader/particle.wgsl b/src/shader/particle.wgsl
new file mode 100644
index 0000000..704cfbe
--- /dev/null
+++ b/src/shader/particle.wgsl
@@ -0,0 +1,46 @@
+struct Camera {
+ scale: vec2f,
+ centre: vec2f,
+};
+
+struct Particle {
+ position: vec2f,
+ data: u32,
+};
+
+@group(0) @binding(0) var<uniform> camera: Camera;
+@group(0) @binding(1) var<storage, read> palette: array<vec4f>;
+@group(0) @binding(2) var<storage, read> particles: array<Particle>;
+
+struct VertexOutput {
+ @builtin(position) clip_position: vec4<f32>,
+ @location(0) world: vec2<f32>,
+ @location(1) @interpolate(flat) instance: u32,
+};
+
+@vertex
+fn vs_main(
+ @builtin(vertex_index) i: u32,
+ @builtin(instance_index) n: u32,
+) -> VertexOutput {
+ let particle = particles[n];
+
+ // (0,0),(1,0),(0,1),(1,1)
+ let corner = vec2<f32>(f32(i & 1u), f32((i >> 1u) & 1u));
+ let world = particle.position + corner;
+
+ var out: VertexOutput;
+ out.clip_position = vec4f((world - camera.centre) * camera.scale, 0.0, 1.0);
+ out.world = world;
+ out.instance = n;
+
+ return out;
+}
+
+@fragment
+fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
+ let particle = particles[in.instance];
+ // TODO can pack more in here and shift
+ let c = palette[particle.data];
+ return c;
+}