s&box
RustCounter-Strike 2s&boxDeadlock
Wiki
Get s&box on Steam
Browse
OverviewGetting StartedCreating GamesEngine & ToolsDocumentationCommunity GamesResources
s&boxDocumentationRenderingShadersClassesFog
SOURCE 2 · C#
Build and play games with s&box.

Facepunch's game engine and creation platform — make games in C#, or jump straight into community games.

Get s&box on Steam

s&box Wiki

  • Overview
  • Getting Started
  • Creating Games
  • Engine & Tools
  • Documentation
  • Community Games
  • Resources

Tools & Community

  • Getting Started
  • Creating Games
  • Engine & Tools
  • Resources

Platforms

  • RustBattle
  • CSBattle
  • Rust Game Wiki
  • CS2 Skins Wiki
  • Deadlock Wiki

About

  • Official Site
  • Developer Wiki
  • GitHub
  • Get on Steam
NOT AFFILIATED WITH FACEPUNCH STUDIOS · © 2026 s&box Wiki (community)
Docs/Rendering
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

AmbientLight
Animated Effects
Attributes and Variables
BeamEffect
Beams
Bindless API
C# Shader Nodes
Classes
← All documentation

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