Spaces:
Running
Running
Update world.wgsl
Browse files- world.wgsl +13 -28
world.wgsl
CHANGED
|
@@ -1,29 +1,14 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
render() {
|
| 17 |
-
const w = this.ctx.canvas.width = this.ctx.canvas.clientWidth;
|
| 18 |
-
const h = this.ctx.canvas.height = this.ctx.canvas.clientHeight;
|
| 19 |
-
|
| 20 |
-
this.ctx.fillStyle = "#000";
|
| 21 |
-
this.ctx.fillRect(0, 0, w, h);
|
| 22 |
-
|
| 23 |
-
this.ctx.fillStyle = "#00ffd0";
|
| 24 |
-
const r = 40 + Math.sin(this.t) * 20;
|
| 25 |
-
this.ctx.beginPath();
|
| 26 |
-
this.ctx.arc(w / 2, h / 2, r, 0, Math.PI * 2);
|
| 27 |
-
this.ctx.fill();
|
| 28 |
-
}
|
| 29 |
}
|
|
|
|
| 1 |
+
@group(0) @binding(0)
|
| 2 |
+
var<storage, read_write> field : array<f32>;
|
| 3 |
+
|
| 4 |
+
@compute @workgroup_size(64)
|
| 5 |
+
fn main(@builtin(global_invocation_id) gid : vec3<u32>) {
|
| 6 |
+
let i = gid.x;
|
| 7 |
+
if (i >= arrayLength(&field)) {
|
| 8 |
+
return;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
// Simple oscillatory field evolution
|
| 12 |
+
let t = f32(i) * 0.01;
|
| 13 |
+
field[i] = sin(t) * 0.5 + 0.5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|