Babylon.js, PlayCanvas & WebGPU
Three.js is not the only way to make 3D games for the browser. Two other open-source projects are worth knowing well enough to choose between them: Babylon.js and PlayCanvas. Both are closer to complete game engines. And all three are moving from WebGL to WebGPU. This lesson compares them and looks at where Three.js is heading.
The same spinning box in three engines
Three.js, as in this course:
import * as THREE from 'three';
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(50, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 1, 3);
camera.lookAt(0, 0, 0);
scene.add(new THREE.HemisphereLight('#fff', '#444', 2));
const box = new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshStandardMaterial({ color: 'orange' }));
scene.add(box);
renderer.setAnimationLoop((t) => { box.rotation.y = t / 1000; renderer.render(scene, camera); });Babylon.js (ES modules from @babylonjs/core):
import { Engine, Scene, ArcRotateCamera, HemisphericLight, MeshBuilder, StandardMaterial, Color3, Vector3 } from '@babylonjs/core';
const canvas = document.querySelector('canvas');
const engine = new Engine(canvas, true); // antialias
const scene = new Scene(engine);
const camera = new ArcRotateCamera('cam', -Math.PI / 2, Math.PI / 3, 3, Vector3.Zero(), scene);
camera.attachControl(canvas, true); // orbit controls built in
new HemisphericLight('light', new Vector3(0, 1, 0), scene);
const box = MeshBuilder.CreateBox('box', { size: 1 }, scene);
const mat = new StandardMaterial('mat', scene);
mat.diffuseColor = new Color3(1, 0.65, 0);
box.material = mat;
scene.onBeforeRenderObservable.add(() => { box.rotation.y += engine.getDeltaTime() / 1000; });
engine.runRenderLoop(() => scene.render());
addEventListener('resize', () => engine.resize());PlayCanvas engine (playcanvas package; entity–component style):
import * as pc from 'playcanvas';
const app = new pc.Application(document.querySelector('canvas'));
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);
app.start();
const camera = new pc.Entity('camera');
camera.addComponent('camera', { clearColor: new pc.Color(0.1, 0.1, 0.12) });
camera.setPosition(0, 1, 3);
camera.lookAt(0, 0, 0);
app.root.addChild(camera);
const light = new pc.Entity('light');
light.addComponent('light');
light.setEulerAngles(45, 30, 0);
app.root.addChild(light);
const box = new pc.Entity('box');
box.addComponent('render', { type: 'box' });
app.root.addChild(box);
app.on('update', (dt) => box.rotate(0, 60 * dt, 0)); // degrees
addEventListener('resize', () => app.resizeCanvas());The shapes of the APIs tell the story: Three.js gives you objects to assemble, Babylon.js gives you a scene with engine services built in (cameras with input, observables, an inspector), and PlayCanvas gives you entities with components, the model of Unity and Godot.
Comparison
| Three.js | Babylon.js | PlayCanvas | |
|---|---|---|---|
| What it is | rendering library + addons | full 3D engine (backed by Microsoft) | engine + cloud editor (engine MIT-licensed) |
| Coordinate system | right-handed, Y up | left-handed by default (scene.useRightHandedSystem = true switches) |
right-handed, Y up |
| Physics | bring your own (cannon-es, Rapier) | plugin system; Havok integration (Physics V2) | built-in rigid bodies (ammo.js) |
| Editor | none official (a web editor for scenes) | Playground, Node Material Editor, Inspector, Sandbox | full collaborative browser editor (accounts/plans: check current terms) |
| UI | HTML/CSS or your own | Babylon GUI (2D and in-world) | built-in UI elements |
| Animation | mixer, clips, skinning | animation groups, blending, skinning | anim state graphs |
| Ecosystem | largest: examples, R3F, tutorials, Stack Overflow answers | strong docs and forum, many features in one package | smaller, focused on its editor workflow |
| Bundle size | small core | larger (modular imports help) | medium |
| Typical users | creative web, product viewers, indie web games, R3F apps | enterprise 3D, games, XR | web games and ads, teams that want an editor |
How to choose:
- Three.js when you want control and a huge community, when the 3D lives inside a web app (especially React), or when you want to learn how things work.
- Babylon.js when you want more engine out of the box (physics, GUI, inspector, glTF tooling, XR helpers) without a separate editor, and like batteries-included APIs.
- PlayCanvas when artists and designers need a visual editor to build levels and you want the team to work in the browser together, Unity-style.
- Unity, Godot or Unreal web exports when the game is primarily a desktop/console game that also runs in the browser (expect larger downloads and longer start-up). See Unity and Godot.
The concepts of this course (scene graph, PBR materials, lights and shadows, color management, glTF, physics bodies and character controllers, draw calls, instancing, LOD) carry over directly: the class names differ, the ideas don't.
WebGPU and Three.js's WebGPURenderer
WebGPU is the successor to WebGL: a modern GPU API (closer to Vulkan, Metal and Direct3D 12) with compute shaders, lower CPU overhead per draw call, and its own shading language, WGSL. It is available in current Chromium-based browsers and has been rolling out in Safari and Firefox; check current support (for example on caniuse.com) for the platforms you target, because WebGL 2 remains the most widely available option.
Three.js supports it through WebGPURenderer (imported from 'three/webgpu'), which:
- uses WebGPU when available and falls back to a WebGL 2 backend otherwise, so one code path covers all browsers;
- describes materials with TSL (Three Shading Language): shader graphs written in JavaScript that compile to WGSL or GLSL, replacing hand-written
ShaderMaterial/onBeforeCompilepatches; - enables compute work on the GPU: particle simulations, culling, procedural geometry;
- is where new rendering features land first.
// Not runnable here: the import map has no 'three/webgpu'.
import * as THREE from 'three/webgpu';
import { color, positionLocal, sin, time } from 'three/tsl';
const renderer = new THREE.WebGPURenderer({ antialias: true });
await renderer.init();
const material = new THREE.MeshStandardNodeMaterial();
material.colorNode = color('#ff8800');
material.positionNode = positionLocal.add(sin(time).mul(0.1)); // a vertex wobble, written in TSLFor a new project, the practical advice today: write ordinary scene code (it's the same for both renderers), start on WebGLRenderer if you need the widest compatibility and the most examples, and evaluate WebGPURenderer if you need compute or many draw calls, testing on your target devices. Custom shaders are the part that differs: GLSL ShaderMaterials don't run on the WebGPU backend, TSL runs on both.
A decision helper
Weigh what matters for your project, score each option, and let the numbers start (not end) the discussion:
// Weighted decision matrix: weights 1-3, scores 1-5 (your own judgement for your project).
const weights = { control: 3, editor: 1, 'built-in physics': 2, community: 3, 'react app': 1 };
const scores = {
'Three.js': { control: 5, editor: 1, 'built-in physics': 2, community: 5, 'react app': 5 },
'Babylon.js': { control: 4, editor: 3, 'built-in physics': 5, community: 4, 'react app': 3 },
'PlayCanvas': { control: 3, editor: 5, 'built-in physics': 4, community: 3, 'react app': 2 },
};
const max = Object.values(weights).reduce((a, b) => a + b, 0) * 5;
for (const [engine, s] of Object.entries(scores)) {
const total = Object.entries(weights).reduce((sum, [k, w]) => sum + w * s[k], 0);
console.log(`${engine.padEnd(11)} ${String(total).padStart(2)} / ${max} ${'█'.repeat(Math.round(total / 2))}`);
}Three.js 40 / 50 ████████████████████
Babylon.js 40 / 50 ████████████████████
PlayCanvas 33 / 50 █████████████████
With these weights Three.js and Babylon.js tie, which is common: for many projects both are good choices, and the tie-breaker is your team's experience. Change the weights for a different project (a team of artists who need an editor: editor: 3, control: 1) and the ranking changes, which is the point. Then build the same small prototype in the top two before committing.
Test yourself
Which of these is left-handed by default?
- Three.js
- Babylon.js
- PlayCanvas
- glTF
What happens when WebGPURenderer runs in a browser without WebGPU?
- It throws an error
- It falls back to a WebGL 2 backend
- It renders nothing
- It switches to Canvas 2D
Why are custom GLSL ShaderMaterials a concern when moving to WebGPURenderer?
- GLSL is deprecated in WebGL
- The WebGPU backend uses WGSL; custom shaders should be written in TSL, which compiles to both
- ShaderMaterial is slower
- They can't use textures