pub struct Atmosphere {
pub sun_direction: Vec3,
pub sun_illuminance: Vec3,
pub altitude_km: f32,
pub km_per_unit: f32,
}Expand description
Hillaire’s atmosphere: a sun, an exposure and a viewpoint, over the planet
crcbl_shaders::atmosphere’s committed tables describe.
Topic 43 §8. Where Sky is three authored
colours, this is the light a real planet’s air scatters — so the sky is blue
overhead because Rayleigh scattering is, and red at a low sun because the
slant path has already taken the blue out, rather than because somebody
picked those colours.
It replaces the gradient rather than adding to it. A renderer given an
atmosphere draws it, lights with its L1 projection and reflects with its
three bands; the Sky it also holds is not read on those frames.
ForwardRenderer::set_atmosphere is what a caller hands this to, and
None is what puts the gradient back.
§What it costs
The sky-view LUT is marched on the host — see
crcbl_shaders::atmosphere::SkyView::build — so the sky’s device cost is
four buffer loads and a blend, the same as the gradient’s. The air in front
of the scene is one more full-screen pass, volumetric-composite, which an
atmosphere frame runs whether or not the fog effect is on: one trilinear
read per covered pixel and no march. What is not free
is changing this value: the first ForwardRenderer::begin_frame after an
atmosphere is set marches the whole LUT and the aerial-perspective LUT
beside it, which is tens of milliseconds of CPU. Every later move of the sun
— or change of Self::km_per_unit — is marched
crcbl_shaders::atmosphere::SKY_VIEW_BUILD_ROWS rows per frame with the
last finished LUT still drawn, so a scene that sweeps the sun pays a stripe
per frame and sees a sky that lags — ForwardRenderer::refresh_sky_view
carries that trade.
Fields§
§sun_direction: Vec3The direction towards the sun, in world space.
Normalised on the way in, so a caller may hand over the same unnormalised
vector it built a DirectionalLight from. A zero vector is taken as
straight up, which is the one direction that leaves the sky azimuthally
symmetric and therefore the one a degenerate input cannot make look
wrong.
sun_illuminance: Vec3The sun’s illuminance above the atmosphere, in linear RGB.
May exceed 1.0, like DirectionalLight::color and for its reason:
the scene target is Rgba16Float and this is a radiance rather than a
display colour. The whole sky is linear in it, so it is an exposure knob
as much as a colour one.
altitude_km: f32The viewpoint’s height above sea level, in kilometres.
Kilometres because that is the unit the planet’s coefficients are quoted in and the one number in this type that is not in the engine’s own units. A scene at ground level passes zero; the LUT is built for one height per sun, which is Hillaire’s own approximation.
km_per_unit: f32How many kilometres one world unit is — the scale the air in front of the scene is marched at.
Aerial perspective: a frame drawn under an atmosphere puts the air
between the eye and every surface in front of that surface, out of
crcbl_shaders::atmosphere::AerialView, and how much air a surface
fifty units away has in front of it is this times fifty kilometres.
The engine’s unit is the metre, so a scene laid out in metres passes
crcbl_shaders::atmosphere::KM_PER_METRE — which is what
Self::NOON carries — and its air is as thin as the physics says: a
plaza’s worth of it is an optical depth under a thousandth. A scene
built at another scale passes its own, and zero is no air at all.
Implementations§
Source§impl Atmosphere
impl Atmosphere
Sourcepub const NOON: Self
pub const NOON: Self
A sun overhead at sea level, normalised so its illuminance is one in every channel, over a scene laid out in metres.
The fixture the render tests build from, and the value a caller starts from before pointing the sun somewhere and scaling it.
Sourcepub fn parameters(self) -> Atmosphere
pub fn parameters(self) -> Atmosphere
This atmosphere in the form crcbl_shaders::atmosphere marches.
The normalisation lives here rather than in the shader crate for the
reason Sky’s own conversion does: that crate names no vector type but
its own arrays, and glam is where a normalise belongs.
Public where that conversion is not, and for a reason rather than
an inconsistency: a test that predicts a frame drawn under this
atmosphere has to march the same sky-view LUT the renderer marched, and
building one from the caller’s own spelling of the sun would put the
normalisation on only one side of that comparison.
crcbl::screenshot::atmosphere_view is the consumer.