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.
Fields
ParticlesLayerName
The layer the map's own particle systems are put on.
public const string ParticlesLayerName = "Particles"Field Value
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
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. Only the value on the main scene is read, for every 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
Only the value on the main scene is read, for every scene.
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
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
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
ObjectBufferGpu
Gets or sets the GPU buffer holding each scene node's lighting (light probe, env map visibility).
public StorageBuffer? ObjectBufferGpu { 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
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
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
StaticOctree
Gets the octree used to spatially partition static scene nodes.
public Octree StaticOctree { get; }Property Value
ToViewerWorld
Maps this scene's space to where the main camera sees it. 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
WorldToVisibility
Gets or sets the transform from scene space into the space 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 ; 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()ChooseLightProbeVolume(Vector3)
Returns the best probe volume containing the given position, or null when none does.
public SceneLightProbe? ChooseLightProbeVolume(Vector3 position)Parameters
position Vector3
Returns
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()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 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 , 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.
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.
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()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, matching the game, 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
Whether the node may draw.
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.
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.
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.
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()
Binds the lighting and draw buffers to their reserved 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 and skip the sun row (pre-warm pass, or all culling disabled).
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()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()
