Skip to content

calculateDaylight

calculateDaylight(hour, settings?): Daylight

Defined in: packages/engine/src/render/daylight.ts:307

What one hour of the day looks like, under the settings the caller is drawing with. One daylight, rewritten by every call: read it before the next.

The settings are a parameter rather than read from the module, because the rig merges a story’s overrides over them and anything read here directly would ignore that merge: a control tuning it would move nothing, silently.

Parameter Type Default value Description
hour number undefined -
settings { clouds: { clumpCells: number; clumping: number; decks: object[]; drift: { x: number; y: number; }; fade: { full: number; gone: number; }; hourOffset: { x: number; y: number; }; scale: number; softness: number; speed: number; sunLift: number; textureSize: number; }; dayCycle: { daylightHours: number; hoursPerCycle: number; nightExposure: number; nightFill: number; noonAzimuth: number; peakElevation: number; realSecondsPerCycle: number; startHour: number; twilightDepth: number; warmthExponents: { blue: number; green: number; }; }; horizonBand: { noonShare: number; peak: number; span: number; }; shadow: { depth: number; halfWidth: number; mapSize: number; normalBias: number; radius: number; }; sky: { distance: number; mieCoefficient: number; mieDirectionalG: number; rayleigh: number; turbidity: number; }; skyIntensity: number; sunIntensity: number; tintStrength: number; } daylightSettings -
settings.clouds { clumpCells: number; clumping: number; decks: object[]; drift: { x: number; y: number; }; fade: { full: number; gone: number; }; hourOffset: { x: number; y: number; }; scale: number; softness: number; speed: number; sunLift: number; textureSize: number; } ... -
settings.clouds.clumpCells number 3 -
settings.clouds.clumping number 0.5 How far a deck’s coverage swings from one part of the sky to another, as a share of the widest swing that coverage allows, and how many banks of it span one tile. One takes the swing as wide as it can go without a sky asked for none having some or one asked for all of it having gaps. Shared by both decks: it is the weather over the meadow rather than anything about a deck.
settings.clouds.decks object[] ... The two decks the field is drawn on, the far one first because that is the order they blend in. Two rather than one, because a single sheet has no depth in it from any angle: every cloud on it is the same distance away, so nothing ever passes in front of anything. Two at different heights cross each other instead — the near one slides across the far one as the camera turns, and one cloud is plainly behind another even in a still frame. They stand at one size in metres, so the far deck’s clouds subtend less and drift slower by exactly the ratio of the two heights, which is what parallax is and needs no second rate anywhere; but each builds its own field from its own lattice, so the two are different weather rather than one sky drawn twice.
settings.clouds.drift { x: number; y: number; } ... -
settings.clouds.drift.x number 0.0125 -
settings.clouds.drift.y number 0.025 -
settings.clouds.fade { full: number; gone: number; } ... Where the layer fades out, as elevation above the horizon rather than as a distance across the ceiling. A flat ceiling crowds the field into more tiles than there are pixels as it approaches the horizon, and past that point it minifies to its own average: an even wash that no amount of drift can move. It has to be gone before it gets there, and where that is depends on the scale and the deck’s height, which is why these are angles and why they are judged on the story rather than derived.
settings.clouds.fade.full number ... -
settings.clouds.fade.gone number ... -
settings.clouds.hourOffset { x: number; y: number; } ... Tiles the field is already carried along at each hour of the day. Without it the drift starts from the same place on every load, so every hour draws the same arrangement of cloud in a different colour and every reload of the meadow opens under the same sky. Elevenths and seventeenths of a day, which is what keeps the sky whole across the two places this could tear. A whole cycle carries the field a whole number of tiles, so the hour wrapping from the last of the day to the first lands where it left off rather than jumping; and neither numerator shares a factor with the hours in a day, so no two hours of the cycle come round to the same sky.
settings.clouds.hourOffset.x number ... -
settings.clouds.hourOffset.y number ... -
settings.clouds.scale number 80 Metres of the cloud ceiling one tile of the field spans, the same for both decks below. Against the height a deck stands at, this is how big its clouds look overhead. It also sets how often the tile comes round across the visible sky, and a tile that repeats often is the other half of what reads as a pattern rather than weather, so it is kept large enough that a deck shows only a few tiles.
settings.clouds.softness number 0.15 How wide a cloud’s edge is, in noise value. Narrow, because summing octaves pulls the field toward its middle and a wide edge over that leaves most of the sky in half-tones — a wash rather than cloud with sky between it. The cloud field’s own tests hold the shares this has to leave.
settings.clouds.speed number 1 What the drift above is multiplied by, and a control rather than a number to tune: one is the rate the game ships. The drift is in tiles a second, so the scale is what turns it into a distance and a deck’s height turns that into an angle.
settings.clouds.sunLift number ... How much higher the layer sees the sun than the meadow does, because it stands above it: the sun sets on a cloud deck after it has set on the ground. This is what makes the clouds orange at the hour the meadow has already lost the key light, and what keeps them off the pure red that colour decays to at the horizon.
settings.clouds.textureSize number 256 -
settings.dayCycle { daylightHours: number; hoursPerCycle: number; nightExposure: number; nightFill: number; noonAzimuth: number; peakElevation: number; realSecondsPerCycle: number; startHour: number; twilightDepth: number; warmthExponents: { blue: number; green: number; }; } ... -
settings.dayCycle.daylightHours number 20 -
settings.dayCycle.hoursPerCycle number undefined -
settings.dayCycle.nightExposure number 0.7 The renderer’s exposure once the sun is that far down: enough of the scattering to read as sky.
settings.dayCycle.nightFill number 0.7 The least the hemisphere fill falls to, so the meadow is a place at night rather than an empty frame. Exposure cannot do this: it scales what is lit, and without this nothing is. It takes over wherever the sun’s own share drops below it, which at this height is an elevation of 28.5 degrees — hours 16.5 to 3.5, so the evening and the early morning are lit by this rather than by the sun, and only their key light still falls. A floor at the horizon instead would step from nothing to the whole of it in one frame. The exposure above multiplies it, so the ground at night is lit by the product and the two move together. That product is what puts midnight at about the brightness the evening reads: with a key light only above the horizon, the same number draws a lit evening and a dim night.
settings.dayCycle.noonAzimuth number ... -
settings.dayCycle.peakElevation number ... -
settings.dayCycle.realSecondsPerCycle number 1200 Real seconds a whole cycle takes. The one number that says how fast the sky moves.
settings.dayCycle.startHour number 10 The hour every load opens on, after which the clock runs. The peak, so the opening scene is the brightest hour and every case sees the same one.
settings.dayCycle.twilightDepth number ... How far below the horizon the sun goes before the sky is as dark as it gets: nautical twilight. Above the horizon nothing dims, so no daytime hour pays for the night.
settings.dayCycle.warmthExponents { blue: number; green: number; } ... -
settings.dayCycle.warmthExponents.blue number 0.6 -
settings.dayCycle.warmthExponents.green number 0.25 -
settings.horizonBand { noonShare: number; peak: number; span: number; } ... -
settings.horizonBand.noonShare number 0.3 The share of that peak it keeps at the sun’s own peak, where the haze reads as distance rather than as a sunset.
settings.horizonBand.peak number 0.55 The band at its strongest, which is with the sun on the horizon.
settings.horizonBand.span number 0.25 How far up the dome it reaches, as a share of the angle from the horizon to the zenith rather than of the dome’s height. The ramp is sampled by the dome’s own vertical coordinate, which runs even in that angle, so the band’s top stands at this share of a right angle and higher up the dome than the same share of its height.
settings.shadow { depth: number; halfWidth: number; mapSize: number; normalBias: number; radius: number; } ... -
settings.shadow.depth number 40 -
settings.shadow.halfWidth number 14 -
settings.shadow.mapSize number 1024 The side of the map in texels, when nobody says otherwise. The app reads the player’s quality level for this instead.
settings.shadow.normalBias number 0.02 -
settings.shadow.radius number 2 -
settings.sky { distance: number; mieCoefficient: number; mieDirectionalG: number; rayleigh: number; turbidity: number; } ... -
settings.sky.distance number 450000 -
settings.sky.mieCoefficient number 0.005 -
settings.sky.mieDirectionalG number 0.8 -
settings.sky.rayleigh number 0.5 -
settings.sky.turbidity number 6 -
settings.skyIntensity number 1.2 -
settings.sunIntensity number 2 -
settings.tintStrength number 0.7 How much of the painted blue the zenith takes, over the top of the scattering. Zero is the atmosphere alone.

Daylight