·5 min read

Why my LOD 3 is bigger than LOD 0

Our lower LODs swelled by about 20 percent because each one was rebuilt on a coarser grid. Building the shape once and removing triangles from it fixed the growth.

gamedevperformanceprocedural-generation

Contents

Our editor merges several blocks into one smooth, melted mesh and then makes levels of detail (LODs) for the game asset. When we measured the results, the lighter LODs were bigger than LOD 0. At LOD 3, the old method came out about 20 percent too big. A creature that should shrink to a few hundred triangles also swelled in silhouette, so it popped when the engine switched LODs.

This post explains why rebuilding each LOD from scratch makes the shape grow, and the change that fixed it: build the skin once at LOD 0 and make the other LODs by removing triangles from that exact mesh.

How we made LODs before

The smooth skin is built on a 3D grid. To get a lighter LOD, the obvious move was to run the same build with a coarser grid. Fewer cells give fewer triangles. It is simple and it reuses the code.

The problem is that the shape does not stay put. We did not dig into the exact reason. Our guess is that a coarse grid places the surface from fewer samples, so thin parts and rounded corners get padded out to the size of a cell, and every such error adds volume. What we did measure is the result: the shape grew at every step down, about 20 percent at LOD 3.

The change

We stopped rebuilding. The new flow:

  1. Build the smooth skin once, at full detail. That is LOD 0, unchanged.
  2. Make LOD 1, 2 and 3 by removing triangles from that same mesh, so every lighter LOD is a simplification of LOD 0 and sits on the same surface.
  3. Give each LOD a volume tolerance, so a removal that changes the shape too much is rejected: 2 percent for LOD 1, 5 percent for LOD 2, 8 percent for LOD 3.

A pure simplification can still drift, since collapsing an edge moves vertices. The tolerance is the guard. We check the volume of each LOD against LOD 0 and fail a test if it is outside its limit.

We also changed how separate pieces are handled. Blocks that do not touch stay separate meshes, and every LOD has the same number of pieces.

Numbers

On our test scene, the triangle counts by LOD are:

LOD Triangles
0 2990
1 1948
2 896
3 346

Each LOD is smaller than the one before it, as it should be. We then measured volume on six scenes against LOD 0, and no LOD gained volume. That is the property we wanted, and it was the failing one before.

A mirrored creature in the editor shows the cost of the old method. With the new approach its LOD 3 has 1014 triangles. The old method gave about 600 for the same creature, which looks better on a budget sheet and was about 20 percent too big in the viewport. We took the larger triangle count, because a mesh at the wrong size is not a cheaper version of the right mesh.

How to measure the volume

You do not need a modelling tool for this. For a closed, consistently wound triangle mesh, the volume is the sum over triangles of the signed volume of the tetrahedron that the triangle forms with the origin: dot(a, cross(b, c)) / 6. Sum it and take the absolute value. It is a few lines of code, it runs in microseconds on a mesh of this size, and it gives one number per LOD that you can compare against LOD 0 in a test. Meshes that are open, or that have flipped triangles, will give a wrong answer, so keep the winding right first.

The test that failed once

The tolerance test failed once, on its first run. LOD 1 came out at 2.05 percent against the 2 percent limit. In that case the test's tolerance was too tight for a build that was otherwise correct, so we fixed the test and went on. After that, typecheck, all 120 tests and the build passed, and we looked at all four LODs in the browser with no page errors.

A side win: the skin got faster

Since the skin is now built once instead of once per LOD, we profiled the build while we were in there. On the test scene it went from 4.3 seconds to 0.9 seconds, with identical output. That is the smaller point of this post, but it is a pleasant side effect of having one source of truth.

What to take from it

If your LODs are generated, and not authored by hand, ask which direction each step moves the shape. Our rules now:

  • Make LOD 0 the single source of truth. Every other LOD derives from it.
  • Prefer removing detail from the real surface over re-sampling the source data on a coarser grid. Re-sampling invents a new surface each time.
  • Put a volume check in the tests, with a number per LOD. "Looks about right" will not catch a 5 percent swell, and a 20 percent swell was visible only as a pop at a distance.
  • Keep the piece count the same at every LOD, so a LOD switch never adds or removes an object.

These are numbers from one editor and one test scene. The principle, though, is easy to check in your own pipeline: export LOD 0 and LOD 3, load both in a viewer, and compare their bounding boxes. If the lighter one is bigger, something is adding material.

More posts

New writing when there is something worth saying. By email or by RSS, whichever you prefer.