Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit0a13e47b57

README.md

Scene setup (asset type)

A scene setup configures a scene as a whole in one asset: its sun and ambient light, its fog, its render features and post effects, or any other effect that applies to a scene. It is an ordered list of members, each an asset whose type implements applicable, with the values the setup states for them. Placed in a scene, it applies every member; selecting the placement shows every parameter of every member, and an edit made there is that placement's own.

Where it lives

  • Source: <name>.sceneSetup/
  • Identity: <name> (the .sceneSetup suffix strips from the identity)
  • Folder shape:
    • sceneSetup.yaml: the definition. Required.
    • README.md: what the setup puts on a scene. Required.
    • .metadata: description and tags. Required.
    • preview.png: its picture. Optional.

The definition

members:
  - id: sun                                        # required, ^[a-z][A-Za-z0-9_]*$, unique
    source: "./sun.sceneLight"                     # any asset that implements applicable
  - id: ambient
    source: "./fill.sceneLight"
    values: { intensity: 0.12 }                    # values for the member's parameters
  - id: fog
    source: "<a fog render feature>"
    enabled: false                                 # optional, default true
  - id: grade
    source: "./grade.postEffect"
    values: { saturation: 0.82, contrast: 1.12 }

A member's values are the values this setup states for that member; the member asset keeps its own, and another holder of it states its own.

A member's source is one of:

  • an identity: lighting.harbour_fill, @builtin::<library>.<name>. It resolves among the assets that can be members, so a name another kind of asset also answers to reaches the member;
  • a path with its type suffix: absolute (/source/lighting/harbour_fill.sceneLight), from the folder holding this setup (harbour_fill.sceneLight, ./harbour_fill.sceneLight, ../shared/fill.sceneLight), or from the world's source folder (lighting/harbour_fill.sceneLight). A path starting ./ or ../ is read from the setup's folder alone.

An identity drops the type suffix, so harbour_dusk.sky and harbour_dusk.sceneSetup in one folder share lighting.harbour_dusk; a member naming that identity is skipped as sceneSetup.member.ambiguous, which names both assets, and its path names the one meant. A source that names nothing is sceneSetup.member.missing, and its values and overrides are kept until it resolves.

A member whose type does not implement applicable is refused by name (sceneSetup.member.unsupported). A key the engine does not read is a warning.

Parameters and paths

A setup's parameters are its members': <member id>/<name> (fog/density), a nested member's under its path (look/reflections/intensity), and <member id>/@enabled for every member. @lit (true by default) says whether the scene renders lit; off, every surface shows its own colour with no light on it, for a stylised game or a menu. asset.schema(setupRef) lists every path with the member's own Field descriptor.

A setup that nests another names its parameters through the member id it gives the nested setup: a setup whose member base is another setup has base/fog/density for that setup's fog/density, and a placement sets base/fog/density. A path that is no parameter is refused naming the paths that end in it.

The value a member receives, for each parameter, first present wins: the placement's override, the outermost setup's values, each inner setup's values, the member asset's live value, then its saved value.

Placing and tuning

-- A world's setup by its identity (`lighting/harbour_dusk.sceneSetup` is
-- `lighting.harbour_dusk`), or by its absolute path, `/source/lighting/harbour_dusk.sceneSetup`.
local root = asset.resolve("lighting.harbour_dusk", "sceneSetup"):instantiate(nil, { name = "lighting" })
local setup = root.component.get("SceneSetup")
setup:set("fog/density", 0.05)                -- this placement's override
setup:set("fog/density", { scale = 3.75 })    -- relative: the setup's density times 3.75
setup:set("fog/heightFalloff", { offset = -0.06 }) -- relative: the setup's value plus -0.06
setup:set("ao/@enabled", true)                -- turns a member on for this placement
setup:reset("fog/density")                    -- back to what the setup says
for path, m in pairs(setup:members()) do print(path, m.state.status) end

The placed root holds the Asset component (its source is the setup) and the SceneSetup component (this placement's overrides); the scene stores nothing of any member. Removing the Asset removes the SceneSetup, and every member's application goes with it.

A relative override ({ scale = n } or { offset = n }, numeric parameters only) lands at the value the setup supplies times scale or plus offset, checked against the parameter's descriptor, and follows that value: edit the setup's fog density and every placement scaling it moves with it. It is saved and synced like any override, and the Inspector shows it as relative.

Where each value comes from. setup:get(path) and each member's values in setup:members() say it: origin is override (this placement's, with relative and supplied for a relative one), definition (with definedBy, the setup stating it, and definedAt, the path it states it at there, so a value inherited through a nested setup names that setup), live (the member asset's live value) or saved. One line proves what a placement shares:

for name, v in pairs(setup:members()["fog"].values) do print(name, v.value, v.origin, v.definedBy) end

A light that follows the sky lands at what the sky makes of it. A sun, a fill or a rim that follows the sky (followSky) states its intensity as its noon peak: the sky gives it that intensity with the sun 30° up or higher and dims it toward the horizon, to about a third at 7° and 0 below it. So a dusk sun stated at 3.2 at 17:51 lands near 0.4. setup:get(path).landed (and setup:set(path, value), which returns the same read) is what it lands at now, beside value, what it states; the card shows 3.2 → lands at 0.4 at 17:51 on the row. The member's state.notice in setup:members() names a light the sky dims to under a third of what it states, a distant fill that lands brighter than the sun it is meant to support, and an ambient term at half the sun or more. Raise the stated intensity, move the hour, or, for a fill or a rim, set followSkyIntensity to false so it keeps what it states.

set in edit mode is a scene edit. In edit mode on a world scene, a set is an authored edit of the scene, recorded and saved: it holds over what build.luau states until it is reset or released (sceneAuthoring releaseAuthored). A reset that leaves the placement with no override records nothing and releases the edit an earlier set recorded. Overrides stated in build.luau are the build's own.

Auditioning another setup

Two placements, or a placement and an application from code, each apply their own sun, ambient term and fog; the effect decides which is in force (the light-tie rule for lights), so an application beside a placed setup reports the members another application holds as held, with heldBy, and its ApplyState.notice names each held member, its asset and its holder. To see a setup in place of the placed one:

  • audition it on the placement, a preview for the session: setup:audition(asset.resolve("lighting.harbour_night", "sceneSetup")) applies it in the placed setup's place and records nothing; setup:endAudition() (or the card's End audition, a flip, a reload) puts the placement's own setup back. set and reset are refused while it lasts;
  • apply it from code (below): it holds over the placement across flips until it is dropped;
  • read its preview: preview.png lights the reference subject @builtin::preview.subjects.lookdev with the setup alone, its exposure fit so a night setup reads (below);
  • point the placement's Asset source at it (a scene edit that stays; releaseAuthored returns the placement to build.luau's setup);
  • or apply it in a scene with no setup placed, such as a scratch scene.

Applying it from code

A setup implements applicable itself, so it can be applied for an owner like any member: setupRef:as("applicable"):apply(owner, values) starts an application and setupRef:as("applicable"):drop(owner) ends it. Each member is applied with the owner "<owner>/<member id>".

  • It takes the effects that hold one at a time. The scene's sun, its ambient term, its sky and each render feature's settings are held by one application at a time: of the applications standing, the newest to state something holds it, so an application made over a placed setup holds them while it stands, and the placement's members report held by it.
  • It stays in force until it is dropped, across edit/play flips and device rebuilds.
  • Its drop hands every effect back to the application before it: the placement's own, or the scene's own lights.

Which of two suns or two fogs is in force is the effect's own to decide; the setup decides nothing about its members. An audition (above) is a preview for the session that a flip ends; an application from code stands until it is dropped.

local night = asset.resolve("lighting.harbour_night", "sceneSetup")
night:as("applicable"):apply("myGame:time", {})   -- night holds over the placement
-- … flips, rebuilds …
night:as("applicable"):drop("myGame:time")       -- the placement's lighting is back

Checking one

asset.validate(setupRef) (an engine API function) reads the definition and every value and returns { ok, problems }: each diagnostic (sceneSetup.member.missing and the rest) with its code, severity, path and message. A problem of severity error refuses a push.

Its picture

A setup's preview.png shows its own lighting on a fixed reference subject, @builtin::preview.subjects.lookdev (a grey ground, a white diffuse sphere, a chrome sphere and a grey card). The preview studio stands the subject and applies the setup to the world with the owner preview for the shot, so its sun, sky and effects are the ones in force, then drops it, which hands every effect back to the scene's own holder. A frame that reads darker than mid grey (a night setup) is shot with its exposure opened up for the picture alone, by up to eight stops, so the night look reads without the setup changing. For those frames the world shows the setup's lighting, so the picture renders only on an explicit request (preview.writePreview, assets.generatePreviews, staging) and never from the preview queue or a live preview; the last picture stands otherwise.

Make one

asset.create("sceneSetup", "dusk", { members = {
    { id = "sun", source = "./sun.sceneLight" },
    { id = "ambient", source = "./fill.sceneLight", values = { intensity = 0.1 } },
} })