What a machine computes

A banked floor drawn in its own frame trades place for sharpness

A renderer that walks a banked floor along its lines of constant depth, snapping each pixel to the nearest one, moves the texture by up to half a pixel across the line. Drawn instead on a lattice turned to those lines, every sample exact, and resampled onto the page once, the texture stays in place and loses contrast. The two errors are different in kind and grow differently: the snapped spans' in proportion to the texture's frequency, the resampled frame's as its square. So the frame is far better on slow textures, twelve times at 0.02 cycles a texel, and worse near the finest a pixel grid carries, with the crossing at 0.28 cycles a texel at every bank; on a checker, whose error lives at its edges, the two stay within a few per cent. Bought with more samples, each improves on its own schedule.

Worth reading first: A texture does not interpolate on the page · The precision a depth buffer has left.

A tilted span walks a staircase measured what it costs a renderer to walk a banked floor along its lines of constant depth, the one direction in which a texture can be stepped across a receding surface without a division at every pixel. The page is made of rows and the constant-depth lines are tilted by the bank, so the walk is a staircase: each pixel takes the attribute at the foot of its perpendicular on the nearest line, and a pixel up to half a pixel off the line takes a depth it does not have. On a 120-pixel span the cost never rose above 1.22 px, twenty-three times better than walking the page’s rows at a 20° bank. The price was bookkeeping: neighbouring spans drew some pixels twice.

The essay ended on an arrangement in which the two lattices would be aligned. A renderer could rasterise the floor in a frame of its own, one axis along the constant-depth direction and the other across it, producing samples on a lattice with no staircase at all, and then resample that image onto the page’s grid once at the end. A resample is a filter, and a filter blurs, so its error is not a misplaced texel but a loss of sharpness. The essay asked what the resampling costs against what the staircase costs; at what bank a resample’s blur first exceeds the staircase; and whether the answer moves when the texture is a checker rather than a gradient, since a filter’s damage depends on what is being filtered and a texel error’s does not.

Three pictures of one floor

The floor here is a plane banked about the line of sight, seen in a square patch 81 pixels across whose middle is 120 pixels below its horizon, drawn at one texel a pixel at the patch’s middle. Three page images are made of it.

The exact one gives each pixel the attribute of the floor at that pixel, which needs a division at every pixel and is what the other two are measured against. The snapped spans are the earlier essay’s walk: a family of constant-depth lines a pixel apart, one through the middle of the patch, and each pixel given the attribute at the foot of its perpendicular on the nearest of them. The own frame turns the page by the bank, so that its rows lie along the constant-depth lines, samples the floor exactly at the integer points of that turned lattice, and gives each page pixel the bilinear blend of the four lattice samples around it.

Stripes of 0.3 cycles a texel on a floor banked 20°, down one column: the snapped spans shift the stripes, the resampled frame softens themA floor banked 20° about the line of sight, 120 px below its horizon, textured with stripes of 0.3 cycles per texel at one texel a pixel, read down the patch's middle column. The exact image (thin line), every pixel's own attribute; the snapped spans (squares), each pixel given the attribute on the nearest line of constant depth, which moves the stripes by up to half a pixel across the span; and the frame (dots), exact samples on a lattice turned to the constant-depth lines and resampled bilinearly, which keeps the stripes in place and takes contrast from their peaks. Over the whole patch the spans are 0.120 rms off the exact image and the frame 0.126.00.2500.5000.7501-20-1001020pixel down the patch's middle columnintensityexactsnapped spansturned framebank 20°, 0.3 cycles a texelrms: spans 0.120, frame 0.126
Fig. 1 Stripes of 0.3 cycles a texel on a floor banked 20°, down the patch’s middle column: the exact image, the snapped spans and the turned frame resampled. The spans shift the stripes by up to half a pixel; the frame keeps them in place and takes contrast from their peaks. The slider sets the stripes’ frequency.

The column shows the difference in kind at once. The snapped spans carry the stripes at full contrast and in slightly the wrong place: a pixel half a pixel from its span reads the stripe as it is half a pixel away, so the stripes are shifted, by different amounts in different pixels as each pixel’s offset from its span changes. The frame carries the stripes in exactly the right place and with less contrast: each pixel is a blend of four exact samples up to a pixel away, and a blend of a stripe’s peak with its shoulders is lower than the peak.

The error that matters is what reaches the page, so both are measured the same way: the root-mean-square difference between each method’s image and the exact one, over the patch, on a scale where black is 0 and white is 1. A texture coordinate misplaced and a contrast lost are then two contributions to one number a viewer would see.

The two errors grow differently

The difference in kind becomes a difference in how each error grows with the texture’s detail.

The spans' error grows with the texture's frequency, the frame's with its square: the frame wins below 0.28 cycles a texel and loses aboveA floor banked 20°, textured with stripes, the rms intensity error of each method's page image against the exact one over an 81 by 81 px patch, against the stripes' frequency. The snapped spans (dashed): 0.0081 at 0.02 cycles a texel, 0.0408 at 0.1, 0.120 at 0.3, in proportion to the frequency. The turned frame (solid): 0.0007, 0.0172, 0.126, as its square. They cross at 0.281 cycles a texel, a little over half the highest frequency a pixel grid can carry.0.010.030.10.310⁻⁴0.0010.010.1stripes, cycles a texelrms error against the exact image0.28snapped spansturned framebank 20°, 81 × 81 px patchrms intensity, 0–1 scale
Fig. 2 The rms error of each page image against the exact one, against the stripes’ frequency, on a floor banked 20°: the snapped spans grow in proportion to the frequency, the turned frame as its square, and they cross at 0.281 cycles a texel.

The snapped spans’ error grows in proportion to the frequency: 0.0081 at 0.02 cycles a texel, 0.041 at 0.1, 0.120 at 0.3. That is what a shift does. A stripe moved by a fixed fraction of a pixel changes the image by that fraction times how steeply the stripe changes, and a stripe of twice the frequency changes twice as steeply.

The frame’s error grows as the square of the frequency: 0.0007 at 0.02 cycles a texel, 0.017 at 0.1, 0.126 at 0.3. That is what a blur does. A bilinear blend reproduces a straight-line change exactly, so its error is set by how curved the texture is across a pixel, and a stripe of twice the frequency is four times as curved.

A straight line and a parabola through the origin cross once, and these two cross at 0.281 cycles a texel. Below it, which is nearly everything a texture holds, the frame is better, and much better the slower the texture: twelve times better at 0.02 cycles a texel, two and a half times at 0.1. Above it, close to the half a cycle a pixel that is the finest a pixel grid can carry at all, the spans are better, because there a blend of four samples loses most of the contrast and a half-pixel shift only moves the stripes a little.

The question about a gradient has its answer here, at the bottom of the scale. A gradient is the slowest texture there is, a change with no curvature at all, and a bilinear resample reproduces it exactly; the snapped spans still move it by up to half a pixel. On a gradient the frame wins outright.

Why one is a line and the other a parabola

The two slopes are worth reading off the figure rather than taking on trust. Between 0.02 and 0.1 cycles a texel the snapped spans’ error rises by a factor of 5.04 for a fivefold rise in frequency, an exponent of 1.00; the frame’s rises by 24.6, an exponent of 1.99. Each is the leading term of what its method does to a smooth texture.

A snapped pixel’s offset from its span is spread evenly over half a pixel either side, as the earlier essay found, and its root-mean-square is about 0.29 px. Displacing a smooth pattern by a small amount changes it by that amount times the pattern’s slope, and the slope of a stripe pattern is proportional to its frequency. So the spans’ error is the stripes’ slope times a fixed 0.29 px: a straight line through the origin.

A bilinear blend of four exact samples has no first-order error at all, because a blend reproduces any straight-line change exactly; that is why a gradient is drawn perfectly. What it misses is the bend of the pattern within a cell, the second derivative, which for stripes is proportional to the square of the frequency. So the frame’s error is the stripes’ curvature times a fixed fraction of a cell’s area: a parabola through the origin, with no linear term to compete with the spans’. The crossing is simply where a line and a parabola meet, and its place, a little over half the grid’s limit, is set by the constants: the 0.29 px of the snap and the fraction of a cell the blend averages over.

The bank does not decide it

The second question was the bank at which the resample’s blur first exceeds the staircase. It has no answer, because neither error depends on the bank once there is one.

Neither method's error depends on how far the floor is banked, once it is banked at all, so the crossing does not move with the bankThe rms error of the snapped spans (dashed) and the turned frame (solid) against the floor's bank from 1° to 45°, for stripes of 0.1 and 0.3 cycles a texel. Each is flat: at 0.1 cycles the spans stay between 0.0393 and 0.0473 and the frame between 0.0170 and 0.0205. The frequency at which they cross is 0.282, 0.281, 0.286 cycles a texel at banks of 5°, 20° and 40°. On a level floor both are exact.00.0500.1000.150010203040the floor's bank (°)rms error against the exact imagespans, 0.1frame, 0.1spans, 0.3frame, 0.3stripes of 0.1 and 0.3 cycles a texel81 × 81 px patch
Fig. 3 The rms error of the snapped spans and the turned frame against the floor’s bank from 1° to 45°, for stripes of 0.1 and 0.3 cycles a texel. Each is flat; the crossing frequency is 0.282, 0.281 and 0.286 cycles a texel at banks of 5°, 20° and 40°.

At 0.1 cycles a texel the snapped spans’ error stays between 0.039 and 0.047 from a bank of 1° to one of 45°, and the frame’s between 0.017 and 0.021. The crossing frequency is 0.282 cycles a texel at a 5° bank, 0.281 at 20° and 0.286 at 40°.

Both are flat for the same reason, the one the earlier essay found for the staircase alone: the cost is the grid’s and not the floor’s. A pixel’s offset from the nearest span, and a pixel’s place among the four lattice samples around it, are both set by where a line of some slope falls against a square lattice, and over a patch of a few dozen pixels those places run through every value whatever the slope. Only at a bank of exactly nothing, where the spans are the page’s rows and the turned lattice is the page’s own, do both errors vanish together. So the bank decides whether there is a choice to make at all, and the texture decides which way it goes.

On a checker the edges decide

A checker is the texture the question singled out, and with reason: it is all edges, a sharp change between two flat colours, and edges are where a shift and a blur both do their damage.

On a checker both methods pay at the edges, and they stay within a few per cent of each other at every size of squareThe same banked floor textured with a checker of a stated frequency, two squares a cycle. The snapped spans (dashed): 0.150, 0.224, 0.218, 0.284, 0.341, 0.373, 0.415, 0.463 at 0.03, 0.05, 0.07, 0.1, 0.15, 0.2, 0.25, 0.3 cycles a texel; the turned frame (solid): 0.155, 0.216, 0.221, 0.274, 0.331, 0.363, 0.399, 0.432. A checker's error is almost all at its edges, where moving an edge by half a pixel and blurring it over a pixel cost about the same, so the two stay within 7% of each other and do not cross.00.2000.40000.1000.2000.300checker, cycles a texelrms error against the exact imagesnapped spansturned framebank 20°, checkerrms intensity, 0–1 scale
Fig. 4 The same banked floor textured with a checker, against its frequency: the snapped spans and the turned frame stay within a few per cent of each other at every size of square, and neither is ahead throughout.

The two stay together. At 0.05 cycles a texel, squares of ten texels, the spans’ error is 0.224 and the frame’s 0.216; at 0.1, 0.284 and 0.274; at 0.3, 0.463 and 0.432. At the slowest checkers the spans are marginally ahead, at the fastest the frame. Within 7% of each other everywhere, they never part the way the stripes did.

The reason is that a checker’s error is almost all at its edges, and at an edge the two methods cost about the same. Moving an edge by up to half a pixel puts the wrong colour in up to half the pixels it crosses; blurring it over a pixel puts an intermediate colour in the pixels either side. Both are a pixel’s worth of wrong colour along every edge, and the flat squares between, which a stripe pattern does not have, are drawn exactly by either. So the answer moves, as the essay suspected it might, and it moves to a tie: for a texture made of edges the choice between snapping and resampling does not matter, and for a texture made of gradual change it matters a great deal.

Buying more samples

Both methods can be made finer, and the cost is samples. Spans a half or a quarter of a pixel apart visit each pixel about twice or four times and keep the nearest; a turned lattice a half or a quarter of a pixel apart draws four or sixteen samples for every pixel of the page.

Paid for in samples, finer spans and a finer frame come out close: the spans halve their error with each doubling, the frame quarters it with each fourfoldSpans spaced a half and a quarter of a pixel apart, and a turned lattice of a half and a quarter of a pixel, against the samples each draws per page pixel (two and four for the spans, four and sixteen for the frame), for stripes of 0.1 and 0.3 cycles a texel. At 0.3 cycles: spans 0.120, 0.061, 0.030; frame 0.126, 0.038, 0.0098. At four samples a pixel the spans read 0.030 and the frame 0.038; at 0.1 cycles, 0.0102 and 0.0044.1248160.0010.0030.010.030.1samples drawn per page pixelrms error against the exact imagespans, 0.1frame, 0.1spans, 0.3frame, 0.3bank 20°spans: 1/h a pixel; frame: 1/h²
Fig. 5 Spans spaced a half and a quarter of a pixel apart, and a turned lattice of a half and a quarter of a pixel, against the samples each draws per page pixel, for stripes of 0.1 and 0.3 cycles a texel.

Each improves on its own schedule. Halving the spans’ spacing halves their error, since a pixel’s offset from its nearest span is halved: at 0.3 cycles a texel, 0.120, 0.061, 0.030. Halving the lattice’s spacing quarters the frame’s error, since the curvature across a cell is quartered: 0.126, 0.038, 0.0098. But the frame pays four samples for each halving where the spans pay two, so on equal samples the two come out close. At four samples a pixel and 0.3 cycles a texel the spans read 0.030 and the frame 0.038; at 0.1 cycles, 0.010 and 0.0044. The frame still wins slow textures and the spans fast ones, by smaller margins.

What the frame costs in memory

Neither method needs more samples than the floor has pixels, when each draws exactly the floor: a triangle has the same area in a turned frame as on the page, so rasterising it in its own frame draws as many samples as rasterising it on the page. The cost of the frame is elsewhere. Its samples must be held somewhere before they are resampled, and a buffer is a rectangle. A page-aligned rectangle of the floor, turned into the floor’s frame, needs a buffer larger by (∣cos⁡θ∣+∣sin⁡θ∣)2(|\cos\theta| + |\sin\theta|)^2 to hold it: 1.17 times as many cells at a 5° bank, 1.64 at 20°, twice at 45°, most of them never written. That is where the bank enters after all. It does not change either method’s error; it changes how much memory the frame wastes to keep its lattice straight, and the spans, which write straight into the page, waste none.

What this rests on

One texel a pixel at the patch’s middle. Across the patch the floor’s depth runs as the reciprocal of the distance below the horizon, which is why, as depth is a reciprocal found for a pair, the texture’s scale changes fastest nearest the horizon. Further toward the horizon the texture is compressed, so a given stripe has a higher frequency in page pixels there and moves toward the spans’ side of the crossing; nearer the eye it moves the other way. A whole floor is therefore better drawn by the frame near the eye and by the spans near the horizon, for one texture.

Bilinear resampling. A resample with a sharper filter, such as a bicubic one, loses less contrast at middle frequencies and rings at edges, and would move the crossing toward the finest frequencies, at some cost on a checker’s edges.

No mipmapping. A real renderer filters a texture before sampling it, to the frequency its pixels can carry, and so never shows the frequencies near half a cycle a pixel where the spans win. A mipmapped texture puts every renderer in the frame’s favoured range.

The spans tile perfectly. The earlier essay found 3.9% of pixels drawn twice by neighbouring spans and none missed; the error here treats each pixel as drawn once, by its nearest span.

Two errors that are not the same error

Along a line of constant depth the page is affine found the direction a texture can be stepped exactly, and a texture does not interpolate on the page why the page’s own rows cannot be. The render is distorted on purpose priced a second pass that resamples a picture into a different shape, and two warped slices draw for a curved monitor found such a pass exact in geometry and close to lossless with a little extra drawing. This essay sets a resample against a snap on the same floor and finds that the comparison depends on neither the floor nor the bank but on the picture: a snap misplaces and a resample softens, misplacement costs in proportion to detail and softening as its square, and so a smooth texture prefers to be softened slightly and a fine one to be misplaced slightly. A staircase winds the mistake round the lattice and the stations are also a staircase found staircases elsewhere in how a picture is rasterised, and whole pixels cut space into shells found the same rounding cutting depth into steps; a renderer facing one has, it turns out, a choice about what kind of error to have.

Still open: whether a floor can be drawn in two frames

The crossing says the frame wins on the near floor, where the texture is spread over many pixels, and the spans on the far floor, where it is compressed toward the horizon. A renderer could use both: draw the near part of a banked floor in its own frame and resample it, and walk the far part in snapped spans, joining them at the depth where the texture’s local frequency reaches the crossing.

The measurement that settles it draws a whole banked floor from the eye to the horizon with a mipmapped texture, finds the depth where the local frequency crosses 0.28 cycles a texel, draws the floor each way and split at that depth, and asks how much the split saves over either method alone; whether the seam where the two meet, a change in the kind of error from softened to misplaced, is visible as a line across the floor; and whether a mipmapped texture, which never reaches the crossing, makes the split pointless by putting the whole floor on the frame’s side.

Walking a banked floor in snapped constant-depth spans misplaces its texture by up to half a pixel; drawing it on a lattice turned to those lines and resampling once keeps the texture in place and softens it. The snap’s error grows in proportion to the texture’s frequency and the resample’s as its square, so the resample is twelve times better at 0.02 cycles a texel and worse above 0.28, near the finest a pixel grid carries. Neither error depends on the bank, so the crossing does not move with it; on a checker, whose error lives at its edges, the two stay within a few per cent. Bought with more samples, the spans halve their error with each doubling and the frame quarters its with each fourfold, and they come out close.

What links here

Computed from the collection, not written here: the essays that point at this one.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A flat tag is an object no other essay names yet.

Depth divisionForeshorteningHomogeneous coordinatesQuantisationResidualVanishing line