Class Scene
Namespace: ValveResourceFormat.Renderer
Assembly: Renderer.dll
Container for scene nodes with spatial partitioning, lighting, and render state management.
public class Scene : IDisposableInheritance
Implements
Constructors
Scene(RendererContext, float)
Initializes a new scene with the given renderer context and optional spatial size hint.
public Scene(RendererContext context, float sizeHint = 32768)Parameters
context RendererContext
The renderer context providing shared GPU resources.
sizeHint float
The initial world-space extent used to size the static octree.
Properties
ActiveLodBitsGpu
Gets or sets the GPU buffer holding one mask per LOD setup in the scene, with the bit of the level that setup selected this frame set.
public StorageBuffer? ActiveLodBitsGpu { get; set; }Property Value
AllNodes
Gets all static and dynamic scene nodes in the order they were added.
public IEnumerable<SceneNode> AllNodes { get; }Property Value
CommandMeshletsGpu
Gets or sets the GPU buffer mapping each aggregate indirect draw command to the meshlet it draws.
public StorageBuffer? CommandMeshletsGpu { get; set; }Property Value
CompactedCountsGpu
Gets or sets the GPU buffer that stores per-aggregate visible draw counts after compaction.
public StorageBuffer? CompactedCountsGpu { get; set; }Property Value
CompactedDrawsGpu
Gets or sets the GPU buffer that receives compacted indirect draw commands after culling.
public StorageBuffer? CompactedDrawsGpu { get; set; }Property Value
CompactionRequestsGpu
Gets or sets the GPU buffer containing compaction request descriptors (count and start index per aggregate).
public StorageBuffer? CompactionRequestsGpu { get; set; }Property Value
CurrentFramePvs
Gets or sets the PVS bitfield for the cluster at the current camera position.
public byte[]? CurrentFramePvs { get; set; }Property Value
byte[]?
DepthPyramid
Gets the hierarchical depth pyramid texture used for GPU occlusion culling.
public RenderTexture? DepthPyramid { get; }Property Value
DepthPyramidValid
Gets whether the depth pyramid is current and safe to use for occlusion culling this frame.
public bool DepthPyramidValid { get; }Property Value
DepthPyramidViewProjection
Gets the view-projection matrix that was used when the depth pyramid was last generated.
public Matrix4x4 DepthPyramidViewProjection { get; }Property Value
DrawBoundsGpu
Gets or sets the GPU buffer containing per-draw-call bounding boxes for indirect culling.
public StorageBuffer? DrawBoundsGpu { get; set; }Property Value
DynamicOctree
Gets the flat spatial set holding dynamic scene nodes.
public SpatialNodeSet DynamicOctree { get; }Property Value
EnableCompaction
Gets or sets whether GPU draw compaction is applied after frustum culling to remove empty indirect draw commands.
public bool EnableCompaction { get; set; }Property Value
EnableDepthPrepass
Gets or sets whether a depth-only prepass is performed before the opaque pass to reduce overdraw.
public bool EnableDepthPrepass { get; set; }Property Value
EnableIndirectDraws
Gets or sets whether GPU indirect drawing is used for eligible aggregate scene nodes.
public bool EnableIndirectDraws { get; set; }Property Value
EnableOcclusionCulling
Gets or sets whether GPU occlusion culling is enabled.
public bool EnableOcclusionCulling { get; set; }Property Value
EnablePvsCulling
Gets or sets whether PVS culling is enabled for this scene.
public bool EnablePvsCulling { get; set; }Property Value
EnableTiledLightCulling
Gets or sets whether lights are binned to screen tiles so shaders iterate only what reaches them.
public bool EnableTiledLightCulling { get; set; }Property Value
Remarks
reads the main scene's copy when driving every binner, so that one alsogoverns the 3D skybox. The skybox scene's own copy is never what the viewer toggles.
EntitySystem
Gets the entity context for this scene. Simulated entities live here and are ticked by
before the scene nodes are updated.public EntitySystem EntitySystem { get; }Property Value
EnvironmentWetness
Wetness coverage, drying amount, rain strength and puddle ripple strength, read from the map's info_map_parameters. Holds that entity's own defaults when the map has none.
public Vector4 EnvironmentWetness { get; set; }Property Value
FogEnabled
Gets or sets whether scene fog is applied during rendering.
public bool FogEnabled { get; set; }Property Value
FogInfo
Gets or sets the fog parameters for this scene.
public WorldFogInfo FogInfo { get; set; }Property Value
HasOutlineObjects
Gets whether there are any selected nodes queued for outline rendering.
public bool HasOutlineObjects { get; }Property Value
HasWater
Gets whether any water surface is queued to draw this frame.
public bool HasWater { get; }Property Value
HasWaterEffects
Gets whether anything is queued to draw into the water effects map this frame.
public bool HasWaterEffects { get; }Property Value
IndirectDrawsGpu
Gets or sets the GPU buffer containing the indirect draw commands for all meshlets.
public StorageBuffer? IndirectDrawsGpu { get; set; }Property Value
InstanceBufferGpu
Gets or sets the GPU buffer containing per-instance object data (tint, transform index, env map visibility).
public StorageBuffer? InstanceBufferGpu { get; set; }Property Value
LightBinner
Gets the tile and depth bin cull passes for this scene.
public LightBinner LightBinner { get; }Property Value
LightingInfo
Gets the world lighting information including light probes, environment maps, and dynamic lights.
public WorldLightingInfo LightingInfo { get; }Property Value
MeshletDataGpu
Gets or sets the GPU buffer containing per-meshlet cull info (bounds and cone data).
public StorageBuffer? MeshletDataGpu { get; set; }Property Value
ObjectLodGpu
Gets or sets the GPU buffer holding per-object LOD masks and setup indices.
public StorageBuffer? ObjectLodGpu { get; set; }Property Value
OcclusionDebug
Gets or sets the occlusion debug renderer, or null if not initialized.
public OcclusionDebugRenderer? OcclusionDebug { get; set; }Property Value
OcclusionDebugEnabled
Gets or sets whether occlusion culling debug visualization is active.
public bool OcclusionDebugEnabled { get; set; }Property Value
PhysicsWorld
Gets or sets the physics simulation world associated with this scene.
public Rubikon? PhysicsWorld { get; set; }Property Value
PostProcessInfo
Gets or sets the post-processing parameters for this scene.
public WorldPostProcessInfo PostProcessInfo { get; set; }Property Value
PuddleWindDirection
Puddle ripple direction, over 0 to 1 for a full turn.
public float PuddleWindDirection { get; set; }Property Value
RenderAttributes
Gets the render attribute overrides applied to all draw calls in this scene.
public Dictionary<string, byte> RenderAttributes { get; }Property Value
RendererContext
Gets the renderer context providing shared GPU resources and shader loading.
public RendererContext RendererContext { get; }Property Value
SceneMeshletCount
Gets the total number of meshlets across all indirect-draw-capable aggregates in the scene.
public int SceneMeshletCount { get; }Property Value
ShowToolsMaterials
Gets or sets whether materials flagged as tools-only are rendered.
public bool ShowToolsMaterials { get; set; }Property Value
StaticOctree
Gets the octree used to spatially partition static scene nodes.
public Octree StaticOctree { get; }Property Value
TransformBufferGpu
Gets or sets the GPU buffer containing world-space transform matrices for all scene nodes.
public StorageBuffer? TransformBufferGpu { get; set; }Property Value
VoxelVisibility
Gets or sets the voxel visibility data.
public VoxelVisibility? VoxelVisibility { get; set; }Property Value
WantsSceneColor
Gets or sets whether any translucent material in the collected draw calls samples the scene color texture.
public bool WantsSceneColor { get; set; }Property Value
WantsSceneDepth
Gets or sets whether any translucent material in the collected draw calls samples the scene depth texture.
public bool WantsSceneDepth { get; set; }Property Value
Methods
Add(SceneNode, bool)
Adds a node to the scene, placing it in either the static or dynamic partition.
public void Add(SceneNode node, bool dynamic)Parameters
node SceneNode
The node to add.
dynamic bool
When true, the node is placed in ; otherwise in .
AdjustEnvMapSunAngle(Matrix4x4)
Applies a rotation delta to the first environment map's world-to-local transform to simulate sun angle changes.
public void AdjustEnvMapSunAngle(Matrix4x4 delta)Parameters
delta Matrix4x4
The rotation matrix to multiply into the env map transform.
CalculateEnvironmentMaps()
Assigns environment maps to scene nodes based on spatial overlap and precomputed handshakes, and uploads env map data to the GPU uniform buffer.
public void CalculateEnvironmentMaps()CalculateLightProbeBindings()
Assigns each scene node its best-matching light probe volume and uploads probe data to the GPU light probe uniform buffer.
public void CalculateLightProbeBindings()Clear()
Removes all nodes from the scene, also disposes loaded materials and gpu mesh buffers.
public void Clear()CollectSceneDrawCalls(Camera, Frustum?)
Frustum-culls the scene and populates the per-pass render lists for the upcoming frame.
public void CollectSceneDrawCalls(Camera camera, Frustum? cullFrustum = null)Parameters
camera Camera
The camera used to sort translucent draw calls by distance.
cullFrustum Frustum?
An optional override frustum for culling; defaults to the camera's view frustum.
CompactIndirectDraws()
Dispatches the GPU draw compaction compute shader, packing non-zero indirect draw commands into to avoid empty draw calls.
public void CompactIndirectDraws()CreateBuffers()
Allocates GPU uniform and storage buffers for lighting, environment maps, light probes, frustum planes, and indirect draws.
public void CreateBuffers()Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()Dispose(bool)
Releases managed GPU resources owned by the scene.
protected virtual void Dispose(bool disposing)Parameters
disposing bool
true when called from .
Find(uint)
Finds a scene node by its scene-unique ID.
public SceneNode? Find(uint id)Parameters
id uint
The node ID to look up.
Returns
The matching , or null if not found.
Find(Entity)
Finds the first scene node whose entity data matches the given entity.
public SceneNode? Find(EntityLump.Entity entity)Parameters
entity EntityLump.Entity
The entity to search for.
Returns
The matching , or null if not found.
FindLightProbe(Vector3)
Returns the best probe volume containing the given position, or null when none does.
public SceneLightProbe? FindLightProbe(Vector3 position)Parameters
position Vector3
Returns
FindNodeByKeyValue(string, string)
Finds the first scene node whose entity data contains a property with the given key and value.
public SceneNode? FindNodeByKeyValue(string keyToFind, string valueToFind)Parameters
keyToFind string
The entity property key to match.
valueToFind string
The expected string value (case-insensitive).
Returns
The matching , or null if not found.
FindNodeByTargetName(string)
Finds the first scene node whose entity name matches with the given pattern.
public SceneNode? FindNodeByTargetName(string pattern)Parameters
pattern string
Targetname to match against, may contain wildcards: * and ? (e.g. door_*).
Returns
The matching , or null if not found.
GenerateDepthPyramid(RenderTexture)
Generates the hierarchical depth pyramid from the given depth texture by downsampling through compute shaders.
public void GenerateDepthPyramid(RenderTexture depthSource)Parameters
depthSource RenderTexture
The full-resolution depth texture to downsample.
GetFrustumCullResults(Frustum)
Returns all scene nodes whose bounding boxes intersect the given frustum, caching static results across frames when the frustum is unchanged.
public List<SceneNode> GetFrustumCullResults(Frustum frustum)Parameters
frustum Frustum
The view frustum to test against.
Returns
A list of visible scene nodes (valid until the next call to this method).
GetNodeTypeById(uint)
Resolves a scene-unique node ID to its partition type and local list index.
public (Scene.NodeType Type, int LocalId) GetNodeTypeById(uint id)Parameters
id uint
The scene-unique node ID assigned by .
Returns
(Scene.NodeType Type, int LocalId)
The node type and local index, or (Unknown, -1) if the ID is not found.
Initialize()
Performs one-time GPU setup: builds acceleration structures, allocates buffers, computes light probe and environment map bindings, and loads internal shaders.
public void Initialize()MarkParentOctreeDirty(SceneNode)
Marks the spatial set that owns the given node as dirty so it will be rebuilt on the next update. Also clears barn light shadow caches.
public bool MarkParentOctreeDirty(SceneNode node)Parameters
node SceneNode
The node whose owning set should be dirtied.
Returns
true if the node was found and its octree was dirtied; false if the node is not part of this scene.
MeshletCullGpu(Frustum)
Dispatches the GPU frustum (and optional occlusion) culling compute shader, writing surviving indirect draw commands to .
public void MeshletCullGpu(Frustum frustum)Parameters
frustum Frustum
The view frustum used to cull meshlets.
Remove(SceneNode, bool)
Removes a node from the scene's static or dynamic partition.
public void Remove(SceneNode node, bool dynamic)Parameters
node SceneNode
The node to remove.
dynamic bool
When true, removes from the dynamic partition; otherwise the static partition.
RenderOpaqueLayer(RenderContext, Shader?)
Renders the opaque pass, optionally with a depth prepass, followed by aggregate indirect draws and static overlay geometry.
public void RenderOpaqueLayer(Scene.RenderContext renderContext, Shader? depthOnlyShader = null)Parameters
renderContext Scene.RenderContext
The render context for this pass.
depthOnlyShader Shader?
Optional depth-only shader; null for a pass that replaces material shaders.
RenderOpaqueRefractLayer(RenderContext)
Renders depth-writing geometry that samples the scene color, collected during . Runs after the framebuffer grab but before water and translucents, so those still sort against its depth.
public void RenderOpaqueRefractLayer(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
The render context for this pass.
RenderOpaqueShadows(RenderContext, Shader, Dictionary<DepthOnlyBucket, List<Request>>)
Renders shadow depth passes for all draw call buckets using their corresponding specialized depth-only shaders.
public static void RenderOpaqueShadows(Scene.RenderContext renderContext, Shader depthOnlyShader, Dictionary<DepthOnlyBucket, List<MeshBatchRenderer.Request>> drawCalls)Parameters
renderContext Scene.RenderContext
The render context for this shadow pass.
depthOnlyShader Shader
The depth-only shader, which the pass takes skinning variants of.
drawCalls Dictionary<DepthOnlyBucket, List<MeshBatchRenderer.Request>>
The bucketed draw calls to render.
RenderOutlineLayer(RenderContext)
Renders all selected nodes using the outline shader to produce selection highlights.
public void RenderOutlineLayer(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
The render context for this pass.
RenderTranslucentLayer(RenderContext)
Renders all translucent draw calls collected during .
public void RenderTranslucentLayer(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
The render context for this pass.
RenderViewmodelOpaqueLayer(RenderContext)
Renders the opaque first-person viewmodel layer collected during . Rendered before the main scene so its reserved near depth range can never be overtaken by world geometry.
public void RenderViewmodelOpaqueLayer(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
The render context for this pass, expected to use the dedicated viewmodel camera and depth range.
RenderViewmodelTranslucentLayer(RenderContext)
Renders the translucent first-person viewmodel layer collected during . Rendered after the main scene (and 3D sky) translucent passes so it composites correctly on top of them.
public void RenderViewmodelTranslucentLayer(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
The render context for this pass, expected to use the dedicated viewmodel camera and depth range.
RenderWaterEffectsLayer(RenderContext)
Renders the draw calls that fill the water effects map; the caller owns the render target.
public void RenderWaterEffectsLayer(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
The render context for this pass.
RenderWaterLayer(RenderContext)
Renders water draw calls collected during .
public void RenderWaterLayer(Scene.RenderContext renderContext)Parameters
renderContext Scene.RenderContext
The render context for this pass.
SetEnabledLayers(HashSet<string>)
Enables or disables scene nodes based on whether their layer name is present in the given set.
public void SetEnabledLayers(HashSet<string> layers)Parameters
The set of layer names that should be visible.
SetFogConstants(ViewConstants)
Writes the scene's fog and weather parameters into the provided view constants structure.
public void SetFogConstants(ViewConstants viewConstants)Parameters
viewConstants ViewConstants
The view constants to update.
SetSceneBuffers()
Updates the lighting buffer, then binds the lighting, environment map, light probe, and barn light buffers to their reserved GPU binding slots.
public void SetSceneBuffers()SetupBarnLightFaceShadow(SceneLight, Frustum)
Collects the shadow draw calls for a single barn light face. The returned buckets are scratch, valid until the next call.
public Dictionary<DepthOnlyBucket, List<MeshBatchRenderer.Request>> SetupBarnLightFaceShadow(SceneLight light, Frustum lightFrustum)Parameters
light SceneLight
The barn light owning the shadow face.
lightFrustum Frustum
The frustum representing the light's view for this face.
Returns
Dictionary<DepthOnlyBucket, List<MeshBatchRenderer.Request>>
SetupSceneShadows(Camera, int)
Updates the sun light shadow cascades and collects shadow draw calls for each of them, if dynamic shadows are enabled.
public void SetupSceneShadows(Camera camera, int shadowMapSize)Parameters
camera Camera
The main camera used to fit the shadow cascades.
shadowMapSize int
The shadow map resolution; pass -1 to produce empty frustums (pre-warm pass).
Update(UpdateContext)
Updates all scene nodes for the current frame, advancing animations and rebuilding spatial sets and GPU buffers if the scene changed.
public void Update(Scene.UpdateContext updateContext)Parameters
updateContext Scene.UpdateContext
Per-frame context data including camera and timestep.
UpdateBuffers()
Uploads the latest lighting, environment map, and light probe data to their respective GPU uniform buffers.
public void UpdateBuffers()UpdateNodeIndices()
Assigns sequential scene-unique IDs to all static and dynamic nodes, starting at 1 (0 is reserved as an invalid ID).
public void UpdateNodeIndices()UpdateOctrees()
Rebuilds the static octree and the dynamic node set from their current node lists, if dirty.
public void UpdateOctrees()
