Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

environmentLighting

The render feature behind EnvironmentLighting and @builtin::systems.imageBasedLighting.ibl. Four compute passes run after lighting:

orderpassoutput
20ibl_environmentthe sky's radiance over the sphere, 128x64 equirectangular
22ibl_irradiancethat map convolved with a cosine hemisphere — the diffuse term
24ibl_specularthe same map convolved with a GGX lobe at 5 roughnesses, stacked
26ibl_applyboth terms, added from the G-buffer

Why prefiltering

A rough surface gathers light from a wide cone. Gathering it per pixel per frame would mean hundreds of samples per pixel. Convolving once into a small map and reading one texel per pixel is what makes it affordable — the split-sum approximation, with the view direction assumed equal to the normal so one prefiltered map serves every viewing angle.

Roughness levels are stacked into one texture because a compute pass writes one storage target. The apply pass blends the two nearest levels so a surface whose roughness varies does not show the bands as steps.

The environment

The sky is evaluated from the scene's live parameters rather than a constant. That link is the whole point: an environment that does not follow the sky is a painted-on highlight.

The sun goes in as a bright cap plus the glow around it. The cap is what a mirror shows; the glow is most of what a rough surface gathers.

Longitude wraps when sampling, so the seam behind the camera does not show as a line in a reflection.

The BRDF

The split-sum environment BRDF uses Karis's analytic fit rather than a precomputed 2D lookup. Its error is well under what an 8-bit target can show, and it removes a pass and a stored texture.

@scene.material carries the base colour, metallic and roughness. Metal has no diffuse lobe, so the diffuse term goes to zero as metallic rises, and F0 moves from 0.04 to the albedo.

Parameters arrive through the ibl_params buffer, packed by @builtin::systems.imageBasedLighting.ibl.