renderFeature
Authoring contract
A .renderFeature folder holds an init.luau that returns a feature module:
return {
setup = function(ctx) -- optional; runs once when the feature goes live
-- A "fragment" pass's `shader` names a POST EFFECT, not a `.shader`
-- guid directly — postprocess.add compiles the shader asset under
-- that name once, here. Enqueueing a name never passed to
-- postprocess.add runs the pass as a no-op every frame (the log
-- reads "effect '<name>' not compiled — pass skipped").
postprocess.add("my_effect", asset.resolve("my.shader.guid", "shader"), { enabled = false })
end,
render = function(ctx) -- required; runs every frame
-- enqueue one or more passes. The spec shape depends on `kind` (see
-- "Pass kinds" below): this is a "fragment" pass (full-screen shader over
-- input textures); a mesh effect (outline, x-ray) is a "geometry" pass
-- with `material` + `select` (see "Geometry passes").
ctx.enqueue {
phase = "afterTransparent",
shader = "my_effect",
inputs = { src = "@scene.color" },
output = myRenderTargetGuid,
}
end,
teardown = function(ctx) end, -- optional; runs once when the feature is destroyed
}
Optional materials/ and shaders/ subfolders hold shader source the feature
constructs GPU programs from. A feature constructs its GPU programs (it does not
reference .material surface assets).
ctx
Built fresh each frame and passed to setup / render / teardown:
| Field | Meaning |
|---|---|
ctx.enqueue(spec) | Queue one render pass for the current frame. |
ctx.viewport | { w, h }: the size the main viewport's scene rasterized at, in pixels (renderer.rasterSize(): the viewport taken down by the render scale). |
ctx.time | The instant this frame's per-frame fields are drawn at, in seconds: the running clock, or the instant a renderer.temporal.hold pins. Absent in a feature that states its inputs. |
ctx.frame | The frame index beside that instant: it counts every frame of the loop, drawn or not, and reads 0 while a hold stands. Absent in a feature that states its inputs. |
ctx.renderPath | "forward" / "deferred" / … — branch passes on the active path. |
ctx.settings | The feature's knobs as they stand this frame — see "Settings". |
ctx.authored | The same knobs as authored: a setting declared with Field.scaled reads its authored value here and the value of the quality level in force in ctx.settings; every other setting reads the same in both. |
Per-frame values and a still picture
A buffer a feature's passes read is part of the picture: written with new words
between two frames, it is a change of the picture, and a renderer draws for as
long as such changes arrive. A field that animates with time (film grain, a
moving noise) seeds from ctx.time and draws while the clock runs. The jitter
an accumulation averages over (a ray offset, a rotated sample pattern) turns
with the renders of the view instead, so the feature's parameters hold the same
words on every frame of a still scene and the renderer stops drawing once the
accumulation settles: a history target's state buffer
(renderer.texture.create { history = true }) carries in y how many renders
in a row the view being drawn has carried, written as each render of the view
begins, and a pass that binds it reads its jitter frame there. While
renderer.temporal.held(), the passes take the frame from the held instant
@frame.clock carries instead (the feature states the hold among its inputs
and writes a flag into its parameters), so two renders under one hold agree.
@builtin::systems.reflections.ssr works this way.
Stating what a feature depends on
A feature whose render gives the same passes while nothing it reads moved says
what it reads, and the engine stops running render on the frames where none of
it did. The module states the inputs with dependsOn, a list of names, with
inputs, a function returning a value, or with both:
return {
stage = "display",
dependsOn = { "settings", "viewport" },
render = function(ctx)
ctx.enqueue(specFor(ctx.settings, ctx.viewport)) -- a spec frozen all the way down
end,
}
| Input | Moves when |
|---|---|
settings | the feature's settings in force change: a configure, or a quality level that scales one. Every feature that states inputs holds this one, named or not. |
viewport | the size the main viewport's scene rasterizes at changes (ctx.viewport). |
renderPath | the active render path changes (ctx.renderPath). |
camera | the camera drawing the viewport moves, turns or changes its projection (ctx.camera). |
camera.cell:<size> | the camera's position crosses into another cell of <size> world units on a side, such as camera.cell:2 (ctx.camera). |
assets | an asset is created, changed or removed anywhere in the world. |
lights | a light the renderer shades with changes: a field of a light component, a light entity's world transform (its own or an ancestor's), a light shown, withheld, spawned or removed, the sun or the ambient term (lighting.revision()). |
inputs is called with no arguments once a frame, and its value is compared with
the one of the frame before by ==: a number or string that counts a revision, or
a table the owner replaces when its content changes (debugViz answers the batch
the debug module holds).
The first render, and a render after the feature restarts or the device rebuilds,
runs whatever the inputs say. Each later frame the engine reads the inputs: when
none moved, render does not run, and the passes the last render handed over
stand in the frame as they stood. A render's passes stand in the frame only while
every spec it enqueued is a table frozen all the way down (the engine reads such
a spec once and keeps it); a render that hands over any other spec runs on every
frame, whatever it states. ctx.time and ctx.frame are not there to read in a
feature that states its inputs, and ctx.viewport, ctx.renderPath and
ctx.camera are there only when an input names them: what changes on every frame
comes from the frame's own buffer, @frame.clock, which every pass binds. A
feature that states nothing runs render on every frame.
renderer.feature.list() and the profiler counts renderFeature.renders and
renderFeature.replays report how many features rendered and how many stood on
their kept passes in a frame.
Settings
A feature declares the knobs it takes as settings, each a Field descriptor
with a default, the way a component declares its public fields. A feature that
declares no settings has nothing to tune: its schema is empty, and applying it
turns it on or off.
local Fields = require("@builtin::modules.field")
local Field, NoSync = Fields.Field, Fields.NoSync
return {
settings = {
intensity = Field.number(1.0, NoSync, "How much of the effect reaches the image."),
quality = Field.enum({ "low", "high" }, "high", NoSync, "How many samples the pass spends."),
},
render = function(ctx)
local s = ctx.settings -- { intensity = 1.0, quality = "high" }, or what a caller set
...
end,
}
The engine holds one settings table per live feature — every declared default,
overridden by what it was handed — and passes it as ctx.settings on every
setup / render / teardown. A feature reads its knobs there and nowhere
else, so any caller tunes any feature by name:
local h = renderer.feature.create(ref, { settings = { intensity = 0.5 } })
renderer.feature.configure(h, { quality = "low" }) -- lays over the rest
renderer.feature.settings(h) -- { intensity = 0.5, quality = "low" }
renderer.feature.find(ref) -- the live handle, or nil
renderer.feature.schema(ref) -- the declared knobs, unrun
A knob the feature does not declare, or a value of the wrong shape, is refused
by name. A scene authors its features on one RenderFeatures entity — a list
of features, each with its settings — which adopts a feature already live
rather than stacking a second, and takes every one down on disable and destroy.
Each entry is an application of its asset (applicable): the asset holds its
one live feature, every application joins it, the settings in force are those
of the application that last stated something new, and the last to leave stops
it. A feature already running when the first application comes is adopted, and
runs on with its own settings once the last leaves. A feature stopped from
outside the asset (renderer.feature.destroy, a
render that raised) stays stopped until an application is stated again.
render runs once per frame; the passes it enqueues run once per render
target drawn that frame — the live viewport, every offscreen capture, every
RTT camera — each at its own resolution. So ctx.viewport is the main
viewport's size, not the size of the target a pass ends up drawing into. Size a
full-screen scratch RT with screen = true and let the engine track the drawn
target (see "Screen-sized targets") rather than deriving it from ctx.viewport.
Screen-sized targets
renderer.texture.create { screen = true } marks a feature RT as full-screen:
before each render target's feature passes, the engine resizes it to that
target's resolution. Create it once — the engine owns its size from then on:
myRt = renderer.texture.create {
width = ctx.viewport.w, height = ctx.viewport.h, -- initial size only
screen = true, format = "rgba16f", name = "my_effect",
}
A target that holds a picture of the scene is rgba16f, which is what the scene
target itself carries: linear light with headroom above the display's white and
no 256-step floor under a dark gradient. Omitting format on a screen-sized
target asks for the same thing. format = "rgba8" is for a mask, a weight or an
occlusion term, where 0..1 is the whole range — hand one of those back over
@scene.color and the frame loses every highlight and bands every gradient, and
the engine says so in the log.
screenScale (default 1.0) takes a fraction of the drawn target's resolution,
for a scratch that runs below composite resolution (a half-res blur passes 0.5).
A screen-sized RT is what makes a full-screen effect composite correctly at any
resolution. Deriving the size from ctx.viewport instead pins the RT to the main
viewport, and every differently-sized render target then composites a mismatched
scratch — the scene scaled into a corner with the rest black.
screenSpace names WHICH image a screen-sized RT follows:
| value | what it tracks |
|---|---|
"scene" (default) | the scene render target, at whatever resolution the render scale asked for. Resized before EVERY render target's feature phases — the main frame and each offscreen one — and cleared to transparent before an offscreen render, so one sink never reads what another left behind |
"composite" | the image the post-scene phases draw into. The presented frame's allocation is resized and drawn by the presented frame alone; an offscreen render that runs a post-scene phase (a capture, a render-to-texture camera whose picture goes through the display stage) draws in an allocation of its own at its own size, cleared to transparent before it draws |
The two carry the same size until the render scale drops below 1. From there,
while the renderer presents the viewport itself, the scene reaches the display's
resolution through an upscale that runs before afterScenePost — so a
composite-space RT is the display's size while a scene-space one is the smaller
rasterized frame. Under a UI viewport panel the panel draws the scene target at
its own rect, nothing upscales beforehand, and both spaces carry the scene's
size.
A scene-space target is scratch: whatever a pass does not rewrite this render is transparent black. The presented frame's allocation of a composite-space target survives every offscreen render untouched.
History targets
An accumulation across frames (temporal antialiasing, a temporal denoiser, any pass that reads what it wrote last time) lives in a history target:
history = renderer.texture.create {
width = ctx.viewport.w, height = ctx.viewport.h, -- initial size only
history = true, format = "rgba16f", name = "my_accum",
}
-- in render(ctx):
ctx.enqueue {
kind = "compute", program = myResolve,
inputs = { scene_color = "@scene.color", accum_previous = history.previous.guid },
buffers = { accum_state = history.state },
storage = { accum_out = history.guid },
phase = "afterLighting",
}
The passes a feature enqueues run once for every view the frame draws (the
viewport, each render-to-texture camera, each capture), so an accumulation has
to be one per view. A history target keeps one pair of images per view, sized to
that view: for the length of a view's render history.guid names the image the
render writes and history.previous.guid the image the same view's previous
render wrote. Another view never resizes, clears or overwrites them, and a
view's images are freed when it stops drawing. A capture drawing the picture
the viewport's latest render drew (its camera and lens, its size, the same of
the scene its layers admit, and its shading), while the viewport samples
where renderer.setProjectionJitter's sequence places it, is the one render
that draws with another view's images: for the length of its render
history.previous.guid names the image the viewport's latest render wrote and
history.guid the viewport's other image, which the viewport's next render
writes over, and history.state reads as it would for that next render. A
viewport whose projection renderer.setProjectionOffset or a reconstructing
upscaler moves samples where no capture follows, and a capture then draws with
images of its own. It follows screenSpace and
screenScale like any screen-sized target; a composite-space one is kept for
every view that runs the post-scene phases: the viewport, a capture, and a
render-to-texture camera whose picture goes through the display stage.
Before each render of a view the engine writes history.state, one
vec4<f32> a pass binds through buffers:
| field | holds |
|---|---|
x | 1 when previous holds this view's previous image; 0 on the view's first render, its first after a camera cut or a change of size, or after a render of the view that ran without the target, and previous then reads transparent black |
y | how many renders in a row have carried the history |
zw | this render's sub-pixel projection offset, in pixels (renderer.setProjectionJitter) |
renderer.setProjectionJitter is the matching per-view sample sequence: every
view walks it by its own count of renders, so the sequence a temporal pass
expects is the one each view's renders sampled.
Post stages
A post effect belongs to one of the frame's named post stages, in frame
order, each stating what the picture holds there: the space an effect there
reads and writes (light, the scene's own light ahead of the display
transform's exposure and tone curve, display, code values, or encoded, the
presented surface's own values) and the size
the picture is held at (raster, the size the scene rasterized; output, the
size the frame is composed and shown at):
| Stage | Space | Resolution | Runs |
|---|---|---|---|
lighting | light | raster | screen-space lighting terms and what draws into the lit scene: occlusion, reflections, indirect light, contact shadows, decals, splats, outlines, diagnostic views. It spans every phase up to afterLighting, so a pass of a feature declaring it may name one of those phases |
medium | light | raster | participating media: aerial perspective, fog, volumetric light |
preTemporal | light | raster | effects reading the jittered raster before reconstruction: depth of field |
temporal | light | raster | the one temporal reconstruction of the raster (TAA); the stage holds one feature at a time |
postTemporal | light | raster | effects reading the reconstructed picture: motion blur |
meter | light | reduced | measuring the picture: the exposure histogram, a fraction of the raster |
optics | light | raster, then output | lens light: bloom, flare, streaks. Its render features run on the raster; the frame then carries the picture to the output size, and the post-process chain's scene layer runs there |
display | display | output | the display transform, then on code values the temporal upscale, debanding, edge antialiasing and sharpening; the chain's display layer, the film grain last |
ui | display | output | the UI, drawn over the finished picture, then what grades the picture with the UI on it: afterUI passes, the chain's all layer, then afterPost passes |
output | encoded | output | the renderer's output stage alone: the one write of the presented surface, in the surface's encoding, rounded to its bit depth with a blue-noise dither (renderer.output). It takes no render feature and no chain effect |
A feature declares the stage it belongs to, and each pass it enqueues with no
phase runs in that stage, at the stage's phase and its band of orders plus the
pass's own local order (a whole number from 0 to 99):
return {
stage = "postTemporal",
render = function(ctx)
ctx.enqueue { kind = "fragment", shader = "my_effect", inputs = { src = "@scene.color" }, order = 0 }
end,
}
Passes sharing an order run in the order they were enqueued, so a chain of passes over shared targets can run at one order, in sequence.
The meter and optics stages are the camera's film. A pass placed in one of
them, stating neither postProcessing nor presented, is part of the camera's
post-process chain (postProcessing = true): a camera running no
post-processing, such as a capture asking for the scene ungraded or an
environment cube face, skips it. A pass stating postProcessing = false runs on
every camera.
render runs once a frame, but each view the frame draws (the viewport, a
capture, a render-to-texture camera, an environment cube face) looks at the
world from its own camera, so an order that depends on where the camera stands
is stated per pass rather than chosen in render. A pass that composites
something standing in the world states the world point it stands at as
sortPoint: { x = .., y = .., z = .. }, { x, y, z } or a vector, so an
entity's position is one. Among the passes of one phase sharing one order
that run together (its fragment, compute and raster passes; its geometry
passes, which run ahead of those), the ones stating a point trade the places
they were enqueued in so that every view runs the one farthest from its own
camera first and the nearest last: composites laid over the frame by each of
them leave the nearest in front from wherever the view looks. Depth is
taken along the view (the distance in front of a perspective camera, the depth
into an orthographic one's box). Passes at the same depth keep the order they
were enqueued in, so the passes of one effect stating one point (a march into a
target and the composite reading it) stay together, and a pass stating no
point keeps its place:
for _, item in ipairs(items) do
ctx.enqueue { kind = "compute", program = march, storage = { out = scratch.guid }, order = 2, sortPoint = item.center }
ctx.enqueue { kind = "fragment", shader = composite, inputs = { src = scratch.guid }, blend = true, order = 2, sortPoint = item.center }
end
A draw or splat pass takes no sortPoint, and a value that is not three finite
numbers is refused by ctx.enqueue.
A pass may name a
stage of its own in place of the feature's, placed the same way: a feature
whose work spans two stages declares one and names the other on those passes,
the way temporal antialiasing declares temporal for its resolve and names
display on its sharpening passes. A pass naming both a stage and a phase is refused. A stage the
frame does not have is refused by renderer.feature.create, naming the stages
there are, and a second feature declaring the temporal stage while one stands
in it is refused naming both; the temporal stage takes the passes of the
feature declaring it alone. A pass that names a phase runs at that phase and
order, as below. renderer.post.stages() reports every stage and what stands
in it: a feature by the stage its passes' position falls in, marked declared
where that is the stage the feature declares or a pass names. Every built-in
render feature declares its stage; postStages's README lists where each
built-in effect runs.
Pass phases
enqueue runs a pass at a named pipeline boundary — a real seam between the
scene's discrete passes — ordered within a phase by order. Each phase is the
point where the scene colour holds a specific, nameable state:
| Phase | Scene colour there |
|---|---|
afterDepthPrepass | the visibility raster written: @scene.depth holds this frame's complete opaque depth, and @scene.motion its opaque motion, before anything shades. Scene colour is not yet drawn; @scene.colorHistory holds the previous frame's lit colour, and the deferred g-buffer the previous frame's surfaces (readsPrevious) |
afterShadows | shadow maps populated; scene colour not yet drawn. @scene.depth and @scene.motion hold what the visibility raster laid at afterDepthPrepass |
afterSky | sky only. @scene.depth holds the frame's opaque depth, so a pass here tells the pixels the geometry pass draws over (depth above 0) from the ones that stay sky (depth 0) |
afterOpaque | opaque drawn, before transparents. @scene.depth (and the deferred G-buffer) are populated. Forward: lit opaque. Deferred: lit opaque too, which the geometry pass shades straight into the scene colour, on a render no pass reads or writes @scene.shaded in; on one that does, the opaque surfaces are in the G-buffer's shaded channel, so the colour is still sky only until the composite (use afterOpaqueLit). Radiance stamped into @scene.emissive reaches the colour at the composite |
afterOpaqueLit | the lit opaque scene, still before transparents, on both paths — the forward opaque draw, or the deferred geometry pass and composite. The background a refractive or transmissive surface samples: the one phase whose colour holds what is behind such a surface without holding the surface itself. A pass that lights or changes the opaque scene runs here, ahead of the air that hazes it (the aerial perspective at 98, the height fog at 100) and of the transparent phase: the built-in lighting terms (probe field, sky light, image-based environment, area lights, local contact shadows, surface weather, capsule occlusion, subsurface scattering, cached indirect, resampled direct, ray-traced shadows), the splat clouds and the outline shells stand at orders 1-96, so the haze covers their light and a see-through draw in front of a surface is not lit by that surface's light |
afterTransparent | transparents drawn, before the OIT composite |
afterLighting | deferred-lighting + OIT composite done — fully lit, final geometry on both paths. Where the air hazes the scene (aerial perspective, height fog), the opaque scene here is already hazed, so light a pass adds here lands over the fog and over every see-through draw |
afterScenePost | the chain's scene layer and the display transform done: display code values, before the chain's display layer and the UI |
afterUI | scene + UI composited |
afterPost | the chain's all layer done — the finished picture in display code values, before the output stage writes it to the surface. A pass here reads that picture as @scene.color and draws over a copy of it |
The last three are the post-scene phases, and they work on the COMPOSITED image:
@scene.color there is the target the UI lands on, not the scene render target.
@scene.depth and @scene.motion still bind — they are the scene's own buffers
for the frame just drawn, which is what lets a pass at these phases reproject the
composite it is handed — and on the deferred path so do the G-buffer channels
(@scene.normal, @scene.material, @scene.shaded, @scene.emissive), the
surfaces of that same frame, so a look drawn over the finished picture reads
what each pixel's surface is without copying the G-buffer at an earlier phase.
All of them keep the SCENE's resolution. Whenever the
render scale is below 1 on the presented frame, that is smaller than
@scene.color, so a pass here maps between the two by uv rather than by texel
index, and takes its own output size from the target it writes.
A texture is a texture. A pass's sampled input names any texture the engine
holds by the handle that made it: a render target or a texture
renderer.texture.create returned (its guid), or a storage texture a compute
shader created (ref:createStorageTexture2D, its key). Which one it is decides
nothing about whether the pass accepts it. A pass sees the contents a texture
holds when the pass runs: a compute shader that wrote the texture in an earlier
pass of the same frame, or in a dispatchEx recorded at the start of the frame,
is read by a pass at any later point of the frame, and a pass that reads a
target an earlier phase of the frame draws sees that draw once the phase has run.
The @scene.* inputs (@scene.color, @scene.depth, …) bind the live frame
buffers; the deferred g-buffer channels (@scene.normal, @scene.shaded, …)
resolve only on the deferred path. Before the pass that shades has drawn — at
afterDepthPrepass — a g-buffer channel holds the previous frame's surfaces,
and a pass reading it there names the slot in readsPrevious
(readsPrevious = { "scene_normal" }); one that does not is held back rather
than handed a stale normal. @scene.colorHistory is the lit colour the target's
previous render ended with, kept by the engine per render target and never
cleared by a frame: what a pass tracing at afterDepthPrepass, against this
frame's depth, takes its light from — reprojected through the previous
view-projection @frame.camera carries. A capture drawn once, or a camera drawn
again after a pause, is drawn lit first when a pass reads the history, so its
first frame holds one.
Every @scene.* channel, what it holds, its format, the phase it is first
valid from, and the other names it answers to:
| Name | Holds | Format | Valid from | Also named |
|---|---|---|---|---|
@scene.color | the scene's lit colour; the display composite at a post-scene phase | the scene target's format at a scene phase, the display composite's at a post one | every phase | — |
@scene.depth | opaque depth, reversed (1.0 near, 0.0 far/empty sky) | Depth32Float — binds through a texture_depth compute slot, not texture2d | afterDepthPrepass on | — |
@scene.motion | screen-space NDC velocity since the previous frame | Rg16Float | afterOpaque on | — |
@scene.normal | world-space normal + the per-pixel surface-flag field | Rgb10a2Unorm | deferred path, afterOpaque through afterPost (previous frame's before — declare readsPrevious) | — |
@scene.shaded | what a surface SENT — its shaded colour, linear and scene-referred | Rgba16Float | deferred path, afterOpaque through afterPost (previous frame's before) | @scene.albedo |
@scene.material | what a surface IS — base colour (RGB565) + metallic + perceptual roughness | Rgba8Uint | deferred path, afterOpaque through afterPost (previous frame's before) | @scene.mr |
@scene.emissive | radiance a pass stamped on the surface, added at the composite | Rgba16Float | deferred path, afterOpaque through afterPost (previous frame's before) | — |
@scene.ao | scene occlusion a feature wrote, read back by shading: occlusion in r, the bent normal laid flat on the octahedron in g and b, and in a whether a bent normal was written | Rgba8Unorm | every scene phase (cleared at the top of the scene render) | — |
@scene.sunOcclusion | the share of the sun's direct light a feature found taken on the way to each pixel's surface (.rgb, 0 none to 1 all), read back by the sun's term alone | Rgba8Unorm | every scene phase (cleared at the top of the scene render) | — |
@scene.reflection | traced reflection radiance (.rgb) + confidence (.a) | Rgba16Float | every scene phase (cleared at the top of the scene render) | — |
@scene.indirect | the indirect diffuse light the surfaces closing each pixel's hemisphere send it (.rgb, in the ambient term's units) + the share of the closed hemisphere it answers for (.a), read back by the diffuse term through zero_scene_indirect_here; the second layer of the texture @scene.reflection is the first of | Rgba16Float | every scene phase (cleared at the top of every scene render) | — |
@scene.decal | the base colour stamped over each pixel's opaque surface, premultiplied by its coverage (.rgb), with that coverage (.a); written at afterDepthPrepass (blend premultiplied), and every opaque surface takes it into its own base colour before it is lit (zero_take_scene_decal, which zero_pbr_shade calls), so the stamp is lit, shadowed and written to @scene.material with the surface; the third layer of the texture @scene.reflection is the first of | Rgba16Float | afterDepthPrepass through afterSky (cleared at the top of every scene render and again once the opaque surfaces have shaded, so a surface drawn after them takes none) | — |
@scene.colorHistory | the lit colour the target's previous render ended with | Rgba16Float | every phase | — |
@scene.media | the media trace's coverage by kind: what the participating media and the see-through draws laid in front of each pixel's opaque surface, as the share the cloud layer covers (.r), a volumetric medium (.g: a volume, smoke, fire, a volume sequence, a fog bank) and a see-through surface (.b: every blended draw, such as water, glass, particles and cards, and a fluid surface) cover, premultiplied, with their coverage in .a. A blended draw covers the share of the pixel its blend equation changes: its alpha under alpha and premultiplied, the strength of the light it adds (its brightest channel, saturating at 1) under additive, and how far its factor departs from 1 under multiply. Each producer blends its trace premultiplied source-over what stands behind it, so the nearer hold the larger share. A view keeps it only while a pass reads it; a pass writing it alone runs only on such a view. @builtin::shaderModules.media_trace reads and writes it | Rgba16Float | afterSky through afterPost, the post-scene phases included (cleared at the top of every scene render) | none |
@scene.mediaSurface | the distance from the camera to what covers each pixel (.r, world units) and its world normal laid flat on the octahedron (.gb; a medium states the direction back toward the camera), premultiplied by the coverage in .a; the second layer of the texture @scene.media is the first of | Rgba16Float | as @scene.media | none |
@scene.lights | the punctual-light storage buffer: 1024 light entries of eleven vec4s each (the light, then its projection, which names the shadow record it casts through), the light grid, then the virtual shadow map's region: a shadow record per casting light and their page tables. A loop runs over the first @frame.camera[4].w entries, the lights in use; the buffer's length counts the regions after the lights too, so arrayLength does not size a light loop | storage buffer | every phase | — |
@scene.shadowPool | the depth pool every shadow-casting light renders its shadow pages into, read beside @scene.lights through @builtin::shaderModules.light_shadows (zero_light_shadow): the shadow a point, spot or area light casts at any world point, the one the surfaces take. A frame with a pass reading it keeps the coarsest page of every map of each casting light whose reach meets the view | Depth24Plus — binds through a texture_depth compute slot | scene phases only | — |
@scene.sunShadow | the sun's virtual shadow map as the view being drawn reads it: its basis, depth range, clipmap levels and window origins and where its page table starts in @scene.lights, read beside @scene.lights and @scene.shadowPool through zero::sun_shadow (zero_sun_visibility): how much of the sun reaches any world point, past the occluders that shadow the surfaces. A frame with a pass reading it keeps the sun's pages under the air the view looks through | storage buffer (ZeroVsmUniform, a kind: buffer slot with array: false) | scene phases only | — |
@scene.environment | the reflection-probe cube array | texture cube array | scene phases only | — |
@scene.environmentSampler | the filtering sampler for @scene.environment | sampler | scene phases only | — |
@scene.reflectionProbes | the environment buffer: the probe blend data naming which probe reaches a point, then the irradiance light-probe volumes | storage buffer | scene phases only | — |
The rendering and ray-tracing guides (guides { path = "topics/rendering" },
guides { path = "topics/raytracing" }) point here rather than repeating this
table.
What a full-frame pass reads, at each stage, on each path. A full-frame
pass is a fragment or compute pass of a render feature, or an effect of the
post-process chain (postprocess.add). The G-buffer channels above are what the
deferred path knows about each pixel's surface, and they are the four the paths
differ on:
| Channel | Deferred path | Forward path |
|---|---|---|
@scene.color, @scene.depth, @scene.motion | every stage (depth and motion from afterDepthPrepass and afterOpaque on, as the table states) | the same |
@scene.normal, @scene.material, @scene.shaded, @scene.emissive | afterOpaque through afterPost: the lighting, medium, preTemporal, temporal, postTemporal, meter, optics, display and ui stages, and every layer of the chain. Before afterOpaque a pass naming one in inputs reads the previous frame's surfaces (readsPrevious), and the surface helpers read their stated substitute with zero_scene_surfaces_drawn() false | none: the forward path draws no G-buffer. A pass naming one as an input is skipped, and the log names the channel and the reason. A shader reading one through the surface helpers reads its stated substitute (zero) and zero_scene_surfaces_drawn() reads false, so it draws a picture of its own there |
Two readers reach them. A pass names a channel in inputs (or a compute
binding), as above. A fragment pass's shader, or a chain effect's, reads them
by screen uv through the post framework's surface helpers (zero_scene_normal,
zero_scene_material, zero_scene_shaded, zero_scene_emissive; the shader
type README's post-process section has the table), which spend none of the
pass's input slots. Either way a render keeps a channel only when
something reads it: a queued pass naming it, a queued fragment pass whose
shader calls its helper, or a running chain effect that does. The channels
are at the scene's resolution, so a pass after an upscale reads them by uv.
A pass before the temporal stage reads each channel as the raster drew it,
with this render's sub-pixel offset. With temporal antialiasing running
(@builtin::systems.antiAliasing.temporalAntiAliasing), a reader after the
temporal stage reads @scene.depth, @scene.normal and @scene.material
restated at each pixel's centre, with no sub-pixel offset, so under a still
camera they hold still the way the resolved picture does: the restatements
run on a frame where a pass after them names the channel or a shader reads it
through its helper, and a chain effect reading the helpers is such a reader.
@scene.shaded and @scene.emissive keep the raster's sub-pixel offset at
every stage. ctx.renderPath names the path a feature's
render(ctx) runs on, and postprocess.status() lists, for each effect, the
channels it reads and, after a frame it drew with their substitute, the
substituteReason.
Two g-buffer channels describe the surface, and they answer different
questions. @scene.shaded is what a surface SENT — the colour the geometry
pass shaded it to, linear and scene-referred, so a surface lit above the
display's peak reads above 1 there. @scene.material is what the surface IS:
the base colour it reflects, its metallic and its perceptual roughness, each in
[0, 1] and each independent of how brightly the surface happens to be lit. A
pass that multiplies incoming light by a reflectance — a bounce multiplier, a
Fresnel tint, an ambient floor — reads @scene.material; a pass that filters
the picture reads @scene.shaded.
@scene.material is an Rgba8Uint channel packing all three into 32 bits, so
its slot declares sample: uint and the module unpacks it:
# bindings.yaml
- { name: scene_material, kind: texture2d, sample: uint }
#include "@builtin::shaderModules.gbuffer_material"
let m = zero_gbuffer_material(scene_material, coord);
let bounce = incoming * m.base_color;
@scene.albedo is another name for @scene.shaded (the SHADED lit colour) and
@scene.mr for @scene.material (the material channel). The engine logs the
substitution once per name, naming the canonical one to write.
@scene.motion carries screen-space velocity: the NDC displacement each pixel's
surface underwent since the previous frame, so a still surface under a still
camera reads (0, 0). Opaque geometry contributes it on both render paths:
the visibility raster writes it for every surface it records, and an opaque
surface whose depth state the raster cannot express writes its own where it
draws. A moving entity, a moving camera and an animated pose all reach it in
the viewport; transparents, particles and sky carry none. A surface a
material's vertex() hook displaces carries the displacement's own velocity. A render target's own camera and a
capture keep no view history, so velocity there is the entity's motion with no
camera term.
@frame.camera is a reserved buffer input carrying the camera CURRENTLY
being drawn: 18×vec4<f32> = the inverse view-projection (columns [0..4),
column-major) + camera world position ([4].xyz, with the number of lights
@scene.lights holds in [4].w) + the previous render's view-projection
(columns [5..9)), which projects a point into the picture that render left +
the view-projection itself (columns [9..13)), which projects a world point
onto the view being drawn and is the matrix the scene rasterized with + the
sub-pixel offset that matrix carries ([13].xy, in NDC; zero without a
temporal upscale) + the view-projection with no sub-pixel offset (columns
[14..18)), the matrix the view's next render states as its previous one, so
a view drawn again from where its camera stands reads [14..18) word for word
equal to [5..9). A compute pass declares a
buffer binding and binds it via inputs = { name = "@frame.camera" }, then
reconstructs a pixel's world position from @scene.depth:
let inv_vp = mat4x4<f32>(cam[0], cam[1], cam[2], cam[3]);
// ndc.z is the `@scene.depth` sample itself. Scene depth is reversed — 1.0 is
// the near plane, 0.0 the far plane and empty sky — and this matrix inverts
// that same range, so a sample goes in unmodified.
let wh = inv_vp * vec4<f32>(ndc, 1.0);
let world_pos = wh.xyz / wh.w;
Like @scene.*, the engine resolves it per render target — so the same pass
reconstructs against the live viewport's camera on screen and against an
offscreen capture's / RTT camera off screen. (Pack a camera matrix into your own
buffer instead and the offscreen render reconstructs against the wrong camera.)
Render-feature passes run in the main viewport render and in offscreen captures / render-to-texture, each against its own camera. The
capturetool'ssource = "position"/"entity"therefore run the pass queue too; using@frame.camerais what keeps those captures matching the live viewport.
The view's matrices
@frame.view is a reserved buffer input carrying the view CURRENTLY being
drawn as the separate matrices a view-space algorithm is written against, which
@frame.camera states only as their product: 17×vec4<f32>, every matrix
column-major and none carrying a sub-pixel offset. Columns [0..4) hold
world-to-view; [4..8) hold view-to-clip, so [4..8) times [0..4) is
@frame.camera's view-projection with no sub-pixel offset ([14..18)).
[8..12) and [12..16) hold the same two matrices as the view's previous
render drew with, the pair @frame.camera's [5..9) is the product of; a view
with no previous render, or one that opens a new shot, states its own matrices
there. [16] holds the camera's near distance in x and its far distance in
y (both 0 where the view's projection is handed in whole, an environment
face, whose view-to-clip holds that whole matrix under an identity
world-to-view), and in zw the sub-pixel offset the render's projection
carries in pixels of the raster it is drawn at, along the NDC axes (x to the
right, y up; zero without a temporal upscale).
Like @frame.camera it is resolved per render target: the viewport, a
capture and a render-to-texture camera each read their own camera's matrices.
Its words differ from view to view and frame to frame, so a versioned pass that
binds it is refused. A pass that stands from frame to frame reads it on the
GPU like the other @frame.* buffers.
# bindings.yaml
- { name: frame_view, kind: buffer, access: read, element: vec4<f32> }
let world_to_view = mat4x4<f32>(frame_view[0], frame_view[1], frame_view[2], frame_view[3]);
let view_to_clip = mat4x4<f32>(frame_view[4], frame_view[5], frame_view[6], frame_view[7]);
let near = frame_view[16].x;
let jitter_pixels = frame_view[16].zw;
inputs = { frame_view = "@frame.view" }
The scene's light
@frame.light is a reserved buffer input carrying the scene's sun and
ambient term as the camera being drawn is shaded by them, the values the lit
passes read in the same frame: 3×vec4<f32> = the direction the sun's light
travels (unit, world space) with its intensity in w, the sun's colour with
w 1 while it casts shadows, and the ambient colour with its intensity in w.
A pass that lights a participating medium (clouds, haze, fog) reads its sun
here rather than carrying one of its own, so a day cycle, a scripted sun and a
sun switched off reach the medium in the frame they reach the surfaces, and a
scene with the sun and every light at zero leaves it black. #include "@builtin::shaderModules.frame_light" reads it, and states the sun's light
either in the units the scene's lights are stated in
(zero_frame_light_sun_irradiance), for a medium that scatters those lights
too, or as the share of a medium's authored brightness the sun lights (its
intensity up to a unit sun, zero_frame_light_sun_tint):
# bindings.yaml
- { name: scene_light, kind: buffer, access: read, element: vec4<f32> }
#include "@builtin::shaderModules.frame_light"
let light = zero_frame_light(scene_light[0], scene_light[1], scene_light[2]);
let toward_sun = zero_frame_light_toward_sun(light);
let sun = zero_frame_light_sun_tint(light) * authored_brightness;
inputs = { scene_light = "@frame.light" }
The frame's clock
@frame.clock is a reserved buffer input carrying what the frame is doing:
3×vec4<f32>, the same for every view drawn in the frame. [0] holds the
shading time in seconds (the instant a renderer.temporal.hold pins while one
stands) in x, the seconds the frame advanced it by in y, that step in
sixtieths of a second in z, and the frame index in w, counted from the
engine's start and wrapping at 2^24 so a float holds it exactly (0 while a hold
stands, with a step of 0). [1] holds four values drawn uniformly from [0, 1)
by hashing the frame index: the seed a pass derives its per-frame random
rotation, jitter or sample offset from. [2] holds in x the wall-clock
seconds since the renderer drew its previous frame (at most 1), which runs in
every mode, paused play and a renderer.temporal.hold included: the step a
rate on the wall clock, such as an exposure adapting, advances by. A pass
reads these words, so a feature
whose passes stand from frame to frame writes none of them into a buffer of its
own, and states no version: a versioned pass that binds the clock is refused,
since the words differ on every frame.
# bindings.yaml
- { name: frame_clock, kind: buffer, access: read, element: vec4<f32> }
let time = frame_clock[0].x;
let step_scale = frame_clock[0].z;
let frame = u32(frame_clock[0].w);
let seed = frame_clock[1];
let wall_step = frame_clock[2].x;
inputs = { frame_clock = "@frame.clock" }
The environment
A compute pass reads the scene's captured surroundings — the reflection-probe cube array, its sampler and the environment buffer (the probe blend data, then the irradiance light-probe volumes) — through three reserved inputs, bound to bindings of the shapes group(0) binds them in:
bindings:
- { name: environment_map, kind: textureCubeArray }
- { name: environment_sampler, kind: sampler }
- { name: zero_environment, kind: buffer, access: read, element: ZeroEnvironment, array: false }
inputs = {
environment_map = "@scene.environment",
environment_sampler = "@scene.environmentSampler",
zero_environment = "@scene.reflectionProbes",
}
Named like that, #include "zero::environment" in the shader resolves the
environment at a world point along a direction — zpbr_sample_environment(world_pos, dir, lod), the probes whose radius reaches the point blended by rank and
proximity, each through its proxy volume, and the sky under them — exactly as a
material's environment term does, so a reflection a pass draws and one a
material draws agree about the room they are in. A pass that reads several
directions at one point selects the probes once, let probes = zpbr_select_probes(world_pos);, and gathers each direction with
zpbr_gather_environment_with_probes(probes, world_pos, dir, lod), which answers
the radiance in rgb and the share of it the probes and sky claimed in a.
The three bind at the scene phases; a post or UI phase carries none. A textureCubeArray binding takes
@scene.environment alone, and a fragment pass has no slot of that shape.
Pass kinds
enqueue runs one of six kinds (the kind field; default "fragment"):
-
"fragment"— a full-screen shader over input textures. The program is a GPU material (orshader) the feature constructed;inputsbind live textures (@scene.*or RT guids),outputis the target RT (omit = the phase's default scene target). Post-process, blur, edge effects.Writing named G-buffer channels (
outputs). Instead of the singleoutputRT, a fragment pass may declare anoutputsarray — one or more targets, each a named engine channel (@scene.shaded/@scene.normal/@scene.emissive/@scene.color) or an RT guid — each with its own blend mode:ctx.enqueue { kind = "fragment", shader = myShaderKey, outputs = { { target = "@scene.shaded", blend = "under" }, -- premultiplied dst-over-src { target = "@scene.emissive", blend = "additive" }, -- one fullscreen pass, two targets (MRT) }, phase = "afterOpaque", -- deferred: G-buffer filled, before the composite }Blend modes — the keywords every pass's
blendtakes,srcbeing what the pass returns anddstwhat the target holds:Keyword Result "replace"src— overwrites"alpha"src.rgb * src.a + dst.rgb * (1 - src.a)— straight-alpha source-over"premultiplied"src + dst * (1 - src.a)— source-over for a colour already multiplied by its alpha"additive"src + dst— sums"under"src * (1 - dst.a) + dst— premultiplied destination-over-source: what the target holds stays in front, which accumulates coverage-weighted contributionsA keyword outside the table raises from
ctx.enqueue, naming the field. A@scene.*channel resolves only where it exists (the deferred G-buffer at a pre-composite phase); a pass whose targets are all unavailable at its phase is skipped (logged).output+blend = trueremains the shorthand for a single alpha-blended target. The shader's returned colour is written to every target in the set.A fragment shader returns
vec4<f32>, so the channels it can target are the float ones.@scene.material(also named@scene.mr) isRgba8Uint, which binds asuint— naming it as an output is refused by name, with the channel's format and class in the log, and the rest of the frame draws. A fragment pass'sinputsreads through the same fixed float slot, so naming@scene.materialthere is refused the same way; a compute pass reads that channel through asample: uintslot instead.What a pass with no
inputssamples. A fragment pass that declares noinputsreads@scene.color— the shape of an effect that filters the scene image. A pass that names@scene.coloramong its ownoutputssamples a 1x1 transparent texel instead, because the scene colour is that pass's render target and one texture is a colour attachment or a sampled resource in a render pass, never both. Declareinputs = { src = "@scene.color" }and write an RT to read the scene image and write somewhere else in one pass. -
"compute"— a workgroup dispatch (shader,storage,buffers,dispatch; see "Compute passes"). -
"geometry"— draw scene geometry with a constructed pipeline. The program is a material the feature built (renderer.material.create); the engine draws the scene's render-objects with that material's pipeline + uniforms. -
"draw"— rasterize the feature's OWN geometry:geometrynames a buffer created withusage = { "vertex" },storage.indexone created withusage = { "index" }, andselectthe one entity whose transform and material the draw lands through.params[0]is how many indices to submit — or name a buffer understorage.indirect(created withusage = { "indirect" }, holding aDrawIndexedIndirectArgsblock: index count, instance count, first index, base vertex, first instance) and the count comes from the GPU instead, so a compute pass that compacts geometry pays only for what it kept and nothing waits on a read-back.first_instancemust be 0; the engine resolves the entity's per-instance data another way, because a non-zero one needs a device feature WebGPU does not guarantee. -
"splat"— rasterize a compute buffer of particle records as instanced camera-facing billboards into feature RTs (see "Splat passes"). -
"raster"— draw geometry the feature makes itself with a.rasterShaderof its own:vertexCountvertices for each ofinstanceCountinstances, pulled from the buffers the pass binds, into the scene or the feature's targets, depth-tested against the scene (see "Raster passes").
Geometry passes
A geometry pass re-draws the scene's meshes with a material you supply — the generic primitive for mesh-space effects (the engine names none of them):
ctx.enqueue {
kind = "geometry",
material = myMaterial, -- the HANDLE renderer.material.create
-- returned (or its registry-key string)
geometry = "@geometry.opaque", -- which drawables: "@geometry.opaque" |
-- "@geometry.transparent" | "@geometry.all"
select = { entityA, entityC }, -- OPTIONAL: restrict to these entities
-- (entity refs); omit = every matching mesh
phase = "afterLighting", -- afterLighting = lit scene + valid depth
}
select restricts the draw to the given entities — the per-instance signal that
turns a whole-scene pass into a chosen-meshes effect. A pass with no select
also draws the instanced populations (renderer.mesh.drawInstanced) its
geometry set takes, every copy at its own slot, so a whole-scene pass sees an
instanced forest as it sees the entities around it. The material decides how
those meshes are drawn; you control three things:
- Pipeline render-state.
renderer.material.createtakes arenderblock —cull(back/front/none),depthWrite(bool),blend(opaque/alpha/additive) — so the pass can rasterize differently from the surface pass:local myMaterial = renderer.material.create({ shader = myShaderKey, -- a .shader you authored (identity, not guid) render = { cull = "none", depthWrite = false }, properties = { outline_color = { 1, 0.4, 0, 1 } }, -- seed the shader's uniforms }, "my_pass_mat") -- pass `myMaterial` (or "my_pass_mat") as the pass `material` - The shader. A geometry
.shaderis a surface shader: authorfn vertex(v: VertexData) -> VertexDatato move vertices (object-localv.position/v.normal) andfn fragment(input: FragmentData) -> vec4<f32>for the colour. - Its properties. A shader reads ONLY the uniforms IT declares in
properties.yaml, viamaterial.<yourProp>. Referencing a field it didn't declare (e.g. a StandardMaterialmaterial.base_color) fails to compile and the mesh renders magenta — declare the property or use a constant.
What effect those three produce (outline, x-ray, wireframe, highlight, …) is yours to design — the engine just draws the selected geometry with your pipeline.
What a pass starts its target from (load)
A geometry or draw pass with no output draws over the phase's own scene target,
which holds the frame as it stands. A pass naming an output render target begins
by setting that target's colour and depth to a starting state, and load says
which:
load | the target starts as |
|---|---|
"clear" (default) | empty: transparent colour and the far depth, so the target holds only what this pass draws |
"keep" | what it holds: colour and depth as the last pass to draw into it left them, so this pass draws over that, depth-tested against it |
Two geometry passes naming one output therefore leave only the second one's draw
by default, since the second pass starts from an empty target. State keep on the
second to draw both, the way one camera draws many entities into one target:
ctx.enqueue { kind = "geometry", material = tagMat, output = mask.guid,
select = groupA, phase = "afterLighting", order = 0 } -- starts from empty
ctx.enqueue { kind = "geometry", material = tagMat, output = mask.guid,
select = groupB, phase = "afterLighting", order = 1,
load = "keep" } -- draws over groupA's
keep loads what the target holds when the pass begins: the draws of the passes
before it this frame, and the previous frame's picture where none drew it first
(and where a screen-sized target is made again, an empty one). The first pass to
draw a target each frame says "clear" so the target starts the frame empty; an
accumulation across frames is the one that says "keep" there too. load is
refused, naming the field, on a pass that is not a geometry or draw pass or that
has no output. A splat pass loads its targets with blend = true, and a raster
pass clears them with clear = true.
How much of each mesh it draws. A pass drawing into a small map (a top-down cover or height map, a coarse occlusion mask) holds none of the detail finer than a texel, and two fields keep it from paying for that detail:
detail = 1.0states the world-space size of the finest detail its target holds. Each static mesh then draws at the coarsest cut of its cluster hierarchy whose error, placed at the object's scale, stays within that size, the cut the scene's own draw takes for a distant object: a building keeps its walls and roof and a tree its crown, in far fewer triangles than their full detail. A mesh drawing from its own vertex streams (a skinned or morphing mesh, one with no cluster set yet) and an instanced population draw in full.rigid = trueleaves out every mesh a skeleton poses or morph targets blend, so a crowd of characters costs the pass nothing.
renderer.feature.drawn() reads what each geometry pass drew on the last drawn
frame, as { objects, triangles } keyed by its material, so the difference
either makes is a number.
Where each surface stands. A geometry pass draws every object through the
pass's own material, at that material's depth bias. objectDepthBias = true
adds to it the depth bias (depthBias, depthBiasSlope, depthBiasClamp) each
object's own material states, so a pass testing against the scene's depth meets
a decal or an overlay its material lifts toward the camera at the depth the
frame drew it at; the zfighting capture view counts surfaces this way. A clamp
either side states caps the sum, and a versioned pass stating it draws in every
view.
Compute passes
A compute pass dispatches a .computeShader program over a workgroup grid:
ctx.enqueue {
kind = "compute",
program = myComputeShader,
storage = { outTex = myStorageRtGuid }, -- slot -> storage-texture RT guid
buffers = { particles = "my_particle_buf" },-- slot -> named compute buffer
inputs = { camera = "@frame.camera" }, -- slot -> @frame.*/@scene.* buffer
dispatch = { x = 64, y = 1, z = 1 },
}
dispatch is optional. Omit it and the pass is dispatched over what it
WRITES: a grid covering its first storage texture, at the @workgroup_size the
shader's entry point declares. With a screen-sized storage target that grid
tracks the render target being drawn, so a screen-space effect covers the live
viewport, an offscreen capture and an RTT camera without the feature knowing any
of their resolutions:
ctx.enqueue {
kind = "compute",
program = myComputeShader,
inputs = { scene_color = "@scene.color", cam = "@frame.camera" },
storage = { outTex = myScreenSizedRt.guid }, -- screen = true
phase = "afterLighting",
}
State an explicit dispatch for a grid that is not one thread per output texel
(a reduction, a particle sim), or when the shader's @workgroup_size is an
override/const expression the engine cannot read.
dispatch = { indirect = <buffer>, offset = <bytes> } takes the grid from the
GPU: the pass runs the workgroup counts (x, y, z, three u32) found offset
bytes into the named compute buffer (default 0; a multiple of 4), which a pass
earlier in the frame wrote. A scheduling pass counts the work that exists this
frame, writes the counts, and the passes after it dispatch over exactly that
work, so a pass that touches one object in ten costs the one in ten:
-- the buffer is created with usage = { "indirect" }; the first pass writes its
-- three counts, the second dispatches over them
local args = schedule:createBuffer("args", { type = "f32", len = 3, usage = { "indirect" } })
ctx.enqueue { kind = "compute", program = schedule, buffers = { args = args }, dispatch = { x = 1, y = 1, z = 1 }, order = 1 }
ctx.enqueue { kind = "compute", program = work, buffers = { items = items }, dispatch = { indirect = args }, order = 2 }
indirect takes the buffer's handle or its name. A pass naming a buffer that does
not exist, was created without usage = { "indirect" }, or holds fewer than
three u32 from offset, is skipped with a warning naming the buffer. A count
of zero in any dimension runs no workgroups. The pass that dispatches from a
buffer does not bind that buffer as a writable storage binding (the GPU reads
the counts while the pass runs); each count stays within the device's
max_compute_workgroups_per_dimension (65,535 on the WebGPU baseline), so a
count past it is split over x and y by the pass that writes it. dispatch states
either x, y, z or indirect, not both. Native and the web build dispatch
the same way.
Each WGSL storage-buffer binding in the shader resolves its bound slot in this
order: an explicit buffers mapping (the handle a buffer's owner holds, or a
name), then inputs (@frame.camera / @frame.view / @frame.light / @scene.lights /
@scene.reflectionProbes), then — when a slot has neither — a buffer whose
engine-side name equals the slot's own name. buffers
is the seam a pass binds through: the buffers a shader works over are the ones
handed to it, whatever each is called. storage binds storage TEXTURES (RT
guids) the same way, one map per resource kind.
A table built from a few settings. A compute pass whose targets follow
from inputs that rarely change (a lookup table, a baked noise volume) states
the version of those inputs as version, a string or a number. The pass runs
in a view only while some render target it writes holds no picture this
program recorded at this version, so the table is built in the first view
after the version moves and skipped in every later view and frame:
ctx.enqueue {
kind = "compute", program = bakeLut,
buffers = { settings = settingsBuf },
storage = { lut_out = lutRt.guid },
phase = "afterSky",
version = string.format("%.17g,%.17g", density, falloff),
}
A pass reading the table later in the frame reads the picture it holds. The
table is built again when the version changes, when the pass's own
params, dispatch, buffers or storage change, when the program's
pipeline is rebuilt (an edit to its source), when a render target it reads
through its inputs holds a new picture (so a table built from another table
is built again whenever that one is, and one built from a camera's target or a
video target whenever that target draws), when another texture it reads there
holds new texels, when a pass of any other version or none writes the target,
when the target is reallocated or cleared, and when the device reports an error
after the build was recorded. What the build reads from a buffer's contents or
from a value its program holds (ref:setParam) belongs in the version. A pass reading a
texture a GPU producer outside the texture cache writes, a 3D texture, or the
scene's acceleration structure and hit tables is built in every view.
A table built from the view being drawn. A table that follows the camera
too (a sky seen from the camera's altitude) binds @frame.camera, and names
what its program reads of the view in viewReads: "@frame.camera.position"
(the camera's world position, @frame.camera[4].xyz) and "@frame.light"
(the whole light buffer). The engine names the build by those values as each
view holds them, so the table is built in a view drawn from where it was not
built and stands in every view and frame drawn from where it was. render
runs once a frame and states what follows from the frame alone in version;
the engine adds what each view holds:
ctx.enqueue {
kind = "compute", program = skyTable,
inputs = { cam = "@frame.camera", lut = transmittanceRt.guid },
buffers = { settings = settingsBuf },
storage = { sky_out = skyRt.guid },
phase = "afterSky",
version = string.format("%.17g,%.17g,%.17g", sun.x, sun.y, sun.z),
viewReads = { "@frame.camera.position" }, -- built again when the camera moves
}
Every view of a frame shares the target, so a capture or a render-to-texture camera standing elsewhere builds the table for its own camera, and the next view drawn from the viewport builds it again for the viewport's. The program reads nothing else of the camera buffer: its orientation, its projection and a temporal upscale's sub-pixel offset move from frame to frame and name no build.
A geometry pass drawing a map of the scene into a render target of its own
(output) takes a version too. Its build is its material (the shader's
install, the row it draws with: its property values, textures, render state
and the buffers it binds, and the picture each render target it samples
holds), its version, its geometry, select, detail and rigid, the render
layers of the camera drawing it, and the meshes its selection takes as they
stand: each one's mesh, geometry, world transform and node pose (or the place
a substrate binding gives it on the device), the cluster sets the meshes draw,
and each instanced population's transforms. So a map of a
scene where nothing moved is drawn once, a mesh that moved, arrived, left or
changed draws it again in the next view, and an edit to some other material
leaves it standing. A selection taking a mesh a skeleton poses or morph targets
blend draws in every view (rigid = true leaves those out), and so does a
material whose properties follow each object's named values.
The material makes the same picture from every view the build stands for: it
places what it draws without the camera's view (a map seen from above, placed
by a vertex_clip hook), and reads the camera being drawn only through
viewStep: its position rounded to whole steps of that size
(floor(position / step + 0.5)), and the build stands for every view whose
camera stands in the same step. What else it reads that changes (the frame
clock, the sun, a texture's texels) belongs in the version. A power of two
rounds alike in Luau, the engine and WGSL (multiply by its reciprocal there):
ctx.enqueue {
kind = "geometry", material = coverMaterial, geometry = "@geometry.opaque",
output = coverMap.guid, phase = "afterLighting",
rigid = true, detail = 1, -- the meshes nothing deforms, at 1-unit detail
version = 1, viewStep = 32, -- drawn again when a mesh moves or the camera steps
}
A pass of any other kind stating a version is refused when it is enqueued, and
so is a geometry pass drawing into the frame, a viewStep without a version
or on another kind, viewReads without a version, on another kind or naming
a buffer no input binds, and a versioned compute pass binding what each view
draws for itself: an @scene.* input, an @scene.* storage target, or a
@frame.* input its viewReads names nothing of.
Raster passes
A raster pass draws geometry the feature makes itself: a .rasterShader's
vs_main runs vertexCount times for each of instanceCount instances, and
pulls whatever it places from the buffers the pass binds. No mesh and no vertex
buffer stand behind it — the shape of an instanced field of grass, kelp,
leaves or debris, one record per instance. This one draws a field of leaves
from a storage buffer, hidden behind the scene's opaque geometry:
local leafShader = asset.resolve("leaves", "rasterShader")
local leaves -- a buffer of vec4 records, one per leaf: xyz position, w size
return {
setup = function(ctx)
leaves = substrate.createBuffer({ name = "leaf_field", type = "vec4", len = 256, kind = "gpu" })
local records = {}
for i = 0, 255 do
local x, z = (i % 16) - 7.5, (i // 16) - 7.5
table.insert(records, x); table.insert(records, 0); table.insert(records, z); table.insert(records, 0.6)
end
leaves:write(records)
end,
render = function(ctx)
ctx.enqueue {
kind = "raster",
shader = leafShader,
phase = "afterLighting",
vertexCount = 4, -- one quad per leaf
instanceCount = 256, -- one leaf per record
topology = "triangle-strip",
cull = "none",
buffers = { quads = leaves }, -- slot -> buffer, as a compute pass binds them
inputs = { cam = "@frame.camera" }, -- the drawn camera, for vs_main
depth = { target = "@scene.depth", test = true, write = true, compare = "less" },
}
end,
}
The fields a raster pass reads:
| Field | Default | Holds |
|---|---|---|
shader | — (required) | the .rasterShader (its reference or guid) whose vs_main and fs_main the pass draws with |
vertexCount | — (required without indirect) | vertices per instance, @builtin(vertex_index) 0 .. n-1 |
instanceCount | 1 | instances, @builtin(instance_index) 0 .. n-1 |
indirect | none | a buffer created with usage = { "indirect" } holding vertex count, instance count, first vertex and first instance as four u32; the counts then come from the GPU, so a compute pass that culls or spawns instances draws exactly what it kept |
topology | "triangle-list" | "triangle-list" or "triangle-strip" |
cull | "none" | "none", "back" or "front"; a triangle wound counter-clockwise on screen faces the camera, as in WebGPU |
depth | none | { target, test, write, compare }, true for { target = "@scene.depth", test = true, write = true, compare = "less" }, or false for no depth buffer |
outputs / output / blend | @scene.color, replaced | where fs_main's colours land and how they blend: @scene.color, @scene.motion, @scene.media, @scene.mediaSurface or render targets the feature created, each "replace", "alpha", "premultiplied", "additive" or "under" (the blend table under "Pass kinds") |
generateMips | none | render targets (made with mips) whose mip chain the pass fills once it has drawn |
params | the shader's own | values for the shader's params: fields, by name, for this pass |
phase | — (required) | any pass phase (see "When it runs") |
clear | false | clear the render targets the pass draws into (colour and depth) before it draws; the scene's own targets are never cleared |
buffers / inputs / storage | — | the shader's bindings, resolved exactly as a compute pass resolves its own |
Depth. depth.target is "@scene.depth" (the opaque depth the frame laid
down) or a render target the feature created, whose own depth buffer the pass
draws and tests against. compare states the visible order a fragment is kept
in — "less" keeps the fragment nearer to the camera than what the target
holds, "greater" the farther one, and "lessEqual", "greaterEqual",
"equal", "always", "never" likewise — the keywords a material's depth test
takes. Every depth buffer a raster pass draws into is reversed, the scene's and
a render target's alike: 1.0 is the near plane and 0.0 the far plane, and the
engine maps each keyword onto the comparison that order takes, so "less" is
the hardware's greater. clear = true clears a render target's depth to 0.0,
the far plane, so the first fragment "less" meets is always kept. The matrix
in @frame.camera already writes reversed depth. A pass placing vertices with a
projection of its own that maps the near plane to 0 and the far plane to 1 (a
light's orthographic shadow matrix built the conventional way) writes
clip.z = clip.w - clip.z in vs_main to store the reversed value, and states
its compare keywords in visible order as above. test = false keeps every
fragment; write = false leaves the depth as it stood, and lets the same pass
sample @scene.depth through its inputs.
A render target's depth as a texture. inputs = { shadow = "@depth.<guid>" }
binds the depth buffer of the render target <guid> (built with the target
the first time a pass draws into it or reads its depth) to a kind: texture_depth binding, so a later raster or
compute pass reads what a raster pass drew there: a shadow map,
a depth pre-pass of the feature's own. Sample it with textureLoad, or with
textureSampleCompare through a comparison sampler (below).
Winding. A triangle whose vertices run counter-clockwise on screen faces
the camera, as in WebGPU: cull = "back" drops the clockwise ones and
cull = "front" the counter-clockwise ones. A projection that mirrors the
picture (a negative determinant, such as one whose x or y axis is flipped)
mirrors every triangle's winding with it; depth does not enter into it.
Colour targets. outputs (or output) names @scene.color,
@scene.motion, the media trace (@scene.media, @scene.mediaSurface) or
render targets the feature created, each with its blend:
"replace", "alpha", "premultiplied", "additive" or "under", as the
blend table under "Pass kinds" defines them. blend beside a single
output takes the same keywords (true is "alpha"), so
output = rt, blend = "additive" sums into rt. A keyword the pass does not
know raises from ctx.enqueue, naming blend.
Motion vectors. A pass whose geometry moves writes its velocity into
@scene.motion as a second target, outputs = { { target = "@scene.color" }, { target = "@scene.motion" } }, with fs_main returning it at
@location(1) as a vec2 NDC displacement since the previous frame: the
current clip position divided by its w, less the sub-pixel offset this
render's matrix carries (cam[13].xy), less the previous clip position divided
by its w. vs_main projects the previous position through the previous
render's view-projection, cam[5..9). @scene.motion is drawn from
afterDepthPrepass to afterLighting; temporal reconstruction and motion blur
read what the pass wrote there.
Samplers. A sampler binding takes how it samples from bindings.yaml:
filter (linear | nearest), mipmap (linear | nearest), address for
every axis or addressU / addressV / addressW (clamp | repeat |
mirror), and anisotropy (1 to 16, with filter and mipmap linear). A
binding that also states compare (never, less, less-equal, equal,
greater, greater-equal, not-equal, always, compared as WebGPU states
them, reference against stored texel) is a sampler_comparison, for
textureSampleCompare on a texture_depth binding. A binding stating none of
these is the engine's linear, clamped sampler. A compute shader declares its
samplers the same way.
bindings:
- { name: albedo, kind: texture2d }
- { name: smp, kind: sampler, filter: linear, mipmap: linear, address: repeat, anisotropy: 8 }
- { name: shadow, kind: texture_depth }
- { name: shadow_smp, kind: sampler, compare: greater-equal }
Textures the feature made. A texture renderer.texture.create made from
pixels (rgba = ...) binds by its handle (or its guid) in inputs, the way a
render target does. It holds its whole mip chain, each level made from the
pixels it was given, so a sampler declaring mipmap reads it at any level.
Mip chains. renderer.texture.create({ width, height, mips = true })
makes a render target holding its whole mip chain (mips = <n> holds n
levels). A pass draws into the first level; naming the target in
generateMips = { target } fills every level below it, each the 2x2 average
of the level above, once that pass has drawn — a raster, fragment or compute
pass alike. Bound in inputs, the target binds its whole chain, so a sampler
declaring mipmap: linear (and anisotropy) reads it the way it reads a
texture asset's. A screen or history target is resized to each view it
follows and holds one level.
local water = renderer.texture.create({ width = 512, height = 512, format = "rgba16f", mips = true })
ctx.enqueue({ kind = "raster", shader = waterShader, phase = "afterOpaque", vertexCount = 3,
output = water, clear = true, generateMips = { water } })
ctx.enqueue({ kind = "raster", shader = seabedShader, phase = "afterOpaque", vertexCount = 6,
inputs = { water = water }, depth = true })
Per-pass values. params = { exposure = 1.5, layer = 2 } gives the
shader's params: fields values for this one pass, laid over the values the
shader holds; a field the shader does not declare skips the pass, with the
field named in the log. A compute pass takes the same table, and so does a
compute shader's ref:dispatch and ref:dispatchEx.
The camera. @frame.camera bound to a read buffer gives vs_main the view
being drawn: cam[9..13) is its view-projection, the matrix the scene
rasterized with, cam[5..9) the previous render's, cam[13].xy the sub-pixel
offset this render's matrix carries, and cam[4].xyz its position. A raster
pass runs once per view — the viewport, every capture, every render-to-texture
camera — each through its own camera.
When it runs. A raster pass runs at the phase it states, in order with the
fragment and compute passes of that phase (by priority, then the order they
were enqueued), so a later pass reads what it drew. @scene.depth as a depth
target and @scene.motion as an output are this view's from
afterDepthPrepass to afterLighting; at afterScenePost, afterUi and
afterPost a raster pass draws into the composite (@scene.color) and its
own render targets, testing against a render target's depth. A field holding a
value of the wrong shape raises from ctx.enqueue, naming the field; a pass
whose shader failed to compile, or whose targets or bindings do not resolve,
is skipped with the reason in the log, said once until the reason changes.
Another way to draw an instanced field. The guide
topics/rendering-instance-data, section "Instanced foliage built in the
vertex shader — grass, kelp, hair cards, debris", draws the same kind of field
through an engine material: a surface shader's vertex() reads each
instance's record with zero_object_data(v.instance_id, lane) and its
v.vertex_index on a mesh drawn with renderer.mesh.drawInstanced. That field
is lit, casts and receives shadows, writes motion vectors and takes fog and
post-processing as every material does. A raster pass is a hand-written vertex
and fragment program with its own pipeline, depth and blend — the shape a
hand-written renderer ports into.
Splat passes
A splat pass draws every record of an f32 buffer as a camera-facing billboard —
the raster primitive behind screen-space particle surfaces (the fluidSurface
system is built entirely on it):
ctx.enqueue {
kind = "splat",
phase = "afterLighting",
output = depthRt.guid, -- or `outputs` for the thickness+color MRT
splat = {
buffer = "my_particles", -- compute-buffer name
stride = 12, -- floats per record
posOffset = 0, -- float offset of the position
count = 200000, -- records to draw
radius = 0.3, -- world particle radius
channel = "depth", -- "depth" | "thickness" | "sprite" | "gaussian"
velOffset = 4, -- optional: velocity → screen-space stretch
stretch = 0.04, -- seconds of motion elongating the billboard
colorOffset = 8, -- optional (thickness): + per-particle RGB → MRT
weightOffset = 7, -- optional (sprite): per-particle intensity
minY = -60.0, -- records below this y collapse (parked/dead)
maxRadiusPx = 120, -- optional: cap on the projected pixel radius
},
}
The "gaussian" channel draws the engine's packed splat records — what
renderer.splat.components decodes a .spz or .ply capture into — as
elliptical-weighted-average Gaussians, and takes fields of its own:
splat = {
buffer = "cloud_records",
stride = 6, -- the packed record is six u32 words
posOffset = 0,
count = 1200000,
radius = 1.0, -- multiplies each splat's stored scale
channel = "gaussian",
orderBuffer = "cloud_order", -- back-to-front permutation; "over" needs one
shBuffer = "cloud_sh", -- optional: quantized higher-order SH
shStride = 24, -- u32 words of SH per record
shDegree = 3,
transform = model, -- object -> world, column-major, 16 floats
prevTransform = prevModel, -- where `transform` stood last frame
opacityScale = 1.0,
}
transform places the cloud: each Gaussian's covariance is conjugated by its
upper-left 3×3, so a non-uniform scale shears the cloud the way it shears a mesh.
prevTransform plus a second entry in outputs makes the channel write an MRT
pair — the colour into the first target, and the screen-space displacement each
splat underwent between the two placements into the second, premultiplied by the
same alpha the colour composites under. That second target therefore resolves to
(coverage-weighted mean displacement, coverage), which is what folds a moving
cloud into @scene.motion. Naming one target, or leaving prevTransform out,
renders the colour alone.
The other three channels write different fragments: "depth" writes nearest-surface
linear view depth (R32Float, hardware-depth-tested on the target's own depth
buffer), "thickness" accumulates additive optical thickness (with
colorOffset and a two-entry outputs list it also accumulates
thickness-weighted color into the second target), and "sprite" accumulates a
soft additive disc scaled by weightOffset. Every channel discards fragments
behind opaque scene geometry by sampling the scene depth at the fragment's own
NDC. maxRadiusPx scales down billboards whose projected major radius would
exceed that many pixels, so particles crossing the near plane stay
droplet-sized instead of filling the screen. Targets clear at the pass;
blend = true on the spec loads them instead to accumulate over a prior
splat pass.
renderer.feature.create(featureRef) instantiates a feature and returns a live
handle (featureRef may be an AssetRef<renderFeature> or its identity string).
The handle appears under /zero/runtime/generated_features/<guid>/ for exactly
as long as the framework runs the feature's render. Its info names the
feature and its guid, and its setup: line states how setup ended: ok,
none for a feature that declares no setup, or raised: <error>. Re-creating
the SAME feature asset replaces the live one rather than stacking a duplicate.
A write to a live feature's asset (its init.luau, or a module beside it)
starts the feature again on the stored definition from the next frame: its
teardown runs, its setup runs on the new definition, and its guid and
handles stay. The knobs set at create or through configure carry over when
the new definition still declares them and accepts the value; every other knob
takes the new default. A definition that fails to load leaves the running
feature in place, with a warning.
A feature whose render raises is logged ([renderer.feature] '<identity>' render error: ...) and released the way renderer.feature.destroy releases
one: its teardown runs, its passes are withdrawn, it leaves
renderer.feature.list(), its runtime folder and registry row go, and every
handle to it reads released. renderer.feature.find(handle) answers nil for
it, which is how a module holding a handle tells that its feature stopped.
renderer.feature.list()→{ {guid, identity} }for every live feature.renderer.feature.destroy(handleOrGuid)(orrenderer.destroy(handle)) tears one down — by handle OR by guid string, so you can stop a feature even after losing its handle (e.g. across separateexecutecalls).
In the Inspector
Selecting a render feature opens its Feature section: whether the feature runs in this session, an Enable or Disable action, and its settings as typed controls. While it runs, the controls hold its live values and an edit reconfigures the running feature (renderer.feature.configure checks it against the schema first). Those edits are session state: they change the running feature only, they are not undoable (Ctrl+Z never reaches them), and Disable or a restart ends them; the feature's declared defaults are what the next Enable starts from. While it does not run, the controls show the declared defaults, read-only, and a write reaching it then is refused. A feature enabled, disabled or reconfigured from a script shows in the section as it happens. A feature that declares no settings says so.
Temporarily yielding a render stage
ref:suspend(holder) destroys the live feature, releasing its render-stage registration, but retains authored applicable owners, enabled states, values and writers. Holders are nonempty stable caller keys; repeating one is idempotent. Applying, editing or restating while suspended updates authored state without recreating a feature. ref:suspended() reports whether any holder remains. ref:resume(holder) releases only that holder; the last release reconciles enabled applications and recreates the feature with the latest values. Dropped or disabled applications are not resurrected. These are render-feature lifetime methods, not additions to the generic applicable contract.
A competing temporal effect must destroy its own feature before releasing its hold on TAA. Use temporalAntiAliasing.yieldTo / resumeFrom; a render callback that merely returns early does not free the single temporal stage.