Rendering

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.

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

float3 ApplyGradientFog( float3 Color, float3 WorldPosition, 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

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

Volumetric Fog

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

Each of these returns the fogged colour, they don't modify their input.

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2026-08-03. Read it rendered on the official docs.

More in Rendering

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.