Log inGet started
Package

atmosphere.module

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

atmosphere

Physically-based atmospheric scattering — aerial perspective on distant geometry, and a sky whose colour follows from the sun's elevation.

local atmosphere = require("@builtin::systems.atmosphere.atmosphere")

atmosphere.set({ aerial = 1, sky = true, worldUnitsPerKm = 1000 })
atmosphere.get()      --> the settings in force
atmosphere.active()   --> are the scattering passes running
atmosphere.drawsSky() --> is the scattering result the sky every view draws
atmosphere.clear()    --> off, settings kept for the next set()

set takes any subset — omitted fields keep their current value, so adjusting one knob does not mean restating the rest. With aerial at 0 and sky off nothing is wanted and the passes are released rather than run at zero strength.

worldUnitsPerKm is the one number that has to match the scene. Scattering is computed in kilometres against Earth's coefficients, so it is what maps a scene onto real atmospheric distance. At the default 1000 a world unit is a metre.

sunDirection follows the scene's sun unless the call pins it. Sun elevation is what drives the entire appearance of a physical sky, so that is what lets a day cycle reach the sky with nothing else authored.

sunIntensity is the solar constant exposure is authored against. The sun that reaches the integral is that times the share of it the scene's sun lights, which get().sceneSunShare reports: the atmosphere exposes itself for any sun from a unit sun (intensity 1) up, and a weaker sun dims the air in proportion. The air is lit by the scene's sun alone, so a scene whose sun is off draws no sunlit sky or haze.

At night the sky draws a starfield (stars) and a moon disc (moonDisc, moonAngularRadius), lit by the scene's strongest distant light, which get().moonDirection / get().moonIntensity report. A scene with no such light draws neither, and one whose distant light is a fill rather than a moon sets moonDisc = false.

The tables the passes build (transmittance and multiple scattering when the medium they follow from changes, atmosphere.tableVersions(), and the sky's radiance per direction for every view) are held here, so another feature's pass can light or haze what it draws by the same air: atmosphere.liveTables() hands their guids and the parameter buffer while the passes run, and nil while they do not. The cloud layer reads its sun, its sky light and its aerial perspective through them.

sunColor defaults to white on purpose: the warm colour of a low sun comes out of the transmittance through a longer air path, not out of a tint.

For an atmosphere a scene should simply have, author the PhysicalAtmosphere component instead — it carries the same settings, persists with the scene, and edits live in the inspector. This module is for code that changes the atmosphere at runtime: a weather system, a cutscene, a quality slider.

The full description of what each knob does and how the passes work is in the package readme: guides { path = "systems/atmosphere" }.