Blog · · 8 min to read

Triangles too thin to paint

Objects model-maker made had thin dark strokes on their paint. They came from triangles thinner than one pixel of the texture, which got no colour and showed its black background. A fix took the strokes on 128 stored models from 29,416 to 1,141 and shipped in model-maker 0.3.2.

The last post was about a fix we stopped. This one is about a fix that shipped. Objects made by model-maker had short, thin dark strokes on their paint: specks on a clay jug, slashes across a stone rim. They were not in the paint. They came from the very last step, called baking.

Four words first

Triangles. A 3-D object on a computer is a skin of small flat triangles, joined edge to edge. model-maker's objects have up to about 60,000 of them. Most are a fair size, but some are slivers: long and very thin, like a needle.

Texture. The colour of the object is kept in one square picture, the texture. Imagine peeling the skin off the object, cutting it into pieces and laying them flat on that picture, like a sewing pattern on cloth. That arrangement is the layout. Each triangle then has its own place on the texture, and a viewer that draws the triangle reads its colour from there.

Texel. One small square of the texture: its pixel. model-maker's textures are 2,048 texels a side, about 4 million texels in all. Each texel holds one colour.

Baking. model-maker paints the object as pictures seen from several sides. Baking copies those colours onto the texture, once, so the finished file needs only the texture. Before the bake, every texel is black. The bake goes through the texels and asks: which triangle holds this texel's centre? That texel takes that triangle's colour. Texels just round each piece take its colour too, a few texels deep. Everything else stays black, but no triangle ever reads there, so it does not matter.

What went wrong

A sliver can be thinner than one texel. Then it may lie between the texels' centres and hold none of them. No texel takes its colour.

That alone would be fine if the sliver sat inside a bigger piece. But the layout groups triangles by the way they face, and a sliver often seems to face another way than the surface round it. So it becomes a tiny piece of its own, alone on the black. On a fox, 1,402 of its 1,737 pieces were a single triangle.

When a viewer draws the object, the sliver reads its colour from its own place on the texture, and finds black. On the object you see a short thin dark line.

Three grids of small squares with a dot in each square's middle. Left: a normal triangle drawn over the grid; the squares whose dots lie inside it are coloured clay, the rest are black. Middle: a thin triangle lies between the dots; every square stays black. Right: the same thin triangle after the fix; the squares it touches are clay, and every other square has a lighter clay colour instead of black
Each square is a texel, each dot its centre. A thin triangle holds no centre, so before the fix it got no colour. After, it colours the squares it touches (darker); every other square takes the nearest colour.

How we found it

Before fixing anything, we checked it was not the paint. Where the strokes showed, the paint itself was light. Baking the stored files again gave the very same strokes. Giving those triangles their neighbours' colour made them disappear. So the fault was in the bake, and every one of the 128 models we had stored had it.

The fix

Two steps, both common in programs that bake textures:

Nothing else changes: the triangles, the layout, and every texel a triangle already held stay exactly as they were. The bake takes about 5 % longer.

A clay jug drawn four times. Top: the whole jug before and after the fix; small black specks show on the plain clay before, not after. Bottom: a close-up of the clay; before, it is dotted with short black lines and specks; after, they are gone
A clay jug, before and after. The shape and the paint are the same; only the bake changed.

How we measured it

We wrote the bars first, the results the fix had to reach, together with the programs that count. Both were locked before any texture of the fixed bake existed, so nothing could be bent to fit.

A dark stroke counted when a thin triangle reads clearly darker than the surface round it and is long enough to see. On 128 stored models (85 animals and 20 objects from our tests, and the 23 examples in Model Maker Studio):

There were eight bars in all. Five passed. Three failed as written; they are in the next section.

The rim of a stone birdbath drawn four times. Top: the whole birdbath before and after the fix. Bottom: a close-up of the carved rim; before, dark slashes cross it; after, almost all are gone, with one or two short marks left
A stone birdbath, before and after. One or two short marks stay on the rim, hard to tell from the stone's dark grain.

What it does not fix

Thin pale lines stay. About 19 a model now, against about 16 before the fix: thin triangles that read a lighter colour than the paint round them. They are the next thing to fix.

Three bars failed as written, and stay failed. We do not reword a bar into a pass after the fact. Beside each, what we found:

Tested on both cards, then shipped

We test model-maker on two graphics cards, one with 16 GB of memory and one with 12 GB. Each had a stored run of 48 painted objects. The fix touches only the bake, which runs on the processor after the card's work is done, so we baked both runs again on the processor: once with the old version, twice with the new one.

The fix shipped in model-maker 0.3.2 on 25 November. Objects you make now come out with almost none of the strokes. An object made before can be baked again from its saved folder with ./model-maker finish, and a finished .glb file (the 3-D file model-maker writes) alone can be mended with ./model-maker repair-texture.

Words used