@motion-core/motion-gpu 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +325 -0
- package/dist/FragCanvas.svelte +511 -0
- package/dist/FragCanvas.svelte.d.ts +26 -0
- package/dist/MotionGPUErrorOverlay.svelte +394 -0
- package/dist/MotionGPUErrorOverlay.svelte.d.ts +7 -0
- package/dist/Portal.svelte +46 -0
- package/dist/Portal.svelte.d.ts +8 -0
- package/dist/advanced-scheduler.d.ts +44 -0
- package/dist/advanced-scheduler.js +58 -0
- package/dist/advanced.d.ts +14 -0
- package/dist/advanced.js +9 -0
- package/dist/core/error-diagnostics.d.ts +40 -0
- package/dist/core/error-diagnostics.js +111 -0
- package/dist/core/error-report.d.ts +67 -0
- package/dist/core/error-report.js +190 -0
- package/dist/core/material-preprocess.d.ts +63 -0
- package/dist/core/material-preprocess.js +166 -0
- package/dist/core/material.d.ts +157 -0
- package/dist/core/material.js +358 -0
- package/dist/core/recompile-policy.d.ts +27 -0
- package/dist/core/recompile-policy.js +15 -0
- package/dist/core/render-graph.d.ts +55 -0
- package/dist/core/render-graph.js +73 -0
- package/dist/core/render-targets.d.ts +39 -0
- package/dist/core/render-targets.js +63 -0
- package/dist/core/renderer.d.ts +9 -0
- package/dist/core/renderer.js +1097 -0
- package/dist/core/shader.d.ts +42 -0
- package/dist/core/shader.js +196 -0
- package/dist/core/texture-loader.d.ts +129 -0
- package/dist/core/texture-loader.js +295 -0
- package/dist/core/textures.d.ts +114 -0
- package/dist/core/textures.js +136 -0
- package/dist/core/types.d.ts +523 -0
- package/dist/core/types.js +4 -0
- package/dist/core/uniforms.d.ts +48 -0
- package/dist/core/uniforms.js +222 -0
- package/dist/current-writable.d.ts +31 -0
- package/dist/current-writable.js +27 -0
- package/dist/frame-context.d.ts +287 -0
- package/dist/frame-context.js +731 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +11 -0
- package/dist/motiongpu-context.d.ts +77 -0
- package/dist/motiongpu-context.js +26 -0
- package/dist/passes/BlitPass.d.ts +32 -0
- package/dist/passes/BlitPass.js +158 -0
- package/dist/passes/CopyPass.d.ts +25 -0
- package/dist/passes/CopyPass.js +53 -0
- package/dist/passes/ShaderPass.d.ts +40 -0
- package/dist/passes/ShaderPass.js +182 -0
- package/dist/passes/index.d.ts +3 -0
- package/dist/passes/index.js +3 -0
- package/dist/use-motiongpu-user-context.d.ts +35 -0
- package/dist/use-motiongpu-user-context.js +74 -0
- package/dist/use-texture.d.ts +35 -0
- package/dist/use-texture.js +147 -0
- package/package.json +94 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Motion Core contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://svelte.dev)
|
|
5
|
+
[](https://gpuweb.github.io/gpuweb/)
|
|
6
|
+
[](https://www.typescriptlang.org)
|
|
7
|
+
[](https://www.npmjs.com/package/@motion-core/motion-gpu)
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
# Motion GPU
|
|
12
|
+
|
|
13
|
+
**A tiny WebGPU runtime for writing Shadertoy-style fullscreen shaders in pure WGSL.**
|
|
14
|
+
|
|
15
|
+
`@motion-core/motion-gpu` is a Svelte 5 package for building fullscreen shader pipelines using WebGPU and WGSL.
|
|
16
|
+
It provides a minimal runtime, scheduler, and render graph designed specifically for fragment-driven GPU programs.
|
|
17
|
+
|
|
18
|
+
Unlike general-purpose 3D engines, Motion GPU focuses on a very narrow problem: **running fullscreen fragment shaders and multi-pass GPU pipelines**.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
# When to Use Motion GPU
|
|
23
|
+
|
|
24
|
+
Motion GPU is designed for applications where the entire scene is driven by fullscreen shaders.
|
|
25
|
+
|
|
26
|
+
Typical use cases include:
|
|
27
|
+
|
|
28
|
+
- Shadertoy-style GPU experiments
|
|
29
|
+
- Generative art
|
|
30
|
+
- Procedural textures
|
|
31
|
+
- Multi-pass post-processing pipelines
|
|
32
|
+
- GPU simulations
|
|
33
|
+
- Shader editors and live-coding tools
|
|
34
|
+
- Interactive visual experiments
|
|
35
|
+
|
|
36
|
+
If your application is primarily a fullscreen fragment shader pipeline, using a full 3D engine can add unnecessary complexity and bundle size.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# Why Not Use Three.js?
|
|
41
|
+
|
|
42
|
+
Three.js is a powerful general-purpose 3D engine.
|
|
43
|
+
Motion GPU focuses on a much narrower problem: running fullscreen WGSL shader pipelines.
|
|
44
|
+
|
|
45
|
+
| Feature | Three.js | Motion GPU |
|
|
46
|
+
| ---------------- | --------------------- | ------------------------- |
|
|
47
|
+
| Scope | Full 3D engine | Fullscreen shader runtime |
|
|
48
|
+
| Shader language | TSL / generated WGSL | Native WGSL |
|
|
49
|
+
| Bundle size | large | tiny (3.5-5x smaller) |
|
|
50
|
+
| Rendering model | Scene graph | GPU pipeline |
|
|
51
|
+
| Shader pipeline | materials | explicit passes |
|
|
52
|
+
| Multi-pass | possible but indirect | first-class |
|
|
53
|
+
| Shader debugging | generated shaders | direct WGSL |
|
|
54
|
+
|
|
55
|
+
Motion GPU is **not a replacement for Three.js**.
|
|
56
|
+
|
|
57
|
+
Instead, it is designed for cases where a full 3D engine would be unnecessary overhead.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
# Core Workflow
|
|
62
|
+
|
|
63
|
+
Motion GPU follows a simple three-step flow:
|
|
64
|
+
|
|
65
|
+
1. Define an immutable material with `defineMaterial(...)`.
|
|
66
|
+
2. Render it with `<FragCanvas />`.
|
|
67
|
+
3. Drive runtime updates with `useFrame(...)`, `useMotionGPU()`, and `useTexture(...)`.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
# What This Package Includes
|
|
72
|
+
|
|
73
|
+
- Fullscreen WebGPU renderer for WGSL fragment shaders
|
|
74
|
+
- Strict material contract and validation (`fn frag(uv: vec2f) -> vec4f`)
|
|
75
|
+
- Runtime uniform and texture updates without rebuilding the pipeline
|
|
76
|
+
- Frame scheduler with task ordering, stages, invalidation modes, diagnostics and profiling
|
|
77
|
+
- Render graph with built-in post-process passes:
|
|
78
|
+
- `ShaderPass`
|
|
79
|
+
- `BlitPass`
|
|
80
|
+
- `CopyPass`
|
|
81
|
+
|
|
82
|
+
- Named render targets for multi-pass pipelines
|
|
83
|
+
- Structured error normalization with built-in overlay UI and custom renderer support
|
|
84
|
+
- Advanced runtime API for namespaced shared user context and scheduler presets
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
# Entrypoints
|
|
89
|
+
|
|
90
|
+
## Root (`@motion-core/motion-gpu`)
|
|
91
|
+
|
|
92
|
+
Primary runtime API:
|
|
93
|
+
|
|
94
|
+
- `FragCanvas`
|
|
95
|
+
- `defineMaterial`
|
|
96
|
+
- `useMotionGPU`
|
|
97
|
+
- `useFrame`
|
|
98
|
+
- `useTexture`
|
|
99
|
+
- `ShaderPass`
|
|
100
|
+
- `BlitPass`
|
|
101
|
+
- `CopyPass`
|
|
102
|
+
|
|
103
|
+
Also exports runtime/core types:
|
|
104
|
+
|
|
105
|
+
- uniforms
|
|
106
|
+
- textures
|
|
107
|
+
- render passes
|
|
108
|
+
- scheduler
|
|
109
|
+
- loader types
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Advanced (`@motion-core/motion-gpu/advanced`)
|
|
114
|
+
|
|
115
|
+
Re-exports everything from root, plus:
|
|
116
|
+
|
|
117
|
+
- `useMotionGPUUserContext`
|
|
118
|
+
- `setMotionGPUUserContext`
|
|
119
|
+
- `applySchedulerPreset`
|
|
120
|
+
- `captureSchedulerDebugSnapshot`
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
# Requirements
|
|
125
|
+
|
|
126
|
+
- Svelte 5 (`peerDependency: svelte ^5`)
|
|
127
|
+
- A browser/runtime with WebGPU support
|
|
128
|
+
- Secure context (`https://` or `localhost`)
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
# Installation
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npm i @motion-core/motion-gpu
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
# Quick Start
|
|
141
|
+
|
|
142
|
+
## 1. Create a material and render it
|
|
143
|
+
|
|
144
|
+
```svelte
|
|
145
|
+
<!-- App.svelte -->
|
|
146
|
+
<script lang="ts">
|
|
147
|
+
import { FragCanvas, defineMaterial } from '@motion-core/motion-gpu';
|
|
148
|
+
|
|
149
|
+
const material = defineMaterial({
|
|
150
|
+
fragment: `
|
|
151
|
+
fn frag(uv: vec2f) -> vec4f {
|
|
152
|
+
return vec4f(uv.x, uv.y, 0.25, 1.0);
|
|
153
|
+
}
|
|
154
|
+
`
|
|
155
|
+
});
|
|
156
|
+
</script>
|
|
157
|
+
|
|
158
|
+
<div style="width: 100vw; height: 100vh;">
|
|
159
|
+
<FragCanvas {material} />
|
|
160
|
+
</div>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## 2. Add animated uniforms via `useFrame`
|
|
166
|
+
|
|
167
|
+
```svelte
|
|
168
|
+
<!-- App.svelte -->
|
|
169
|
+
<script lang="ts">
|
|
170
|
+
import { FragCanvas, defineMaterial } from '@motion-core/motion-gpu';
|
|
171
|
+
import Runtime from './Runtime.svelte';
|
|
172
|
+
|
|
173
|
+
const material = defineMaterial({
|
|
174
|
+
fragment: `
|
|
175
|
+
fn frag(uv: vec2f) -> vec4f {
|
|
176
|
+
let wave = 0.5 + 0.5 * sin(motiongpuUniforms.uTime + uv.x * 8.0);
|
|
177
|
+
return vec4f(vec3f(wave), 1.0);
|
|
178
|
+
}
|
|
179
|
+
`,
|
|
180
|
+
uniforms: {
|
|
181
|
+
uTime: 0
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
</script>
|
|
185
|
+
|
|
186
|
+
<FragCanvas {material}>
|
|
187
|
+
<Runtime />
|
|
188
|
+
</FragCanvas>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```svelte
|
|
192
|
+
<!-- Runtime.svelte -->
|
|
193
|
+
<script lang="ts">
|
|
194
|
+
import { useFrame } from '@motion-core/motion-gpu';
|
|
195
|
+
|
|
196
|
+
useFrame((state) => {
|
|
197
|
+
state.setUniform('uTime', state.time);
|
|
198
|
+
});
|
|
199
|
+
</script>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
# Core Runtime Model
|
|
205
|
+
|
|
206
|
+
## Material Phase (compile-time contract)
|
|
207
|
+
|
|
208
|
+
`defineMaterial(...)` validates and freezes:
|
|
209
|
+
|
|
210
|
+
- WGSL fragment source
|
|
211
|
+
- Uniform declarations
|
|
212
|
+
- Texture declarations
|
|
213
|
+
- Compile-time `defines`
|
|
214
|
+
- Shader `includes`
|
|
215
|
+
|
|
216
|
+
A deterministic material signature is generated from resolved shader/layout metadata.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Frame Phase (runtime updates)
|
|
221
|
+
|
|
222
|
+
Inside `useFrame(...)` callbacks you update per-frame values:
|
|
223
|
+
|
|
224
|
+
- `state.setUniform(name, value)`
|
|
225
|
+
- `state.setTexture(name, value)`
|
|
226
|
+
- `state.invalidate(token?)`
|
|
227
|
+
- `state.advance()`
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Renderer Phase
|
|
232
|
+
|
|
233
|
+
`FragCanvas` resolves material state, schedules tasks, and decides whether to render based on:
|
|
234
|
+
|
|
235
|
+
- `renderMode` (`always`, `on-demand`, `manual`)
|
|
236
|
+
- invalidation / advance state
|
|
237
|
+
- `autoRender`
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
# Hard Contracts and Validation Rules
|
|
242
|
+
|
|
243
|
+
These are enforced by runtime validation.
|
|
244
|
+
|
|
245
|
+
1. Material entrypoint must be:
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
fn frag(uv: vec2f) -> vec4f
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
2. `ShaderPass` fragment entrypoint must be:
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
fn shade(inputColor: vec4f, uv: vec2f) -> vec4f
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
3. `useFrame()` and `useMotionGPU()` must be called inside `<FragCanvas>` subtree.
|
|
258
|
+
|
|
259
|
+
4. You can only set uniforms/textures that were declared in `defineMaterial(...)`.
|
|
260
|
+
|
|
261
|
+
5. Uniform/texture/include/define names must match WGSL-safe identifiers:
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
[A-Za-z_][A-Za-z0-9_]*
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
6. `needsSwap: true` is valid only for `input: 'source'` and `output: 'target'`.
|
|
268
|
+
|
|
269
|
+
7. Render passes cannot read from `input: 'canvas'`.
|
|
270
|
+
|
|
271
|
+
8. `maxDelta` and profiling window must be finite and greater than `0`.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
# Pipeline Rebuild Rules
|
|
276
|
+
|
|
277
|
+
## Rebuilds renderer
|
|
278
|
+
|
|
279
|
+
- Material signature changes (shader/layout/bindings)
|
|
280
|
+
- `outputColorSpace` changes
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Does not rebuild renderer
|
|
285
|
+
|
|
286
|
+
- Runtime uniform value changes
|
|
287
|
+
- Runtime texture source changes
|
|
288
|
+
- Clear color changes
|
|
289
|
+
- Canvas resize (resources are resized/reallocated as needed)
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
# Development
|
|
294
|
+
|
|
295
|
+
Run from `packages/motion-gpu`:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
bun run build
|
|
299
|
+
bun run check
|
|
300
|
+
bun run test
|
|
301
|
+
bun run test:e2e
|
|
302
|
+
bun run lint
|
|
303
|
+
bun run format
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## Performance
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
bun run perf:core
|
|
312
|
+
bun run perf:core:check
|
|
313
|
+
bun run perf:core:baseline
|
|
314
|
+
bun run perf:runtime
|
|
315
|
+
bun run perf:runtime:check
|
|
316
|
+
bun run perf:runtime:baseline
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
# License
|
|
322
|
+
|
|
323
|
+
This project is licensed under the MIT License.
|
|
324
|
+
|
|
325
|
+
See the `LICENSE` file for details.
|