Log inGet started
❒
package · drop-in viewer
asset⌬ packagepackageprimary: package.yaml·originates fromworld 07158574-5…

ambientOcclusion

Ambient occlusion: the contact darkening of indirect light in corners, creases and where objects meet, and the dimming of the probe and sky reflections that look into them.

by◐lumi·posted 4mo ago
What it does

ambientOcclusion system

Ambient occlusion: the contact darkening of indirect light in corners, creases and where objects meet, and the dimming of the probe and sky reflections that look into them.

Without it, every concave region takes as much ambient and environment light as a flat one: a box resting on a floor has no seam, a corner is as bright as the wall, a polished floor reflects the open sky right up to the foot of a wall, and an untextured scene reads as plastic.

One effect answers two questions for every pixel: what share of the hemisphere above the surface is open, and in which direction it opens (the bent normal). Its answers go into the scene's occlusion channel before anything shades. Every lit material takes the open share on its ambient term (FragmentData.ambient_visibility), and PBR shading (zero_pbr_shade, which the pbr shader and the materials built on it run) takes it on its indirect term alone: on the diffuse lobe with the light a surface's own colour bounces back into a crease, and on the probe and sky part of the reflection lobe as the share of that lobe the open cone around the bent normal holds. A reflection a render feature traced on the screen keeps the light it found, the material's own occlusion alone scaling it. Direct light, emissive surfaces and transparents keep the light they carry.

With indirect, the same search gathers the light those occluders send. Every part of the hemisphere an occluder closes sees the occluder, and the light it sent toward the camera in the view's previous render is what reaches the surface through that part, in the occluder's own colour: a white floor beside a red wall turns red near the wall, a white box carried past a lit wall takes its colour, and a lantern's glow spills onto the stones around it. The diffuse lobe takes that light in place of the surroundings' light the occlusion took away, so turning it on adds no light the scene did not already send.

Using it

The scene's occlusion is a component; author it once and it persists with the scene:

local id = entity.spawn("ambient_occlusion").id
entity(id).component.add("AmbientOcclusion", {
    intensity = 0.9,      -- how far the darkening goes, 0..1
    radius = 1.5,         -- world-space reach
    quality = "auto",     -- auto | low | medium | high | ultra
})

Every field is live: edit one in the inspector and the shading follows. Setting intensity to 0 turns it off without losing the rest.

For code that adjusts occlusion at runtime (a quality slider, a cutscene), reach for the module directly, with the same options:

local ao = require("@builtin::systems.ambientOcclusion.ao")

ao.set({ intensity = 0.9 })   -- any subset; the rest is kept
ao.set({ indirect = true })   -- bounced light from what closes each hemisphere
ao.get()                      -- the settings in force, and the level `auto` picked
ao.qualityLevels()            -- the cost each level pays
ao.active()                   -- is the pass running
ao.stats()                    -- what the pass built and ran this frame
ao.clear()                    -- off, settings kept

What the knobs do

fieldeffect
intensityHow far the darkening goes, in [0, 1]. 0 turns it off and releases the pass.
radiusWorld-space reach, roughly "how big is a crease worth darkening". Constant in world space, so it does not swell as the camera approaches, and measured through the drawn camera's own projection.
powerContrast curve on the visibility term. Above 1 deepens the dark end.
thicknessWorld-space thickness assumed for an occluder: the estimate closes the part of the hemisphere between an occluder's front face and a back face this far behind it, so light passes behind a rail, a post or a wire thinner than the reach.
biasHow far a neighbour must rise above the tangent plane before it closes part of the hemisphere, in [0, 1]. Raise it if a flat surface shades itself in patches; lower it if fine creases disappear.
qualityThe cost of the estimate. auto (the default) follows the device's quality tier; the levels are in the table below.
tracedTrace the hemisphere against the scene acceleration structure while the scene's ray tracing is on (renderer.setRaytrace(true)). A frame drawn without ray tracing takes the screen-space estimate.
temporalCarry the estimate across the renders of each view (true by default): the viewport, every camera rendering to a texture and every capture keep their own accumulation, and a capture drawing the viewport's picture carries the viewport's on (the capture toolbox README has the rule). Each render walks directions the renders before it did not, so the occlusion a view shows holds still, moving or not, and gathers far more samples than one render takes.
indirectGather the light the occluders send (screen-space indirect diffuse): true or a strength, 1 physical and 0 or false off (the default). It scales with intensity as the darkening does. The light comes from the view's previous render, so what is off screen, or hidden behind something nearer, sends none, and the shading's own estimate of the light a crease returns stands in for it there.
qualityscreen-space slices x stepsdepth taps per texeltraced rays per texelresolution
low1 x 6123half
medium2 x 8326half
high3 x 8486half
ultra4 x 129612full

auto draws a desktop's or a browser's high tier at medium, and a handheld's high tier and every medium and low tier at low (renderer.qualityTier(); ao.get().level names the level in force). Every level below ultra computes occlusion on a half-resolution grid: a quarter of the texels, each still costing its level's work. Occlusion is low-frequency almost everywhere, and the filter lifts the coarse grid back to the frame, weighting each texel by the depth where it sits so silhouettes survive the upsample. What a half-resolution grid loses is the innermost pixel of a sharp crease.

How it renders

The pass runs at afterDepthPrepass, where this frame's opaque depth is complete and nothing has shaded yet, in the lighting post stage:

  1. The estimate. Screen-space, it is ground-truth ambient occlusion over a visibility bitmask: a few slices are walked through the texel, the hemisphere along each is cut into 32 sectors, every depth tap closes the sectors between its occluder's front face and its back face thickness behind it, and the open sectors are integrated against the cosine lobe around the normal; their mean direction is the bent normal. Traced, it is a cosine-weighted hemisphere of short rays: the fraction that reaches nothing within radius is the visible fraction, their mean direction the bent normal. Both reconstruct the surface's normal from this frame's depth and store through one function. A tap off the frame says nothing about the hemisphere and is left out, so the frame's edges read like its middle.
  2. The accumulation. Each view's previous result is found again through that view's previous view-projection and blended with this render's estimate, wherever the depth says the surface is the same one; a surface uncovered this render starts from its own estimate. The accumulation is a history target, so every view reads and writes its own, and a view's first render or its first after a cut starts over.
  3. The filter lifts the grid to the frame's resolution, weighing each tap by how close its depth is to the pixel's, so occlusion does not cross a silhouette, and writes the scene's occlusion channel (@scene.ao).
  4. With indirect, the walk of step 1 is ao_pass_indirect: for each run of sectors a tap closes first, it finds the occluder in the view's previous render (@scene.colorHistory, the lit colour that render ended with) and, where that render drew the same surface there and the face turns toward the surface, adds its light weighed by the run's share of the cosine lobe. ao_light_temporal carries that light across the view's renders the way step 2 carries the occlusion, and ao_light_filter lifts it into the scene's indirect channel (@scene.indirect, the second layer of group 0's screen-space light channel), with the share of the closed hemisphere it answers for. A material's diffuse term reads it at its own pixel (zero_scene_indirect_here) and takes it in place of the light the occlusion took from it, and takes its own crease-return estimate only for the share the gather did not answer. A capture drawn once is drawn lit first, so it gathers from a picture of its own; a reflection probe's cube faces take no gathered light.

Shading reads the channel at its own pixel the same frame, on the forward and deferred paths alike. Depth and camera come from the render target being drawn (@scene.depth, @frame.camera), so the result is correct in offscreen captures and render-to-texture cameras at their own resolutions. A capture's first render has no history and takes the first sampling pattern, so two captures of the same scene read the same. A capture drawing the viewport's picture carries the viewport's accumulation on instead, and reads as the viewport's next frame. Sky pixels have no surface to occlude.

Seeing the occlusion on its own

While occlusion is running, ambientOcclusion is a capture view: the visible fraction with no scene colour, white where the hemisphere is open and dark where it is closed.

capture { pass = "ambientOcclusion" }

It is the fastest way to tell a shading problem from an occlusion one, and to compare two radius values or quality levels without the lighting in the way. The pass makes the target it draws the view into when a capture asks for the view and releases it once captures stop asking, so a scene nobody is capturing holds no picture of its own occlusion.

Files

ambientOcclusion.package/
  AmbientOcclusion.component/      -- the scene's occlusion, authored and persisted
  ao.module/                       -- ao.set / .get / .qualityLevels / .active / .stats / .clear
  ambientOcclusion.renderFeature/  -- the pass: estimate, accumulation, filter, occlusion channel, capture view
  ao_grid.shaderModule/            -- what every pass shares: grid coordinates, noise, the bent normal's encoding
  ao_common.shaderModule/          -- the prelude both estimators are written against
  ao_walk.shaderModule/            -- the screen-space walk both screen-space estimates share
  ao_pass.computeShader/           -- the screen-space estimate
  ao_pass_indirect.computeShader/  -- the screen-space estimate with the light the occluders send
  ao_light_temporal.computeShader/ -- the accumulation of that light across each view's renders
  ao_light_filter.computeShader/   -- the depth-aware filter that writes the indirect channel
  ao_trace.computeShader/          -- the traced estimate
  ao_temporal.computeShader/       -- the accumulation across each view's renders
  ao_filter.computeShader/         -- the depth-aware filter that writes the channel
  ao_view.computeShader/           -- the isolated capture view

At lower quality levels

The ambientOcclusion feature's quality scales with the device's quality level (Field.scaled): the values a setup authors are the high look, and renderer.feature.resolved(handle) states what each level draws. The graphics-quality guide lists the rules.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

This asset doesn't declare a schema or structured payload.

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported on this asset or on the parts this page shows. Parts it leaves out are not counted here.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.