Class Scene
Namespace: ValveResourceFormat.Renderer
Assembly: Renderer.dll
Container for scene nodes with spatial partitioning, lighting, and render state management.
public class Scene : IDisposableInheritance
object ← Scene
Implements
Constructors
Scene(RendererContext)
Initializes a new scene with the given renderer context, with empty spatial sets.
public Scene(RendererContext context)Parameters
context RendererContext
The renderer context providing shared GPU resources.
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
CompactionRequestsGpu
Gets or sets the GPU buffer containing compaction request descriptors (count and start index per aggregate).
public StorageBuffer? CompactionRequestsGpu { get; set; }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
DynamicSet
Gets the flat spatial set holding dynamic scene nodes.
public SpatialNodeSet DynamicSet { 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
FogInfo
Gets or sets the fog parameters for this scene.
public WorldFogInfo FogInfo { get; set; }Property Value
InstanceBufferGpu
Gets or sets the GPU buffer each draw reads at its base instance (tint, transform index, skinning).
public StorageBuffer? InstanceBufferGpu { get; set; }Property Value
LightingDebug
Gets the debug views of this scene's baked lighting.
public SceneLightingDebug LightingDebug { 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
PhysicsWorld
Gets or sets the physics world holding this scene's collision, which particle systems in the scene trace against. Null when the scene has no world of its own.
public PhysicsWorld? PhysicsWorld { get; set; }Property Value
Player
Gets or sets the player in this scene, if there is one.
public PlayerEntity? Player { get; set; }Property Value
PostProcessInfo
Gets or sets the post-processing parameters for this scene.
public WorldPostProcessInfo PostProcessInfo { get; set; }Property Value
ProjectedDecals
Gets the decals projected onto the scene's depth, such as bullet impacts.
public ProjectedDecalSystem ProjectedDecals { get; }Property Value
PuddleWindDirection
Puddle ripple direction, over 0 to 1 for a full turn.
public float PuddleWindDirection { get; set; }Property Value
float
RenderAttributes
Gets the render attribute overrides applied to all draw calls in this scene.
public Dictionary<string, byte> RenderAttributes { get; }Property Value
Dictionary<string, byte>
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
int
Settings
Gets the rendering toggles.
public RenderSettings Settings { get; }Property Value
Skybox2D
Gets or sets the 2D sky the map's sky entities provide, or null when it has none.
public SceneSkybox2D? Skybox2D { get; set; }Property Value
StaticSet
Gets the flat spatial set holding static scene nodes.
public SpatialNodeSet StaticSet { get; }Property Value
ToViewerWorld
Transform from this scene's space to the world space of the main camera. Identity, except for a 3D sky.
public Matrix4x4 ToViewerWorld { 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
VisibilityBoxes
Gets the info_visibility_box volumes spawned in this scene.
public VisibilityBoxSet VisibilityBoxes { get; }Property Value
VoxelVisibility
Gets or sets the voxel visibility data.
public IWorldVisibility? VoxelVisibility { get; set; }Property Value
WorldGroup
Gets the world group this scene belongs to, such as skyboxWorldGroup0, or null for the main world.
public string? WorldGroup { get; init; }Property Value
string?
WorldToVisibility
Gets or sets the transform from scene space into the space Scene.VoxelVisibility was compiled in.
public Matrix4x4 WorldToVisibility { 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 Scene.DynamicSet; otherwise in Scene.StaticSet.
Remarks
Called while the scene is updating, such as from a node's own update, the node joins after the update and is first updated and drawn on the next frame. Adding a node removed during the same update keeps it in the scene instead.
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.
AreLayersEnabled(ImmutableArray<WorldLayer>)
Gets whether every one of some layers is enabled, as a node on them needs to be shown.
public bool AreLayersEnabled(ImmutableArray<WorldLayer> layers)Parameters
layers ImmutableArray<WorldLayer>
The layers, of which none means always shown.
Returns
bool
Whether all of them are enabled.
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()ChooseEnvironmentMap(Vector3)
Returns the environment map that best covers a position: one whose volume contains it, the highest priority among those and then the nearest to its origin, otherwise the one whose volume is nearest.
public SceneEnvMap? ChooseEnvironmentMap(Vector3 position)Parameters
position Vector3
A position in this scene.
Returns
The environment map, or null when the scene has none.
ChooseLightProbeVolume(Vector3, AABB?)
Returns the probe volume that best covers a position: one that contains it, the highest priority among those and then the nearest to its origin, otherwise the nearest one that reaches the object.
public SceneLightProbe? ChooseLightProbeVolume(Vector3 position, AABB? objectBounds = null)Parameters
position Vector3
A position in this scene.
objectBounds AABB?
The bounds of the object lit at the position. A volume that does not contain the position is only chosen when it is within half the diagonal of the bounds from their center, or always when this is null.
Returns
The probe volume, or null when the scene has none.
Clear()
Removes all nodes from the scene, also disposes loaded materials and gpu mesh buffers.
public void Clear()CreateBuffers()
Allocates GPU uniform and storage buffers for lighting, environment maps, light probes, frustum planes, and indirect draws.
public void CreateBuffers()DeleteNodes()
Removes and deletes every node and the 2D sky, keeping shared materials and mesh buffers loaded.
public void DeleteNodes()Remarks
The partitions are emptied before any node is deleted, so a node that removes and deletes nodes it owns finds them already gone from the scene and leaves their deletion to it.
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 Scene.Dispose().
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 SceneNode, or null if not found.
Find(Entity)
Finds the scene node of the given entity: the node a spawned entity is drawn as, otherwise the first node carrying its data.
public SceneNode? Find(EntityLump.Entity entity)Parameters
entity EntityLump.Entity
The entity to search for.
Returns
The matching SceneNode, 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 SceneNode, 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 SceneNode, or null if not found.
GetEnvMapsUsedBy(SceneNode, List<SceneEnvMap>)
Adds the environment map a node reflects, if it has one.
public void GetEnvMapsUsedBy(SceneNode node, List<SceneEnvMap> envMaps)Parameters
node SceneNode
A node in this scene.
envMaps List<SceneEnvMap>
The list the environment map is added to.
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 Scene.UpdateNodeIndices().
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()IsLayerEnabled(WorldLayer)
Gets whether a layer is enabled, as every layer is until Scene.SetLayerEnabled(WorldLayer, bool) disables it.
public bool IsLayerEnabled(WorldLayer layer)Parameters
layer WorldLayer
The layer.
Returns
bool
Whether the nodes on the layer may be shown.
IsNodeInPvs(SceneNode, ReadOnlySpan<byte>)
Tests a node against a visibility row, such as a PVS or the sun row. A node that touches no visibility cluster is never vis culled, and an empty row passes everything.
public bool IsNodeInPvs(SceneNode node, ReadOnlySpan<byte> visibilityRow)Parameters
node SceneNode
The node to test.
visibilityRow ReadOnlySpan<byte>
A cluster bitfield, one bit per cluster id.
Returns
bool
Whether the node may draw.
MarkParentSetDirty(SceneNode)
Marks the spatial set that owns the given node as dirty so it will be rebuilt on the next update.
public bool MarkParentSetDirty(SceneNode node)Parameters
node SceneNode
The node whose owning set should be dirtied.
Returns
bool
true if the node was found and its set was dirtied; false if the node is not part of this scene.
RebindLighting()
Binds every node to the light probe volumes and environment maps again, once the entities that register them have spawned again.
public void RebindLighting()Remove(SceneNode, bool)
Removes a node from the scene's static or dynamic partition.
public bool 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.
Returns
bool
Whether the node was in the partition, or is leaving it when the scene is updating.
Remarks
Called while the scene is updating, the node is no longer updated from then on and leaves before the frame draws, so it may be deleted right away.
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.
SetLayerEnabled(WorldLayer, bool)
Enables or disables a layer.
public void SetLayerEnabled(WorldLayer layer, bool enabled)Parameters
layer WorldLayer
The layer.
enabled bool
Whether the nodes on it may be shown.
SetLayersEnabled(IEnumerable<WorldLayer>, bool)
Enables or disables some layers, leaving the others as they are.
public void SetLayersEnabled(IEnumerable<WorldLayer> layers, bool enabled)Parameters
layers IEnumerable<WorldLayer>
The layers.
enabled bool
Whether the nodes on them may be shown.
SetSceneBuffers()
Binds the lighting and draw buffers to their reserved slots.
public void SetSceneBuffers()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()UpdateInstanceTransformBuffers()
Update GPU draw and object data.
public void UpdateInstanceTransformBuffers()UpdateNodeEnvironmentMaps(SceneNode)
Picks a node's environment maps again, for when its SceneNode.LightingOrigin changed after the scene was lit. A dynamic node's light probe volume follows on its own, in Scene.UpdateInstanceTransformBuffers().
public void UpdateNodeEnvironmentMaps(SceneNode node)Parameters
node SceneNode
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()UpdateSpatialSets()
Rebuilds the static and dynamic node sets from their current node lists, if dirty.
public void UpdateSpatialSets()
