v0.6.0.| WebGL / WebGPU | Three.js / Babylon.js | WasmGPU | |
|---|---|---|---|
| Origin | 2011 / 2023 | 2010 / 2013 | 2026 |
| Implementation Language | JavaScript & C++ | JavaScript / TypeScript | TypeScript & Rust |
| Application Language | JavaScript & GLSL / WGSL | JavaScript / TypeScript & GLSL / WGSL | JavaScript / TypeScript & WGSL (& Python via Pyodide) |
| Buildtime Optimization | Not available | Transpilation, tree-shaking, minification | Transpilation & LLVM, tree-shaking & Binaryen, minification |
| Graphics Engine | WebGL / WebGPU | WebGL-native & WebGPU-adoptive | WebGPU-native |
| Vectorization | Not available | Scalar | SIMD128 |
| API Ergonomics | Verbose | Streamlined | Streamlined |
| WebGL / WebGPU | Three.js / Babylon.js | WasmGPU | |
|---|---|---|---|
| Scene Graph Memory | Not available | Object-oriented (AoS) | Data-oriented (SoA) |
| Math Execution | JavaScript | JavaScript | WebAssembly |
| Transform Updates | Not available | Recursive traversal | Linear iteration |
| Garbage Collection | Manual & low/high pressure via JavaScript engine | Automatic & high pressure via JavaScript engine | Automatic & low pressure via WebAssembly driver |
| Render Loop | Run by JavaScript | Run by JavaScript | Run by JavaScript & WebAssembly |
| WebGL / WebGPU | Three.js / Babylon.js | WasmGPU | |
|---|---|---|---|
| Uniform Uploads | Manual packing | Extraction & packing | Zero-copy views & no packing |
| Render State Caching | Manual | State filtering | Pipeline caching |
| Instancing | Manual | Manual | Automatic |
| Visibility Culling | Not available | Frustum culling in JavaScript | Frustum culling in WebAssembly |
| Skinning | Not available | Data textures | Storage buffers |
| Anti-aliasing | Not available | MSAA | SMAA |
| Textures | Manual | Managed objects | Managed objects |
| Animation System | Not available | Executed in JavaScript | Executed in WebAssembly |
| Asset Importing | Not available | glTF 2.0 | glTF 2.0 |
| Camera Controls | Not available | Built-in | Built-in |
| WebGL / WebGPU | Three.js / Babylon.js | WasmGPU | |
|---|---|---|---|
| GPGPU | Manual, low-level, high-boilerplate | Integrated, high-abstraction, scene-centric | Automated, kernel-driven, compute-optimized |
| Ndarray Abstraction | Not available | Not available | CPU & GPU ndarrays |
| GPU Readback | Manual | Manual | Async readback ring |
| Python Interoperability | Not available | Not available | With Pyodide |
| Scientific Primitives | Manual | Manual | Point clouds & glyph fields |
| Colormap Support | Manual | Manual | Built-in & custom |
| Data-driven Materials | Manual | Manual | Data material |
Examples:
./examples/esm.html to see how to get started with the ESM build../examples/iife.html to see how to get started with the IIFE build../examples/gltf.html to see how a glTF model of a chessboard can be loaded and imported../examples/compute.html to see how the compute subsystem can be used to render a Mandelbulb../examples/python.html to see how the a point cloud can be used with Python interoperability via Pyodide and the compute subsystem to render a galaxy.Super basic example to render a cube:
// Setup
import { WasmGPU } from "https://cdn.jsdelivr.net/gh/Zushah/WasmGPU@0.6.0/dist/WasmGPU.min.js";
const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas, { antialias: true});
// Scene, camera, and controls
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(-2, 2, -2);
camera.lookAt(0, 0, 0);
const controls = wgpu.createControls.orbit(camera, canvas);
// Lights
scene.addLight(wgpu.createLight.directional({
direction: [1, -1, -1],
color: [1, 1, 1],
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) => {
controls.update(dt);
wgpu.render(scene, camera);
});
Using the IIFE bundle instead of the ESM bundle is exactly the same as above, except you must use an HTML script tag instead of a JavaScript import statement:
<script src="https://cdn.jsdelivr.net/gh/Zushah/WasmGPU@0.6.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.npm run test.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).