On a phone, touch the left half of the screen for a movement stick, drag on the right half to look around, and use ▲▼ on the right edge to climb and descend.
Real-Time Ray Tracing in the Browser
— Concave Mirrors, Cylinders and Shattering Glass
With rasterization, the way games usually draw, a mirror can barely show one reflection. This demo goes further with real-time ray tracing, following rays of light one by one on your GPU, right in the browser: mirrors facing mirrors that reflect dozens of times, a concave mirror that hangs your image upside down in midair, the unpredictable inside of a mirrored cylinder, mirrors you can shoot and crack, and fallen shards reflecting one another. Fly the drone around and see for yourself.
How to Use
| Drag / WASD / QE | Look around / fly forward, back, left and right (Shift to go faster) / descend and climb |
|---|---|
| SCENE | Mirror setup (also restores broken mirrors) / ☀ Day toggles day and night / ✦ relights the candles |
| DRONE | 3rd / 1st (V): view from behind the drone or through its camera. Light (L): the drone's light. ◎ Fire (Space): shoot a steel ball at the center of the screen. Mirrors crack, and collapse after 16 hits |
| BUDDHA | Mirror / Original: the statue as a polished mirror, or in its original material (the scanned color and carving). With Original, the light becomes a wide floodlight that casts shadows on the statue |
| ⚙ | Bounces: how many reflections to follow (up to 64). Mode: Compare puts a rasterization-style render next to ray tracing; Depth colors each pixel by how many times its light bounced. Plus fine-tuning for mirrors and lights |
Ray Tracing vs Rasterization — Why Mirrors Are Hard
Rasterization paints shapes onto the screen. It is fast, but it has no idea what can be seen from a given point. So mirrors are faked: render the scene again from a mirrored camera and paste it in, or substitute a photo of the surroundings taken in advance (an environment map). These tricks fall apart for reflections of reflections, curved mirrors, and mirrors broken into pieces.
Ray tracing works the other way around: for every pixel it follows the light path backward. When a ray hits a mirror, it simply bends in the reflected direction and keeps going, so flat or curved, one bounce or dozens, it is all the same mechanism. Set View to Compare in ⚙ to see the difference at a glance.
Things to Try
| Yourself in a concave mirror Concave | A concave mirror 17 m across. Up close, your image is large and upright. As you back away it swells to fill the mirror at the amber lights (the center of curvature), then flips upside down. The candle on the drone shows which way is up. A statue stands below the center of curvature, and its real image floats upside down in midair above the path. |
|---|---|
| Inside the cylinder Cylinder | A cylinder mirrored inside and out. From outside it is an ordinary convex mirror, but fly over the rim and down inside: the rim repeats in nested rings, and images stretch sideways around the wall. What do you see from the very center? Find out. |
| A cracked mirror Space to shoot | The pieces between the cracks tilt slightly differently, so the reflection breaks up piece by piece. The opposite mirror reflects the cracked one, so the cracks repeat into the distance too. |
| Shards reflecting shards 16 hits per mirror | The mirror collapses along its cracks, and each shard falls, bounces and piles up as a rigid body with its own mass. Every shard on the floor is a tiny mirror: shards reflect shards, and the mirrors still standing reflect the rubble. Interreflection like this only comes from tracing rays. |
| Light bouncing along L for the light | At night (turn ☀ off), switch on the light: a beam through the haze folds back and forth between the mirrors. Aim it at a cracked mirror and it splits and scatters, one beam per shard angle. |
Mirror Setups
| Tunnel | Two parallel mirrors: images line up endlessly, the classic infinity mirror |
|---|---|
| Room | All six faces are mirrors: images spread into a 3D lattice in every direction |
| Kaleido / Corner | Three mirrors at 60° (a kaleidoscope) / three at right angles (exactly 8 images) |
| Constellation | A mirror room full of LED bulbs hanging from the ceiling (best at night). Fly close and the propeller wash sets them swinging |
| Cylinder / Concave | A mirrored cylinder / a giant concave mirror |
Most setups have a mirror-polished Buddha statue (from a 3D scan published by the Cleveland Museum of Art) and candles at the center, to show a complex curved mirror reflecting and being reflected by the mirrors around it.
When the angle between mirrors divides 180° evenly, like 90° or 60°, the images line up in a perfectly regular pattern. The combinations of mirror reflections form a reflection group, the same mathematics behind kaleidoscope patterns and crystal symmetry.
How It Works
- Rendering
- Full-screen ray tracing (WebGPU)
- Bounces
- Up to 64
- Curved
- Spheres, cylinders, a 100k-triangle statue (BVH)
- Shards
- Up to 8192 rigid bodies (BVH once at rest)
- Cracks
- One crack pattern drives reflection, light and shards
- At rest
- Jittered frames accumulated and averaged
Flat mirrors, the concave mirror, the cylinder, the statue and the broken shards are all drawn by the same computation: follow the ray, reflect it, repeat. Numerous objects such as the statue's triangles and the shards on the floor are organized in nested boxes (a bounding volume hierarchy), so each ray only tests the boxes it passes through. A cracked mirror's crack pattern is decided at the moment of impact, and the shifted reflections, the split light beams and the shapes of the falling shards all follow that same pattern. While the camera is still, slightly jittered frames are averaged to smooth out fine reflections.
For the basics of ray tracing versus rasterization, try Ray Tracing vs Rasterization in Explorables (Japanese).
FAQ
What is real-time ray tracing?
Ray tracing draws an image by following, for every pixel, the path of light back from the eye into the scene. Real-time ray tracing does this dozens of times per second, so reflections, shadows and reflections of reflections follow the actual light paths instead of approximations.
How is ray tracing different from rasterization?
Rasterization paints shapes onto the screen. It is fast, but it does not know what can be seen from a given point, so mirrors are faked with a single planar reflection or an environment map. Ray tracing follows light paths, so dozens of bounces, curved mirrors and shattered mirrors all work the same way.
What do I need to run this demo?
A browser with WebGPU support (recent Chrome or Edge, for example). Nothing to install, and no ray-tracing-capable GPU is required.
Does it use the GPU's dedicated ray-tracing hardware (RT cores)?
No. WebGPU does not expose it yet, so ray intersections with the mirrors, the statue and the glass shards are computed in shaders. The statue's triangles and the shards piled on the floor are organized in bounding volume hierarchies (BVH) so that each ray only tests the boxes it passes through.
References
- T. Whitted: An Improved Illumination Model for Shaded Display, Communications of the ACM, 23(6), 1980.
- J. Amanatides: Ray Tracing with Cones, Computer Graphics (Proc. SIGGRAPH '84), 18(3), 1984.
- I. Wald: On fast Construction of SAH-based Bounding Volume Hierarchies, Proc. IEEE Symposium on Interactive Ray Tracing, 2007.
- H. S. M. Coxeter: Regular Polytopes, 3rd ed., Dover, 1973.
- Buddha statue 3D data: Cleveland Museum of Art, 1950.86 Buddha of the Future (Miroku Bosatsu), CC0 1.0.