Skip to main content

Atmosphere

Struct Atmosphere 

Source
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: Vec3

The 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: Vec3

The 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: f32

The 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: f32

How 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

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Atmosphere

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Atmosphere

Source§

impl Debug for Atmosphere

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Atmosphere

Source§

impl PartialEq for Atmosphere

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Atmosphere

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HalThreadSafe for T
where T: Send + Sync,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.