Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit0a13e47b57

README.md

skyLight

The light the scene takes from what is drawn behind it. It captures that picture into a cube of six textures it owns, gathers the cube into a diffuse term and a set of reflection bands, and adds both to every lit surface in a pass of its own, at the strengths its parameters state. Whatever draws the backdrop (a gradient, a material, a photograph, clouds) is what it captures: the capture is a render of the captureLayers, with no knowledge of what draws them.

Every step is a call in its init.luau:

  1. Capture. Six cameras, one per cube face, each 90 degrees across, stand at capturePosition drawing only captureLayers and running only the render-feature passes captureFeatures names: by default the ones an environment capture runs, so a fog or a volumetric medium filling the air stays out of the light that lights it. Each is held disabled and rendered once into a faceSize x faceSize texture.
  2. Gather. skyLight_faces folds the six faces into one equirectangular map, which ibl_irradiance convolves into the diffuse term and ibl_specular into five reflection bands of rising roughness. These run on the frames after a capture.
  3. Light. Every frame skyLight_apply adds both terms to the lit G-buffer, the diffuse term scaled by diffuse and the reflection by reflection.
  4. Publish. With publishReflection on, environment.captureSky puts the sky, drawn from capturePosition, into the environment's sky slot: the reflection every surface the reflection probes leave uncovered shows, water and transparent surfaces among them, which the G-buffer pass never reaches. Turned off, or with the feature torn down, the slot is switched off.

A capture is taken when the feature is set up, when what it draws changes (captureLayers, captureFeatures, capturePosition, faceSize, or recapture, a count an author changes to ask for one), and, with followSky on, when the scene's sky row or the direction of its sun changes, at most once per recaptureInterval seconds. The diffuse term and the reflection bands are gathered from every capture whatever the strengths, so a strength changed relights from them.

What a render feature draws into the capture (an atmosphere's sky, a layer over the sky) is part of the picture. A capture, and the sky slot the sky light publishes, is taken once every live render feature has drawn with the settings it holds, so a setup applied in one step is captured as it stands once all its members are in force; the wait ends after 120 drawn frames at most. With followSky on, a change of value in the settings of a render feature that runs in environment captures (its contentRevision in renderer.feature.list) takes a capture and, with publishReflection on, publishes the sky into the slot again, at most once per recaptureInterval seconds. The sky light's own settings do not count.

A render drawn while the renderer still held builds for the scene (pipelines, shader compiles; the pipelinesPending of the face camera's lastRender in camera.observe()) holds the scene as it looked before they landed. The six faces are rendered again, at growing intervals of drawn frames, until one is drawn with nothing pending; redraws counts those repeats.

Parameters

namedefaultwhat it is
diffuse0.15The strength of the captured surroundings' diffuse light on surfaces, 0 to 4.
reflection0.25The strength of the captured surroundings in surfaces' reflections, 0 to 4.
captureLayersskyThe render layers the capture draws.
captureFeaturesenvironmentWhich render-feature passes the capture runs: environment, the ones an environment capture runs (the sky and what is drawn into it; the air and overlays stay out), or all.
capturePosition(0, 0, 0)Where the six capture views are taken from.
faceSize64The width and height of each capture view, in texels.
followSkytrueWhether a change to the sky row, the sun's direction or the settings of a render feature that runs in environment captures takes a capture.
recaptureInterval0.5The fewest seconds between two captures followSky takes.
recapture0A count; any change takes a capture.
publishReflectionfalseWhether the sky also fills the environment's sky slot, the reflection a surface no reflection probe covers shows.
occlusionSourceemptyThe member whose picture of how much of the sky each surface sees (live.skyVisibility) scales the diffuse and reflection terms, as its identity; empty, the terms are not scaled.

With both strengths at 0 it enqueues no lighting pass and still gathers the captured environment, which other members read. The textures it captured into and gathered (faces, environment, irradiance, reflection), the number of captures taken (captures), of repeated renders (redraws) and of gathers that have written the irradiance and reflection maps (gatherCount) are readable at modules.state("@builtin::systems.sky.skyLight.live").

# a setup member
- id: skyLight
  source: "@builtin::systems.sky.skyLight"
  values:
    diffuse: 0.15
    reflection: 0.25