v0.4.0.| WebGL / WebGPU | Three.js / Babylon.js | WasmGPU | |
|---|---|---|---|
| Origin | 2011 / 2023 | 2010 / 2013 | 2026 |
| Primary Implementation Language | JavaScript & C++ | JavaScript / TypeScript | TypeScript & Rust |
| Graphics Engine | WebGL / WebGPU | WebGL-native & WebGPU-adoptive | WebGPU-native |
| Scene Graph Memory | Not available | Object-oriented (AoS) | Data-oriented (SoA) |
| Math Execution | JavaScript | JavaScript | WebAssembly |
| Transform Updates | Not available | Recursive traversal | Linear iteration |
| Uniform Uploads | Manual packing | Extraction & packing | Zero-copy views & no packing |
| Garbage Collection | Manual & low/high pressure via JavaScript engine | Automatic & high pressure via JavaScript engine | Automatic & low pressure via WebAssembly driver |
| Instancing | Manual | Manual | Automatic |
| Asset Importing | Not available | glTF 2.0 | glTF 2.0 |
| Textures | Manual | Managed objects | Managed objects |
| Animation System | Not available | Executed in JavaScript | Executed in WebAssembly |
| Skinning | Not available | Data textures | Storage buffers |
| Visibility Culling | Not available | Frustum culling in JavaScript | Frustum culling in WebAssembly |
| Anti-aliasing | Not available | MSAA | SMAA |
| Render State Caching | Not available | State filtering | Pipeline caching |
| Render Loop | Run by JavaScript | Run by JavaScript | Run by JavaScript & WebAssembly |
Basic examples:
<canvas></canvas>
<script type="module">
// Setup
import { WasmGPU } from "https://cdn.jsdelivr.net/gh/Zushah/WasmGPU@0.4.0/dist/WasmGPU.min.js";
const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
// Scene and camera
const scene = wgpu.createScene([0.05, 0.05, 0.1]);
const camera = wgpu.createCamera.perspective({ fov: 60, near: 0.1, far: 1000 });
camera.transform.setPosition(0, 4, 2);
camera.lookAt(0, 0, 0);
// Lights
scene.addLight(wgpu.createLight.ambient({
color: [1, 1, 1],
intensity: 0.01
}));
scene.addLight(wgpu.createLight.directional({
direction: [1, -1, -1],
color: [1, 0.95, 0.9],
intensity: 1.5
}));
// Cube
const cube = wgpu.createMesh(
wgpu.geometry.box(1, 1, 1),
wgpu.material.standard({
color: [1, 0, 0],
metallic: 0.7
})
);
scene.add(cube);
// Render
wgpu.run((dt, time) => {
cube.transform.rotateY(dt * 0.8);
cube.transform.rotateX(dt * 0.3);
cube.transform.setPosition(0, 0.8 + Math.sin(time * 2) * 0.15, 0);
wgpu.render(scene, camera);
});
</script>
Using the IIFE bundle instead of the ESM bundle is exactly the same as above, except you must use a script tag instead of an import statement:
<script src="https://cdn.jsdelivr.net/gh/Zushah/WasmGPU@0.4.0/dist/WasmGPU.iife.min.js"></script>
npm install../src/ rather than ./dist/.npm run build.npm run start or use the live server extension.The ./dist/ folder generates:
WasmGPU.js / WasmGPU.min.js — ESM bundleWasmGPU.iife.min.js — IIFE bundlewasm.js — Bridge to load WebAssemblywasm.wasm — WebAssembly driverNote: wasm.js and wasm.wasm must be located beside the WasmGPU bundles, i.e. in the ./dist/ folder. These files are automatically copied from the ./build/ folder by esbuild.config.js so this should not be a problem, but it could become one.
The ./build/ folder generates:
wasm.js — Bridge to load WebAssemblywasm.d.ts — WebAssembly type declarationswasm.wasm — WebAssembly driverwasm.wat — WebAssembly text formatWasmGPU is available under the Mozilla Public License 2.0 (MPL-2.0).