Enhancing Slop New York's Lighting
I forked mrdoob's Slop New York and rebuilt its frame on the pipeline this series proposes. Here is how one frame is rendered, with the output of every stage, and how it compares with the original at six locations.
Ben Houston • • 14 min read
The earlier parts of this series proposed a lighting pipeline for Three.js and a way to plug it into materials. A proposal needs a scene that is not a test scene, so I went looking for one.
mrdoob's Slop New York is all of Manhattan in WebGPURenderer and TSL, with traffic, pedestrians and four times of day. I forked it and rebuilt its frame on the pipeline from Part 3, with every source of bounced light going through the lists of Part 5. It runs at slop-nyc-enhanced.ben3d.ca.
This post follows one frame through that pipeline and shows what each stage outputs. It is a proof of concept. The city is outdoors, so the lightmaps and probe grids of the indoor pipeline have no part in it, and I have left out the interior-mapped rooms behind the windows, where my changes did not achieve much.
Before and after#
The "before" in each pair is mrdoob's repository at the commit I forked from. The camera and the time of day are the same in both. The traffic and the pedestrians are simulated, so they differ.






The differences are largest where the sun does not reach. In the original, a shaded street is lit by the whole sky, so the taxi glows and the brick is grey. In the fork, the street receives only the sky it can see, plus the light the buildings around it bounce. Wet asphalt and paintwork reflect the street they are in. In open sun at midday the two are close, as they should be.
| Before | After | |
|---|---|---|
| Scene renders | One forward pass with 4× MSAA | A depth pre-pass, then a beauty pass that shades on its depth |
| Reflections | SSR with 42 m rays, added to the finished image at half strength; sky glints painted into materials | Hi-Z SSR with 150 m rays at half resolution, read by the material as indirect specular |
| Bounced light | None. GTAO darkens the lit image | SSGI at half resolution, read by the material as indirect diffuse |
| Sky light in a street | Darkened by a function of height above the street | Darkened by how much sky the pixel sees over the skyline, from a height map |
| Reflections on the player's vehicle | The sky | A cube map captured at the vehicle |
| Anti-aliasing | MSAA | TRAA |
The frame#
The rest of this post takes one frame apart. This is the frame, a side street in Midtown at golden hour:

The three.js build is the branch behind bhouston/three.js#188, which carries the prototype of the indirect lighting lists and the SSR changes this frame depends on.
1. The pre-pass#
The frame starts by drawing the opaque geometry without shading it. The pre-pass writes what the screen-space passes need: depth, an octahedral normal in two channels, roughness and metalness, and motion vectors.
const prePass = pass( scene, camera ); prePass.setMRT( mrt( { output: opaqueFragment( packNormalToOctahedral( outermostNormalView ) ), metalrough: vec2( outermostMetalness, outermostRoughness ), velocity: vec4( velocity, 0, previousViewZ ) } ) );

The roughness image shows the puddles as dark patches on the road and the taxi as nearly black. The normals and the two material values are those of the outermost lobe: the clearcoat where a material has one, the base layer elsewhere. That is the surface a reflection ray leaves from.
No overdraw. The beauty pass shares the pre-pass's depth buffer and does not clear it:
const beautyPass = pass( scene, camera, { depthTexture: prePass.renderTarget.depthTexture, autoClearDepth: false } );
Every hidden fragment now fails the depth test before its shader runs, so each pixel is shaded once. That matters more here than it did in the original, because a fragment now reads SSR, SSGI and the sky visibility on top of a clustered light list.
Two things had to change to make that work:
- Vertex positions had to be invariant. The pre-pass and beauty shaders of a material differ in everything except the position, and the compiler was free to round the two differently. Sidewalks and some buildings lost fragments to their own depth and flashed under the TRAA jitter. WGSL's
@invarianton the position fixed it. - Alpha-to-coverage became an alpha test. Without MSAA there is no coverage mask, so the park fences drew as solid walls. Leaves, fences and fire escapes are cut out at half coverage, in both passes.
The pre-pass is not free. It is a second traversal of the scene, and in this scene the traversal is the expensive part. I come back to that under "What it costs" below.
2. Motion vectors for people and fire escapes#
TRAA, and the histories of SSR and SSGI, all reproject through the motion vectors. Wherever those are wrong, the history is rejected and the pixel is left with a single noisy sample.
Two kinds of object in this city move their vertices in the vertex shader, where the built-in velocity cannot see it. The pedestrians skin themselves in their position node, so their velocity was measured against the bind pose at the origin. The fire escapes are lifted into place after their instance transform, so theirs was measured from the vertex before its lift. Both showed up as shimmer.

The fix is the same in both cases: compute the previous position the way the current one is computed. Each crowd keeps the bones every person was last drawn with, and the pass that writes motion vectors skins the vertex with those as well. The fire escape applies its lift to positionPrevious too. After the fix, the only motion in the image is the pedestrians' own stride.
3. The previous frame#
SSR and SSGI need a lit image to gather from, and this frame has not been lit yet. They read the previous frame's TRAA output instead, reprojected into this frame, in linear HDR before bloom and tone mapping. A mip chain on it serves the wide cones of rough reflections.

Validity is zero for the sky and wherever the reprojected pixel fails its depth check, here the pedestrians and some of the leaves. A ray that lands there gets no coverage, and the next source in the list answers instead.
4. Screen-space reflections#
The pre-pass buffers are downsampled once, depth-aware, and SSR, SSGI and the sky visibility all work from that half-resolution copy, as proposed in mrdoob/three.js#35641. SSR traces one GGX-distributed ray per pixel through a Hi-Z pyramid, shares rays between neighbouring pixels, and reads each hit as a cone from the mip chain:
const ssrNode = ssr( previousBeauty, lowDepth, lowSceneNormal, { camera, stochastic: true, metalnessNode: lowMetalRough.r, roughnessNode: lowMetalRough.g, tracing: 'adaptive', // Hi-Z coneTracing: true, rayReuse: true } );
Ray reuse filters over space, so there is no spatial denoiser. The result is accumulated over up to 16 frames and brought to full resolution with a joint bilateral upsample.

The output is radiance and coverage, and nothing else. SSR applies no Fresnel and samples no environment map. White in the coverage image is where a ray hit something on screen. The taxi's roof and the tops of the buildings are black: their reflections point at things the screen does not hold.
With SSR in front of the environment map, the puddles stop reflecting an open sky that the street cannot see:

It is clearer at night in Times Square, where the brightest things in the frame are on screen:

5. Screen-space global illumination#
SSGI runs at the same half resolution from the same previous frame. One horizon search per pixel, 4 slices of 32 steps over a radius of 32 m, returns the light of the directions the screen blocks and how much of the hemisphere stays open.
A few samples per pixel are far too sparse to use directly. They go through an edge-aware blur, two à-trous passes guided by depth and normals, and are then accumulated over time and upsampled like SSR.

The warm light on the shopfront at the left is the lit sidewalk bouncing onto it, which the original had no way to produce. The fourth panel is not applied as AO. One minus it is the source's coverage: where SSGI found a surface in 40% of the directions, the sources behind it light the other 60%. Darkening the result by AO afterwards would count the same corner twice.
In the finished image its effect in this frame is small: contact darkening under the taxi and along the kerbs, and some warmth on the walls beside lit ground.

6. Sky occlusion#
The last source in the diffuse list is the environment, and here the environment is the sky. In a street canyon most of the sky is hidden, and SSGI cannot say so: its radius is 32 m and the buildings are 200 m tall.
The original handles this with a function of height: about a third of the sky at the pavement, rising to all of it at 68 m. It is the same on a narrow street and on a wide avenue.
The fork draws the buildings into a top-down height map when the city loads: 2 m texels over a 4 × 16 km area, with a max-mip pyramid so that a far step cannot miss a thin tower. A half-resolution pass then finds the horizon in 16 compass directions around each pixel, 13 steps each from 4 m to 256 m, and integrates the cosine-weighted sky above it in closed form. It is the slice integral of GTAO, run over the city in place of the depth buffer.

It goes into the diffuse list as a source like any other. Its coverage is the share of the sky the buildings hide, and its light is what those buildings bounce: the ground colour of the time of day's hemisphere light, one colour for every direction. That is a single bounce and a crude one, but it replaces sky light with building light, where the canyon AO replaced it with black.

7. The hero probe#
SSR has nothing to say about the player's own vehicle. Its roof reflects what is above and behind the camera, and none of that is on screen. In the original it reflects the sky, even in a street where the sky is a strip between two walls.
The hero probe is a 128² cube map captured at the vehicle, with the vehicle hidden. It updates one face per frame, and reuses the frame's shadow cascades, since three.js would otherwise fit and draw them again for each face's camera.

It is a source in both lists, behind SSR and SSGI and in front of the environment, and only the meshes of the player's vehicle receive it. Everything else is too far from the probe's centre for its reflections to be right.

The cube's plain mip chain stands in for a GGX prefilter. That is good enough for a clearcoat and wrong for anything rough.
8. The beauty pass#
Everything above exists so that this pass can shade each pixel once, with all of it available. The two lists are set on the pass:
beautyPass.contextNode = builtinIndirectContext( { specular: [ ssrSource, heroSpecular ], diffuse: [ ssgiSource, heroDiffuse, skyOcclusionSource ] } );
Each material resolves the lists in its own shader. A source's light is added, scaled by what the sources before it left uncovered, and the environment fills whatever remains. The result goes through the material's BRDF like any other light.
The fork can show what the lists resolved to, taken from the shaders themselves. Indirect specular, one source at a time:

And indirect diffuse, shown as a white surface would reflect it:

Switching the sources on one at a time, starting with the sky occlusion, which changes the look the most:

What the materials had to become#
A list can only feed a lobe that exists. The original's materials were built for a renderer with one reflection source, so they carried their own: the car paint was a metal with sky and sun glints painted into its colour, the puddles had an emissive copy of the sky and the neon, and the Chrysler crown had the sky mixed into its albedo. With SSR resolved in the BRDF, each of those was a second reflection added to the real one.
So the reflective materials moved to MeshPhysicalNodeMaterial, with each layer as a lobe of its own:
- Vehicle paint and bus livery: a rough dielectric base under a glossy clearcoat.
- Wet road and sidewalk: the water is a clearcoat over the asphalt.
- The rivers: a dielectric with the IOR of water.
- Clothing: a sheen lobe.

This is why the pre-pass writes the outermost lobe. SSR's buffer holds one answer per pixel, and on a clearcoated surface the coat is the reflection worth tracing. The prototype in Part 5 had per-pixel sources answer only the base lobe; this scene needed them to answer the clearcoat.
9. TRAA and the rest#
TRAA resolves the beauty pass with the pre-pass's depth and motion vectors. It is the only anti-aliasing in the frame, and its output is what the next frame's SSR and SSGI read.

The scene renders at full resolution, with no upscaler after TRAA. Bloom, grading and ACES tone mapping follow, unchanged from the original.
What it costs#
On an Apple M3, in Chrome at 1920×993, the fork runs at about 30 fps, and the limit is the CPU. This is where the time goes, from a profile of the branch:
| Render call | Draw calls | CPU ms |
|---|---|---|
| Pre-pass | 778 | 9.4 |
| Beauty pass | 778 | 8.7 |
| Hero probe, one cube face | 544 | 6.7 |
| Shadow maps, 2 cascades | 372 | 2.4 |
| All post effects, about 30 full-screen passes | 30 | 1.8 |
SSR, SSGI, the denoising, TRAA and bloom together cost about a fifth of one scene render in CPU time. Rendering nine times fewer pixels raised the frame rate from 30 to 35 fps. What the frame pays for is submitting 2,500 draw calls from JavaScript, across three renders of the scene and its shadow maps.
So the pre-pass buys its fragment savings with 778 more draw calls, and on this machine that is a poor trade. I have not measured what it saves in shading. The hero probe costs about a fifth of the frame for the reflections on one vehicle. Both point at the same work: fewer draw calls for each scene render, through batching and culling, which is a different project from the lighting.
What this proves, and what it does not#
The lists held up. Five sources go into two lists in one call. The sky occlusion was added last, as one more entry in the diffuse list, and no material changed to receive it. The resolved-light outputs used in this post came out of the same mechanism: a source that answers nothing and notes what the shader resolved.
Coverage was the right contract. Every hand-over in this frame is a coverage: SSR to the hero probe to the sky, SSGI to the sky occlusion to the sky. Each source could be switched off for these screenshots by scaling its light and coverage together, and the sources behind it filled in.
The materials are part of the work. Most of the visible difference in Times Square comes from removing reflections that were painted into materials. A renderer that offers a way in for reflections also has to stop materials from faking them.
What it does not show:
- The indoor pipeline. There are no lightmaps, no probe grid and no reflection probes here. The sky occlusion and the hero probe stand in for them outdoors.
- Occlusion applied per source. The hero probe and the environment's specular are not occluded.
- A correct fill for the hidden sky. One bounce colour for a whole city is a placeholder.
- A frame rate. 30 fps on a laptop is a proof of concept. The main slowness in this example is the large number of draw calls it takes to render the scene. That cost is paid three times a frame: in the pre-pass, in the beauty pass and in the hero probe's cube map capture. The screen-space lighting itself is a small part of the frame.
Try it at slop-nyc-enhanced.ben3d.ca. The gear button opens the inspector, where every buffer in this post is an entry in the Show list and each source has an intensity slider. The capture button saves a lighting breakdown like the one above from wherever you are standing. The code is the ssr-brdf branch of my fork.
Thank you to mrdoob for the city, and for publishing it in a form that invites this.