Skip to main content
Scene covers shapes, players and particles. For anything else there’s @native/gpu: plain WebGPU with the game frame on top. We’ll build a sonar pulse, a ring that spreads from your feet over the floor and the walls. The trick is one full-screen triangle. For each pixel it reads the scene’s depth, turns it back into a world position, and lights it up if it’s near the ring.

Step 1: A device


Step 2: The shader

HLSL here, so the frame camera comes from gpu.hlsli. Bindings follow WebGPU: group as the space, binding as the register number.

Step 3: The pipeline

frame.camera, frame.sceneDepth and frame.color are virtual: the views you make once keep pointing at the current frame, resizes included.

Step 4: Every frame

Pings start at your feet every three seconds. Submit the pass to the transparent hook from a render listener.
What you submit is replayed every frame until your next render replaces it, so the ring keeps up with the camera even when your script is busy.

Going further

  • The same shader in WGSL: drop language: "hlsl" and declare the camera as a struct (the layout is in gpu.hlsli). WGSL matrices take camera.viewProj * vec4f(p, 1.0).
  • frame.worldDepth instead of sceneDepth ignores players and smoke boxes: the ring then only runs over the map.
  • frame.on("transparent", (encoder) => ...) saves you the encoder and the submit.