Class Renderer
Namespace: ValveResourceFormat.Renderer
Assembly: Renderer.dll
Main renderer for Source 2 scenes with support for shadows, post-processing, and multiple render passes.
public class Renderer : ISceneHostInheritance
object ← Renderer
Implements
Constructors
Renderer(RendererContext)
Initializes a new renderer with the given context.
public Renderer(RendererContext rendererContext)Parameters
rendererContext RendererContext
Shared context providing loaders and caches.
Properties
BarnLightShadowBuffer
Depth-only framebuffer atlas used for barn light shadow mapping.
public Framebuffer? BarnLightShadowBuffer { get; }Property Value
BaseBackground
Default background used when no skybox is available.
public SceneBackground? BaseBackground { get; protected set; }Property Value
BloomAmountBuffer
8-bit target at the scene resolution holding the bloom amount that materials write per pixel, and 0 elsewhere, which the bloom threshold reads.
public Framebuffer? BloomAmountBuffer { get; }Property Value
Camera
Active camera used for view and projection transforms.
public Camera Camera { get; set; }Property Value
DefaultSunAngles
Default sun angles for lighting used by viewers without lighting information
public static Vector2 DefaultSunAngles { get; }Property Value
DefaultSunColor
Default sun color for lighting used by viewers without lighting information
public static Vector4 DefaultSunColor { get; }Property Value
DeltaTime
Time elapsed since the last frame, in seconds.
public float DeltaTime { get; set; }Property Value
float
EffectsBloomBuffer
HDR target at a reduced resolution that the effects bloom layer draws into. The bloom post process adds it in separately from the scene.
public Framebuffer? EffectsBloomBuffer { get; }Property Value
EntitySystem
The entity world the scenes are spawned into, ticked once a frame ahead of the scenes that draw it.
public EntitySystem EntitySystem { get; }Property Value
FogShadowBuffer
Depth-only framebuffer atlas used for the shadows of the lights of the volumetric fog. Maps stay in it between frames.
public Framebuffer? FogShadowBuffer { get; }Property Value
ForceResolveSceneDepth
When set, forces Renderer.ResolvedSceneDepth to be refreshed this frame even if no material or occlusion pass requests it. Used by overlays (e.g. world-space text) that need the scene depth to occlude themselves against geometry. Must be set before Renderer.Render(RenderContext).
public bool ForceResolveSceneDepth { get; set; }Property Value
bool
HasSky
Gets whether a 3D sky can be drawn, from a skybox_reference or a sky_camera_volume.
public bool HasSky { get; }Property Value
bool
IsWireframe
When true, geometry is rendered as wireframe lines.
public bool IsWireframe { get; set; }Property Value
bool
LightTilesOverlay
Gets the fullscreen tile mask overlay drawn in the tile debug render modes.
public LightTilesOverlay LightTilesOverlay { get; }Property Value
LockedCullFrustum
When not null, culling uses this frustum instead of the camera frustum, freezing the cull state. Setting it also freezes the 3D sky's cull frustum.
public Frustum? LockedCullFrustum { get; set; }Property Value
LockedCullPosition
When not null, PVS queries use this position instead of the camera position, freezing the PVS state.
public Vector3? LockedCullPosition { get; set; }Property Value
MainFramebuffer
Target framebuffer for the main scene render; must be set before calling Renderer.Render(RenderContext).
public Framebuffer? MainFramebuffer { get; set; }Property Value
MainViewState
Gets the main scene state in the main view, or null until the first update.
public SceneViewState? MainViewState { get; }Property Value
ParallelSimulation
Whether scene nodes simulate across the thread pool. Off runs them in scene order.
public bool ParallelSimulation { get; set; }Property Value
bool
PerfStats
Per-frame rendering statistics, including CPU/GPU profiling timings
public PerfStats PerfStats { get; }Property Value
Postprocess
Post-processing renderer handling tone mapping, bloom, and MSAA resolve.
public PostProcessRenderer Postprocess { get; set; }Property Value
Prewarming
Set while the shader specialization prewarm frame is being drawn.
public bool Prewarming { get; set; }Property Value
bool
RendererContext
Shared renderer context containing loaders and caches.
public RendererContext RendererContext { get; }Property Value
ResolvedSceneColor
Resolved (non-MSAA) scene color in rgba16f format, used for refraction, bloom input, and luminance computation. Filled by Renderer.GrabFramebufferCopy(Framebuffer, bool, bool).
public RenderTexture? ResolvedSceneColor { get; }Property Value
ResolvedSceneDepth
Resolved (non-MSAA) scene depth in R32F format, used for the depth pyramid and occlusion culling. Filled by Renderer.GrabFramebufferCopy(Framebuffer, bool, bool).
public RenderTexture? ResolvedSceneDepth { get; }Property Value
Scene
The main scene to render.
public Scene Scene { get; }Property Value
Scenes
Gets the scenes drawn, the main scene first, then the added ones in the order they were added. The main view draws those of the main world group, and the 3D sky those of the sky's world group.
public IReadOnlyList<Scene> Scenes { get; }Property Value
Settings
Gets the rendering toggles for all scenes. Each scene reads a copy that is refreshed once per frame in Renderer.Update(UpdateContext).
public ref RenderSettings Settings { get; }Property Value
ShadowDepthBuffer
Depth-only framebuffer used for directional (sun) light shadow mapping.
public Framebuffer? ShadowDepthBuffer { get; }Property Value
ShadowTextureSize
Width and height in texels of the shadow depth buffers.
public int ShadowTextureSize { get; set; }Property Value
int
ShowSoundDebug
Gets or sets whether the vsnd name of every active positioned sound is billboarded in the world.
public bool ShowSoundDebug { get; set; }Property Value
bool
SkyCamera
Camera the 3D sky is drawn through.
public Camera SkyCamera { get; }Property Value
Skybox2D
Gets or sets the 2D sky drawn when no scene in view has one.
public SceneSkybox2D? Skybox2D { get; set; }Property Value
SunCascadeCount
Gets or sets how many sun shadow cascades are drawn, 2 or 3.
public int SunCascadeCount { get; set; }Property Value
int
Textures
Named textures bound to reserved slots for all render passes.
public List<(ReservedTextureSlots Slot, string Name, RenderTexture Texture)> Textures { get; }Property Value
List<(ReservedTextureSlots Slot, string Name, RenderTexture Texture)>
TranslucentDepthBuffer
Scene depth with the translucent surfaces drawn over it, read as g_tTranslucentSceneDepth.
public Framebuffer? TranslucentDepthBuffer { get; }Property Value
Uptime
Total time elapsed since the renderer was started, in seconds.
public float Uptime { get; set; }Property Value
float
ViewBuffer
GPU uniform buffer containing per-view constants such as view-projection matrices.
public UniformBuffer<ViewConstants>? ViewBuffer { get; set; }Property Value
ViewmodelCamera
Secondary camera used to render the first-person viewmodel layer with its own FOV. Synced to Renderer.Camera's position/orientation each frame; see Renderer.RenderScenesWithView(RenderContext).
public Camera ViewmodelCamera { get; }Property Value
WaterEffectsBuffer
Screen space map of ripple, silt and foam decals that the fancy water shader reads.
public Framebuffer? WaterEffectsBuffer { get; }Property Value
WaterEffectsDownsample
Scene pixels per water effects texel, horizontally and vertically.
public static (int X, int Y) WaterEffectsDownsample { get; }Property Value
Methods
AddScene(Scene)
Starts drawing a scene; it must be initialized before the next frame.
public void AddScene(Scene scene)Parameters
scene Scene
Clear()
Empties the entity world and every scene, leaving the renderer ready to load something else.
public void Clear()Dispose()
Releases GPU resources owned by this renderer.
public void Dispose()DrawMainScene()
Renders the opaque and translucent layers of the main view to Renderer.MainFramebuffer.
public void DrawMainScene()DrawOverScenes<TState>(Framebuffer, ref TState, OverSceneDraw<TState>)
Binds every scene the main camera sees in turn, the 3D sky first and the main scene last, with the view constants and buffers it was rendered with, for drawing in the world over a frame that has already been rendered. The scene textures stay bound. The caller binds the target and sets the render state.
public void DrawOverScenes<TState>(Framebuffer framebuffer, ref TState state, Renderer.OverSceneDraw<TState> draw)Parameters
framebuffer Framebuffer
Framebuffer drawn into, the size of the scene.
state TState
State passed to draw, so it does not need to capture it.
draw Renderer.OverSceneDraw<TState>
Draws into one scene, given a render context with the view state it was culled with.
Type Parameters
TState
FindNode(Entity)
Finds the node an entity was loaded as, in whichever scene it went into.
public SceneNode? FindNode(EntityLump.Entity entity)Parameters
entity EntityLump.Entity
The entity to look for.
Returns
Its node, or null when it has none.
FindNodeByTargetName(string)
Finds a node by its entity's targetname, in whichever scene it went into.
public SceneNode? FindNodeByTargetName(string pattern)Parameters
pattern string
The target name to match.
Returns
The first matching node, or null when there is none.
GrabFramebufferCopy(Framebuffer, bool, bool)
Resolves MSAA and copies color and/or depth from the framebuffer into Renderer.ResolvedSceneColor and Renderer.ResolvedSceneDepth.
public void GrabFramebufferCopy(Framebuffer framebuffer, bool copyColor, bool copyDepth)Parameters
framebuffer Framebuffer
copyColor bool
copyDepth bool
Initialize()
Allocates GPU resources required for rendering; must be called once before Renderer.Render(RenderContext).
public void Initialize()LoadDefaultLighting(Scene, Resource)
Load default lighting, used by viewers without lighting information
public static void LoadDefaultLighting(Scene scene, Resource ibl)Parameters
scene Scene
ibl Resource
LoadRendererResources()
Loads the embedded BRDF LUT and cube fog textures, and the game's blue noise where it has one, into Renderer.Textures.
public void LoadRendererResources()PostprocessRender(Framebuffer, Framebuffer, bool)
Multisampling resolve, postprocess the image, and convert to gamma.
public void PostprocessRender(Framebuffer inputFramebuffer, Framebuffer outputFramebuffer, bool flipY = false)Parameters
inputFramebuffer Framebuffer
outputFramebuffer Framebuffer
flipY bool
RemoveEntities()
Removes every entity, every spawn group, and the lighting volumes, post process info and projected decals the entities registered with the scene. The loaded world stays in place for the entities to spawn again.
public void RemoveEntities()RemoveScene(Scene)
Stops drawing a scene and disposes it; the entities in it are already removed.
public void RemoveScene(Scene scene)Parameters
scene Scene
Remarks
The SpawnGroupManager calls this as the spawn group that loaded the scene unloads.
Render(Framebuffer)
Renders the scene to the specified framebuffer. The result will be in linear space.
public void Render(Framebuffer framebuffer)Parameters
framebuffer Framebuffer
Framebuffer with hdr color support.
Render(RenderContext)
Renders shadows and then the full scene using the provided render context.
public void Render(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
RenderNodes(Framebuffer, Shader, IReadOnlySet<SceneNode>)
Draws some nodes of the last frame again over every scene they were drawn in, each node all at once, with a shader that replaces their materials. The draws can test against the resolved scene depth. The caller binds and clears the target and sets the render state.
public bool RenderNodes(Framebuffer framebuffer, Shader shader, IReadOnlySet<SceneNode> nodes)Parameters
framebuffer Framebuffer
Framebuffer drawn into, the size of the scene.
shader Shader
The shader every draw is made with.
nodes IReadOnlySet<SceneNode>
The nodes to draw. Those the last frame did not draw are left out.
Returns
bool
Whether anything was drawn.
RenderSceneShadows(RenderContext)
Renders opaque shadow casters for the directional (sun) light into Renderer.ShadowDepthBuffer.
public void RenderSceneShadows(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
RenderScenesWithView(RenderContext)
Renders every view using the camera and framebuffer specified in the render context.
public void RenderScenesWithView(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
TrimRenderTargets()
Shrinks the render targets to their lowest memory footprint.
public void TrimRenderTargets()Update(UpdateContext)
Advances the simulation, updates scene draw calls, and prepares shadow data for the next frame.
public void Update(Scene.UpdateContext updateContext)Parameters
updateContext Scene.UpdateContext

