This article's documentation is for anything that uses the Source engine. Click here for more information.

Env cascade light: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
(Not necessarily a bug. Just the way the entity works.)
 
(113 intermediate revisions by 33 users not shown)
Line 1: Line 1:
'''env_cascade_lighting''' is a point entity available in Counter-Strike: Global Offensive.  
{{LanguageBar}}
{{note| It is recommended to have a [[light_environment]] in your map to create radiosity based lighting, as this ent does not bake radiosity and only creates a real-time shadow map}}
{{This is a|logical entity|name=env_cascade_light|since=Counter-Strike: Global Offensive|notext=1}}{{also|{{Xe}}}}
{{bug| HDR must be enabled to activate cascade lighting.}}
{{CD|CCascadeLight}}
[[File:CSM Example.jpg|thumb|CSM in {{csgo|4.1}}]]
[[File:Env_cascade_light_-_BMS_CSM_comparison.gif|thumb|Comparison of CSM and without CSM in {{bms|3.1}} ([https://developer.valvesoftware.com/w/images/archive/5/58/20240908185746%21Env_cascade_light_-_BMS_CSM_comparison.gif Click here for full-res version])]]
It casts an extremely accurate shadow map via the <code>tools/tools[[skybox]]</code> texture, augmenting the lighting cast by {{ent|light_environment}} with real-time shadows. This form of shadow mapping is known as '''[https://learn.microsoft.com/en-us/windows/win32/dxtecharts/cascaded-shadow-maps Cascaded Shadow Maps]''', or '''CSM''' for short, which works by rendering very detailed shadow maps which becomes a lower and lower resolution depending on the distance the viewer is from the surface, similar to [[mipmaps]]. Some games automatically add this entity to the map, but it can be placed manually as well.


It casts an extremely accurate shadow map via the "tools/slybox" texture, acting as a real-time variation of [[light_environment]]. This form of lighting is known as [http://msdn.microsoft.com/en-us/library/windows/desktop/ee416307(v=vs.85).aspx cascade shadow maps] which works by rendering shadow maps at scaling  resolutions based on the players initial camera vector from the center of a spatial grid. These shadow maps are then stitched together, with the the accuracy and quality of the shadow maps scaling lower the further they are away from the player, thus trading accuracy for performance.
{{Note|Although you can toggle this entity, you can have only one {{ent|env_cascade_light}} present in your level. Any others will not work.}}
{{bug|
* In {{insurgency}}, shadows will be very faint if the map hasn't been compiled with [[HDR]].
* In {{insurgency}}, [[Naming Lights|Lightstyles]] will break when this entity exists.|hidetested=1}}
 
{{note|
* You still need to have a {{ent|light_environment}} in your map as well to create [[lightmap]] based lighting, which is not done by this entity.
* {{src13|4}} doesn't have this entity, but there is an [https://github.com/celisej567/Fake-CSM-Mapbase attempt] of porting it.
* {{asd|4}}'s counterpart to this entity is {{ent|Light_deferred_global}}{{also|{{lw}}}}
* You alternatively can [[Implementing_Deferred_lighting_into_Source_2013|implement]] {{lw|4}}'s Deferred lighting as it is the most robust implementation currently being available to the public.
}}
{{important|
* {{Xe|4}}'s implementation requires the <code>-CascadeShadows</code> and <code>-StaticPropLighting3</code> parameters in [[VRAD]] for CSM to work correctly.
* Due to lighting changes in {{Xe|4}}, this entity has many additional parameters.}}
 
==Keyvalues==
{{KV Targetname}}
{{KV|Light Color|intn=color|color255|This is the color of the sunlight. For {{csgo|4}}, the color is automatically copied from the {{ent|light_environment}}.
{{bug|In {{bms|4}}, do not use a color value that differs from what is written in ''light_environment'' entity, otherwise the cascade light will not work properly.|hidetested=1
}}
}}
{{KV|Max shadow distance|intn=maxshadowdistance|float|Maximum dynamic shadow distance. Higher values are slower, default on PC is 400 units.}}
{{KV|Use light_environment's angles|intn=uselightenvangles|bool|If true, the CSM shadow angles are automatically taken from a {{ent|light_environment}}'s angles. If false, this entity's '''Pitch Yaw Roll''' is used.}}
{{KV|LightRadius1|to=LightRadius3|intn=LightRadius1|float|Used for controlling shadow softness in cascades 1, 2, and 3.|only={{Xe}}}}
{{KV|Depthbias1|to=Depthbias3|intn=Depthbias1|float|DepthBias for cascades 1, 2, and 3.|only={{Xe}}}}
{{KV|Slopescaledepthbias1|to=Slopescaledepthbias3|intn=Slopescaledepthbias1|float|Slope DepthBias for cascades 1, 2, and 3.|only={{Xe}}}}
{{KV|ViewModelDepthbias|intn=ViewModelDepthbias|float|DepthBias for viewmodel cascade.|only={{Xe}}}}
{{KV|ViewModelSlopescaledepthbias|intn=ViewModelSlopescaledepthbias|float|DepthBias for viewmodel cascade.|only={{Xe}}}}
{{KV|CSM_Volume_Mode|intn=CSMVolumeMode|choices|Use Manual mode for better quality and performance. In near future Auto mode will be removed from the game.|only={{Xe}}|}}
:*0: Auto: Static cache will update once every 10 frames (approx) covering max shadow distance or whole map around player.
:*1: Manual : Static cache area coverage and updates are managed via CSM Volumes' I/O.
{{KV EnableDisable}}
 
==Inputs==
{{I|SetAngles|Sets the direction shadows cast in.|param=string}}
:{{note|Affects nothing.}}
{{I|LightColor|Changes color of the sunlight.|param=color255}}
<dd>{{bug|Doesn't work as expected. With {{csgo|4}}'s implementation, the color only changes on static props, not on world geometry or dynamic objects. It only changes the shadow color (only in world geometry, not in models), with no change upon reloading the game. With {{Xe|4}}'s implementation, the only thing you can do is change shadows color to turquoise and change the intensity of these shadows, however this doesn't effects shadows on the [[viewmodel]].
{{expand|title=Examples|noborder=1|1=
{{p2ce|4.1}} uses {{csgo|4.1}}'s implementation of CSM
{{csgo|2}} ({{p2ce|2}}):
<br>
<gallery mode=nolines widths=320px heights=250px>
File:beforeCSMLC.jpg|Before <code>ent_fire env_cascade_light lightcolor 255 0 0 255</code>.
File:afterCSMLC.jpg|After <code>ent_fire env_cascade_light lightcolor 255 0 0 255</code>.  
</gallery>
{{Xe|2}}:
<gallery mode=nolines widths=320px heights=250px>
File:beforeBMS,jpg.jpg|Before <code>ent_fire env_cascade_light lightcolor 255 0 0 255</code>.
File:afterBMS.jpg|After <code>ent_fire env_cascade_light lightcolor 255 0 0 255</code>.
</gallery>
}}|tested={{p2ce}}{{bms}}}}</dd>
{{I|LightColorScale|Boosts the color of the sunlight. Non-functional, only resets the Light Color.|nofgd=1|deprecated=1}}
:{{bug|Affects nothing in {{Xe|4}}.|hidetested=1}}
{{I|SetCSMVolume|Set CSM Volume via trigger volume.|only={{Xe}}}}
{{I|SetCSMVolumeToSceneBounds|Set CSM Volume to scene bounds.|only={{Xe}}}}
{{I|SetCSMVolumeViaCSMVolumeEntity|param=targetname|Set CSM Volume to CSM Volume Entity.|only={{Xe}}}}
{{I|Disable|param=void|Disable this entity.}}
:{{note|Only in {{Xe|4}} work as expected. {{csgo|4}}'s implementation only disable blobby shadows and lighting in [[viewmodel]], also cause freeze for some seconds.}}
{{I|Enable|param=void|Enable this entity.}}
:{{note|Only in {{Xe|4}} work as expected. {{csgo|4}}'s implementation only enable blobby shadows and lighting in [[viewmodel]], also cause freeze for some seconds.}}
 
==Cascade Shadow Mapping Volumes==
{{bms|2}} provides very powerful optimization feature, called Cascade Shadow Mapping Volumes (CSM volumes for short). Initially, there were 2 different modes for rendering shadow maps for static cascade, which type to use - determines the value from the property, the property is '''CSM_Volume_Mode'''. CSM volumes allow you to automatically limit rendering of cascade shadows, swap areas there you want to have static cascade shadows (this is cascade shadows from static props with world geometry (brush entities as well) and also change value for '''Max shadow distance''' property.
 
'''CSM_Volume_Mode''' property can have 2 different values:
 
*Auto - you will not be able to swap areas there you want to have static cascade shadows, value from '''Max shadow distance''' property never changes, static cascade shadows will also disappear with dynamic cascade shadows. Good enough if map isn't very open space or if it's not too big.
 
*Manual - static cascade shadows rendering areas depends on values from the inputs, value from '''Max shadow distance''' property also depends on values from the inputs. This allows you to save many FPS for maps with big open space areas (especially for [[Xen]] levels).
 
There are 3 different inputs for this feature, which create 3 different ways to use CSM volumes.
 
The first input is '''SetCSMVolume'''. This input changes CSM volume and sets min and max bounds via {{ent|trigger_csm_volume}} entity. The size of {{ent|trigger_csm_volume}} entity decides the size of the world or level to be rendered into CSM shadow maps. To use it, specify the area in which you want to set CSM volume via {{ent|trigger_csm_volume}} entity (also works with {{ent|trigger_multiple}} and other triggers for some reason). In {{ent|trigger_csm_volume}} make the following output:
 
<gallery mode=nolines widths=320px heights=250px>
File:csmvol1.jpg|An example (instead of <code>cascade</code> there should be your {{ent|env_cascade_light}} name).
</gallery>
 
In this way, static cascade shadows will not appear outside of min and max bounds.
 
<gallery mode=nolines widths=320px heights=250px>
File:csmvolg1.jpg|Example with console message about min and max bounds (this appear when you touch such CSM volume). Note that we have static cascade shadows in this area.
File:csmvolg2.jpg|Example in room that is outside of the bounds. Note that we don't have have static cascade shadows in this area.
</gallery>
 
The second input is '''SetCSMVolumeToSceneBounds'''. It resets CSM volume to scene bounds. To use it, use the steps from the previous way, but replace '''SetCSMVolume''' input with '''SetCSMVolumeToSceneBounds''' input.
 
In this way, static cascade shadows never disappear, but dynamic still disappear.
<gallery mode=nolines widths=320px heights=250px>
File:csmvolgScene.jpg|Example with console message about CSM volume reset (this appear when you touch such CSM volume). Note that we have static cascade shadows (from the tree and world geometry in this case), but we don't have dynamic cascade shadows (from the crate and the ropes in this case).
</gallery>
 
 
The third input and the last way is '''SetCSMVolumeViaCSMVolumeEntity'''. It does the same thing that does '''SetCSMVolume''', but instead of {{ent|trigger_csm_volume}} you are using {{ent|env_cascade_volume}} entity. This way is deprecated, but still can be used in some very rare cases. {{ent|env_cascade_volume}} is disabled in original [[FGD]], you need to open <code>base.cfg</code>, find line <code>3169</code> and uncomment the code (or just use [https://github.com/MyGamepedia/Enhanced-Black-Mesa-FGD Enhanced Black Mesa FGD]). The next step is to place the entity, give a name and set values for '''RadiusX''', '''RadiusY''' and '''RadiusZ''' properties. What values to set to have required results ? Image that the entity position is brush center, and the values for the properties is the values what you see in 2D {{hammer|4}} window while some brush entity is selected. The last step is to add output for entity that will set CSM volume in this way, this can be trigger or any other entity. '''SetCSMVolumeViaCSMVolumeEntity''' requires parameter to work, the parameter is the name of {{ent|env_cascade_volume}} which we set up early.
<gallery mode=nolines widths=320px heights=250px>
File:csmvolent.jpg|An example.
</gallery>
In this way, we get results that are identical to the result from '''SetCSMVolume''' input.
 
 
{{important|All these features are fully disabled with ridiculous value for setting '''Sun Shadow Quality''' ({{command|cl_csm_qualitymode|4}}).}}
{{bug|All these features doesn't work properly in multiplayer.|hidetested=1}}
 
== See also ==
* {{ent|trigger_csm_volume}} - cascade volume brush entity
* {{ent|env_cascade_volume}} - cascade volume point entity
* {{ent|light_environment}} - baked static sunlight
* {{ent|Shadow_control}} - dynamic shadows
* {{ent|env_sun}} - glowing sun effect
* [[Skybox Basics]]
* [[Skybox lighting]]
* [[Advanced Lighting]]
* [[Effect flags]] (dynamic light effects)
* {{ent|newLight_Dir}} - directional sun light with godrays only
* {{ent|newLight_Point}} - point deferred light entity
* {{ent|newLight_Spot}} - spot deferred light entity
* {{ent|NewLights_settings}} - entity that changes deferred light settings
* [[New Specular]] - specular shader for new lights
* {{ent|light_deferred}} - deferred light
* {{ent|light_deferred_global}} - deferred global light
 
== External links ==
* [https://drive.google.com/file/d/1BEEXsHwpL6iHuzZvbYEeOuRuuSqpEHHh/view?usp=drive_link Example of CSM volumes (all 3 ways) in test map]
* [https://chetanjags.wordpress.com/2023/07/17/blackmesa-xenengine-part3-csm-2-0/ BlackMesa XenEngine: Part3 – CSM 2.0] (page from Black Mesa developer about their own CSM implementation)
* [https://chetanjags.wordpress.com/2023/07/11/blackmesa-xenengine-part2-how-a-frame-is-rendered/ BlackMesa XenEngine: Part2 – How a Frame is Rendered] (page from Black Mesa developer about new graphics features)
* [https://chetanjags.wordpress.com/2022/06/01/blackmesa-xenengine-part1-a-heavily-modified-source-engine/ BlackMesa XenEngine: Part1 – Heavily Modified Source Engine] (page from Black Mesa developer about Black Mesa engine, better known as [[Xengine]])
 
[[Category:Lighting]]

Latest revision as of 15:32, 12 July 2025

English (en)Translate (Translate)

env_cascade_light is a logical entity available in all Source Source games since Counter-Strike: Global Offensive Counter-Strike: Global Offensive.(also in Xengine)

C++ Class hierarchy
CCascadeLight
CBaseEntity
Comparison of CSM and without CSM in Black Mesa (Click here for full-res version)

It casts an extremely accurate shadow map via the tools/toolsskybox texture, augmenting the lighting cast by light_environment with real-time shadows. This form of shadow mapping is known as Cascaded Shadow Maps, or CSM for short, which works by rendering very detailed shadow maps which becomes a lower and lower resolution depending on the distance the viewer is from the surface, similar to mipmaps. Some games automatically add this entity to the map, but it can be placed manually as well.

Note.pngNote:Although you can toggle this entity, you can have only one env_cascade_light present in your level. Any others will not work.
Icon-Bug.pngBug:
  • In Insurgency, shadows will be very faint if the map hasn't been compiled with HDR.
  • In Insurgency, Lightstyles will break when this entity exists.
Note.pngNote:
Icon-Important.pngImportant:
  • Xengine Xengine's implementation requires the -CascadeShadows and -StaticPropLighting3 parameters in VRAD for CSM to work correctly.
  • Due to lighting changes in Xengine Xengine, this entity has many additional parameters.

Keyvalues

Name (targetname) <string>[ Edit ]
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

Light Color (color) <color255>
This is the color of the sunlight. For Counter-Strike: Global Offensive Counter-Strike: Global Offensive, the color is automatically copied from the light_environment.
Icon-Bug.pngBug:In Black Mesa Black Mesa, do not use a color value that differs from what is written in light_environment entity, otherwise the cascade light will not work properly.
Max shadow distance (maxshadowdistance) <float>
Maximum dynamic shadow distance. Higher values are slower, default on PC is 400 units.
Use light_environment's angles (uselightenvangles) <boolean>
If true, the CSM shadow angles are automatically taken from a light_environment's angles. If false, this entity's Pitch Yaw Roll is used.
LightRadius1 (LightRadius1) to LightRadius3 <float> (only in Xengine)
Used for controlling shadow softness in cascades 1, 2, and 3.
Depthbias1 (Depthbias1) to Depthbias3 <float> (only in Xengine)
DepthBias for cascades 1, 2, and 3.
Slopescaledepthbias1 (Slopescaledepthbias1) to Slopescaledepthbias3 <float> (only in Xengine)
Slope DepthBias for cascades 1, 2, and 3.
ViewModelDepthbias (ViewModelDepthbias) <float> (only in Xengine)
DepthBias for viewmodel cascade.
ViewModelSlopescaledepthbias (ViewModelSlopescaledepthbias) <float> (only in Xengine)
DepthBias for viewmodel cascade.
CSM_Volume_Mode (CSMVolumeMode) <choices> (only in Xengine)
Use Manual mode for better quality and performance. In near future Auto mode will be removed from the game.
  • 0: Auto: Static cache will update once every 10 frames (approx) covering max shadow distance or whole map around player.
  • 1: Manual : Static cache area coverage and updates are managed via CSM Volumes' I/O.
Start Disabled (StartDisabled) <boolean>
Stay dormant until activated (with theEnableinput).

Inputs

SetAngles <stringRedirectInput/string>
Sets the direction shadows cast in.
Note.pngNote:Affects nothing.
LightColor <color255RedirectInput/color32>
Changes color of the sunlight.
Icon-Bug.pngBug:Doesn't work as expected. With Counter-Strike: Global Offensive Counter-Strike: Global Offensive's implementation, the color only changes on static props, not on world geometry or dynamic objects. It only changes the shadow color (only in world geometry, not in models), with no change upon reloading the game. With Xengine Xengine's implementation, the only thing you can do is change shadows color to turquoise and change the intensity of these shadows, however this doesn't effects shadows on the viewmodel.
Examples
Portal 2: Community Edition Portal 2: Community Edition uses Counter-Strike: Global Offensive Counter-Strike: Global Offensive's implementation of CSM

Counter-Strike: Global Offensive Counter-Strike: Global Offensive (Portal 2: Community Edition Portal 2: Community Edition):

Xengine Xengine:

  (tested in: Portal 2: Community EditionBlack Mesa)
LightColorScale  !FGD Obsolete
Deprecated.
Boosts the color of the sunlight. Non-functional, only resets the Light Color.
Icon-Bug.pngBug:Affects nothing in Xengine Xengine.
SetCSMVolume  (only in Xengine)
Set CSM Volume via trigger volume.
SetCSMVolumeToSceneBounds  (only in Xengine)
Set CSM Volume to scene bounds.
SetCSMVolumeViaCSMVolumeEntity <targetnameRedirectInput/string> (only in Xengine)
Set CSM Volume to CSM Volume Entity.
Disable <void>
Disable this entity.
Note.pngNote:Only in Xengine Xengine work as expected. Counter-Strike: Global Offensive Counter-Strike: Global Offensive's implementation only disable blobby shadows and lighting in viewmodel, also cause freeze for some seconds.
Enable <void>
Enable this entity.
Note.pngNote:Only in Xengine Xengine work as expected. Counter-Strike: Global Offensive Counter-Strike: Global Offensive's implementation only enable blobby shadows and lighting in viewmodel, also cause freeze for some seconds.

Cascade Shadow Mapping Volumes

Black Mesa Black Mesa provides very powerful optimization feature, called Cascade Shadow Mapping Volumes (CSM volumes for short). Initially, there were 2 different modes for rendering shadow maps for static cascade, which type to use - determines the value from the property, the property is CSM_Volume_Mode. CSM volumes allow you to automatically limit rendering of cascade shadows, swap areas there you want to have static cascade shadows (this is cascade shadows from static props with world geometry (brush entities as well) and also change value for Max shadow distance property.

CSM_Volume_Mode property can have 2 different values:

  • Auto - you will not be able to swap areas there you want to have static cascade shadows, value from Max shadow distance property never changes, static cascade shadows will also disappear with dynamic cascade shadows. Good enough if map isn't very open space or if it's not too big.
  • Manual - static cascade shadows rendering areas depends on values from the inputs, value from Max shadow distance property also depends on values from the inputs. This allows you to save many FPS for maps with big open space areas (especially for Xen levels).

There are 3 different inputs for this feature, which create 3 different ways to use CSM volumes.

The first input is SetCSMVolume. This input changes CSM volume and sets min and max bounds via trigger_csm_volume entity. The size of trigger_csm_volume entity decides the size of the world or level to be rendered into CSM shadow maps. To use it, specify the area in which you want to set CSM volume via trigger_csm_volume entity (also works with trigger_multiple and other triggers for some reason). In trigger_csm_volume make the following output:

In this way, static cascade shadows will not appear outside of min and max bounds.

The second input is SetCSMVolumeToSceneBounds. It resets CSM volume to scene bounds. To use it, use the steps from the previous way, but replace SetCSMVolume input with SetCSMVolumeToSceneBounds input.

In this way, static cascade shadows never disappear, but dynamic still disappear.


The third input and the last way is SetCSMVolumeViaCSMVolumeEntity. It does the same thing that does SetCSMVolume, but instead of trigger_csm_volume you are using env_cascade_volume entity. This way is deprecated, but still can be used in some very rare cases. env_cascade_volume is disabled in original FGD, you need to open base.cfg, find line 3169 and uncomment the code (or just use Enhanced Black Mesa FGD). The next step is to place the entity, give a name and set values for RadiusX, RadiusY and RadiusZ properties. What values to set to have required results ? Image that the entity position is brush center, and the values for the properties is the values what you see in 2D Hammer Hammer window while some brush entity is selected. The last step is to add output for entity that will set CSM volume in this way, this can be trigger or any other entity. SetCSMVolumeViaCSMVolumeEntity requires parameter to work, the parameter is the name of env_cascade_volume which we set up early.

In this way, we get results that are identical to the result from SetCSMVolume input.


Icon-Important.pngImportant:All these features are fully disabled with ridiculous value for setting Sun Shadow Quality (cl_csm_qualitymode 4).
Icon-Bug.pngBug:All these features doesn't work properly in multiplayer.

See also

External links