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 octree 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 octrees.
Properties
AllNodes
Gets all static and dynamic scene nodes in the order they were added.
public IEnumerable<SceneNode> AllNodes { get; }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 or sets the hierarchical depth pyramid texture used for GPU occlusion culling.
public RenderTexture? DepthPyramid { get; }Property Value
DepthPyramidValid
Gets or sets whether the depth pyramid is current and safe to use for occlusion culling this frame.
public bool DepthPyramidValid { get; }Property Value
DepthPyramidViewProjection
Gets or sets 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 octree used to spatially partition dynamic scene nodes.
public Octree 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 CPU-side 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
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
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
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
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
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 the dynamic octree; otherwise the static octree.
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()ClearShadowCache(SceneLight)
Invalidates the cached shadow draw calls for all faces of the given barn light, forcing a rebuild next frame.
public static void ClearShadowCache(SceneLight light)Parameters
light SceneLight
The barn light whose shadow cache should be cleared.
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.
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.
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.
GetOcclusionTestResults()
Retrieves non-blocking GPU occlusion query results from the previous frame and marks octree nodes as occluded or visible.
public void GetOcclusionTestResults()Initialize()
Performs one-time GPU setup: builds octrees, allocates buffers, computes light probe and environment map bindings, and loads internal shaders.
public void Initialize()MarkParentOctreeDirty(SceneNode)
Marks the octree 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 octree 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.
RenderOcclusionProxies(RenderContext, Shader)
Submits GPU occlusion queries for static octree nodes using proxy geometry, to be retrieved the following frame.
public void RenderOcclusionProxies(Scene.RenderContext renderContext, Shader depthOnlyShader)Parameters
renderContext Scene.RenderContext
The render context providing the camera position.
depthOnlyShader Shader
The depth-only shader used to render the proxy bounding boxes.
RenderOpaqueLayer(RenderContext, Span<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, Span<Shader> depthOnlyShaders = default)Parameters
renderContext Scene.RenderContext
The render context for this pass.
An optional span of depth-only shaders; when provided and is set, a depth prepass is performed.
RenderOpaqueShadows(RenderContext, Span<Shader>, Dictionary<DepthOnlyProgram, 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, Span<Shader> depthOnlyShaders, Dictionary<DepthOnlyProgram, List<MeshBatchRenderer.Request>> drawCalls)Parameters
renderContext Scene.RenderContext
The render context for this shadow pass.
A span of shaders indexed by .
drawCalls Dictionary<DepthOnlyProgram, 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.
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 fog parameters into the provided view constants structure.
public void SetFogConstants(ViewConstants viewConstants)Parameters
viewConstants ViewConstants
The view constants to update with fog uniforms.
SetSceneBuffers()
Updates and binds the lighting, environment map, light probe, and barn light buffers to their reserved GPU binding slots.
public void SetSceneBuffers()SetupBarnLightFaceShadow(SceneLight, int, Frustum)
Ensures the shadow draw call cache for a single barn light face is up to date, rebuilding it if the light frustum changed.
public void SetupBarnLightFaceShadow(SceneLight light, int faceIndex, Frustum lightFrustum)Parameters
light SceneLight
The barn light owning the shadow face.
faceIndex int
The face index within the barn light to update.
lightFrustum Frustum
The frustum representing the light's view for this face.
SetupSceneShadows(Camera, int)
Updates the sun light shadow frustum and collects shadow draw calls for the directional light, if dynamic shadows are enabled.
public void SetupSceneShadows(Camera camera, int shadowMapSize)Parameters
camera Camera
The main camera used to fit the shadow frustum.
shadowMapSize int
The shadow map resolution; pass -1 to produce an empty frustum (pre-warm pass).
Update(UpdateContext)
Updates all scene nodes for the current frame, advancing animations and rebuilding octrees 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 dirty static and dynamic octrees from their current node sets.
public void UpdateOctrees()
