Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 47 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@

<h1 align="center">ThreeRT</h1>

<p align="center"><b>The native runtime for three.js — hardware path tracing at 60 fps, or a clean WebGPU app.</b></p>
<p align="center"><b>three.js, down to the metal.</b></p>

<p align="center">
One engine, two renderers: <b><code>path</code></b> traces every light on ray-tracing hardware at 60 fps,<br>
and <b><code>webgpu</code></b> (macOS &amp; Linux, <a href="docs/RENDERING-METHODS.md">architecture</a>) runs standard three.js natively with zero path-tracer code.
</p>
<p align="center">ThreeRT is a native runtime for three.js: no browser between your scene and the GPU.</p>

<p align="center">
<a href="https://github.com/meshy-dev/ThreeRT/actions/workflows/ci.yml"><img src="https://github.com/meshy-dev/ThreeRT/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
<a href="https://www.npmjs.com/package/@threert/scene"><img src="https://img.shields.io/npm/v/@threert/scene?label=%40threert%2Fscene&color=f97316" alt="@threert/scene on npm"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT licence"></a>
<a href="https://threert.dev/download/"><img src="https://img.shields.io/badge/clients-macOS%20%C2%B7%20iOS-lightgrey" alt="Clients for macOS and iOS"></a>
<a href="https://threert.dev/download/"><img src="https://img.shields.io/badge/clients-macOS%20%C2%B7%20iOS%20%C2%B7%20Steam%20Deck%20%C2%B7%20Android-lightgrey" alt="Clients for macOS, iOS, Steam Deck and Android"></a>
<a href="https://discord.gg/n7vsVmAKCK"><img src="https://img.shields.io/badge/chat-Discord-5865F2" alt="Discord"></a>
</p>

<p align="center">
<a href="https://threert.dev"><b>Website</b></a> ·
<a href="https://threert.dev/blog/">Blog</a> ·
<a href="https://threert.app">Apps</a> ·
<a href="https://threert.dev/download/">Download</a> ·
<a href="https://threert.dev/docs/">Docs</a> ·
Expand All @@ -34,66 +32,39 @@
</p>

<p align="center">
<a href="https://threert.dev"><img src="docs/images/reel.webp" width="100%" alt="Twelve scenes path-traced live by ThreeRT: Bistro at night with a crowd, OpenStrike, Tokyo at dusk, Beeple's Zero-Day, a voxel city demolished, glowing balls down a staircase, a wrecking ball through a tower of glowing bricks, 400 lanterns, and product and interior scenes"></a>
<br>
<sub>ThreeRT, live on an Apple M3 Max: this repository's demos and OpenStrike, a shooter built on the engine, on its own map.</sub>
<a href="https://threert.dev"><img src="docs/images/hero.webp" width="100%" alt="three.js, down to the metal: 45 times smaller than Electron, on a Sony PS3, ray-traced at 60 fps"></a>
</p>

## Three + RT
## Down to the metal

**Three**, for the API you already know. **RT**, for the three things it adds:
Take the browser out from under three.js, and three things open up.

- **Ray tracing.** Every light is traced: shadows, bounce light, reflections, and glowing surfaces that light the room. No shadow maps, no light probes, no lightmaps, no baking.
- **Real time.** 60 fps in production scenes with the camera moving: Amazon Lumberyard Bistro and Beeple's Zero-Day, on a laptop. Not a still that converges once you stop.
- **Runtime.** A native runtime for three.js, not only a renderer. Scene code and game logic run inside the engine: choose the `path` renderer for hardware ray tracing, the `webgpu` renderer (`node tools/build.ts --renderer webgpu`) for a clean native app with zero ray-tracing overhead, or run as plain three.js in any browser.
- **45× smaller.** `webgpu` (macOS and Linux) runs three.js r187 and its own `WebGPURenderer`, unchanged, on a native `navigator.gpu` over wgpu, with the same pixels as Chrome. A desktop app is 9.9 MB installed where its Electron build is 445 MB; a three.js wallpaper on Wayland uses 15.6 % CPU where Chromium uses 39.9 %, and none while a window covers it.
- **On a Sony PS3.** On hardware with no WebGPU and no JIT, three.js r187's scene graph runs on QuickJS and a native renderer draws it on the RSX at 1920 × 1080, with a PocketJS interface in the same frame. Experimental, 16 to 30 fps: [three.js on a Sony PS3](https://threert.dev/blog/ps3/).
- **Ray-traced, 60 fps.** On GPUs with ray-tracing hardware, `path` traces every light in a three.js-style scene: shadows, bounce light, reflections and glowing surfaces, nothing baked, at 60 fps in production scenes.

## Renderers: `path` and `webgpu`
**Three + RT:** Three, for the API you already know; RT, for ray tracing, real time, and the runtime under both.

ThreeRT stays one engine and one runtime with two renderers selected at build time (`node tools/build.ts --renderer path` or `--renderer webgpu`). They share the native runtime (`runtime/`) with one-way dependencies (`threert-path → threert-runtime ← threert-webgpu`), enforced by CI (`node tools/check-webgpu-gate.ts`) so a `webgpu` build links no ray-tracing code at all.
## Renderers: what each keeps of three.js

| | `path` | `webgpu` ([`docs/RENDERING-METHODS.md`](docs/RENDERING-METHODS.md)) |
|---|---|---|
| **Renderer** | Rust + wgpu compute path tracer (hardware ray queries, OIDN, DLSS / MetalFX) | Standard three.js `WebGPURenderer` over native `navigator.gpu` (wgpu) |
| **Scene API** | `@threert/scene` (physical lighting units) | Plain `three.js` + TSL node materials (+ PocketJS UI) |
| **GPU** | Ray-tracing hardware (Apple M-series, RTX, RDNA2+) | Any GPU wgpu supports (Metal, Vulkan, D3D12) |
| **Footprint** | Full ThreeRT clients | Proven at **9.9 MB installed / 4.5 MB download** (vs 445 / 170 MB Electron) |

## Hello world looks right

Write a scene at tutorial size and leave every setting at its default.

```ts
import { Scene, PerspectiveCamera, Mesh, BoxGeometry, MeshStandardMaterial, DirectionalLight, SkyAtmosphere } from "@threert/scene";

export default function build() {
const scene = new Scene();
const sun = new DirectionalLight(0xffffff, 90000).setSunAngles(28, 100); // lux
scene.add(sun);
scene.environment = new SkyAtmosphere({ sun });

const plaster = new MeshStandardMaterial({ color: 0xd9d4cc, roughness: 0.92 });
const wall = new Mesh(new BoxGeometry(6.6, 3, 0.3), plaster);
wall.position.set(0, 1.5, -3.15);
scene.add(wall);
// ... the rest of the room: a floor, a window, a sofa, a lamp

const camera = new PerspectiveCamera(58, 16 / 9, 0.05, 200);
camera.position.set(-2.3, 1.45, 2.4);
camera.lookAt(1.0, 0.9, -1.2);
scene.add(camera);
return { scene, camera };
}
```
Each way of running a three.js project keeps part of three.js and replaces the rest. In this repository, two renderers are selected at build time (`node tools/build.ts --renderer path` or `--renderer webgpu`). They share the native runtime (`runtime/`) with one-way dependencies (`threert-path → threert-runtime ← threert-webgpu`), enforced by CI (`node tools/check-webgpu-gate.ts`) so a `webgpu` build links no ray-tracing code at all. A third way, a native renderer for three.js's scene graph, runs on a PlayStation 3 and is built in PocketJS.

| three.js, as written | ThreeRT, all defaults |
|---|---|
| ![A room in three.js: flat walls, no sunlight on the floor](site/media/hello/sun-room-three.webp) | ![The same room in ThreeRT: sunlight through the window, bounce light on the walls](site/media/hello/sun-room-rt.webp) |
| | `path` | `webgpu` ([`docs/RENDERING-METHODS.md`](docs/RENDERING-METHODS.md)) | PlayStation 3 (experimental) |
|---|---|---|---|
| **Keeps of three.js** | Its scene API, as `@threert/scene` (physical lighting units) | three.js and its `WebGPURenderer`, unchanged, + TSL node materials | The scene graph: objects, geometry, materials, lights |
| **Replaces** | The renderer, with a path tracer | The browser, with the native runtime | three.js's renderer, with a native one |
| **Renderer** | Rust + wgpu compute path tracer (hardware ray queries, OIDN, DLSS / MetalFX) | three.js r187 `WebGPURenderer` over native `navigator.gpu` (wgpu) | C on the RSX, hand-written PBR, sky and unlit shaders; three.js r187 on QuickJS (no JIT) |
| **GPU** | Ray-tracing hardware (Apple M-series, RTX, RDNA2+) | Any GPU wgpu supports (Metal, Vulkan, D3D12) | The PlayStation 3's RSX, 1920 × 1080 |
| **UI** | The game HUD | PocketJS over the 3D frame | PocketJS in the same frame |
| **Footprint** | Full ThreeRT clients | Proven at **9.9 MB installed / 4.5 MB download** (vs 445 / 170 MB Electron); also a Wayland wallpaper host (`webgpu/wallpaper`) | 16–30 fps in four demos, not yet profiled; in [PocketJS](https://github.com/pocket-nexus/pocketjs/tree/main/programs/ps3), not built by `tools/build.ts` |

### A native renderer for the scene graph

The sun through the window, the sky, the bounce light off the floor and the lamp's glow come from tracing the scene. Light is in physical units: the sun is 90,000 lux, and an emissive surface is a light source. The whole file is [`scenes/sun-room.ts`](scenes/sun-room.ts).
three.js's `WebGPURenderer` needs WebGPU, and it does its per-frame work in JavaScript, which runs several times slower without a JIT. A PlayStation 3 has neither WebGPU nor a JIT. There the scene code still imports `three` and builds a three.js scene graph; once a frame, a small renderer walks the graph, packs each object's transform and material into typed arrays, and hands them to native code that draws on the RSX. three.js's own renderer never runs, so what lives in it does not carry over: shadows, `ShaderMaterial` and TSL, three.js's post-processing. This sits between `webgpu`, which keeps all of three.js, and a [port](docs/PORTS.md), which keeps only a game's rules. [`docs/RENDERING-METHODS.md`](docs/RENDERING-METHODS.md) has what it draws and what it costs.

## Against three.js at full power
## Ray-traced: against three.js at full power

The same scene file, run by both engines on the same Mac. three.js gets everything it has: shadow maps, image-based lighting and, on WebGPU, its own SSGI, SSR and TRAA.
On GPUs with ray-tracing hardware: the same scene file, run by both engines on the same Mac. three.js gets everything it has: shadow maps, image-based lighting and, on WebGPU, its own SSGI, SSR and TRAA.

| three.js r187 | ThreeRT |
|---|---|
Expand All @@ -110,9 +81,23 @@ The reference is an unbiased offline render (4,096 samples per pixel, no denoise

## Get started

### Play and make games
### Run three.js natively (`webgpu`, macOS and Linux)

```bash
npm install
node tools/build.ts --renderer webgpu # the runtime and the webgpu renderer; no path-tracer code is linked
node tools/check-webgpu-gate.ts --render # dependency isolation, JS layering, binary size, a headless render
```

The sample is plain three.js and TSL ([`webgpu/sample/scene.ts`](webgpu/sample/scene.ts)); the Omarchy wallpaper host is [`webgpu/wallpaper`](webgpu/wallpaper). How it is built and measured: [`docs/RENDERING-METHODS.md`](docs/RENDERING-METHODS.md).

### three.js on a Sony PS3

The PS3 runtime and its three.js renderer are built in [PocketJS](https://github.com/pocket-nexus/pocketjs/tree/main/programs/ps3), with PSL1GHT, for a console with custom firmware. How it works and what it measured: [three.js on a Sony PS3](https://threert.dev/blog/ps3/).

### Play and make games (`path`)

1. **[Download ThreeRT](https://threert.dev/download/)** for macOS (14 or later, Apple silicon) or iPhone and iPad (iOS 17 or later). The client fetches a game's code and traces it on the device's own GPU.
1. **[Download ThreeRT](https://threert.dev/download/)** for macOS (14 or later, Apple silicon), iPhone and iPad (iOS 17 or later), Steam Deck or Android. The client fetches a game's code and traces it on the device's own GPU.
2. Open an example from the app's library or from [threert.app](https://threert.app), where ThreeRT apps and games are published.
3. Write your own with the `threert` command line that ships inside the Mac app:

Expand Down Expand Up @@ -194,18 +179,21 @@ npm run test:render # the r
| Directory | What |
|---|---|
| [`renderer/`](renderer) | The engine: the Rust + wgpu path tracer, live viewport, denoiser, post, and an embedded QuickJS that runs scene code (`threert-render`); `voxel-core` and `physics-core` (Rapier) also build for wasm32 |
| [`runtime/`](runtime) | The native runtime: the JavaScriptCore guest, web-platform globals (timers, fetch, WebSocket, storage, Canvas 2D), and the PocketJS host |
| [`webgpu/`](webgpu) | The `webgpu` renderer: `navigator.gpu` over wgpu, the sample, the headless `webgpu-shot`, and the Wayland wallpaper host |
| [`packages/`](packages) | `@threert/scene`, `@threert/gameplay`, `@threert/voxel` |
| [`scenes/`](scenes), [`games/`](games) | The reference catalog (Cornell box, material grid, Bistro, Zero-Day, …) and the playable content |
| [`tests/`](tests) | The render test suite (analytic and temporal checks) and the three.js compatibility set |
| [`tools/`](tools) | Bundling, benches and gates, the three.js comparison, the Tokyo pipeline |
| [`compare/`](compare) | Hello-world scenes side by side in three.js and ThreeRT |
| [`ue5/`](ue5) | UE5 reference captures (Lumen and the Path Tracer): the ground truth the renderer is measured against |
| [`site/`](site) | [threert.dev](https://threert.dev): the landing page, Download and Docs (the apps themselves are on [threert.app](https://threert.app)) |
| [`site/`](site) | [threert.dev](https://threert.dev): the landing page, the blog, Download and Docs (the apps themselves are on [threert.app](https://threert.app)) |

## Documentation

- [Getting started](https://threert.dev/docs/): the client, a first scene, the dev loop, packages
- [`docs/RENDERING-METHODS.md`](docs/RENDERING-METHODS.md): one runtime, two renderers (`path` and `webgpu`), crate layout and size-gate rules
- [Blog](https://threert.dev/blog/): engineering notes; the first is [three.js on a Sony PS3](https://threert.dev/blog/ps3/)
- [`docs/RENDERING-METHODS.md`](docs/RENDERING-METHODS.md): what each way of running keeps of three.js: the `path` and `webgpu` renderers, native scene-graph renderers, crate layout and size-gate rules
- [`docs/RUNTIME.md`](docs/RUNTIME.md): how scene code runs in the engine: setup, handlers, world handlers, frame scripts, physics
- [`docs/MATERIAL_FUNCTIONS.md`](docs/MATERIAL_FUNCTIONS.md): a WGSL body on a material, run by the path tracer at every hit
- [`docs/VOXEL.md`](docs/VOXEL.md): the voxel engine, measured on a destructible level
Expand Down
56 changes: 54 additions & 2 deletions docs/RENDERING-METHODS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Renderers: Path Tracer (`path`) and WebGPU (`webgpu`)
# Renderers: Path Tracer (`path`), WebGPU (`webgpu`), and native scene-graph renderers

> Status: active (2026-11-28). Both the `path` renderer (`renderer/`) and the `webgpu` renderer
> (`runtime/` + `webgpu/`, built via `node tools/build.ts --renderer webgpu`, gated by
Expand All @@ -7,11 +7,19 @@
> runs three.js r187's `WebGPURenderer` natively on PocketJS's JavaScriptCore guest
> (`pocket-nexus/pocketjs#773`, `#774`, `#775`), originally proven in
> `pocket-nexus/pocket-agents-island#28`, `#29`. Windows support remains planned.
> A native renderer for three.js's scene graph runs, experimentally, on a **PlayStation 3** (2026-12-02).
> It is built in PocketJS, not in this repository: [Native scene-graph renderers](#native-scene-graph-renderers).

ThreeRT is one engine and one runtime with **two renderers**, chosen per project and per build:
ThreeRT is one engine and one runtime with **two renderers** in this repository, chosen per project and
per build. They differ in what they keep of three.js: `path` keeps its scene API and replaces the renderer;
`webgpu` keeps three.js and its renderer and replaces the browser. A third way, for hardware with neither ray
tracing nor WebGPU, keeps three.js's scene graph and replaces its renderer
([below](#native-scene-graph-renderers)).

| | **`path`** (Path Tracer) | **`webgpu`** (WebGPU — macOS & Linux) |
|---|---|---|
| Keeps of three.js | its scene API, as `@threert/scene` | three.js and its `WebGPURenderer`, unchanged |
| Replaces | the renderer | the browser |
| What draws | ThreeRT's wgpu compute path tracer: hardware ray queries, OIDN, DLSS / MetalFX, the physical sky and post chain | three.js r187's own `WebGPURenderer`, running natively: `navigator.gpu` implemented over wgpu inside the engine's JavaScript guest |
| Scene code | `@threert/scene` (physical units) | plain `three.js` + TSL node materials |
| GPU | ray-tracing hardware (Apple M-series, RTX, RDNA2+) | any GPU wgpu supports (Metal, Vulkan, D3D12) |
Expand Down Expand Up @@ -91,6 +99,50 @@ the `dlss` / `oidn` / `net` / `audio` features, and the default build stay as th
The JavaScriptCore guest and native text path live in PocketJS (`pocket-guest-jsc`,
`pocket-wgpu-render`'s `TextPainter`); ThreeRT depends on them rather than copying them.

## Native scene-graph renderers

`webgpu` needs two things from a device: a GPU that wgpu drives, and a JavaScript engine fast enough for
`WebGPURenderer`'s per-frame work. A PlayStation 3 has neither: its RSX predates WebGPU's feature set, and
homebrew has no JIT (PocketJS runs QuickJS on the Cell's PPU). There a native renderer draws three.js's scene
graph instead of three.js's own renderer:

- The scene code is unchanged three.js: it imports `three` (0.187.0) and builds `Object3D`s, geometries,
materials and lights.
- Once a frame, `RSXRenderer` (TypeScript, about 800 lines) calls `updateMatrixWorld`, walks the graph, and
packs each object's matrix and material parameters into typed arrays. Geometry and textures are uploaded
once and cached by id.
- Native code (`rsx3d.c`) draws them on the RSX with three hand-written shader pairs: PBR (metalness and
roughness, an environment map, a directional, a hemisphere and three point lights, fog), a sky dome, and
unlit points and lines. A planar mirror uses the stencil buffer.
- PocketJS draws its UI into the same 1920 × 1080 frame after the 3D pass, without a clear.

What it draws: `Mesh`, `InstancedMesh`, `Points`, `Line` and `LineSegments`; `MeshStandardMaterial`,
`MeshPhysicalMaterial`, `MeshPhongMaterial`, `MeshLambertMaterial`, `MeshBasicMaterial` and
`MeshNormalMaterial`, mapped onto the PBR or the unlit shader; ambient, hemisphere, directional and point
lights; `Fog` and `FogExp2`; `PerspectiveCamera`. What lives in three.js's renderer does not carry over:
**shadows, `ShaderMaterial`, `onBeforeCompile` and TSL, render targets and post-processing**. The mirror is
the renderer's own option, not three.js's `Reflector`.

Measured on a PlayStation 3 (CECH-2500, system software 4.81 with custom firmware), 1920 × 1080, from the
demos' own counters. "Submit" is PPU time spent writing the 3D pass's commands, not GPU time.

| Demo | Triangles | Draws | Submit | fps |
|---|---:|---:|---:|---:|
| Showroom: torus knot, PBR satellites, planar mirror | 25,990 | 26 | 0.1 ms | 20 |
| Material grid: 20 spheres, metalness × roughness, mirror | 58,886 | 43 | 0.1 ms | 26 |
| Galaxy: planet, rings, 2,400 point sprites | 5,678 | 7 | 0.1 ms | 30 |
| Instanced wave: 196 instances | 2,362 | 199 | 28.9 ms | 16 |

The RSX has no hardware instancing, so an `InstancedMesh` costs one draw and one constant upload an instance:
that is the 28.9 ms. Where the other demos' frames go (QuickJS walking the graph, the RSX shading 1080p with
a mirror pass, or waiting on vsync) is **not measured yet**, and the Cell's six SPUs are not used.

It is not a `--renderer` of this repository. It shares no crate with `runtime/`: the PS3 build is PocketJS's
(PSL1GHT, `ppu-gcc`, a C host program), and the code is in `pocket-nexus/pocketjs` (`platforms/ps3/`,
`apps/ps3-three-showcase/`). A shared interface for scene-graph renderers waits for a second device that needs
one. It sits between `webgpu`, which keeps all of three.js, and a [port](PORTS.md), which keeps a game's rules
and replaces everything else.

## Open questions

- **The guest on Windows and Linux.** three.js's `WebGPURenderer` does per-frame work in JavaScript;
Expand Down
Binary file added docs/images/hero.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/social-preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading