Parametric fields, compiled for the browser.

WebGPU compute kernels and deterministic mesh solvers from Yuleng Lab.

Field kernel
64×40 cells, dt 0.016 s
2.8 Hz
0.32
1.15

Three compute passes, zero host stalls.

Switch stages to inspect bindings and copy WGSL.

Semi-Lagrangian trace across ping-pong textures.
advect.wgsl @workgroup_size(8, 8, 1)
@group(0) @binding(0) var vin: texture_2d<f32>;
@group(0) @binding(1)
var vout: texture_storage_2d<rgba16float, write>;

@compute @workgroup_size(8, 8, 1)
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
  let c = vec2<i32>(id.xy);
  let v = textureLoad(vin, c, 0).xy;
  let p = vec2<i32>(vec2<f32>(c) - v * 0.016);
  textureStore(vout, c, textureLoad(vin, p, 0));
}

Keep geometry on the device.

0 B

Host readback per frame on 1024×1024 solver passes.

Frame dispatch graph rgba16float, indirect
Staging readback mapAsync copies 4.19 MB to host
Indirect graph dispatchWorkgroupsIndirect feeds draw directly
Operator note

Indirect counts keep contours resident in VRAM.

Targets, limits, and modules.

Dependency-free ES modules and standalone WGSL kernels.

Runtime and shader toolchain specifications
Subsystem Specification Delivery
Compute backend WebGPU WGSL Zero dependencies
Workgroup tile 8×8 threads, ping-pong Static layout
Field precision f16 velocity, f32 SDF Fixed step
Package format Native ES modules No bundler
License and source MIT or Apache-2.0 ops@yuleng.eu.org

Run a solver in plain JavaScript.

Bind a canvas, pick a kernel, and stream uniform state.

mount-field.js ES2022
import { createSolver } from "/assets/yuleng-field.js";

const solver = await createSolver({
  canvas: document.getElementById("field-canvas"),
  kernel: "curl",
});

solver.setUniforms({ freq: 2.8, visc: 0.32 });
solver.stepLoop();