Blog » gg, weeks 8 to 11: a pond, fog, night, and a month on a laptop

Four weeks on a laptop with an integrated GPU: the pond gets a surface, fog becomes a medium, the goldens leave git, and night stops being black.

I spent the last four weeks travelling. The desktop and its 3070 stayed home, so everything in this post was built and measured on the Meteor Lake laptop the quality tiers exist for. Its GPU is integrated and every pass costs several times what it does at home, which turned out to be useful: a mistake that hides in the noise on the 3070 is hard to miss here.

It also means none of this has run on the machine I normally use. I'm home again now, and there's a list.

Water, part 2

Part 1 ended with a pond-shaped hole and no water in it. It has a surface now.

a pond at noon ringed with yellow reeds, lily pads on dark water, a stream running in behind

The demo basin's pond. The reeds grow where part 1's depth window puts them, the lily pads sit on the still surface, and the stream feeding it is a carved river.

The scene pass splits at the sky now. Opaque geometry draws first and gets copied aside, and the water refracts into that copy, absorbing and scattering light along the path down to the bed and back. There are no waves yet, and it only reflects the sky.

The first version refused every refraction tap, and finding out why took ninety minutes. The frame sits inside a larger padded target, and with the new shader reading the scene copy by uv, every tap read the wrong pixel and failed its depth check. The refraction's debug view was the one view that had been put off, and when it finally existed it showed the whole pond as refused in its first frame.

Write the debug view first. A feature that draws an image has an intermediate, and a broken intermediate usually composes into something that only looks a bit off. You need the view to tune the feature anyway.

The plan also left out that light leaving water gets divided by the square of its refractive index, and the pond came up 1.78 times too bright.

The first build read the water table behind a branch in every lit surface shader, and with no water anywhere that cost 7.6% of the scene pass. That read is now a second flavour of each pipeline, and a frame with no water in view pays nothing.

Goldens, out of git

Last post the golden images were eating the repository and I had a plan I hadn't committed to. It's done. The images are release assets named by their digest, and git holds one manifest per device with a case name and a SHA-256 on each line. Re-recording three cases is a three-line diff and three uploads.

The per-device part is new. The comparator is close to bit-exact by design and two rasterisers disagree by whole percentages, and a tolerance wide enough for both would stop seeing real regressions. So a baseline belongs to the device that drew it: there's a lavapipe set for CI and one for this laptop's GPU.

The laptop records its whole set in a minute and a half. Lavapipe needs an hour for the same frames, so I stopped running it here, and that set is four weeks stale now. CI will be red on it until it's re-recorded.

Leaving git cost me the before-and-after view my git client gave me for free, and a script builds that page now: every case that moved, side by side, with a flip, a swipe and an amplified difference.

An integrated GPU

The scene colour target went from sixteen-bit floats to B10G11R11, since nothing reads its alpha and the smaller format halves the attachment. The first build failed a good few goldens, because every frame had gone slightly darker: by less than one pixel's tolerance, and by enough to fail the mean. It turns out Intel's driver truncates when it stores into that format, and so does lavapipe. Every scene colour is now rounded to the format's grid in the shader before it's written, and here that costs as much as the format saved in the scene pass.

No Vulkan query reports whether a device rounds or truncates, so the renderer draws one colour three quarters of the way between two steps and reads back which step it got. A device that rounds gets the shader's rounding compiled out. I assume the 3070 is one of those, and I'll know this week.

Mesh shaders went the other way. Last post's table had them winning on the ridge, and on the laptop that arm ran at 348 ms a frame. Mesa's Intel driver charges vkCmdDrawMeshTasksIndirectCountEXT for the maximum count it's handed, whatever count it then reads, and a region's maximum is its whole capacity, nearly all of it empty. A mesh region is now a single launch through a task stage with that call gone, which brought the frame down to 47.5 ms. Cooked index ranges still draw it in 38.6, so automatic declines mesh shaders on that driver and the 3070 keeps them.

The laptop's packaged validation layer is too old for Vulkan 1.4, so nothing here had been running under validation. With a current SDK installed it found five defects in a day, and one of them had been on screen the whole time: since the Vulkan port the window had been showing the frame squashed, with a margin beside it, because the present blit copied the whole padded target. Every test renders offscreen. Oops.

And this driver draws a stray triangle. One or two frames in a hundred carry a triangle whose vertices belong to something else in the scene, and as far as I can tell it isn't mine. The mesh path never does it, and the visual tests set a driver option that halves it.

The air

The demo basin is too small to hold weather, so weather got a scene: the village on two kilometres of ground that climbs to a ridge. Rain or snow is now decided by the air at each surface's height.

a few houses on a plain under a clear sky, and behind them a ridge that turns white above a sharp line

The snow line sits where the air is at one degree.

The clouds used to drift by adding the wind up frame by frame, which left no way to work out where the rain was at a given hour. Now the drift is the wind integrated over game hours from the start of the year. Rain at a point is a pure function of the clock that a game can ask for across the C ABI, and the ground under a passing shower is wet where the shower has been. The price is sensitivity: by day 268 a change of 0.2 mm/s in the wind moves the sky four kilometres. I can live with that.

While I was in there I found the clouds moving upwind. Every cloud texture was sampled at position plus drift, so the sky went one way while the trees bent the other, and nobody had noticed, me included.

The bigger change is the air itself. The exponential haze is gone, and one froxel volume replaces it in every sky mode. Everything that fills the air goes through it: a ground fog layer, fog volumes, the rain's veil, lamps lighting the mist around them, and a rainbow. Fog forms the way radiation fog does. It needs damp ground, still air and a clear sky, builds from evening through dawn, and burns off once the sun is high enough.

a dark rain cloud over a plain between two hills, with a full rainbow under it

The bow is geometric optics through a drop, convolved by the sun's disc. The primary sits at 42.4 degrees with red on the outside.

The fog march cost 14.6 ms on the laptop when it first worked. Stopping it from asking shadow cascades it had already left, then halving its steps per slice, took it to 6.8, and I couldn't tell the frames apart. The plan budgets 0.6 ms on the 3070, and I don't know yet whether it gets there.

A forest

Foliage got a scene too: a kilometre of wood with about nine thousand trees in it.

the edge of a wood across a meadow, green conifers mixed with red and yellow broadleaves

The wood from its meadow.

A tree made of leaf cards is lit as a pile of cards, each facing wherever it happens to face. The cook now bends a crown's normals toward an ellipsoid fitted over it, and the tree is lit as one volume. It also bakes an occlusion term per vertex by rasterising the model from many directions, which darkens the cards deep in a crown. Neither adds anything I can measure to a frame. Distant crowns thin out by dropping whole cards, with the survivors' alpha scaled up to make up the area that went.

Leaves also glow when the sun is behind them. The first version put a select on the shadow lookup of every lit surface, and it cost 4 to 8% of the scene pass on scenes with no leaves in them at all. Eighteen goldens had been re-recorded for it before that number existed. Backed out. It came back as a pipeline variant that only transmissive materials use, and a scene without leaves pays nothing for it.

Pro-tip: Measure a shader change against the shipped module before you record a single frame for it. A golden tells you the image is right. It has no opinion about what the image cost.

The review

At the end of September I stopped adding things. The engine had grown fast for two months and too much of it was sized to whatever got the demo scene working. So the whole codebase went through a review with one question: is this the implementation a real engine would ship? It came back with 190 findings, and working through them took most of two weeks.

The embarrassing one was normal maps. The cook generated tangents with the wrong handedness for any mesh that didn't author them, and those meshes read a normal map's green channel upside down. Then there were the packs, where most of the village kit's normal maps are authored green-down and one ships with red and green swapped. A PNG doesn't record which way up it is. The pixels do, though. A normal map baked from a surface is the gradient of a height field and has no curl, so the pack builder now reads each map four ways, takes the reading with the least curl, and warns when that disagrees with what the map claims to be.

the same village view twice, the right one brighter with clearer relief on the roof tiles

The village before the review and after it. The roof tiles catch the light the right way up, the tonemap rolls saturated highlights toward white, and the scene meters its exposure.

Some of the rest:

  • The ACES curve was Narkowicz's fit. It's Hill's fit of the RRT and ODT now, with middle grey held where it was.
  • A negative scale mirrors an entity properly, with winding and tangent frames following it.
  • Undo has a byte budget.
  • A game can run a parallel-for on the engine's worker pool.

Night

I opened the demo, dragged the clock to midnight and got a black screen. No sky, no moon, nothing. The renderer could draw a night, but the demo scene had a fixed exposure of 1.0, and a full-moon night wants about 116.

Turning on metering and rod vision fixed midnight and broke dusk. Rod vision is one blend over the whole frame, keyed on the metered luminance, and the first band made dusk look like a black-and-white filter with one vivid red tree left in it.

the village at dusk twice: grey with blue-white lamps on the left, in colour with warm lamps on the right

Dusk under the first rod-vision band, and under the one that shipped.

The catch is that a moonlit night meters brighter than late twilight, and no band on that number can grey the night without greying twilight first. I took a low band and capped the exposure.

Then the two bodies. One of the sun and the moon used to drive both the direct light and every scattering table, so the sun's twilight glow vanished the moment a risen moon outshone it at the ground. Both scatter now, and the direct light goes to whichever delivers more.

The last piece was how much the cloud layer dims the ambient. That was measured along the light, and since a slanting moon shines through more cloud than sits overhead, it's measured straight down now.

the village at midnight twice: black except for two lamps on the left, moonlit roofs and path on the right

Midnight under a full moon, before and after that last change.

Stars glow again as well. The bloom's first level weights by luminance to kill fireflies, and that weighting threw away nearly all of a star's light. Stars now draw a second time straight into that level.

Hitches

A game can now ask for assets before it needs them, and the feature was the easy part.

  • The frame that first touched a new allocator block paid to populate all of it. Blocks are smaller now, and the arenas exist before anything asks for them.
  • One buffer copy was slow to record, because Mesa's Intel driver searches for a way to factor a copy's length and some lengths take a while. Copies go out in spans it resolves at once.
  • Spawning a thousand parented entities in one tick took 82 ms. It takes 0.7.
  • Releasing a sculpt stroke re-cooked the water whether or not the stroke had been near any. A release on dry ground went from 95 ms to 31.

Where it stands

The pond has a surface, the air is a medium, the forest is lit like a forest and night looks like night.

None of it has run on the 3070, though. The lavapipe baselines are four weeks behind, a lot of the device tests have only run on Intel, and half the costs in this post want a second column. That's the first week back, and after that it's waves, then the clouds. The traversal slice still hasn't started.

Credits

Everything in these shots that isn't engine is bought or borrowed:

  • The buildings, props, trees, foliage and rocks are Quaternius kits: the Medieval Village and Stylized Nature MegaKits, bought as the paid source versions, plus the free Ultimate Stylized Nature set. All of it is released CC0, and he takes Patreon support.
  • The ground materials are Poly Haven textures, CC0.
  • The type is Inter by Rasmus Andersson, under the SIL Open Font License.