Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit0a13e47b57

README.md

procedural

The procedural sky backdrop: a day/night gradient from zenithColor through horizonColor to groundColor, shaped by horizonHeight (how far up the horizon colour reaches, below), with a sun disc and glow, stars and a moon, drawn by the procedural_sky shader over a runtime material of its own.

It enqueues no pass. It writes one Sky row (skyType = "procedural") on a temporary entity, which the engine draws as the scene's sky while that row is in force. The lights that follow the sky (lighting.followSky, as a sceneLight with followSky states) take the sun's direction from timeOfDay. An applied light (a sceneLight) keeps its own colour and intensity as its noon peak and lands at them multiplied by the curve of the sun's elevation: (1, 1, 0.95) and 1 from 30° up, warmer and dimmer toward the horizon (about 0.3 at 7°), and intensity 0 below it. A plain light takes the curve's colour and daylight 10 x sunPeakIntensity x the daylight factor (twice the sun's elevation, clamped to 0..1), zero below the horizon. sunIntensity controls the drawn disc, not the light a plain follower casts. A sceneLight with skyOffset keeps that offset from the sun.

The colours drawn

Three colour sets make the gradient, and the sun's elevation at the hour drawn says which shows:

SunWhat is drawn (both strengths 1)
30° up and higher (about 08:00 to 16:00)zenithColor, horizonColor, groundColor
0° to 30° upthe base colours, falling toward the night set as the sun sinks
about 1° to 16° up (about 06:05 to 07:05 and 16:55 to 17:55)also leaning up to half way toward dawnZenithColor and dawnHorizonColor
below the horizon (about 18:00 to 06:00)nightZenithColor, nightHorizonColor, nightGroundColor

nightStrength and dawnStrength (0 to 1, default 1) say how far each set draws over the base colours. The tint sets serve a sky that runs through the day (autoCycle), where one set of base colours cannot be both noon and midnight. A sky that holds one hour states its look in the base colours with both strengths at 0, so zenithColor, horizonColor and groundColor are drawn as written at that hour. When the sets draw over more than a fifth of the authored zenith and horizon at the stated hour, the backdrop says so: its ApplyState.notice (and a sky's describeSky().notice) names the hour, the share of the authored colours drawn, the set and the strength that mask them.

The gradient's shape

Above the horizon the sky runs from horizonColor at the horizon to zenithColor overhead. horizonHeight (degrees, 0.5 to 80, default 7.933) is the elevation where it is halfway between the two. At the default the sky 10° up is still half horizon colour, so a frame looking level reads mostly horizon. A sky whose overhead colour should show at eye level, with the horizon colour a band along the horizon, lowers it: at 2 the sky 10° up is 77% zenith colour and 30° up 94%; at 1 the sky 5° up already is three quarters. Raising it spreads the horizon colour up the sky.

# <name>.sky / sky.yaml: a teal-violet sky over an orange band
members:
  - id: backdrop
    source: "@builtin::systems.sky.backdrops.procedural"
    values:
      timeOfDay: 17.7
      zenithColor: [0.16, 0.22, 0.42]
      horizonColor: [0.95, 0.45, 0.18]
      horizonHeight: 2
      dawnStrength: 0
      nightStrength: 0

The backdrop draws the sky. The gradient as drawn at the hour drawn is readable through sky.drawnGradient(); light from the drawn sky reaches the scene through a member that captures it, such as skyLight.

With autoCycle on, the hour runs from timeOfDay at cycleSpeed game-seconds per real second on the session clock, so every client of a session draws the same hour; it holds still while gameplay is paused. Name it as a sky's backdrop member.