antiAliasing.package
- EdgeAntiAliasing.component
- README.md9.3 KB
- TemporalAntiAliasing.component
- antiAliasing.module
- fxaa.renderFeature
- fxaa_pass.computeShader
- package.yaml19 B
- rcas.computeShader
- stable_depth.computeShader
- stable_surface.computeShader
- taa.renderFeature
- taa_resolve.computeShader
- temporalAntiAliasing.module
- temporal_resolve.shaderModule
This package holds more than this page lists. See all of its files in its world.
README.md
antiAliasing system
Geometry is rasterised at one sample per pixel, so a silhouette crossing a pixel either covers its sample or does not. A shallow-angle edge therefore comes out as a staircase of hard steps rather than as a line, and that staircase is the most recognisable artifact of an unfiltered render. In motion it gets worse: the step pattern shifts as the edge moves, a specular highlight flashes on and off as it crosses the sample point, and fine texture crawls.
Two corrections live here, and they work from different information.
Edge antialiasing (EdgeAntiAliasing, FXAA) works from the finished frame
alone. It finds each edge and shifts that pixel's sample across it. Fixed cost,
no dependencies, corrects the staircase in a still image — and knows nothing
about time, so what only appears in motion stays.
Temporal antialiasing (TemporalAntiAliasing) samples a different point
inside each pixel every frame and accumulates the frames, following the scene's
own motion to know where each pixel's surface was. That recovers detail no single
frame holds and settles exactly what edge antialiasing cannot see — the crawling
and flickering that exist only between frames. It needs the scene's velocity, and
costs a small amount of softening, which its sharpness puts back on the shown
picture.
A world created from the default template runs temporal antialiasing from its
first frame: the template's .world_settings names antialiasing = "taa" under
[render], and the world entrypoint applies it as the world loads, tuned by
[render.taa]. A world whose settings name "off", or name no mode, runs none.
They compose: edge antialiasing cleans up within a frame, the temporal pass handles what happens between them.
Using them
local id = entity.spawn("antialiasing").id
entity(id).component.add("TemporalAntiAliasing", { historyWeight = 0.9 })
entity(id).component.add("EdgeAntiAliasing", { edgeThreshold = 0.125 })
Every field is live. For runtime control (a quality slider, or turning one off) drive the modules:
local antiAliasing = require("@builtin::systems.antiAliasing.antiAliasing")
local temporalAntiAliasing = require("@builtin::systems.antiAliasing.temporalAntiAliasing")
temporalAntiAliasing.enable({ historyWeight = 0.9, sharpness = 0.2 })
antiAliasing.enable({ edgeThreshold = 0.125 })
Each module has .enable / .get / .active / .disable, acting on its
render feature asset (fxaa, taa): enable lands each value where it takes
effect (a component's or a placed setup's own value when it states it, else the
asset's live value) and applies the pass when nothing else does, disable drops
the module's own application, and a component's stays. A component applies the
asset with its fields, owned by its entity; of two, the one edited last is in
force.
Temporal antialiasing draws at a quality level: its quality (on the
component and in enable) is low, medium, high, or auto (the
default), which follows the device's quality tier (renderer.qualityTier()).
high sharpens the shown picture by sharpness; medium and low show the
accumulation unsharpened, and the sharpening pass and the copy of its result
into the picture leave the frame. The accumulation is the same at every level.
temporalAntiAliasing.drawn() reports the level in force and the sharpening it
draws.
To see temporal antialiasing as a player sees it, read the frame the screen
showed: capture { source = "presented" } (frames = n for a run of
consecutive frames, which is how convergence and flicker read), or
renderer.presentedFrames() for the pixels with each frame's jitter and
history reset. Every view keeps its own accumulation: a render-to-texture
camera accumulates over its own renders, and an offscreen capture draws a fresh
view whose single render has no history behind it, so it shows none of the
accumulation and leaves the viewport's untouched. A capture drawing the picture
the viewport draws (the camera holding the viewport, at the viewport's size,
admitting the same of the scene) continues the viewport's accumulation
instead: it is the frame the viewport presents next, and the viewport's own
accumulation goes on as it would have. The capture toolbox README has the
rule.
What the edge knobs do
| field | effect |
|---|---|
edgeThreshold | How much a pixel's luminance must differ from its neighbours', as a fraction of the brightest of them, before it counts as an edge. Lower catches fainter edges and costs more. |
edgeThresholdMin | The absolute floor under that test. It keeps the pass off dark areas, where a small relative step is still visually flat. |
subpixel | How strongly features finer than one pixel are corrected. |
searchSteps | How far the pass walks along an edge looking for its end. Longer reach resolves shallower edges, at linear cost. |
What the temporal knobs do
| field | effect |
|---|---|
historyWeight | How much of the accumulated result to keep each frame. Higher resolves more detail and settles smoother, at the cost of taking longer to let go of what a surface used to look like. |
neighbourhoodClamp | How far outside the neighbourhood's own colour spread an accumulated sample may sit before it is pulled back in. Lower rejects more, trading some of the settling for a result that follows change faster. |
sharpness | How strongly the shown picture is sharpened, in [0, 1]: a contrast-adaptive pass (rcas) after the display transform, which steepens edges without lifting either side past its plateau and is never written back into the accumulation. 0 shows the accumulation as it is. |
motionRejection | How much fast motion shortens the memory, which is what stops a moving object trailing behind itself. |
stillSamples | How many renders a pixel whose surface holds still accumulates, in [1, 256]. Each render samples a different point inside the pixel, so a still pixel holding several whole passes through the sample sequence settles on their average instead of rippling as the samples visit it; fewer let a still picture follow a slow change of its lighting sooner. |
How they render
fxaa.renderFeature runs one compute pass in the display stage, on display
code values, so its edge thresholds read luma the way a viewer sees it. A
picture of the edge antialiasing is read from the presented frame
(renderer.presentedFrames, a capture with source = "presented"): the
display stage's render-feature passes draw there. The result is not a
blur. A blur softens everything; this moves each edge pixel's sample
perpendicular to the edge by a sub-pixel amount, so the step between two flat
regions becomes a gradient while both regions are left as they were. That is why
the pass has to find the edge's direction and extent rather than filtering a
neighbourhood — the offset depends on where along the edge the pixel falls, so a
pixel near the middle of a long edge barely moves and one near an end moves
nearly a full half-texel.
Luminance drives every decision there. The eye resolves luminance detail far more finely than chroma, so a step that reads as a jagged edge is a step in luminance, and an edge that is pure chroma needs no correction. A pixel whose neighbourhood varies less than the threshold is passed through untouched, which is what keeps flat regions and gentle gradients out of the filter entirely. Features finer than a pixel produce no long edge to walk, so the 3x3 luminance average carries their correction instead.
taa.renderFeature offsets where the projection samples each frame and
accumulates the frames that produces, reprojecting through @scene.motion and
bounding what it carries by the neighbourhood's own colour statistics. Its README
covers the sample sequence, the tests that decide whether an accumulated sample
is still about the same surface, and why the bound is computed in YCoCg. The
accumulation itself is temporal_resolve, the one resolve the temporal upscale
(@builtin::systems.temporalUpscale) folds its frames through as well. Both
then restate the frame's depth from stable_depth, the depth sample nearest
each pixel's centre while nothing there moves, so an effect after them draws
lines and patterns that hold still with the picture.
Files
antiAliasing.package/
EdgeAntiAliasing.component/ -- the scene's edge antialiasing, authored and persisted
antiAliasing.module/ -- .enable / .get / .disable / .active
fxaa.renderFeature/ -- the edge pass
TemporalAntiAliasing.component/ -- the scene's temporal antialiasing, authored and persisted
temporalAntiAliasing.module/ -- .enable / .get / .disable / .active
taa.renderFeature/ -- the accumulation pass + the per-frame sample offset
taa_resolve.computeShader/ -- the accumulation at render scale 1
temporal_resolve.shaderModule/ -- the temporal resolve every reconstruction accumulates through
stable_depth.computeShader/ -- the depth a reconstruction restates for the passes after it
stable_surface.computeShader/ -- the G-buffer normal and material restated beside it
rcas.computeShader/ -- the sharpening of the shown picture after the temporal stage