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: f32Optical 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: f32The 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: f32Where 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: Vec3The 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: f32What 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: f32What 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: f32How 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.