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(0x444444, 2.0f, 6.0f);

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

Construction

Constructors


Fog()

Constructs a fog object.

cpp
Fog::Fog(Type type, const Color& color);
ParameterDescription
type
color

Factories preferred


Fog::CreateExponential() std::unique_ptr<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 std::unique_ptr<Fog> Fog::CreateExponential(const Color& color, float density);
ParameterDescription
color
density

Fog::CreateLinear() std::unique_ptr<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 std::unique_ptr<Fog> Fog::CreateLinear(const Color& color, float near, float far);
ParameterDescription
color
near
far

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.

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 {};

far float

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

cpp
float far {};

near float

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

cpp
float near {};

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.