Skip to content

Fog shaders

Fog shaders are used to define how fog is added (or subtracted) from a scene in a given area. Fog shaders are always used together with FogVolume and volumetric fog. Fog shaders only have one processing function, the fog() function.

The resolution of the fog shaders depends on the resolution of the volumetric fog froxel grid. Accordingly, the level of detail that a fog shader can add depends on how close the FogVolume is to the camera.

Fog shaders are a special form of compute shader that is called once for every froxel that is touched by an axis aligned bounding box of the associated FogVolume. This means that froxels that just barely touch a given FogVolume will still be used.

Built-ins

Values marked as "in" are read-only. Values marked as "out" are for optional writing and will not necessarily contain sensible values. Samplers cannot be written to so they are not marked.

Global built-ins

Global built-ins are available everywhere, including in custom functions.

Built-inDescription
in float TIMEGlobal time, in seconds.
in float PIA PI constant (3.141592). A ratio of a circle's circumference to its diameter and amount of radians in half turn.
in float TAUA TAU constant (6.283185). An equivalent of PI * 2 and amount of radians in full turn.
in float EAn E constant (2.718281). Euler's number and a base of the natural logarithm.

Fog built-ins

All of the output values of fog volumes overlap one another. This allows FogVolume to be rendered efficiently as they can all be drawn at once.

Built-inDescription
in vec3 WORLD_POSITIONPosition of current froxel cell in world space.
in vec3 OBJECT_POSITIONPosition of the center of the current FogVolume in world space.
in vec3 UVW3-dimensional uv, used to map a 3D texture to the current FogVolume.
in vec3 SIZESize of the current FogVolume when its shape has a size.
in vec3 SDFSigned distance field to the surface of the FogVolume. Negative if inside volume, positive otherwise.
out vec3 ALBEDOOutput base color value, interacts with light to produce final color. Only written to fog volume if used.
out float DENSITYOutput density value. Can be negative to allow subtracting one volume from another. Density must be used for fog shader to write anything at all.
out vec3 EMISSIONOutput emission color value, added to color during light pass to produce final color. Only written to fog volume if used.