This integration is focused on one workflow:
- write shaders in TypeScript with TypeGPU (
'use gpu') - transform them with
unplugin-typegpu - pass generated WGSL to Motion GPU
defineMaterial
You keep Motion GPU runtime ergonomics (FragCanvas, useFrame, render modes, passes) and move shader authoring to typed TypeScript.
Integration model
Boundary is simple:
- Author shader logic in TypeScript with TypeGPU.
unplugin-typegputransforms shader functions.tgpu.resolve(...)returns WGSL (string).- Motion GPU consumes that WGSL in
defineMaterial({ fragment }). - Motion GPU still enforces fragment contract:
fn frag(uv: vec2f) -> vec4f
1. Enable transformer in build pipeline
Vite example:
If you bundle inside a worker pipeline, use the matching integration (for example Rolldown/Rollup plugin variant) and include it in that worker bundler as well.
2. Author shader in TypeScript (shader.ts)
3. Use generated WGSL in Motion GPU (App.svelte / runtime file)
Access Motion GPU runtime bindings in TypeGPU
Motion GPU provides built-ins in shader scope:
motiongpuFrame.resolutionmotiongpuFrame.timemotiongpuFrame.delta
In TypeGPU, expose them via rawCodeSnippet(...) as shown above.
For user uniforms declared in defineMaterial({ uniforms }), reference:
motiongpuUniforms.<name>
Example:
You must still declare uStrength in defineMaterial({ uniforms: { uStrength: ... } }).
Recommended file split
For this integration, keep a strict 2-file split:
shader.ts: TypeGPU authoring ('use gpu') +tgpu.resolve- runtime component (
.svelte/.tsx): Motion GPUFragCanvas,defineMaterial,useFrame
This keeps shader logic isolated from runtime orchestration and makes testing/refactoring easier.