Env fog controller: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (confirmed switching fog controllers works in gmod)
(updates. man, this page was in a bad state!)
Line 1: Line 1:
{{base point|env_fog_controller}}
{{lang|Env fog controller}}
[[File:fog_controller.png|left|link=]]{{base point|env_fog_controller}} It determines the properties of aerial fog for the whole map.


==Entity description==
{{tip|In multiplayer games, fog may be changed per-client by sending the {{ent|player}} entity (probably best accessed through {{ent|!activator}}) a <code>SetFogController</code> input.}}
[[File:fog_controller.png|left|link=]]


It determines the density of aerial fog for the whole map.
{{confirm|Does <code>player</code> have this input in ''all'' games? It's known to exist in HL2, CSS, and GMOD.}}


{{map_properties}} {{clr}}
In {{l4ds}}, multiple <code>env_fog_controller</code>s may be used in conjunction with {{ent|fog_volume}}s to create different fog effects where needed. In addition, an <code>env_fog_controller</code> can be set as the ''Master'' fog controller under flags, in cases where a <code>fog_volume</code> is not tied to any specific <code>env_fog_controller</code>, or if no <code>fog_volume</code> is used in a region.


In [[Left 4 Dead]] and [[Left 4 Dead 2]], multiple env_fog_controllers may be used in conjunction with [[fog_volume|fog_volumes]] to create different fog effects where needed. In addition, an env_fog_controller can be set as the "Master" fog controller under flags, in cases where a fog_volume is not tied to any specific fog_controller, or if no fog_volume is used in a region.
Adding fog to a map can cause/require changes to the [[lighting]] for realism. Light is scattered and absorbed as it passes through fog. The denser the fog, the greater the effect.
*[[Falloff]] - (or attenuation) is the rate at which light intensity decreases over distance. Falloff distance decreases as fog gets thicker.
*[[Lighting#Tyndall effects|Tyndall effects]] - can be seen when the fog particles reflect light toward the viewer. Halos and light beams become more visible as fog gets thicker.
*Diffused Lighting - the boundary-line between light and shadow becomes more blurred (diffuse) as fog gets thicker. See [[Lightmap#Lightmap Scale|Lightmap Scale]] and {{ent|shadow_control}}'s "distance" parameter.


In {{HL2}} mods/games using Source 2007 and Source 2013 you can create client-side fog changing functionality in a multiplayer game using [[trigger_multiple]]. Have at least 2 env_fog_controllers with different fog settings and one checked with the '''Master flag'''(which will be the default fog). Use OnStartTouch > !activator > '''SetFogController''' > [name of env_fog_controller entity]. The input will appear as red, but it still works. Use OnEndTouch() to change the fog back. '''Interpolate Time''' affects the transition of the fog color and fog distance parameters between controllers, however '''Far Z Clip Plane''' as well as '''Fog Max Density''' change instantaneously(which can appear jarring). Confirmed in [[Counter-Strike: Source]] and [[Garry's Mod]].
Older Source games render fog as a plane a certain distance away from the camera. This method is bad, as rotating the camera will strengthen or weaken the apparent amount of fog in a particular spot, even though the viewer hasn't moved at all. In Left 4 Dead{{confirm}} onward, this is fixed by implementing a new radial method which is independent from the viewing angle.


{{note|The [[3D Skybox]] fog levels set by the [[sky_camera]] parameters should correspond to your [[env_fog_controller]] settings.}}
{{note|The [[3D Skybox]] fog levels set by the {{ent|sky_camera}} parameters should correspond to your <code>env_fog_controller</code> settings.}}
{{tip|By adding fog to a level, you can hide a '''FarZ''' Clip Plane, and reduce the amount of rendered geometry, improving game performance.}}
{{bug|The '''StartFogTransition''' input does not seem to work correctly in {{game link|Counter-Strike: Global Offensive}}. The fog will transition to nothing and then abruptly change to the target lerp values at the end of the interpolate time.}}
Adding fog (to represent haze, mist, diffuse smoke or dust) to the atmosphere has important implications for 'realistic' [[Lighting]]. Light is scattered and absorbed as it passes through fog. The denser the fog, the greater the effect.
* [[Falloff]] - (or attenuation) is the rate at which light intensity decreases over distance. Falloff distance decreases as fog gets thicker.
* [[Lighting#Tyndall effects|Tyndall effects]] - can be seen when the fog particles reflect light toward the viewer. Halos and Lightbeams become more visible as fog gets thicker.
* Diffused Lighting - the boundary-line between light and shadow becomes more blurred (diffuse) as fog gets thicker. See [[Lightmap#Lightmap Scale|Lightmap Scale]] and [[shadow_control]]'s "distance" parameter.


== Keyvalues ==
{{code class|CFogController|fogcontroller.cpp}}
;* fogenable {{boolean}}
: Enable fog on map load. {{note|The default for this entity is False.  In order to actually have fog, you will need to change this.}}


;* fogstart <[[float]]>
==Flags==
: How far from the viewer the fog should start.
*1: Master - If multiple <code>env_fog_controller</code>s are active, this one will always take priority.
 
;* fogend <[[float]]>
: How far from the viewer the scene should be completely fogged.
 
;* fogmaxdensity <[[float]]>
: Fog Max Density [0..1]
 
;* farz <[[integer]]>
: Far Z Clip Plane
: This setting is used for optimizing your map. Anything beyond this distance (in world units) will not be rendered. It is recommended to keep this number higher then your ''fogend'' value and ensure fogmaxdensity is set to 1.
 
;* fogcolor {{color}}
: Primary Fog Color.
 
;* fogblend {{boolean}}
: This will enable blending between ''fogcolor'' and ''fogcolor2'', based on the direction the player is looking. If the player's viewpoint is equal to the ''fogdir'' vector, the fog will be drawn with ''fogcolor2'' (red); if facing in the opposite direction, the fog will be drawn with ''fogcolor'' (blue). If facing perpendicular to the fogblend axis, the fog will be a 50/50 blend of ''fogcolor'' and ''fogcolor2'' (purple).
: This can be used to approximate the effect of light diffusing through the fog, but since the fogblend effect is applied for the entire rendered scene, it is best to keep the two colors relatively close to make the blending less obvious.
: For example, sunlight with a Yaw of 45 degrees and a Pitch of -45 degrees could be enhanced using a ''fogdir'' of "-1 -1 1", a ''fogcolor'' of "120 110 100" and a ''fogcolor2'' of "80 70 60".
 
;* fogcolor2 {{color}}
: Secondary Fog Color.
 
;* fogdir <[[vector]]>
: Primary Fog Direction
: A vector (given by three space-separated numbers X Y Z) which points from the secondary ''fogcolor2'' towards the primary ''fogcolor''.
 
;* use_angles {{boolean}}
: Use Angles for Fog Dir
: Use ''angles'' instead of ''fogdir'' for the fogblend-axis.
 
{{KV Angles}}
 
;* {{EP1 add|foglerptime}} <[[float]]>
: Interpolate time


==Keyvalues==
{{KV|Fog Enabled (fogenable)|boolean|Make fog start active.}}
{{KV|Fog Start (fogstart)|float|How far away from the viewer the fog should start.}}
{{KV|Fog End (fogend)|float|How far away from the viewer the fog reaches '''Fog Max Density'''.}}
{{KV|Fog Max Density (fogmaxdensity)|float|Maximum density the fog may reach. Expressed as a decimal percent, so for 45% put 0.45.}}
{{KV|Far Z Clip Plane (farz)|integer|Anything beyond this distance in world units will not be rendered. This should be higher than '''Fog End'''. If this is used, '''Fog Max Density''' should be set to <code>1</code> otherwise the [[void]] may be visible.}}
{{KV|Primary Fog Color (fogcolor)|color255|Primary Fog Color.}}
{{KV|Secondary Fog Color (fogcolor2)|color255|Secondary Fog Color. If '''Fog Blend''' is disabled, this color will never appear.}}
{{KV|Fog Blend (fogblend)|boolean|Enables color blending between '''Primary Fog Color''' and '''Secondary Fog Color'''. When the viewer looks in the '''Primary Fog Direction''', fog will appear as the ''Primary'' color. When looking away from the specified direction, fog appears as the ''Secondary'' color. If the camera is not pointed directly at or away from the direction, a blend of the two colors will result. Sunlight with a '''Yaw''' of 45 degrees and a '''Pitch''' of -45 degrees could be enhanced using a '''Primary Fog Direction''' of "-1 -1 1", a '''Primary Fog Color''' of "120 110 100" and a '''Secondary Fog Color''' of "80 70 60".}}
{{KV|Primary Fog Direction (fogdir)|vector|A vector (given by three space-separated numbers X Y Z) which the viewer camera is checked against to figure out the blend between the primary and secondary fog colors.}}
{{KV|Use Angles for Fog Dir (use_angles)|boolean|Use '''Pitch Yaw Roll''' for the '''Fog Blend''' direction instead of '''Primary Fog Direction'''. There isn't much use for this unless you want the direction to rotate.}}
{{KV|Interpolate time (foglerptime)|float|Fade time for the <code>StartFogTransition</code> input.}}
{{KV|HDR Color Scale (HDRColorScale)|since=L4D|float|Multiplier for fog color when in [[HDR]] mode.}}
{{KV|Zoom Fog Scale (ZoomFogScale)|since=CSGO|float|Scalar for fog start and end distances when the player is looking through a gun's scope (e.g. AWP).}}
{{KV DXLevelChoice}}
{{KV DXLevelChoice}}
{{KV Targetname}}
{{KV SystemLevelChoice}}
 
{{KV BaseEntity|css=1}}
== Flags ==
* 1 : Master (Has priority if multiple env_fog_controllers exist)
 
== Inputs ==
;* SetStartDist <[[float]]>
: Set the fog start distance.
 
;* SetEndDist <[[float]]>
: Set the fog end distance.
 
;* TurnOn
: Turn the fog on.
 
;* TurnOff
: Turn the fog off.
 
;* SetColor {{color}}
: Set the primary fog color.
 
;* SetColorSecondary {{color}}
: Set the secondary fog color.
 
;* SetFarZ <[[integer]]>
: Set the far clip plane distance.
 
;* SetAngles {{angles}}
: Set the angles to use for the secondary fog direction.
 
;* {{EP1 add|SetColorLerpTo {{color}} }}
: Set the primary fog color.
 
;* {{EP1 add|SetColorSecondaryLerpTo {{color}} }}
: Set the secondary fog color.
 
;* {{EP1 add|SetStartDistLerpTo <[[float]]> }}
: Set the fog start distance.
 
;* {{EP1 add|SetEndDistLerpTo <[[float]]> }}
: Set the fog end distance.
 
;* {{EP1 add|StartFogTransition}}
: Start fog transition.
 
;* SetFogController <[[targetname]]>
: Set the active fog controller. {{tip|This input should be used if [[fog_volume]] is not a valid entity. You can use this input by creating a trigger_multiple and setting its input to: (OnStartTouch > !activator > SetFogController > *Controller Name*)}} {{note|This input will also show up as red (invalid) but it will still work. If done correctly the [[Hammer Check For Problems Dialog]] should have no errors.}}


{{I Targetname}}
==Inputs==
{{IO|TurnOn|Turns the fog on.}}
{{IO|TurnOff|Turns the fog off.}}
{{IO|SetStartDist|param=float|Sets the '''Fog Start''' distance.}}
{{IO|SetEndDist|param=float|Sets the '''Fog End''' distance.}}
{{IO|SetColor|param=color255|Sets the '''Primary Fog Color'''.}}
{{IO|SetColorSecondary|param=color255|Sets the '''Secondary Fog Color'''.}}
{{IO|SetFarZ|param=integer|Sets the '''Far Z Clip Plane''' distance.}}
{{IO|SetAngles|param=angles|Sets the angles to use for the '''Primary Fog Direction'''.}}
{{IO|Set2DSkyboxFogFactor|param=float|since=l4d2|Set the current amount of fog to blend into the 2D skybox. Expressed as a decimal percent, so for 45% put 0.45. {{l4d2}} only.}}
{{IO|SetZoomFogScale|param=float|since=CSGO|Sets the '''Zoom Fog Scale'''.}}
{{IO|SetColorLerpTo|param=color255|since=EP1|Stores a value for '''Primary Fog Color''' that is set once the <code>StartFogTransition</code> input fires.}}
{{IO|SetColorSecondaryLerpTo|param=color255|since=EP1|Stores a value for '''Secondary Fog Color''' that is set once the <code>StartFogTransition</code> input fires.}}
{{IO|SetStartDistLerpTo|param=float|since=EP1|Stores a value for '''Fog Start''' that is set once the <code>StartFogTransition</code> input fires.}}
{{IO|SetEndDistLerpTo|param=float|since=EP1|Stores a value for '''Fog End''' that is set once the <code>StartFogTransition</code> input fires.}}
{{IO|SetMaxDensityLerpTo|param=float|since=L4D|Stores a value for '''Fog Max Density''' that is set once the <code>StartFogTransition</code> input fires. This one does ''not'' have any non-"LerpTo" counterpart.}}
{{IO|Set2DSkyboxFogFactorLerpTo|param=float|since=l4d2|Set the current amount of fog to blend into the 2D skybox. Expressed as a decimal percent, so for 45% put 0.45. This will only change once the <code>StartFogTransition</code> input fires. {{l4d2}} only.}}
{{IO|StartFogTransition|since=EP1|When fired, the fog fades to any new values sent through the "<code>LerpTo</code>" inputs. Fade time is determined by the '''Interpolate time''' keyvalue.


== Outputs ==
{{bug|Does not work correctly. The fog will transition to nothing and then abruptly change to the new values at the end of the interpolation time. Seen in {{l4d2}}{{csgo}}.}}}}
{{O Targetname}}
{{I BaseEntity|prel4d=1}}


== Fog Technique ==
==Outputs==
Source 2007 fog seems to be implemented based on a plane based fog technique versus a more modern radially fog technique.  As a result the viewer will be able to see further into the fog along the edges.  Furthermore, the fog is rotation dependent.  Something that appears under fog at one view may change if the player rotates slightly.
{{O BaseEntity|l4d=1}}


== See also ==
==See Also==
* [[Fog tutorial]]
*[[Fog tutorial]]
* [[Fog Basics]]
*[[Fog Basics]]
* [[Dust, Fog, & Smoke]]
*[[Dust, Fog, & Smoke]]
* {{l4d}}{{l4d2}} [[fog_volume]]

Revision as of 11:10, 25 September 2018

English (en)Hrvatski (hr)中文 (zh)Translate (Translate)
Fog controller.png

Template:Base point It determines the properties of aerial fog for the whole map.

Tip.pngTip:In multiplayer games, fog may be changed per-client by sending the player entity (probably best accessed through !activator) a SetFogController input.
Confirm:Does player have this input in all games? It's known to exist in HL2, CSS, and GMOD.

In Left 4 Dead seriesLeft 4 Dead series, multiple env_fog_controllers may be used in conjunction with fog_volumes to create different fog effects where needed. In addition, an env_fog_controller can be set as the Master fog controller under flags, in cases where a fog_volume is not tied to any specific env_fog_controller, or if no fog_volume is used in a region.

Adding fog to a map can cause/require changes to the lighting for realism. Light is scattered and absorbed as it passes through fog. The denser the fog, the greater the effect.

  • Falloff - (or attenuation) is the rate at which light intensity decreases over distance. Falloff distance decreases as fog gets thicker.
  • Tyndall effects - can be seen when the fog particles reflect light toward the viewer. Halos and light beams become more visible as fog gets thicker.
  • Diffused Lighting - the boundary-line between light and shadow becomes more blurred (diffuse) as fog gets thicker. See Lightmap Scale and shadow_control's "distance" parameter.

Older Source games render fog as a plane a certain distance away from the camera. This method is bad, as rotating the camera will strengthen or weaken the apparent amount of fog in a particular spot, even though the viewer hasn't moved at all. In Left 4 Dead[confirm] onward, this is fixed by implementing a new radial method which is independent from the viewing angle.

Note.pngNote:The 3D Skybox fog levels set by the sky_camera parameters should correspond to your env_fog_controller settings.
C++ In code, it is represented by theCFogControllerclass, defined in thefogcontroller.cppfile.

Flags

  • 1: Master - If multiple env_fog_controllers are active, this one will always take priority.

Keyvalues

Fog Enabled (fogenable) ([todo internal name (i)]) <boolean>
Make fog start active.
Fog Start (fogstart) ([todo internal name (i)]) <float>
How far away from the viewer the fog should start.
Fog End (fogend) ([todo internal name (i)]) <float>
How far away from the viewer the fog reaches Fog Max Density.
Fog Max Density (fogmaxdensity) ([todo internal name (i)]) <float>
Maximum density the fog may reach. Expressed as a decimal percent, so for 45% put 0.45.
Far Z Clip Plane (farz) ([todo internal name (i)]) <integer>
Anything beyond this distance in world units will not be rendered. This should be higher than Fog End. If this is used, Fog Max Density should be set to 1 otherwise the void may be visible.
Primary Fog Color (fogcolor) ([todo internal name (i)]) <color255>
Primary Fog Color.
Secondary Fog Color (fogcolor2) ([todo internal name (i)]) <color255>
Secondary Fog Color. If Fog Blend is disabled, this color will never appear.
Fog Blend (fogblend) ([todo internal name (i)]) <boolean>
Enables color blending between Primary Fog Color and Secondary Fog Color. When the viewer looks in the Primary Fog Direction, fog will appear as the Primary color. When looking away from the specified direction, fog appears as the Secondary color. If the camera is not pointed directly at or away from the direction, a blend of the two colors will result. Sunlight with a Yaw of 45 degrees and a Pitch of -45 degrees could be enhanced using a Primary Fog Direction of "-1 -1 1", a Primary Fog Color of "120 110 100" and a Secondary Fog Color of "80 70 60".
Primary Fog Direction (fogdir) ([todo internal name (i)]) <vector>
A vector (given by three space-separated numbers X Y Z) which the viewer camera is checked against to figure out the blend between the primary and secondary fog colors.
Use Angles for Fog Dir (use_angles) ([todo internal name (i)]) <boolean>
Use Pitch Yaw Roll for the Fog Blend direction instead of Primary Fog Direction. There isn't much use for this unless you want the direction to rotate.
Interpolate time (foglerptime) ([todo internal name (i)]) <float>
Fade time for the StartFogTransition input.
HDR Color Scale (HDRColorScale) ([todo internal name (i)]) <float> (in all games since Left 4 Dead)
Multiplier for fog color when in HDR mode.
Zoom Fog Scale (ZoomFogScale) ([todo internal name (i)]) <float> (in all games since Counter-Strike: Global Offensive)
Scalar for fog start and end distances when the player is looking through a gun's scope (e.g. AWP).
Minimum / Maximum DX Level (mindxlevel / maxdxlevel) <integer choices> (removed since Left 4 Dead)
The entity will not exist if the engine is running outside the given range of DirectX Versions.
Choices
Warning.pngWarning:If these are used, the object may break when the user switches their DirectX settings.[missing string]
Minimum / Maximum Effect Details Level (mincpulevel / maxcpulevel) <integer choices> (in all games since Left 4 Dead)
Don't render for players with Effect Details levels that exceed the minimum or maximum.
Choices
  • 0: Default ("Low" for mincpulevel, "High" for maxcpulevel)
  • 1: Low
  • 2: Medium
  • 3: High
Minimum / Maximum Shader Details Level (mingpulevel / maxgpulevel) <integer choices> (in all games since Left 4 Dead)
Don't render for players with Shader Details levels that exceed the minimum or maximum.
Choices
  • 0: Default ("Low" for mingpulevel, "Very High" for maxgpulevel)
  • 1: Low
  • 2: Medium
  • 3: High
  • 4: Very High
See also:  cpu_level / gpu_level convars


Inputs

TurnOn
Turns the fog on.
TurnOff
Turns the fog off.
SetStartDist <floatRedirectInput/float>
Sets the Fog Start distance.
SetEndDist <floatRedirectInput/float>
Sets the Fog End distance.
SetColor <color255RedirectInput/color32>
Sets the Primary Fog Color.
SetColorSecondary <color255RedirectInput/color32>
Sets the Secondary Fog Color.
SetFarZ <integerRedirectInput/integer>
Sets the Far Z Clip Plane distance.
SetAngles <anglesRedirectInput/Vector>
Sets the angles to use for the Primary Fog Direction.
Set2DSkyboxFogFactor <floatRedirectInput/float> (in all games since Left 4 Dead 2)
Set the current amount of fog to blend into the 2D skybox. Expressed as a decimal percent, so for 45% put 0.45. Left 4 Dead 2 only.
SetZoomFogScale <floatRedirectInput/float> (in all games since Counter-Strike: Global Offensive)
Sets the Zoom Fog Scale.
SetColorLerpTo <color255RedirectInput/color32> (in all games since Half-Life 2: Episode One)
Stores a value for Primary Fog Color that is set once the StartFogTransition input fires.
SetColorSecondaryLerpTo <color255RedirectInput/color32> (in all games since Half-Life 2: Episode One)
Stores a value for Secondary Fog Color that is set once the StartFogTransition input fires.
SetStartDistLerpTo <floatRedirectInput/float> (in all games since Half-Life 2: Episode One)
Stores a value for Fog Start that is set once the StartFogTransition input fires.
SetEndDistLerpTo <floatRedirectInput/float> (in all games since Half-Life 2: Episode One)
Stores a value for Fog End that is set once the StartFogTransition input fires.
SetMaxDensityLerpTo <floatRedirectInput/float> (in all games since Left 4 Dead)
Stores a value for Fog Max Density that is set once the StartFogTransition input fires. This one does not have any non-"LerpTo" counterpart.
Set2DSkyboxFogFactorLerpTo <floatRedirectInput/float> (in all games since Left 4 Dead 2)
Set the current amount of fog to blend into the 2D skybox. Expressed as a decimal percent, so for 45% put 0.45. This will only change once the StartFogTransition input fires. Left 4 Dead 2 only.
StartFogTransition  (in all games since Half-Life 2: Episode One)
When fired, the fog fades to any new values sent through the "LerpTo" inputs. Fade time is determined by the Interpolate time keyvalue.
Icon-Bug.pngBug:Does not work correctly. The fog will transition to nothing and then abruptly change to the new values at the end of the interpolation time. Seen in Left 4 Dead 2Counter-Strike: Global Offensive.  [todo tested in ?]


Outputs

See Also