Class WorldLightingInfo
Namespace: ValveResourceFormat.Renderer.World
Assembly: Renderer.dll
Scene lighting data including lightmaps, reflection probes, and shadow maps.
public class WorldLightingInfo : IParticleLightingInheritance
object ← WorldLightingInfo
Implements
Constructors
WorldLightingInfo(Scene)
Scene lighting data including lightmaps, reflection probes, and shadow maps.
public WorldLightingInfo(Scene scene)Parameters
scene Scene
Fields
SunCascadeCount
Number of sun shadow cascades rendered and sampled. Cascade 0 is the tightest.
public const int SunCascadeCount = 2Field Value
int
Properties
ActiveSunCascadeCount
Gets the number of cascades in use after the last WorldLightingInfo.UpdateSunLightFrustum(Camera, float) call. Cascades beyond it only keep their layer cleared, which samples as fully lit.
public int ActiveSunCascadeCount { get; }Property Value
int
BarnLightShadowAtlasSize
Gets the size of the barn light shadow atlas texture, as recorded by the last WorldLightingInfo.BinBarnLights(Camera, int) call.
public int BarnLightShadowAtlasSize { get; }Property Value
int
BarnLights
Gets the list of real-time barn lights.
public List<SceneLight> BarnLights { get; }Property Value
BinnedBarnLightFaces
Gets which light face each binned slot holds, in the same order as WorldLightingInfo.BinnedBarnLightVolumes, so a cull bit traces back to the face it culled.
public ReadOnlySpan<BarnLightFaceSlot> BinnedBarnLightFaces { get; }Property Value
ReadOnlySpan<BarnLightFaceSlot>
BinnedBarnLightVolumes
Gets what bounds every binned barn light face, in the order the shading pass indexes them, so a cull item's bit position is its light index.
public ReadOnlySpan<BarnLightCullVolume> BinnedBarnLightVolumes { get; }Property Value
ReadOnlySpan<BarnLightCullVolume>
EnableDynamicShadows
Gets or sets a value indicating whether dynamic shadow rendering is enabled.
public bool EnableDynamicShadows { get; set; }Property Value
bool
EnvMapArray
Gets the cubemap array the environment maps sample, once WorldLightingInfo.BuildEnvMapArray has run.
public RenderTexture? EnvMapArray { get; }Property Value
EnvMapHandshakes
Gets the environment map lookup by handshake ID.
public Dictionary<int, SceneEnvMap> EnvMapHandshakes { get; }Property Value
Dictionary<int, SceneEnvMap>
EnvMaps
Gets the list of environment map probes.
public List<SceneEnvMap> EnvMaps { get; }Property Value
HasBakedShadowsFromLightmap
Gets a value indicating whether the lightmap contains baked shadow data.
public bool HasBakedShadowsFromLightmap { get; }Property Value
bool
HasOwnSun
Gets whether the source map has an environment light.
public bool HasOwnSun { get; }Property Value
bool
HasValidLightProbes
Gets or sets a value indicating whether the scene has a complete and usable light probe set.
public bool HasValidLightProbes { get; set; }Property Value
bool
HasValidLightmaps
Gets or sets a value indicating whether the scene has a complete and usable lightmap set.
public bool HasValidLightmaps { get; set; }Property Value
bool
IsSunShadowBaked
Gets whether the map's own sun is a mixed light. Static geometry's shadows from it are baked, so static geometry stays out of its shadow cascades.
public bool IsSunShadowBaked { get; }Property Value
bool
LightProbes
Gets the list of scene light probes.
public List<SceneLightProbe> LightProbes { get; }Property Value
LightingData
Gets or sets the GPU lighting constants buffer for the scene.
public LightingConstants LightingData { get; set; }Property Value
LightmapGameVersionNumber
Gets or sets the game-specific lightmap sub-version number.
public int LightmapGameVersionNumber { get; set; }Property Value
int
LightmapVersionNumber
Gets or sets the lightmap version number from the world data.
public int LightmapVersionNumber { get; set; }Property Value
int
Lightmaps
Gets the lightmap textures indexed by uniform name.
public Dictionary<string, RenderTexture> Lightmaps { get; }Property Value
Dictionary<string, RenderTexture>
ProbeAtlas
Gets the atlas the light probes sample, once WorldLightingInfo.BuildProbeAtlas has run.
public LightProbeAtlas? ProbeAtlas { get; }Property Value
ProbeHandshakes
Gets the light probe lookup by handshake ID.
public Dictionary<int, SceneLightProbe> ProbeHandshakes { get; }Property Value
Dictionary<int, SceneLightProbe>
ShadowMapper
Gets the shadow mapper that culls and packs light shadow faces each frame.
public ShadowMapper ShadowMapper { get; }Property Value
SunCastDirection
Gets the normalized direction sun light travels, away from the sun.
public Vector3 SunCastDirection { get; }Property Value
SunLightFrustums
Gets the frustums used for sun light shadow caster culling, one per cascade.
public Frustum[] SunLightFrustums { get; }Property Value
Frustum[]
SunLightShadowBias
Gets or sets the depth bias applied to sun light shadows to reduce self-shadowing artifacts.
public float SunLightShadowBias { get; set; }Property Value
float
SunLightShadowCoverageScale
Gets or sets a scale factor applied to the sun light shadow coverage area.
public float SunLightShadowCoverageScale { get; set; }Property Value
float
SunViewProjections
Gets the combined view-projection matrices used for sun shadow rendering, one per cascade.
public Matrix4x4[] SunViewProjections { get; }Property Value
UseSceneBoundsForSunLightFrustum
Gets or sets a value indicating whether the sun light frustum is fitted to the scene bounds rather than the camera.
public bool UseSceneBoundsForSunLightFrustum { get; set; }Property Value
bool
Methods
AddEnvironmentMap(SceneEnvMap)
Registers an environment map with the scene. Separate cubemaps are packed into an array before they are sampled, see WorldLightingInfo.BuildEnvMapArray.
public void AddEnvironmentMap(SceneEnvMap envmap)Parameters
envmap SceneEnvMap
The environment map to add.
AddProbe(SceneLightProbe)
Registers a light probe with the scene, validating its texture set against the lightmap version.
public void AddProbe(SceneLightProbe lightProbe)Parameters
lightProbe SceneLightProbe
The light probe to add.
BinBarnLights(Camera, int)
Culls and bins visible barn lights for the current frame, packing their shadow faces into the atlas.
public void BinBarnLights(Camera camera, int atlasSize)Parameters
camera Camera
The camera used for culling and shadow resolution selection.
atlasSize int
Pixel size of the shadow atlas texture.
BindBarnLightBuffer()
Binds the barn light storage buffer to its reserved shader slot.
public void BindBarnLightBuffer()BindLightmapTextures()
Binds the scene's lightmap, light probe atlas, and barn light cookie textures to their reserved units.
public void BindLightmapTextures()BorrowSun(WorldLightingInfo?)
Uses the sun from donor when this map has none, or clears it when donor is null.
public void BorrowSun(WorldLightingInfo? donor)Parameters
donor WorldLightingInfo?
ClearBarnLights()
Clear renderable barn light lists.
public void ClearBarnLights()CreateBarnLightBuffer()
Allocates the GPU storage buffer used to pass barn light data to shaders.
public void CreateBarnLightBuffer()CreateShaderArguments(bool, bool)
Creates baked lighting combo args for an object, based on object and scene lighting state.
public Dictionary<string, byte> CreateShaderArguments(bool hasLightmapUvs = false, bool hasVertexLighting = false)Parameters
hasLightmapUvs bool
hasVertexLighting bool
Returns
Dictionary<string, byte>
DisposeBarnLights()
Releases the barn light GPU buffer, cookie atlas texture, and sampler objects.
public void DisposeBarnLights()FitSunLightDepthRange(int, float, float)
Tightens a cascade's WorldLightingInfo.SunViewProjections depth range around its collected casters, given their extent along WorldLightingInfo.SunCastDirection in world units. A tight range shrinks the world-space size of the normalized shadow bias. Receivers outside the range clamp in the shader and still compare correctly against every caster. The fit derives from the same culled set that renders, so it covers every rendered caster. WorldLightingInfo.SunLightFrustums keeps the generous culling range.
public void FitSunLightDepthRange(int cascade, float casterMin, float casterMax)Parameters
cascade int
The cascade index to tighten.
casterMin float
Smallest caster projection onto the cast direction, or float.MaxValue when no casters were collected.
casterMax float
Largest caster projection onto the cast direction.
GetSunMinRoughness(float)
Gets the roughness the highlight of the sun is no sharper than. Only CS2 keeps the sun from shining as a point; the other games leave its highlight as sharp as the material is.
public float GetSunMinRoughness(float lightMinRoughness = 0.04)Parameters
lightMinRoughness float
The minimum roughness the light itself asks for.
Returns
float
The minimum roughness, zero where it does not apply.
MarkStoredLightsChanged()
Marks the stored lights for WorldLightingInfo.StoreChangedLights().
public void MarkStoredLightsChanged()SampleAmbientLight(Vector3)
The indirect (ambient) light arriving at a world position.
public Vector3 SampleAmbientLight(Vector3 position)Parameters
position Vector3
World position to sample at.
Returns
Linear light colour.
Remarks
A scene without baked lighting answers white, as the particle shaders light it; one with baked lighting answers a flat grey.
SetSunDirectionFromAngles(Vector3)
Points the sun uniforms at the given Euler angles, keeping the sun color.
public void SetSunDirectionFromAngles(Vector3 angles)Parameters
angles Vector3
StoreChangedLights()
Stores the lights again if they changed since they were last stored.
public void StoreChangedLights()StoreLightMappedLights_V1(List<SceneLight>)
Stores stationary and dynamic light data into WorldLightingInfo.LightingData using the V1 lightmap format. Stationary lights sit at their baked lightmap index and are lit through the per-texel strength textures; dynamic lights are appended after them and evaluated per pixel.
public void StoreLightMappedLights_V1(List<SceneLight> lights)Parameters
lights List<SceneLight>
The list of scene lights to store.
StoreLightMappedLights_V2(List<SceneLight>)
Stores environment light data and queues real-time barn lights using the V2 lightmap format.
public void StoreLightMappedLights_V2(List<SceneLight> lights)Parameters
lights List<SceneLight>
The list of scene lights to store.
StoreLights(List<SceneLight>)
Stores the map's lights to GPU, replacing any stored before.
public void StoreLights(List<SceneLight> lights)Parameters
lights List<SceneLight>
UpdateGpuLightBuffers()
Re-stores the GPU light properties.
public void UpdateGpuLightBuffers()UpdateSunLightFrustum(Camera, float)
Recalculates WorldLightingInfo.SunViewProjections and WorldLightingInfo.SunLightFrustums for the camera view, with extents from WorldLightingInfo.SunCascadeExtentFractions. Frustums get a generous depth range for caster culling, tightened by WorldLightingInfo.FitSunLightDepthRange(int, float, float).
public void UpdateSunLightFrustum(Camera camera, float shadowMapSize = 512)Parameters
camera Camera
The active camera used to position the sun shadow frustum.
shadowMapSize float
The shadow map resolution used to compute coverage and texel snapping.

