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
 
(67 intermediate revisions by 14 users not shown)
Line 1: Line 1:
{{langsp}}
{{LanguageBar}}
It is also available in {{Bms|4}}
{{tabsBar|main=env_cascade_light}}
{{This is a|logical entity|name=env_cascade_light|since=Counter-Strike: Global Offensive|notext=1}}
{{CD|CCascadeLight}}
[[File:CSM Example.jpg|thumb|CSM in {{csgo|4.1}}]]
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.


While {{asd|4}} doesn't have support for this entity its [[Light environment]] does cast dynamic shadows by default.
{{important|
[[File:CSM Example.jpg|thumb|CSM in {{csgo|3.1}}]]
* 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. CSM relies upon a fifth channel <!--first 4 channels are RGB and exponent, even in non-HDR mode--> in the lightmap to mask dark and light areas.
[[File:Env_cascade_light_-_BMS_CSM_comparison.gif|thumb|Comparison of CSM and without CSM in {{bms|3.1}}<br>(Click to preview)]]
* If this entity is missing from your map, the CSM will still be created automatically!
It casts an extremely accurate shadow map via the <code>tools/[[skybox]]</code> texture, acting as a real-time variation of {{ent|light_environment}}. This form of lighting is known as [https://learn.microsoft.com/en-us/windows/win32/dxtecharts/cascaded-shadow-maps Cascaded Shadow Maps], or CSM, 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|In {{jb3}}, this will only occur if both {{ent|env_cascade_light}} and {{ent|shadow_control}} are missing, and the BSP contains lightmap alpha. {{confirm|{{strata}} probably works similarly.}} }}
 
}}
{{note|Due to lighting changes in {{bms}}, this entity has additional parameters.}}
{{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.}}
{{note|{{bms|4}}'s implementation requires <code>-cascadeshadows</code> parameter for [[VRAD]], this for CSM to work correctly.}}
{{codenote|
 
* {{src13|4}} doesn't have this entity, but there is an [https://github.com/celisej567/Fake-CSM-Mapbase attempt] of simulating it.  
{{bug|In {{insurgency}}, shadows will be very faint if the map hasn't been compiled with [[HDR]].}}
* {{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.
{{bug|In {{insurgency}}, [[Naming Lights|Lightstyles]] will break when this entity exists.}}
}}
 
{{bug|
{{note|You still need to have a <code>light_environment</code> in your map as well to create [[lightmap]] based lighting, which is not done by this entity.}}
* In {{insurgency}}, shadows will be very faint if the map hasn't been compiled with [[HDR]].
 
* In {{insurgency}}, [[lightstyle]]s will break when this entity exists.|hidetested=1}}
{{note|Older games like {{hl2}} don't have this entity, but there is an [https://github.com/celisej567/Fake-CSM-Source-2013 attempt] of porting it.}}
{{note|You alternatively can implement Biohazards [https://github.com/SCell555/sdk-2013-deferred deferred lighting] here is a port for {{src13mp|4.1}} as originally it was made for {{as|4.1}}.{{warning|This port contains many bugs, optimization is broken or missing, even on simple maps there will be low performance.}}}}
{{todo|Make tutorial on how to implement deferred lighting in your source engine project, and also how to use it.}}
{{csgo}} Represented by class <code>CCascadeLight</code>.


==Keyvalues==
==Keyvalues==
{{KV|Light Color|intn=color|color255|This is the color of the sunlight. For {{csgo}}, the color is automatically copied from the light_environment.}}
{{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}}.}}
{{KV|Max shadow distance|intn=maxshadowdistance|float|Maximum dynamic shadow distance. Higher values are slower, default on PC is 400 units.}}
{{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|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 angles is used.}}
{{KV|LightRadius1|to=LightRadius3|intn=LightRadius1|float|Used for controlling shadow softness in cascades 1, 2, and 3.|only=BMS}}
{{KV Angles}}
{{KV|Depthbias1|to=Depthbias3|intn=Depthbias1|float|DepthBias for cascades 1, 2, and 3.|only=BMS}}
{{KV StartDisabled}}
{{KV|Slopescaledepthbias1|to=Slopescaledepthbias3|intn=Slopescaledepthbias1|float|Slope DepthBias for cascades 1, 2, and 3.|only=BMS}}
:{{bug|hidetested=1|Non-functional in {{csgo}}. Fixed in {{jb3}}.}}
{{KV|ViewModelDepthbias|intn=ViewModelDepthbias|float|DepthBias for viewmodel cascade.|only=BMS}}
{{KV|ViewModelSlopescaledepthbias|intn=ViewModelSlopescaledepthbias|float|DepthBias for viewmodel cascade.|only=BMS}}
{{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=BMS|}}
:*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}}
{{KV BaseEntity}}


==Inputs==
==Inputs==
{{IO|SetAngles|Sets the direction shadows cast in.|param=string}}
{{I|SetAngles|Sets the direction shadows cast in.|param=string}}
{{note|Effects nothing.}}
:{{bug|Affects nothing.}}
{{IO|LightColor|Changes color of the sunlight.|param=color255}}
{{I|LightColor|Changes color of the sunlight.|param=color255}}
{{bug|Doesn't work as expected. With {{csgo|4}}'s implementation lighting color changes only in static props, not in world geometry and dynamic objects, for some reason it's change shadows color (only in world geometry, not in models), game reload nothing change. With {{bms|4}}'s implementation the only thing you can do is change shadows color to turquoise and intensity of these shadows, however this doesn't effects shadows in [[viewmodel]].
<dd>{{bug|Doesn't work as expected. 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.  
{{expand|title=Examples|noborder=1|1=
{{expand|title=Examples|noborder=1|1=
{{note|{{p2ce|1}} uses {{csgo|1}}'s implementation of CSM}}
{{p2ce|4.1}} uses {{csgo|4.1}}'s implementation of CSM
{{Csgo|2}}:
<br>
<br>
<gallery mode=packed heights=250px>
<gallery mode=nolines widths=320px heights=250px>
File:beforeCSMLC.jpg| thumb | left |Before <code>ent_fire env_cascade_light lightcolor 255 0 0 255</code>.  
File:beforeCSMLC.jpg|Before <code>ent_fire env_cascade_light lightcolor 255 0 0 255</code>.  
File:afterCSMLC.jpg| thumb | left |After <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>
</gallery>
{{Bms|2}}:
}}|tested={{p2ce}}}}</dd>
<gallery mode=packed heights=250px>
{{I|LightColorScale|Boosts the color of the sunlight. Non-functional, only resets the Light Color.|nofgd=1|deprecated=1}}
File:beforeBMS,jpg.jpg| thumb | left |Before <code>ent_fire env_cascade_light lightcolor 255 0 0 255</code>.
{{I EnableDisable}}
File:afterBMS.jpg| thumb | left |After <code>ent_fire env_cascade_light lightcolor 255 0 0 255</code>.
:{{bug|hidetested=1|Doesnt work correctly in {{CSGO}}; cascade light must be [[kill]]ed instead. Fixed in {{jb3}}.}}
</gallery>
}}
}}
{{IO|LightColorScale|Boosts the color of the sunlight. Non-functional, only resets the Light Color.|nofgd=1|deprecated=1}}
{{bug|Effects nothing in {{bms|4}}.}}
{{IO|SetCSMVolume|Set CSM Volume via trigger volume.|only=BMS}}
{{IO|SetCSMVolumeToSceneBounds|Set CSM Volume to scene bounds.|only=BMS}}
{{IO|SetCSMVolumeViaCSMVolumeEntity|param=targetname|Set CSM Volume to CSM Volume Entity.|only=BMS}}
{{IO|Disable|param=void|Disable this entity.}}
{{note|Only in {{bms|4}} work as expected. {{csgo|4}}'s implementation only disable blobby shadows and lighting in [[viewmodel]], also cause freeze for some seconds.}}
{{IO|Enable|param=void|Enable this entity.}}
{{note|Only in {{bms|4}} work as expected. {{csgo|4}}'s implementation only enable blobby shadows and lighting in [[viewmodel]], also cause freeze for some seconds.}}
{{I BaseEntity}}
 
==Outputs==
{{O BaseEntity}}


== See also ==
== See also ==
 
* {{ent|light_environment}} - baked static sunlight
* {{ent|light_environment}}
* {{ent|Shadow_control}} - dynamic shadows
* {{ent|Shadow_control}}
* {{ent|env_sun}} - glowing sun effect
* {{ent|env_sun}}
* [[Skybox Basics]]
* [[Skybox Basics]]
* [[Skybox lighting]]
* [[Skybox lighting]]
* [[Advanced Lighting]]
* [[Advanced Lighting]]
* [[Effect flags]] (dynamic light effects)
* [[Effect flags]] (dynamic light effects)
* {{ent|newLight_Dir}}
 
* {{ent|newLight_Point}}
[[Category:Lighting]]
* {{ent|newLight_Spot}}
* {{ent|NewLights_settings}}
* [[New_Specular]]
* [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 [[Xenengine]])

Latest revision as of 12:29, 4 December 2025

English (en)Translate (Translate)
Edit Tabs

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

C++ Class hierarchy
CCascadeLight
CBaseEntity

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.

Icon-Important.pngImportant:
  • You still need to have a light_environment in your map as well to create lightmap based lighting, which is not done by this entity. CSM relies upon a fifth channel in the lightmap to mask dark and light areas.
  • If this entity is missing from your map, the CSM will still be created automatically!
Note.pngNote:In Jabroni Brawl: Episode 3, this will only occur if both env_cascade_light and shadow_control are missing, and the BSP contains lightmap alpha.
Confirm:Strata Source probably works similarly.
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.
Cpp.pngCode:
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.

Keyvalues

Name (targetname) <string>
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.
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 angles is used.
Pitch Yaw Roll (Y Z X) (angles) <QAngle>
This entity's orientation in the world. Pitch is rotation around the Y axis, yaw is the rotation around the Z axis, roll is the rotation around the X axis.
Start Disabled (StartDisabled) <boolean>
Stay dormant until activated (with theEnableinput).
Icon-Bug.pngBug:Non-functional in Counter-Strike: Global Offensive. Fixed in Jabroni Brawl: Episode 3.

Inputs

SetAngles <stringRedirectInput/string>
Sets the direction shadows cast in.
Icon-Bug.pngBug:Affects nothing.  [todo tested in ?]
LightColor <color255RedirectInput/color32>
Changes color of the sunlight.
Icon-Bug.pngBug:Doesn't work as expected. 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.
Examples
Portal 2: Community Edition Portal 2: Community Edition uses Counter-Strike: Global Offensive Counter-Strike: Global Offensive's implementation of CSM


  (tested in: Portal 2: Community Edition)
LightColorScale  !FGD Obsolete
Deprecated.
Boosts the color of the sunlight. Non-functional, only resets the Light Color.

EnableDisable:

Enable / Disable
Enable/disable this entity from performing its task. It might also disappear from view.
Icon-Bug.pngBug:Doesnt work correctly in Counter-Strike: Global Offensive; cascade light must be killed instead. Fixed in Jabroni Brawl: Episode 3.

See also