Fog

This class applies atmospheric effects to a fragment.

Only useful if you're doing your own Shading Model, otherwise this is already all implied when you use ShadingModelStandard.

API

Apply All

Fog::Apply( float3 WorldPosition, float2 ScreenPosition, float3 Color );

This will apply all types of atmospheric effects onto current pixel (float3 Color) if they are available on scene:

  • Gradient fog
  • Cubemap fog
  • Volumetric fog

If you only need specific fog effects, see the functions below.

Gradient Fog

ApplyGradientFog( inout float3 Color, float3 WolrdPosition, float3 PositionToCamera );

For both gradient and cubemap fog, you need to calculate PositionToCamera. This can be done by simply subtracting world-space camera position from pixel world position:

float3 PositionToCamera = worldPos.xyz - g_vCameraPositionWs;

Cubemap Fog

ApplyCubemapFog( float3 Color, float3 WolrdPosition, float3 PositionToCamera );

Volumetric Fog

ApplyVolumetricFog( float3 Color, float3 WorldPosition, float2 ScreenPosition );





Created 8 Dec 2024
Updated 10 Jun 2026