Skip to content

Fog

Describes atmospheric fog applied to a scene.

Fog is a scene-level effect that blends fragment color toward a fog color based on distance from the camera. It can be used to suggest large scale, hide distant detail, and soften transitions into the background.

cpp
// Adds linear fog to scene
my_scene->fog = Fog::CreateLinear({
  .color = 0x444444,
  .near = 2.0f,
  .far = 6.0f
});

// Adds exponential fog to scene
my_scene->fog = Fog::CreateExponential({
  .color = 0x444444,
  .density = 0.3f
});

Construction

Constructors


Fog()

Constructs a fog object.

cpp
Fog::Fog(Type type, const Color& color);
ParameterDescription
typeFog::Type specifying the attenuation model.
colorFog color used for fully fogged fragments.

Factories preferred


Fog::CreateExponential() Fog

Creates an exponential fog object.

Exponential fog increases with distance using a density parameter, typically with a factor like or a related variant, which produces a smooth atmospheric falloff.

cpp
static Fog Fog::CreateExponential(const ExponentialParameters& params);
ParameterDescription
paramsInitialization parameters.

Fog::CreateLinear() Fog

Creates a linear fog object.

Linear fog increases its effect given a distance range along the view direction, typically using a factor similar to .

cpp
static Fog Fog::CreateLinear(const LinearParameters& params);
ParameterDescription
paramsInitialization parameters.

Types

Fog::Type enum

Fog attenuation models.

Selects how fog intensity increases with distance. Linear fog uses a depth range, while exponential fog uses a density-based curve that grows smoothly with distance.

ValueDescription
LinearDepth-based fog using a near and far distance range.
ExponentialDensity-based fog using a continuous falloff curve.

Fog::ExponentialParameters struct

Parameters for constructing an exponential Fog object.

ParameterDescription
color ColorFog color.
density floatExponential density factor (higher values produce thicker fog).

Fog::LinearParameters struct

Parameters for constructing a linear Fog object.

ParameterDescription
color ColorFog color.
near floatDistance at which fog begins to appear.
far floatDistance at which fog reaches full intensity.

Properties

color Color

Fog color applied at full intensity.

cpp
Color color {};

density float

Density factor for exponential fog (used when type is Exponential).

cpp
float density {0.00025f};

far float

End distance for linear fog (used when type is Linear).

cpp
float far {1000.0f};

near float

Start distance for linear fog (used when type is Linear).

cpp
float near {1.0f};

type Type

Fog attenuation model.

cpp
Type type {};

Functions

GetType() Type

Returns the fog type.

cpp
Type Fog::GetType() const;

Released under the MIT License.