whoelsebut.me

← Writing/Graphics / Godot

How to Shatter an 18-Triangle Floor

Turning 694,542 triangles of pre-broken stone into nine rectangles—without losing the mortar, the tumbling rubble, or the lighting.

In Erebus’ Maw, the opening screen is calm. You’re looking down at a torchlit stone courtyard, deciding where to place your first miniature before a fight begins. Nobody has swung a weapon. Not a single flagstone has cracked.

Yet if you freeze that frame and turn off the floor node, 694,542 camera triangles vanish from the render queue—along with 1.26 million shadow-pass triangles.

We had originally modeled the floor out of the shards it would later shatter into. That made our first crater wonderfully straightforward to program: pick a cluster of chunks, toss them into the air, reveal the dark rock underneath. The catch was that every quiet planning screen paid full freight for future destruction. Each of the courtyard’s 245 tiles came pre-sliced into four fracture sectors—980 pieces in all—and every piece carried a full set of vertical cut walls and a sealed underside. Together, buried cut walls (250,800 triangles) and buried undersides (222,950 triangles) accounted for roughly 68% of the floor’s camera geometry. A watertight bottom looks great when a slab flips end over end in front of the camera. While the floor is closed, it is an absurdly expensive way to render the dark.

Here is the same opening frame before and after the rebuild. On the left, hiding the paving removes 694,542 camera primitives. On the right, it removes 272—only 18 of which draw the entire playable surface.

Side-by-side comparison of the original 694,542-triangle paving and the compact 272-triangle replacement
Left: 980 pre-fractured stone sectors. Right: an 18-triangle top surface with 254 triangles of rim, walls, and stone bed underneath. Look closely at the lit mortar seams and contact shadows—the macro composition holds, with small, measurable pixel differences.

Getting from the left frame to the right wasn’t just a mesh decimation pass. It meant faking carved stone depth across flat triangles, swapping the entire world out from under the player the millisecond a single rock lifts off the ground, and tracking down a lighting bug that looked spotless in every still screenshot—right up until the first stone moved.

Why batching (and half-measures) weren’t enough

We were already instancing those fracture sectors with Godot’s MultiMesh. That cut CPU draw-call overhead, which is nice, but instancing doesn’t make triangles free: every visible instance still pours its full index buffer through the vertex stage, and Godot culls a MultiMesh as a single bounding volume rather than piece by piece.

Worse, our courtyard isn’t lit only by a single moon. A shadow-casting brazier sits right on the stone. Point lights render into a six-face shadow cube, so geometry hidden from the camera can still get submitted multiple times to the shadow atlas. In a pre-optimized scene, one floor mesh can show up in the camera pass, the directional shadow pass, and several faces of the brazier’s cube map on the very same frame.

Before tearing the floor down to studs, we tried the sensible, conservative fix: keep the original high-resolution displaced top surface and outer perimeter wall, and only expose internal cut walls and undersides once a sector actually lifted.

That shell dropped the whole scene’s camera count from 1,072,816 down to 606,778, and in a frozen comparison only 55 pixels differed (just six by more than two channel levels out of 255). A variant that kept tile-edge walls stalled at 710,586.

That experiment drew the real dividing line. Stripping buried faces bought us a respectable win while changing almost nothing visually, yet we were still pushing hundreds of thousands of triangles to draw a flat octagonal slab. If we wanted the floor out of the profiler’s way, we had to replace the intact surface with the geometry the player actually sees—and earn back the stone relief in the shader.

Nine rectangles

Look at the arena from straight above. The courtyard is a chamfered grid of 15 rows. Counting tiles across the board from top to bottom gives:

11, 13, 15, 17, 19, 19, 19, 19, 19, 19, 19, 17, 15, 13, 11

Sum those widths and you get all 245 tile positions. Now merge any neighboring rows that share the same left and right edges. The seven middle rows collapse into a single rectangle; each of the four tapered rows on either end needs one strip of its own.

Nine rectangles. Eighteen triangles.

Plan view comparing all 245 individual tile positions on the left against the 9 merged rectangles and 18 triangles on the right
Same 245-tile footprint, two very different vertex buffers. Left: every tile addressed individually. Right: nine merged strips forming an 18-triangle crown.

Our offline baker walks the rows in order, closing a strip whenever the next row’s half-width changes, then traces the outer perimeter to extrude vertical rim walls (136 triangles) above a beveled plinth and dark recessed stone bed (118 triangles). Tilt the camera low and the diorama still has thick masonry edges; blow a crater through the center and you still stare down into solid bedrock rather than the void.

All told, the baked paving resource—which bundles the intact sheet, a single closed tile, the stone bed, 16 seated fracture variants, four flying rubble meshes, and a relief texture—shrank from 1.38 MB down to 130 KB (and later to 101 KB after a second pass on cut walls).

Carving mortar back into flat triangles

Here is the problem with flattening a displaced stone floor: a normal map can bend how light reflects off a groove, so a static overhead shot looks fine. Orbit the camera, though, and the illusion collapses. On real displaced masonry, deep mortar seams slide slightly behind the lip of the stone as your viewing angle drops. On a flat textured plane, the cracks stay glued in place like printed linoleum.

We needed view-dependent parallax—specifically, parallax that matched the chunky, pixel-painted look of the original floor rather than turning it smooth.

Our floor texture is adapted from ambientCG’s Tiles 130 (CC0 1.0), spanning 12.8 × 6.4 court units across a 160 × 80 paint grid—an exact 0.08-unit painted cell along both axes. Alongside the color map, we pack normal X/Y, roughness, and height into a single RGBA relief texture.

On the old dense floor, every 0.08-unit paint cell was split diagonally into two displaced triangles, pulled downward by up to 0.12 court units along the mortar lines. To reproduce that exact stepped geometry on an 18-triangle sheet, the baker precomputes the four corner depths (northwest, northeast, southeast, southwest) of every paint cell—averaging adjacent height texels with seamless wrap—and packs all four corners into one RGBA texture.

Inside the fragment shader, given fractional coordinates (x, y) within a cell, we reconstruct height using the same diagonal two-triangle split rather than bilinear interpolation:

float w_nw = 1.0 - max(x, y);
float w_ne = max(x - y, 0.0);
float w_se = min(x, y);
float w_sw = max(y - x, 0.0);

Because those four weights sum to one and zero out the opposite corner on either side of the diagonal, every cell behaves like the exact pair of sloped planes the dense mesh used to draw.

With the height field reconstructed, the fragment shader steps the view ray downward through the 0.12-unit relief band in six probes. As soon as the ray dips below the reconstructed stone surface, we linearly interpolate between the current and previous probe and shift the horizontal texture lookup to that crossing point. Straight overhead, the horizontal shift is tiny; at grazing angles, mortar edges visibly recess behind neighboring flagstones.

That six-step search wasn’t free. On an Apple M1 Max, it cost an extra 0.237 ms during placement and 0.495 ms mid-fight compared to a flat-mapped compact sheet. In return, mean RGB error against the original dense floor dropped by more than half, from 1.687 down to 0.794 levels out of 255. Spending a quarter of a millisecond to keep the mortar believable across the entire arena was an easy trade.

Swapping the floor out from under a flying rock

An 18-triangle sheet has one glaring flaw: you can’t punch a jagged hole in the middle of it.

The trick is not to try. The intact sheet only draws when every single stone is at rest. The instant any chunk leaves its socket, we hide the 18-triangle sheet completely and switch to an instanced representation:

  • Every untouched tile renders from a preallocated MultiMesh pool of closed single-tile meshes.
  • Every partially broken tile renders only its remaining seated sectors from a bank of 16 meshes (four fracture sectors × four even/odd tile parity phases, needed because a 1.0-unit tile is 12.5 paint cells wide).
  • Every airborne chunk renders from four flying-rubble MultiMesh banks, rebuilt each active frame with updated tumbling transforms.
The moment the first two stone chunks lift off the courtyard floor
First lift: 79 fracture motions are queued in the scheduler, but the sheet stays intact until this exact frame—when the first two sectors tick past zero flight age.

One small timing detail saved us from an ugly pop. When a heavy attack lands, our fracture scheduler queues dozens of sector lifts with staggered delays so shockwaves ripple outward across the stone. In our test fixture, the scheduler holds 79 queued motions before a single rock actually moves. If you swap away from the sheet when motions are scheduled, you trigger the pool transition early under an unbroken floor. Instead, we hold the 18-triangle sheet until at least one sector’s flight age turns strictly positive.

Managing which tiles are closed uses a classic swap-and-pop dense prefix:

  1. Every closed tile lives in the active prefix of the closed-tile MultiMesh buffer, tracked by a slot index.
  2. Suppose slots 0..3 hold tiles A, B, C, D, and a chunk breaks out of B.
  3. We move the last active tile (D) into B’s slot, update both slot mappings, and decrement the MultiMesh’s visible_instance_count by one. The active prefix is now A, D, C.
  4. If a second chunk lifts from B, its airborne counter simply increments from 1 to 2—it’s already out of the closed pool.
  5. Once B’s final airborne chunk bounces and settles home, B appends back onto the end of the active prefix. When zero tiles remain open, the closed pool yields back to the 18-triangle sheet.

Gluing paint to tumbling stone

When a rock vaults into the air along its 4t(1 - t) parabolic arc and somersaults past the camera, its top surface has to stay painted like the exact patch of flagstone it broke out of. Sample the chunk’s current world coordinates and the floor texture swims across the rock like a projector beam.

Instead, every flying instance carries a compact coordinate stamp—((x + 10) / 32, (z + 8) / 32)—packing its home tile coordinates. The shader unpacks that stamp and adds the sample’s local horizontal offset to recover its original socket on the courtyard. Rendering and lighting use the live tumbling transform; top pigment and relief stay bolted to the home socket. Meanwhile, exposed cut walls and undersides sample a separate fractured-stone lookup keyed by local cut coordinates, so a flipping slab shows pale sheared rock underneath and weathered flagstone on top.

Gray stone is great at disguising off-by-one UV bugs. To verify our addressing, we swapped in a screaming diagnostic pigment chart during motion so a single misaligned cell would jump right off the screen:

Top-down diagnostic paint chart showing exposed green stone bed inside an active crater surrounded by high-contrast patterned cells
Diagnostic render during an active crater. Bright green masks the exposed stone bed; the high-contrast grid lets an automated check decode the exact sampled address of every resting and airborne piece.

The bug that every intact screenshot missed

At this point we had a working compact floor, parallax mortar, and swap-and-pop craters. Our opening-frame comparison against the original dense floor came back clean: a mean channel difference of 0.88 / 255.

Then we ran the crater comparison—and the error exploded to 12.22 / 255. Out of 921,600 pixels in a 720p frame, 372,949 shifted by more than 16 levels. Nearly half the screen had gone wrong because of a crater in the upper-right corner.

Broken closed-tile instance lighting showing a displaced circular light pool on the left half of the arenaCorrected closed-tile lighting at the exact same crater frame
Top: the broken build at active crater—notice the bright circular pool of light floating detached across the left side of the courtyard. Bottom: the exact same frame after fixing the light receiver offset.

Look at the top image. A giant circular pool of warm light has detached itself from the brazier and slid across the left side of the courtyard like a stray theatre spotlight.

The bug came down to confusing three positions that every parallax-mapped shader has to keep straight: where the fragment was rasterized, where its paint was sampled after raymarching, and where it should receive light.

On the intact 18-triangle sheet, the mesh sits at the courtyard’s origin, so deriving a light receiver position from court coordinates happened to land in the right spot. The moment the first chunk lifted, however, the sheet hid and the closed-tile MultiMesh took over. For every tile in that pool, Godot’s view-space VERTEX already included the tile’s per-instance translation. Reconstructing a fresh light position from court coordinates double-applied (or mis-transformed) that offset—causing every untouched tile in the courtyard to ask the renderer for lighting at the wrong address.

The fix was disarmingly simple: never rebuild the view-space position from scratch. Start from the rasterized view-space VERTEX that Godot already gave you, compute only the small delta from the court-space raster point to the parallax-shifted receiver point, transform that delta into view space, and add it on.

One bug fix, and the numbers snapped into line:

Candidate buildPlacement (/255)Crater (/255)Crater px > 16Overlap (/255)
First compact pass (flat mortar)1.841.4132,6111.31
Parallax mortar + instance-lighting bug0.8812.22372,94911.26
Receiver delta fix0.880.539,3780.47
Final floor release (revised bed)0.880.549,6910.49

If we had only checked intact screenshots, that bug would have shipped straight into combat.

Testing the ugly states (and chasing down a noisy tail)

Normal play is terrible at catching state-machine edge cases, so we built a deterministic eight-state capture fixture across four camera angles:

  1. Still (0 motions, 0 airborne, 0 open tiles)
  2. Pending delay (79 queued motions, 0 airborne, 0 open tiles—proving we don’t swap early)
  3. First lift (2 airborne in 2 open tiles—exercising the sheet-to-pool handoff)
  4. Active crater (79 airborne across 33 open tiles)
  5. Overlap (a second shockwave hits mid-crater: 141 queued, 91 airborne across 35 open tiles)
  6. Partial landing (tile (4, 0) regains one sector—its open bitmask drops from 3 to 2—at the exact moment newly delayed pieces raise total airborne sectors to 140 across 51 open tiles)
  7. Natural settlement (everything lands back into 0 open tiles)
  8. Forced reset (instant state wipe)
Side-by-side comparison of overlapping crater and buckling impacts, dense floor on the left and compact floor on the right
Overlapping impacts: dense reference on the left, compact floor release on the right. Only 0.89% of pixels cross the 16/255 threshold.

Across all eight states, the green exposed-bed silhouette matched the dense reference exactly, the diagnostic pigment probe decoded the right coordinates on all 18,271 resting and 12,964 active samples, and letting pieces settle on their own—or forcing a hard reset—brought back the exact opening frame at every camera angle.

Measuring frame times honestly

For performance, we ran paired replays in Godot 4.6.1 (Compatibility renderer, 1280×720, VSync disabled, fixed 60 Hz simulation step, dummy audio) on an Apple M1 Max. The short floor-only sweep confirmed massive geometry savings—placement dropped from 1,072,816 → 378,546 camera primitives (−694,270) and 1,915,876 → 656,002 shadow primitives (−1,259,874), cutting median frame time from 9.21 → 7.09 ms. Interestingly, in the frozen crater test we shaved nearly 670,000 camera triangles while removing just one draw call (222 → 221)—proof that raw triangle volume inside shared draws, not call count, had been the culprit.

But those quick 36-frame sweeps also spat out an uncomfortable anomaly: 95th-percentile frame times actually rose on the frozen crater (6.66 → 9.09 ms) and tutorial handoff (9.60 → 11.44 ms). Rather than hand-waving a noisy short run, we built a longer steady-state harness—90 warmup frames followed by 360 measured frames across three alternating trials (1,080 measured frames per build and scene)—and added a punishing repeated-impact loop that triggers a crater every 120 frames and a buckling fault 16 frames later, hammering slot swaps and MultiMesh updates continuously.

Bar chart comparing median frame times on M1 Max between original sectors and compact floor across four steady scenarios
Steady-state floor trial (1,080 frames)Median (before → after)p95 (before → after)
Placement9.23 → 7.01 ms9.96 → 8.62 ms
Held crater7.48 → 5.31 ms7.94 → 5.86 ms
Repeated overlapping impacts8.77 → 6.46 ms9.64 → 8.25 ms
Tutorial with retained campaign8.53 → 6.37 ms9.67 → 7.45 ms

With proper warmup and alternating runs, both medians and 95th percentiles dropped decisively across every single workload—roughly 2.1 to 2.3 ms saved per frame, even while continuously shattering and rebuilding the board.

One last trim on the cut walls

Later, after we optimized the rest of the arena’s scenery and miniatures, partially broken tiles floated back to the top of the profile. Each seated cut wall still consisted of four stacked rows of polygons just so each vertical pixel row could hold its own paint and light receiver—even though all four rows lay on the exact same vertical plane.

We collapsed each horizontal interval down to a single quad and moved the row selection into the fragment shader: interpolate the local crown and raster heights, compute (crown_height - raster_height) / (crown_height + 0.20), multiply by 4, floor it, and snap to the row center (-0.025, -0.075, -0.125, -0.175). On the already optimized scene, that trimmed frozen craters from 80,278 → 70,066 camera triangles and fresh shadow updates from 530,824 → 459,340, with only six crater pixels shifting past 16/255.

What happened once the floor stopped shouting

One trap in performance write-ups is comparing the first prototype against the final shipped build and letting a single feature take credit for six months of work. Keeping each milestone attached to its own baseline makes the real story much clearer:

Opening placement, whole sceneCameraShadowCombined
Early dense court (before dedicated depth meshes)1,187,5044,823,6446,011,148
Dense floor + shadow bake (floor baseline)1,072,8161,915,8762,988,692
Compact floor + original props378,546656,0021,034,548
Final painted hulls + final paving15,71442,38458,098

Once the floor dropped from 694,542 camera triangles to 272, the remaining 378K triangles belonged to scenery, miniatures, and gear—built from the same old one-quad-per-painted-sample workflow. Rebuilding those into fitted low-poly hulls with baked paint textures brought the entire opening frame down to 58,098 combined submissions, cutting renderer buffers from 24.46 MiB to 9.55 MiB (at the cost of ~5 MiB more texture memory).

Full-scene comparison of the original dense court on the left and the final baked hulls and compact floor on the right
From 2.99 million combined submissions (after the initial shadow bake) down to 58,098 across the entire scene.

Three surprises stood out from that broader pass:

  • Seven coffins were burning 335,556 submissions. Each stone sarcophagus had 6,214 exposed paint quads (86,996 camera + 248,560 shadow across seven copies). Replaced with 96-triangle painted hulls, all seven cost 2,592 combined. Across 101 equipped items, median triangle count fell from 70,536 to 426 (an equipped Iron Heart dropped from 124,740 to 990); across 45 miniatures, the median fell from 8,896 to 664.
  • Never treat a triangle budget as religion. The north brazier holds a bright flame inside a basket of iron teeth. Any geometric error right next to a point light projects wildly across the whole courtyard: a neat 564-triangle hull only overlapped 48.4% of the real shadow footprint. Giving it a dedicated 2,396-triangle shadow caster brought overlap to 99.6%.
  • Fewer triangles doesn’t always mean faster frames. A clever 12-triangle bounding box that raymarched miniature voxels in the fragment shader looked dreamy in a primitive counter—and ran slower (8.30 ms vs. 7.01 ms for its control). Fitted meshes with two texture reads won easily.

Keeping the power claim honest

We didn’t measure battery impact for the floor swap in isolation, so there is no floor-only battery claim here. What we did measure—comparing the final painted-hull + cut-wall release against the compact-floor baseline on our M1 Max at a paced 60 FPS—was Apple’s cumulative GPU energy counter over 720-frame windows (~12.1 seconds per run, three-run medians):

  • Placement: 7.60 W → 6.16 W (128.1 → 103.8 mJ/frame, −19.0%)
  • Repeated craters & buckling: 7.96 W → 6.22 W (134.0 → 105.0 mJ/frame, −21.6%)

Every final trial landed below the lowest reference trial. Intriguingly, paced median frame delivery barely budged (within 0.06 ms)—a reminder that once a game hits its frame-rate cap, players don’t feel extra headroom as smoother motion; they feel it as a cooler laptop and longer battery life.


The ending I keep coming back to isn’t a profiler chart. It’s the moment the last tumbling chunk bounces twice, settles back into its socket, and hands the entire courtyard silently back to 18 triangles—leaving a frame that matches the opening shot pixel for pixel.

Notes & companion reading

All measurements were captured on November 24, 2026 in Godot 4.6.1 (Compatibility renderer) on an Apple M1 Max. Flagstone color and relief maps are adapted from ambientCG Tiles 130 (CC0 1.0).

Companion post: for what happened to our pixel-locked shadows when we flattened the floor to 18 triangles, read When the Shadows Gave Away the Trick.