Projects & toysCase study
The solar system behind this page
Every page on this site sits on top of a live solar system. You can click the sun, the planets keep time by Kepler’s laws, and every couple of minutes the moon slides into Earth’s shadow. Until July 2026 it was DOM elements and SVG circles. This is the story of the rebuild: how the scene is set up, the three parts that took the most tries (the sun, the wireframe view and the eclipse), and what it costs to run.
Why a solar system at all? I’ve always loved space, and building one, with planets orbiting the sun, is one of the best-loved assignments in COS 126, the Princeton intro class that made me fall in love with computer science. I was later a lab TA for it, and I have a lot of good memories of helping students fix the bugs in their solar systems, then seeing their excitement and satisfaction as the planets began to move around the sun on their laptops.
3D graphicsWebGPUPersonal project · · 12 min read
01 · The setup
Two canvases and one camera
In the old background the stars were DOM elements that React re-rendered every frame, and the planets were SVG circles riding CSS animations. My first WebGL version was a hybrid that read each SVG planet’s position every frame and drew a 3D sphere on top of it. Then I flipped it: the 3D scene became the source of truth, and the DOM follows it.
There are two fullscreen canvases, fixed in place behind the page.
- The star canvas has an orthographic camera in which one world unit is one CSS pixel, which makes it easy to line things up with the DOM. It draws the background stars, the gold coin in the corner and the title on the landing page (each letter is drawn to an offscreen 2D canvas, and a star is dropped wherever there’s ink).
- The solar canvas sits on top with a perspective camera: the sun, the planets, the moon and a satellite. Its background is transparent, so the stars show through.
Two is the limit, and I found it by shipping three. The coin first went out on a third canvas with its own GPU context, and in Chrome the star canvas began losing its context and getting it back, replaying its fade-in each time. The stars strobed. I moved the coin into the star canvas.
A route is a place to stand
The canvases stay mounted when you navigate. There is one camera, and each route is a place for it to stand. The landing page looks straight down on the orbits like a textbook diagram. The home page perches at the edge of the sun. The about page looks across Earth, and so does the page you’re reading. The shop sits on the moon. Going from one to another is a two-second swoop, so a page change is a camera move and never a cut. As the camera turns, the star canvas pans to match, and the two read as one sky.
Neither canvas receives a pointer event. Everything you can click in the scene is an ordinary link in the DOM, moved every frame to wherever its planet lands on screen, so focus rings, middle-click and screen readers all keep working. The outline you see when you hover a planet is the convex hull of its projected vertices, written into an SVG path.
One renderer, two backends: WebGPU, with WebGL 2 behind it
Both canvases draw through the three.js WebGPURenderer. A browser with WebGPU gets WebGPU, and every other browser gets the same renderer’s WebGL 2 backend. That only works if no shader is written in GLSL, so every custom material here is written in TSL, the three.js shading language: TypeScript that builds a node graph, which three.js compiles to WGSL or GLSL as needed. To see the fallback on a machine that has WebGPU, add ?webgl=1 to any URL: here’s the home page on WebGL 2. If the port went well, you can’t tell.
The port had one bug I’m fond of. WebGPU draws point primitives exactly one pixel wide, so every star had to become an instanced sprite, with its position, color and size as per-instance attributes. WebGPU also caps a pipeline at eight vertex buffers, and a sprite’s own quad uses two of them. Mine came to nine. Nothing errored. The stars just weren’t there. They now share a single interleaved buffer, twelve floats to a star.
- Renderer
- three.js WebGPURenderer, with its WebGL 2 backend as the fallback
- Shaders
- TSL, compiled to WGSL or GLSL
- Scene
- React Three Fiber, with two canvases and one camera rig
- Finishing
- An HDR composite: bloom, lens flare, AgX, FXAA and dither
02 · The sun
A sun built in three layers
The sun has been rebuilt more often than anything else here, and one page is to blame. On the landing page it’s a small disk in the middle of a diagram, and almost anything looks fine at that size. On the home page the camera sits at its edge and it’s the biggest thing on screen. A textured ball with a soft glow behind it looks like exactly that.
A surface that moves
The surface went first. A texture can’t change, so I made the photosphere a shader: five octaves of fractal noise, warped by more of the same noise and animated in time. Convection cells and dark spots drift, grow and dissolve, and the edge darkens and reddens the way the real sun’s does.
A corona that stays on the edge
Next came the corona, the flares around the rim. My first two attempts were flat: a quad that always faces the camera, lined up with the sun in screen space. Both drifted off the edge of the disk as the camera moved.
The version that stuck does no lining up. The corona is a shell twice the sun’s radius with only its inside faces drawn, and each pixel of the shell works out how close its own line of sight passes to the sun’s center. (The snippets here are TSL, the three.js shading language written as TypeScript, which is why they say a.mul(b) where a shader would say a * b.)
const centerView = modelViewMatrix.mul(vec4(0, 0, 0, 1)).xyz;
const rayDir = normalize(positionView);
const b = length(centerView.sub(rayDir.mul(dot(centerView, rayDir))));The first line is the sun’s center as the camera sees it, the second is the direction through this pixel, and the third is the closest that line of sight gets to the center, which is b. A line of sight that just grazes the sphere passes exactly one radius from the center, so b minus the radius is the distance past the edge. It’s measured by the same projection that draws the sun, which is why the corona lines up from any angle.
Glare that nobody draws
Through all of that, the light around the sun was still a painting: a soft sprite parked behind it. In October I stopped drawing glow and let it happen instead. The solar canvas now renders into a half-float texture, where a color can be brighter than white, and the sun’s surface leaves its shader eight times brighter than that. A chain of passes turns that into pixels, in the order a camera does it:
- Exposure. One number per camera position, eased along with the camera during a swoop.
- Bloom. Whatever is still brighter than the threshold spills light onto the pixels around it.
- Lens flare. Faint ghosts, made from only the brightest core of the bloom.
- AgX tone mapping. The squeeze down to what a screen can show. The ACES curve the site used before bends a bright orange toward yellow. AgX holds it.
- FXAA. Smooth edges, as a pass over the finished picture.
- Blue-noise dither. Half a step of noise, because the canvas is 8-bit and dark gradients band.
Nothing in that list draws the sun’s glare. Glare is what bloom does to something that bright. Hover the sun on the landing page and its radiance rises by 30%, and the glare swells without a line of code that mentions it. Exposure comes before bloom, so how much of the scene blooms depends on where the camera stands: the home page stops down to 0.75 beside the sun, and the shop opens up to 1.25 out on the moon.
What went wrong on the way
The satellite became a second sun. It’s a polished metal ball that orbits close to the sun, where the light is more than ten times stronger than it is at Earth. Its highlight crossed the bloom threshold and swelled into a blob the size of the sun. I capped how much light a single pixel can hand to the bloom. The sun doesn’t miss it, because glare grows with the number of pixels over the threshold, and its disk has far more of those than a glint does.
A brown wash covered the frame. The canvas has to stay transparent, so each pixel stores how much of it an object covers, in its alpha channel, with the color already multiplied by that coverage (premultiplied alpha). A soft sprite that covers a tenth of a pixel is stored as a tenth of its light. Tone curves lift dim values, and tone mapping that number directly lifted every faint edge into a brown wash. The cure is to divide the coverage out, tone map the real color, and multiply the coverage back in.
Then the glare disappeared. Glare has no coverage: it’s light landing where nothing was drawn. The stock three.js output step zeroes any pixel that nothing covers, which removes the glare in the one place it matters, out past the sun’s edge. I wrote the last step myself:
const coverage = sceneColor.a;
const object = exposed.rgb.div(max(coverage, COVERAGE_FLOOR));
const covered = toDisplay(object.add(glare));
const open = toDisplay(glare);
const mapped = mix(open, covered, coverage);
const brightest = max(mapped.r, max(mapped.g, mapped.b));
return vec4(mapped, max(coverage, brightest));Where something was drawn, the object and the glare on top of it are tone mapped together. Where nothing was, the glare is tone mapped alone, and coverage blends the two. The alpha the browser gets is whichever is larger, the coverage or the brightness of the result, so bright glare hides the stars behind it and faint glare lets them through.
And the stars went out. The scene renders lazily, the first time something asks three.js for its texture. The first thing to ask is the bloom, which has just reset the clear color to opaque black for its own blur passes, and the scene cleared itself to opaque black and covered the star canvas. One line in the scene’s before-render hook sets the clear color back to transparent.
03 · Mesh view
A wireframe with no wires in it
A switch on this site redraws the whole scene. It’s at the bottom left of this page on anything wider than a phone, and it’s labeled “3D Disco Space”. The code is more sober and calls the two looks space view and mesh view, so I will too. Space view is the scene as a camera would see it. Mesh view turns every body into a glowing, see-through lattice, the way a maps app flips from satellite to map.
The switch used to be day and night. Day was a pink gradient sky on a site designed against a dark one, and it took 21 blocks of CSS overrides to keep the text readable. Mesh view has a dark background too, so I deleted all 21.
Why not draw a wireframe?
The obvious way to get this look is the wireframe flag on a material, which draws every triangle edge. Earth’s globe is 96 segments by 96, so that’s 54,720 line segments, and on the home page they landed inside a circle I measured at 147 pixels across. It renders as fog. The usual next thing to try is EdgesGeometry, which keeps only the edges where two faces meet at more than some angle. With that angle at 15 degrees a smooth sphere has no such edges, and EdgesGeometry hands back nothing. At the three.js default of 1 degree it returns 16,800 of them for Earth, still far too many.
So mesh view has no wires in it. Every body keeps its geometry and its material, and the material gains a patch that paints lines of latitude and longitude from each pixel’s position on the object. This function draws one set of lines:
const wireGridLine = Fn(([coord]: [FloatNode]) => {
const w = min(fwidth(coord), 0.35);
const d = abs(fract(coord.sub(0.5)).sub(0.5)).div(max(w, 1e-4));
return smoothstep(0, 1.4, d).oneMinus();
});fract and the arithmetic around it measure how far this pixel is from the nearest grid line. fwidth is how much the coordinate changes across one screen pixel, so dividing by it turns that distance into pixels. The line comes out the same width whether Earth is 147 pixels across or filling the window, and smoothstep, a soft ramp between two values, fades its edge. The min handles the seam where longitude wraps around: the derivative spikes there, and capping it turns the spike into a missing line, which beats a bright stripe down the back of every globe.
See-through without sorting
You can see through the lattice: the far side’s lines show between the near side’s. That is usually a headache, because transparent surfaces have to be drawn back to front and a sphere overlaps itself. Mesh view never sorts anything. Each body’s lines are added to whatever is already on screen, and nothing is written to the depth buffer, the per-pixel record of what’s in front. A sum comes out the same in any order. It only works because the lattice is light on a dark sky. You can’t add your way to a darker pixel.
One number, uWire, runs from 0 to 1, and every patched material reads it. Flipping the switch eases it over 700 milliseconds, and the whole scene crossfades.
A review pass caught six bugs in that change. The one worth passing on: the wire shader forced alpha to 1, and alpha was the only thing hiding bodies that fade out but stay in the scene. In mesh view the moon turned up on pages where it’s meant to be invisible.
The sun gets a mirror ball
At first the sun wore a neon cage like everything else. But I wanted this view to be the playful one, less focused on realism, and the sun as a disco ball seemed perfect. The planets are just dancers spinning in its light.
It’s tiled like a real one: 26 rows of square mirrors from pole to pole, each tilted slightly off true. A mirror needs something to reflect and the scene has no environment, so the shader invents a room: a warm gradient and four spotlights fixed in space around the ball. A tile lights up only when its reflection of your line of sight lands inside a spotlight’s beam. The ball turns about three times a minute, and the glints come and go in patches as tiles march through the beams. The spotlights are brighter than white, so the glints bloom.
04 · The eclipse
An eclipse every 140 seconds
I took a liberty to get it. The moon orbits in the same plane as Earth, without its real five-degree tilt, so it’s eclipsed on every pass. The real moon manages a few a year. Mine gets one every 140 seconds, and each lasts about half a minute.
First, the clockwork: orbits that keep time by Kepler
An eclipse that turns up on time needs a timetable. Until September the orbit speeds were picked by hand, and Mercury had been given Earth’s. The home page’s camera turns with Earth, so Mercury hung motionless in its sky. Every planet also spun the wrong way on its axis.
Now I give a planet a radius and it gets its speed from Kepler’s third law:
// T² ∝ a³, so ω ∝ a^-3/2, anchored to Earth's
const orbit = (orbitRadius: number) => ({
orbitRadius,
orbitSpeed: EARTH_ORBIT_SPEED * (orbitRadius / EARTH_ORBIT_RADIUS) ** -1.5,
});Move a planet outward and it slows down by itself. Mercury and Mars keep their real eccentricities, so their positions come from Kepler’s equation, which has no closed form. Four rounds of Newton’s method each frame land within a millionth of a radian. On the landing page you can watch the result: Mercury moves about one and a half times as fast at its closest to the sun as at its farthest.
Earth’s circle is deliberate. The links on the home page orbit at a steady rate in front of that same camera, and an Earth that sped up and slowed down would slide them across the screen.
Earth’s shadow on the moon
Shadows in 3D normally come from shadow maps, which render the scene a second time from the light’s point of view. This scene doesn’t need the general tool: the light that matters comes from one point, the sun, and everything it lands on is a sphere. For spheres I can do the geometry directly, per pixel. The idea, like the one behind the satellite’s reflections, comes from Maxime Heckel’s post Lighting that feels just right (opens in a new tab).
Each pixel of the moon asks one question: from here, how much of the sun’s disk is Earth covering? Seen from that pixel the sun is a disk of some angular size, Earth is another, and their centers are some angle apart. This is the moon’s shader working that out (occ is the occluder, here Earth):
const sunAngle = asin(min(sunRadius.div(sunDist), 1));
const occAngle = asin(min(radius.div(occDist), 1));
const apart = acos(
clamp(dot(point.negate(), toOcc).div(sunDist.mul(occDist)), -1, 1),
);
const maxCover = min(occAngle.div(sunAngle).pow(2), 1);
const cover = maxCover.mul(
smoothstep(
abs(occAngle.sub(sunAngle)),
occAngle.add(sunAngle),
apart,
).oneMinus(),
);If Earth looks bigger than the sun and sits squarely over it, the cover is total. That’s the umbra. If the two disks only overlap, the cover is partial, and that’s the penumbra. The true overlap of two disks has an awkward formula, and a smoothstep from “the edges just touch” to “one disk is inside the other” stays within 8 percentage points of it. I don’t blur the shadow’s edge. It’s soft because the sun has a width.
In the deepest shadow a little light is left, and it’s red: about 12% of the red, 4.5% of the green and under 2% of the blue. That’s the copper of a real lunar eclipse, when the only sunlight reaching the moon has been bent around Earth through its atmosphere.
It matters where in the shader the shadow is applied. The scene’s other patches work on a pixel’s final color, after the moon’s own faint glow has been added. Darkening there would dim the glow too, and the glow is what keeps the moon findable, since on the about page it’s a link. So the eclipse sits inside the lighting model and scales only the sun’s share.
Even then there was no shadow to see, and the glow was why. I had it set to 0.22, and AgX lifts dim, flat light a long way. On the about page the glow was most of what the camera saw. The moon’s phases were flattened and the eclipse never showed. At 0.08 both do.
The same trick, for the satellite’s reflections
The satellite, my link to the projects page, got the same treatment. Polished metal with nothing to reflect renders nearly black, and the usual fix is an environment map, a picture of the surroundings wrapped around the scene. Mine does the geometry instead. Each pixel of the hull bounces the camera’s line of sight off the surface and tests that ray against five spheres: the sun and the four inner planets. The nearest hit wins. The sun comes back as its own gold, held to 60% of the bloom cap from earlier, so the reflection can glint but can’t bloom. A planet comes back in its average color, lit on whichever side faces the sun. That’s five ray tests for each pixel of the hull and no texture reads. The satellite is up close on Projects & toys.
05 · Performance
What it costs, and who doesn’t have to pay
A fullscreen 3D scene is a lot to put behind a résumé. A good share of the work went into keeping its cost away from people who only came to read.
The short version: the words are on screen before any of it loads, a slow machine gets a cheaper picture or one that stops drawing, and if the scene can’t start at all, the page still works.
The long version: loading, frame costs, slow machines and failures
Getting it on screen
Every page is pre-rendered to HTML when the site is built, so the words are readable before any of this exists. three.js is the biggest piece of JavaScript on the site, about 360 KB gzipped, and it lives in its own chunk, preloaded next to the app.
Keeping it there took one unglamorous fix. Two small components imported a couple of string constants from a file that also imported three.js, which pulled the whole library into the bundle every page loads first. I moved the constants. A lazy chunk stays lazy only until somebody imports a constant from it.
Every frame
- Pixel ratio is capped at 1.5. On a 2x screen, full resolution means 78% more pixels to shade, for a soft backdrop nobody is studying.
- Idle things stop. Once the title’s stars have settled and the cursor is elsewhere, their simulation skips its work until something changes.
- The sun pays by the pixel. Its shader is the heaviest in the scene, and its cost scales with how much of the screen it covers, which is only a lot on the home page.
- No backdrop blur over a canvas. The panel you’re reading used to be frosted glass. With two animating canvases behind it, the browser had to re-blur the backdrop on every canvas frame and every frame of scroll, and scrolling the about page froze. It’s a flat color at a higher opacity now, and looks much the same.
- Reduced motion counts. With it switched on, the stars stop cycling through hues and pulsing.
Slower machines
The finishing passes come in two tiers. Phones, machines with four cores or fewer and anything rendering in software get the lite one: bloom at a quarter of the frame’s size where the full tier uses half, and no lens flare. The full tier is also the only one that draws Jupiter, Saturn, Uranus and Neptune, once the window is wide enough to fit their orbits.
Software rendering gets cut back further. Some visitors have no usable GPU: virtual machines, blocklisted drivers, the servers that run PageSpeed Insights. There the browser rasterizes on the CPU, and this scene kept nearly five cores busy to deliver about 10 frames a second. When the renderer’s name comes back as SwiftShader or llvmpipe, the scene now drops to 1x resolution, swaps in a cheaper sun and stops rendering continuously. It draws at up to 30 frames a second while it has somewhere to go (the intro, a swoop, a few seconds after any input) and then holds its last frame.
In a headless Chrome on SwiftShader on my own machine, that took the GPU process from about 4.7 cores to about 0.2 once the page settles. It didn’t move the Lighthouse score at all: 31 before, 31 after. Nearly all the blocking time on that path is spent once, creating the contexts and compiling shaders. The change was for the people on those machines and did nothing for the number.
When it doesn’t work
The scene has also failed outright, for a whole visit. A page loaded into a hidden pane or a collapsed iframe starts with a viewport of 0 by 0, and reading pixels back from a canvas with no area throws, which left no background until the next reload. The samplers now return nothing for an empty canvas and run again when the size arrives.
WebGPU brought a second way to fail. Its renderer starts asynchronously, and if the canvas re-rendered during that wait (a resize, a route change, a click on the view switch in the first 100 milliseconds), React Three Fiber built a second renderer that was never told the canvas’s size. The page stayed black. Upgrading to React Three Fiber 9.8 fixed it.
If there’s no WebGL at all, or the chunk fails to load, an error boundary swallows it. You get a plain dark sky and a page that works, and on the home page, where the ways onward are planets, ordinary links appear in their place.
06 · Looking back
Three things I’d take to the next one
- Derive it, don’t paint it. The corona’s edge comes from the view ray, the glare from the bloom, the orbit speeds from Kepler and the shadow from two angles. Each replaced something I had placed or tuned by eye. The corona is the clearest case: lined up in screen space it drifted twice, and computed from the view ray it can’t.
- Know how small your scene is. Shadow maps and environment maps solve the general problem. Mine is one sun and a handful of spheres, and admitting that meant a page of geometry and no extra render passes.
- Transparency was the expensive feature. The brown wash, the vanishing glare and the stars going out all trace back to one decision: a see-through canvas stacked on another canvas. Three of the four things that went wrong with the sun came from that decision, not from the sun.
There’s more to do. The moon’s orbit could take its real tilt, which would turn the eclipse from a timetable into an occasion, and Earth’s night side has no city lights yet.
All of it is running behind this panel right now. Go have a look.