builtinAOContext
A small helper function that defines a built-in Ambient Occlusion (AO) context for a node graph. It uses context() to register the given aoNode on the rendering pipeline's getAO hook so that AO is automatically taken into account during lighting.
Core Advantages
It injects AO in a declarative way without touching existing shading logic: if there is already an AO input, it multiplies it by the provided aoNode; if not, it uses aoNode as the AO source. It also automatically skips materials with transparent = true, so glass, particles and other transparent objects are not incorrectly darkened.
Common Uses
Injecting a baked AO texture or screen-space AO (SSAO, HBAO, etc.) into a standard PBR lighting setup without manually multiplying AO in every material.
Enabling AO only for specific objects or node graphs by wrapping their lighting node with builtinAOContext.
Stacking an extra procedural AO term (for example based on height, curvature or noise) on top of an existing AO pipeline.
Look-dev workflows where you want to quickly swap or compare different AO sources or intensity curves by simply replacing the aoNode.
How to adjust
builtinAOContext itself has no adjustable properties; its behavior is entirely driven by the aoNode you pass in and by which node graph you wrap. In practice: (1) keep aoNode in the 0–1 range, where 1 means no occlusion and 0 means fully occluded; (2) shape aoNode with pow, mix, smoothstep, etc. to avoid overly dark AO; (3) pass the full lighting or material node graph as the second argument so that AO only affects that part of the shader. When material.transparent is true the AO hook is automatically skipped, so you do not need extra checks for transparent materials.
Code Examples
1// 1. AO factor node in the 0–1 range (smaller = stronger occlusion)
2const ao = texture( aoMap ).g.oneMinus();
3
4// 2. Any lighting / shading node that should receive AO
5const shaded = someLightingNode;
6
7// 3. Wrap the node graph with a built-in AO context
8const shadedWithAO = builtinAOContext( ao, shaded );
9
10// 4. Use it as the final color node for your material
11material.colorNode = shadedWithAO;