Vixen
dd8b0a81
csharp
public static class SmaaAreaTexture

SMAA's coverage table: how much of a pixel a reconstructed silhouette covers, for every pattern and every pair of distances the blending-weight pass can find.

Read the guide page for this →

Remarks

Generated, not shipped. The reference SMAA distribution carries this as a 179 KB byte array in a header, which is a binary blob in source control that nobody can review and nothing can regenerate. It is an analytic function — the area under a straight line, clipped to one pixel column — so it is written here as the arithmetic that produces it, and SmaaAreaTextureTests pins the values a pencil can check.

What the table is. The weight pass finds a run of edge texels along one boundary, measures how far the run extends to each side of the pixel it is shading, and reads the crossing edges at the two ends. Those two crossings — four bits, since each end may be crossed above the line, below it, both or neither — say which silhouette the staircase came from, and the two distances say where in that silhouette this pixel sits. The table holds the answer for all sixteen patterns.

The layout is the reference's, minus what SMAA 1x cannot use. Sixteen patterns are placed in a 5×5 grid of MaxDistance-square blocks — five slots per axis because the pass indexes them with 3·below + above, which takes the values 0, 1, 3 and 4 and never 2. The reference texture is 160 wide because its right half holds the diagonal patterns, and 560 tall because it stacks seven sub-sample offsets for SMAA S2x and 4x. This engine has neither: diagonal detection is not implemented and there is no multi-sample resolve to offset for, so those 83 200 texels would be zeroes with nothing to read them. What is generated is the 80×80 that SMAA 1x addresses.

⚠ The distance axis is quadratic. Texel i holds the answer for a run reaching i² pixels, and the shader indexes it with sqrt(d). That is the reference's compression and it is worth keeping: resolution matters at a distance of one or two, where the coverage changes fastest, and not at sixteen, where it barely changes at all.

Fields and properties (6)

  • public const int MaxDistance

    How many texels one pattern's block spans on each axis.

  • public const int Patterns

    How many pattern slots there are per axis.

  • public const int Side

    The table's width and height in texels.

  • public const int BytesPerTexel

    How many bytes one texel is. Two: coverage on each side of the line.

  • public const int ByteCount

    The whole table's size in bytes.

  • public const double SmoothingMaxDistance

    The run length past which a U-shape is no longer smoothed.

Methods (3)

  • public static byte[] Generate()

    The table, RG8, row-major from the top: red is the coverage below the line, green above.

  • public static (int X, int Y) Block(int pattern)

    Where a pattern's block sits in the 5×5 grid.

  • public static (double Below, double Above) Coverage(int pattern, double left, double right)

    The coverage the pixel at gets from one pattern, in a run that reaches pixels to its left and to its right.

Used by (2)

  • SmaaRendererVixen.Rendering.PostFx
  • SmaaTestsVixen.Rendering.PostFx.Tests