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

Global Variables

Shaders have access to a number of variables that are available from everywhere. They are defined per-view, meaning that some data will vary depending on current viewport. Compute shader can access this data as well, as long as they are being dispatched from render context.

:::info I don't love these names but they're not going to go anywhere, so you're free to use them. In all likelihood in the future we'll get together and create a bunch of nicer #define's for them, so g_flTime will be accessible viaTime.Now, or just time etc. :::

:::info This page only includes variables that are actually used by the engine and have useful purpose for shaders. You can look up a full list of all global per-view variables, including unused ones, here: game/core/shaders/common.fxc :::

TypeNameDescription
floatg_flTimeCurrent time

These projection matrices are used for conversions between various coordinate spaces.

TypeNameDescriptionHelper Functions
float4x4g_matWorldToProjectionConverts world-space coordinates to projection-space. In vertex shaders, it is common to convert world-space vertex position back to projection space before finalizing vertex manipulationsPosition4WsToPs, Position3WsToPs
float4x4g_matProjectionToWorldConverts projection-space coordinates to world-space. Used in Depth::GetWorldPosition to reconstruct world-space position of ray from depth buffer...
float4x4g_matWorldToViewConverts world-space coordinates to view-space. This coordinate system is built relative to the camera, with it as the originPosition4WsToVs, Position3WsToVs
float4x4g_matViewToProjectionConverts view-space coordinates to projection-spacePosition4VsToPs, Position3VsToPs
float4x4g_matProjectionToViewConverts projection-space coordinates to view space...
float4x4g_matCurrFrameViewToPrevFrameProjConverts view-space coordinates of current frame to projection-space coordinates of previous frameReprojectFromLastFrameSs
float4g_vInvProjRow3Row 3 of the inverse projection matrix...
TypeNameDescription
float3g_vCameraPositionWsCamera position in world space
float3g_vCameraDirWsCamera direction in world space
float3g_vCameraUpDirWsCamera up direction in world space
float4g_vCameraAnglesCamera raw pitch/yaw/roll in radians, unused
floatg_flCameraFOVCamera FOV in radians
floatg_flNearPlaneCamera's near plane
floatg_flFarPlaneCamera's far plane
TypeNameDescription
floatg_flViewportMinZDepth buffer min range for current viewport
floatg_flViewportMaxZDepth buffer max range for current viewport
float2g_vViewportSizeViewport width (X) and height (Y)
float2g_vViewportOffsetViewport top left XY coords for offset if it's on a shared render target
float2g_vRenderTargetSizeRender target width (X) and height (Y)
float2g_vInvViewportSizeReciprocal of original viewport size (1.0 / g_vViewportSize)
float4g_vFrameBufferCopyInvSizeAndUvScaleReciprocal of frame buffer size. X and Y are 1.0f / viewport size, Z and W are always 1.0. This property is considered unused, but you still may see it in some older shaders
TypeNameDescription
float4g_vRandomFloatsRandom floats in each component, values change every frame

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2026-07-30. 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.