A banked floor drawn in its own frame trades place for sharpness
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.
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 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.
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.
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.
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 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.
- One plane is nearly free — both name depth division, homogeneous coordinates, quantisation
- The near plane can be any plane — both name depth division, homogeneous coordinates, quantisation
- A frame is an interval — both name foreshortening, residual
- A lamp behind the camera — both name depth division, homogeneous coordinates
- A pixel is not a point — both name quantisation, residual
- A texture reaches the horizon as a rate — both name foreshortening, homogeneous coordinates
Named objects
A flat tag is an object no other essay names yet.
Depth divisionForeshorteningHomogeneous coordinatesQuantisationResidualVanishing line