three-realtime-rt — turn-on ray traced lighting for three.js (soft shadows, 1-bounce GI, temporal denoise, WebGL2)

I wanted “RTX on” for ordinary three.js scenes — no material rewrites, no WebGPU requirement. After my own attempt stalled a while back, I challenged an AI (Claude) to build it with me steering and testing, and the result works well enough that I think it’s worth sharing here.

Live demo: three-realtime-rt — ray traced three.js
Source (MIT): GitHub - GoldwinXS/three-realtime-rt: Turn-on ray traced lighting for three.js: BVH-traced soft shadows, global illumination, procedural sky, temporal denoise + TAA. · GitHub

Integration is one call swap on a normal scene (MeshStandardMaterial, standard lights):

import { RealtimeRaytracer } from "three-realtime-rt";

const rt = new RealtimeRaytracer(renderer);

rt.compileScene(scene);

rt.render(scene, camera); // instead of renderer.render(...)

Architecture — hybrid deferred, the way games do “RTX”:

  1. three.js rasterizes the G-buffer (albedo/roughness, normals/metalness, world pos, emissive) — materials and textures stay pixel-perfect.
  2. A fragment shader traces only the lighting against a GPU BVH (three-mesh-bvh): area-sampled soft shadow rays per light + one cosine-weighted GI bounce with next-event estimation; escaped rays sample a procedural sky, so the sky is a soft area light.
  3. Output is demodulated irradiance, which survives denoising cleanly: temporal reprojection → edge-avoiding à-trous (SVGF-lite) → composite → TAA with neighbourhood clamping.
  4. Lighting traces at half resolution and is reconstructed by joint bilateral upsample + the temporal stack.
  5. Two-level BVH: static geometry uploads once; dynamic meshes refit per frame, so moving objects cast correct ray traced shadows (demo drops 40 Rapier rigid bodies).

Runs ~60fps at 1080p on an RTX 3060 (no RT cores used — it’s all shader math, so it runs on any WebGL2 GPU, scaled by raw compute).

Proof it holds up in a real project: I also built a small stealth game on this library where the ray traced light IS the game mechanic - you hide from sweeping guard lights in the shadows they cast. Playable here: Shadow Heist — ray traced stealth

There’s a pay-what-you-want supporter pack (ready-to-run starter template, all examples, and a long-form write-up of the pipeline) if you’d like to support development: three-realtime-rt Supporter Pack by GoldwinXS

Feedback on the denoiser quality and any scenes that break it would be very welcome.