Skip to main content

Fog

Struct Fog 

Source
pub struct Fog {
    pub density: f32,
    pub falloff: f32,
    pub reference_height: f32,
    pub color: Vec3,
    pub sun_scattering: f32,
    pub light_scattering: f32,
    pub anisotropy: f32,
}
Expand description

Exponential height fog: how thick the air is, and what colour it scatters.

Topic 43 §4’s cheapest large win. Density falls off exponentially with height above reference_height, and mesh.slang’s fragment stage integrates it along the ray from the eye to each shaded point — so a distant surface fades towards color and a valley fills while a hilltop stays clear, from four numbers and no extra pass.

Fog::NONE is the default and is exactly no fog, not nearly none: a zero density gives a zero optical depth, whose transmittance is exactly one, and the shader composites as two multiplies rather than an interpolation so that one returns the unfogged radiance bit for bit. Every golden blessed before fog existed still matches.

ForwardRenderer::set_fog is what a caller hands this to, and crcbl_shaders::fog is the arithmetic both sides run.

Fields§

§density: f32

Optical depth added per world unit travelled at the reference height.

Zero is off. The useful range is small — a density of one puts a surface a single unit away behind more than half the fog — so this is tenths and hundredths for a scene measured in metres.

§falloff: f32

The height over which the density falls by a factor of e.

Larger is a thicker atmosphere reaching further up; zero or less is fog that does not thin with height at all, which is the limit this approaches rather than a special case in the shader.

§reference_height: f32

Where the density is density, in render-space y.

Usually the ground the scene sits on, so the fog is thickest where the geometry is and thins above it.

§color: Vec3

The radiance the fog scatters towards the eye.

May exceed 1.0, like DirectionalLight::color and for the same reason: the scene target is Rgba16Float and this is a radiance rather than a display colour, so a bright sky’s haze is allowed to bloom.

§sun_scattering: f32

What fraction of the sun’s radiance the medium scatters towards the eye, per unit length.

Read only by the froxel path — RenderEffects::VOLUMETRIC_FOG — and zero everywhere else. mesh.slang’s closed form integrates absorption along the view ray and has no direction in it at all, so there is nowhere for a phase function to go; a caller who sets this without switching the effect on gets the frame they had.

Zero is exactly off: the scattering source is a sum, so a zero term leaves color’s environment term bit for bit.

§light_scattering: f32

What fraction of a point or spot light’s radiance the medium scatters towards the eye, per unit length — the glow around every punctual light in the scene, and the cone a spot cuts through the air.

One coefficient for every light rather than one per light: the medium is what scatters, and it is the same air around all of them. Separate from sun_scattering because a scene’s sun and its lamps are authored in different units, and a haze that reads right against the sun would swamp the frame around a lamp of the same number.

Read only by the froxel path, on sun_scattering’s terms, and zero is exactly off for the same reason: the term is added to the scattering source and a zero adds nothing. A light’s glow is evaluated once per froxel, at its slice’s midpoint, and occluded by the light’s own shadow tiles where its row names them. What the midpoint misses — a small light in a long far slice — is in docs/backlog.md under The froxel column casts its shaft.

§anisotropy: f32

How the medium redistributes what it scatters: positive forward, zero evenly, negative back.

The g of crcbl_shaders::volumetric::phase, clamped there to MAX_ANISOTROPY. Mie scattering in fog is around 0.8, which is what makes looking towards the sun through it bright and looking away from it flat; smoke is lower. Read only by the froxel path, on sun_scattering’s terms.

Implementations§

Source§

impl Fog

Source

pub const NONE: Self

No fog, which is what a renderer nobody has called ForwardRenderer::set_fog on carries.

The colour is black and unobservable: it is read only through the density, which is zero here.

Trait Implementations§

Source§

impl Clone for Fog

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 Fog

Source§

impl Debug for Fog

Source§

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

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

impl Default for Fog

Source§

impl PartialEq for Fog

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 Fog

Auto Trait Implementations§

§

impl Forget for Fog

§

impl Freeze for Fog

§

impl Move for Fog

§

impl RefUnwindSafe for Fog

§

impl Send for Fog

§

impl Sync for Fog

§

impl Unpin for Fog

§

impl UnsafeUnpin for Fog

§

impl UnwindSafe for Fog

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.