s&box
RustCounter-Strike 2s&boxDeadlock
Wiki
Get s&box on Steam
Browse
OverviewGetting StartedCreating GamesEngine & ToolsDocumentationCommunity GamesResources
s&boxDocumentationRenderingShadersClassesG Buffer
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

G-Buffer

Materials that write to Depth PrePass also write to a G-Buffer, if you are using the standard ShadingModel, you just have to make sure you have a Depth(); mode enabled.

It contains minimal information about the object before we do the lighting pass, like it's Normals and Roughness, it can be used in post-processing to do all sorts of effects like accurate Ambient Occlusion and Screen-Space Reflections.

You can sample the G-Buffer in any shader with:

float3 Normals::Sample( int2 ScreenPosition )
float Roughness::Sample( int2 ScreenPosition )

If the object in that texel does not write to the G-buffer, then it reconstructs normal maps from it

Writing to G-Buffer

You can write to G-Buffer yourself, if you are writing your own custom shading model, or need to do this for any other reason. Just like it's mentioned above, make sure your shader has Depth() mode enabled.

if ( DepthNormals::WantsDepthNormals() )
    return DepthNormals::Output( Normal, Roughness, Opacity );
  • DepthNormals::WantsDepthNormals() will check if we're in the appropriate mode for writing to g-buffer. (depth prepass, S_MODE_DEPTH == 1)
  • float3 Normal must be a world-space normal vector in (-1 to 1) range
  • Red, green and blue channels are reserved for the normals, and alpha is for roughness/opacity. By default, g-buffer will write normals (RGB channels) and roughness (alpha)
  • float Roughness and float Opacity are optional, if they're skipped then g-buffer will set roughness/opacity to 1

If your shader has alpha test enabled, (defined by S_ALPHA_TEST combo) then Output will write normals (RGB) and opacity (alpha) instead of roughness.

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2025-06-15. 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.