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

$treesway: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Added a little backstory to this shader in the description, removed the mention of it working in L4D2 because it doesn't, I just tested it a while ago.)
No edit summary
 
(63 intermediate revisions by 23 users not shown)
Line 1: Line 1:
When this parameter is added, it will make the material morph around to an [[env_wind]] entity to give it the effect that it's blowing in the wind, this effect is used for the trees you see in {{csgo}}[[Counter-Strike:_Global_Offensive|Counter-Strike: Global Offensive]] and various foliage seen in  {{insurgency}}[http://store.steampowered.com/app/222880 Insurgency 2014]. The effect assumes that the model is facing upwards, and the commands specify how much it should be affected by the [[env_wind]] entity.  This shader has possibly been in Valve games since [[Left_4_Dead|Left 4 Dead]], but was never enabled and used by Valve until [[Counter-Strike:_Global_Offensive|Counter-Strike: Global Offensive]], mods using the [[Alien_Swarm|Alien Swarm]] codebase can enable this shader to take advantage of it.
{{LanguageBar}}


{{note|These parameters only work in recent engine branches like {{csgo}} and other games based on it like {{insurgency}}, along with mods that have it enabled like [http://store.steampowered.com/app/270370 Lambda Wars].}}
[[File:de_lake_treesway.gif|thumb|Tree with treesway on {{csgomap|de_lake|game=csgo}} in CS:GO (click to preview).]]
{{This is a|shader parameter|name=$treesway|shader=VertexLitGeneric|since=Left 4 Dead 2}} {{also| {{tf2branch}} {{Bms}} {{GMOD}} {{mapbase}} }} In {{GMOD}} {{mapbase}}, it can also be used for {{ent|UnlitGeneric}}.
<code>$treesway</code> morphs the vertices of a mesh with a given material around using the parameters of an {{ent|env_wind}} entity to give the appearance of tree leaves and foilage blowing in the wind. The subparameters of <code>$treesway</code> determine how much the {{mono|env_wind}} entity should affect the morphing, and all of them (except <code>$treeswaystatic</code>) must be specified in order for the effect to work properly. This shader parameter assumes any model using it is facing upwards.


Requires <code>[[VertexLitGeneric]]</code>.
{{note|This shader parameter is disabled by default in the {{as}} SDK. It can re-enabled by modding.}}
{{warning|Due to the way bumped lighting is calculated, <code>$treesway</code> will not sway materials which use {{ent|$bumpmap}}.}}
{{bug|{{clr}}
* This shader parameter does not work with [[$detail#Parameters and Effects|$detailtexturetransform]].
* In {{GMOD}}{{mapbase}}, using a shadow-casting [[env_projectedtexture|projected texture]] on materials with this parameter will cause flickering. As a workaround, try to keep trees away from where player flashlights can reach. {{ent|$halflambert}} may also partially fix the issue.
* In {{mapbase}}, using a shadow-casting [[env_projectedtexture|projected texture]] will cause shadows not reacting to <code>$treesway</code>, shadows don't move, except in {{gmod}} and Games now running on the 'TF2 SDK' ( 2025 Version of SDK2013MP ).}}


==Syntax==
{{note|There was a TODO here, asking about the impact of $singlepassflashlight and $flashlightnolambert on this.<br>
its important to clarify this to avoid further confusion:<br>
These are Parameteres that affect the rendered Material only.<br>
For creating the 'Shadow Map' ( Depth Texture, Projected Texture, etc ), an entirely separate Shader is used.<br>
That Shader (DepthWrite) did not have the $TreeSway Code, causing Shadows to be entirely unaffected by this feature.<br>
It can't 'simply' be added either, only some Parameters from the original Material are copied to it.<br>
And in case of SDK2013SP ( What MapBase is running on, for now ) does not allow an easy replacement of the existing DepthWrite Shader.}}


    $treeSway                        "1"
    $treeSwayHeight                  "8"
    $treeSwayStartHeight              ".5"
    $treeSwayRadius                  "1"
    $treeSwayStartRadius              "0.0"
    $treeSwaySpeed                    "2"
    $treeSwayStrength                ".1"
    $treeSwayScrumbleSpeed            "3"
    $treeSwayScrumbleStrength        ".2"
    $treeSwayScrumbleFrequency        "20"
    $treeSwayFalloffExp              "2"
    $treeSwayScrumbleFalloffExp      "3"
    $treeSwaySpeedHighWindMultiplier  ".2"
    $treeSwaySpeedLerpStart          "1000.0"
    $treeSwaySpeedLerpEnd            "2500.0"


==Additional parameters==


; <code>$treeSway <bool></code>
{{modernImportant|While $TreeSway can be used to animate a {{ent|prop_static}}, lightmap shadows casted by swaying static props will remain static.<br>'''''If [[CSM]] is unavailable''''', consider using a {{ent|prop_dynamic}} instead. This can be combined with an animation containing more realistic pre-baked wind physics than can be achieved with $treesway.<br>As {{ent|prop_dynamic}} cannot be lit by [[VRAD]] per-vertex, it may be desirable to use a pre-baked {{ent|$lightmap}} (if available) in such situations, to restore some ambient lighting quality.}}
: Turns the effect on or off.


; <code>$treeSwayHeight [[Float]]</code>
==Parameters==
: The height in which the effect is applied.


; <code>$treeSwayStartHeight [[Float]]</code>
{{MatParamDef|$treesway|int|What option to use for the tree swaying effect.
: The height from the origin in which the effect starts blending in.
:*0: No Sway
:*1: "Classic" tree sway.
:*2: Radial tree sway effect, intended for use on rectangular sheets of plastic/tarp attached at four corners. It inverts the sway scale radius to be 1 at (0,0,0) in model space and to fall off radially towards the edges of the model. {{note|Models using <code>$treesway 2</code> are expected to be built lying in the X Y plane in model space, with their center at the origin.}}}}
{{MatParamDef|$treeswayheight|float|The starting height in Hammer units where the effect should start being fully applied. Default 1000.}}
{{MatParamDef|$treeswaystartheight|float|The height from the model's origin in which the effect starts blending in. Default 0.2.}}
{{MatParamDef|$treeswayradius|float|The radius from the model's origin in Hammer units in where the effect should start being fully applied. Default 300.}}
{{MatParamDef|$treeswaystartradius|float|The radius from the model's origin in which the effect starts blending in. Default 0.1.}}
{{MatParamDef|$treeswayspeed|float|The speed multiplier of large movement such as the trunk. Default 1.}}
{{MatParamDef|$treeswaystrength|float|The distance multiplier of large movement such as the trunk. Default 10.}}
{{MatParamDef|$treeswayscrumblespeed|float|The falloff of the effect on large movement such as the trunk. Higher means a more stable center. Default 0.1.}}
{{MatParamDef|$treeswayscrumblestrength|float|The speed multiplier of the small movement such as the leaves. Default 0.1.}}
{{MatParamDef|$treeswayscrumblefrequency|float|The distance multiplier of the small movement such as the leaves. Default 0.1.}}
{{MatParamDef|$treeswayfalloffexp|float|The frequency of the rippling of a sine wave in small movement such as the leaves. Default 1.5.}}
{{MatParamDef|$treeswayscrumblefalloffexp|float|The falloff of the effect on small movement such as the leaves. Higher means a more stable center. Default 1.}}
{{MatParamDef|$treeswayspeedhighwindmultipler|float|Speed multiplier when <code>env_wind</code> triggers a gust. Default 2.}}
{{MatParamDef|$treeswayspeedlerpstart|float|Minimum wind speed in which a gust triggered by <code>env_wind</code> will start affecting the material. Default 3.}}
{{MatParamDef|$treeswayspeedlerpend|float|Minimum wind speed in which a gust triggered by <code>env_wind</code> will fully affect the material. Default 6.}}
{{MatParamDef|$treeswaystatic|float|Use a static wind value instead of the values from <code>env_wind</code>. If enabled, <code>env_wind</code> is not required.|only={{tf2branch}}{{csgo}}{{GMOD}}{{mapbase}}}}
{{MatParamDef|$treeswaystaticvalues|vector2|Sets the static wind values used by <code>$treeswaystatic</code>, syntax <code>[x y]</code>. Default <code>[0.5 0.5]</code>.|only={{mapbase}}}}


; <code>$treeSwayRadius [[Float]]</code>
== External links ==
: The radius from the origin in which the effect is applied.
https://gamebanana.com/tuts/12924 - How to achieve a similar effect without <code>$treeSway</code>, on all source engine games. Alternatively, use an animated {{ent|prop_dynamic}}, for a more realistic (but more [[expensive]]) effect.


; <code>$treeSwayStartRadius [[Float]]</code>
[[Category:Shader parameters|t]]
: The radius from the origin in which the effect starts blending in.
 
; <code>$treeSwaySpeed [[Float]]</code>
: The speed multiplier of large movement such as the trunk.
 
; <code>$treeSwayStrength [[Float]]</code>
: The distance multiplier of large movement such as the trunk.
 
; <code>$treeSwayFalloffExp [[Float]]</code>
: The falloff of the effect on small movement such as the trunk. Higher means a more stable center.
 
; <code>$treeSwayScrumbleSpeed [[Float]]</code>
: The speed multiplier of the small movement such as the leaves.
 
; <code>$treeSwayScrumbleStrength [[Float]]</code>
: The distance multiplier of the small movement such as the leaves.
 
; <code>$treeSwayScrumbleFrequency [[Float]]</code>
: The frequency of the rippling of a sine wave in small movement such as the leaves.
 
; <code>$treeSwayScrumbleFalloffExp [[Float]]</code>
: The falloff of the effect on small movement such as the leaves. Higher means a more stable center.
 
; <code>$treeSwaySpeedHighWindMultiplier [[Float]]</code>
: Speed multiplier when [[env_wind]] triggers a gust.
 
; <code>$treeSwaySpeedLerpStart [[Float]]</code>
: Minimum wind speed in which a gust triggered by [[env_wind]] will start affecting the material.
 
; <code>$treeSwaySpeedLerpEnd [[Float]]</code>
: Minimum wind speed in which a gust triggered by [[env_wind]] will fully affect the material.
 
 
[[Category:List of Shader Parameters|T]]

Latest revision as of 11:46, 23 August 2025

English (en)Русский (ru)Translate (Translate)
Tree with treesway on de_lake de_lake in CS:GO (click to preview).

$treesway is a material shader parameter for the VertexLitGeneric shader available in all Source Source games since Left 4 Dead 2 Left 4 Dead 2. (also in Team Fortress 2 branch Black Mesa Garry's Mod Mapbase) In Garry's Mod Mapbase, it can also be used for UnlitGeneric. $treesway morphs the vertices of a mesh with a given material around using the parameters of an env_wind entity to give the appearance of tree leaves and foilage blowing in the wind. The subparameters of $treesway determine how much the env_wind entity should affect the morphing, and all of them (except $treeswaystatic) must be specified in order for the effect to work properly. This shader parameter assumes any model using it is facing upwards.

Note.pngNote:This shader parameter is disabled by default in the Alien Swarm SDK. It can re-enabled by modding.
Warning.pngWarning:Due to the way bumped lighting is calculated, $treesway will not sway materials which use $bumpmap.
Icon-Bug.pngBug:
  • This shader parameter does not work with $detailtexturetransform.
  • In Garry's ModMapbase, using a shadow-casting projected texture on materials with this parameter will cause flickering. As a workaround, try to keep trees away from where player flashlights can reach. $halflambert may also partially fix the issue.
  • In Mapbase, using a shadow-casting projected texture will cause shadows not reacting to $treesway, shadows don't move, except in Garry's Mod and Games now running on the 'TF2 SDK' ( 2025 Version of SDK2013MP ).  [todo tested in ?]
Note.pngNote:There was a TODO here, asking about the impact of $singlepassflashlight and $flashlightnolambert on this.

its important to clarify this to avoid further confusion:
These are Parameteres that affect the rendered Material only.
For creating the 'Shadow Map' ( Depth Texture, Projected Texture, etc ), an entirely separate Shader is used.
That Shader (DepthWrite) did not have the $TreeSway Code, causing Shadows to be entirely unaffected by this feature.
It can't 'simply' be added either, only some Parameters from the original Material are copied to it.

And in case of SDK2013SP ( What MapBase is running on, for now ) does not allow an easy replacement of the existing DepthWrite Shader.


Icon-Important.pngImportant:While $TreeSway can be used to animate a prop_static, lightmap shadows casted by swaying static props will remain static.
If CSM is unavailable, consider using a prop_dynamic instead. This can be combined with an animation containing more realistic pre-baked wind physics than can be achieved with $treesway.
As prop_dynamic cannot be lit by VRAD per-vertex, it may be desirable to use a pre-baked $lightmap (if available) in such situations, to restore some ambient lighting quality.

Parameters

What option to use for the tree swaying effect.
  • 0: No Sway
  • 1: "Classic" tree sway.
  • 2: Radial tree sway effect, intended for use on rectangular sheets of plastic/tarp attached at four corners. It inverts the sway scale radius to be 1 at (0,0,0) in model space and to fall off radially towards the edges of the model.
    Note.pngNote:Models using $treesway 2 are expected to be built lying in the X Y plane in model space, with their center at the origin.
The starting height in Hammer units where the effect should start being fully applied. Default 1000.
The height from the model's origin in which the effect starts blending in. Default 0.2.
The radius from the model's origin in Hammer units in where the effect should start being fully applied. Default 300.
The radius from the model's origin in which the effect starts blending in. Default 0.1.
The speed multiplier of large movement such as the trunk. Default 1.
The distance multiplier of large movement such as the trunk. Default 10.
The falloff of the effect on large movement such as the trunk. Higher means a more stable center. Default 0.1.
The speed multiplier of the small movement such as the leaves. Default 0.1.
The distance multiplier of the small movement such as the leaves. Default 0.1.
The frequency of the rippling of a sine wave in small movement such as the leaves. Default 1.5.
The falloff of the effect on small movement such as the leaves. Higher means a more stable center. Default 1.
Speed multiplier when env_wind triggers a gust. Default 2.
Minimum wind speed in which a gust triggered by env_wind will start affecting the material. Default 3.
Minimum wind speed in which a gust triggered by env_wind will fully affect the material. Default 6.
$treeswaystatic <float> (only in Team Fortress 2 branchCounter-Strike: Global OffensiveGarry's ModMapbase)
Use a static wind value instead of the values from env_wind. If enabled, env_wind is not required.
Sets the static wind values used by $treeswaystatic, syntax [x y]. Default [0.5 0.5].

External links

https://gamebanana.com/tuts/12924 - How to achieve a similar effect without $treeSway, on all source engine games. Alternatively, use an animated prop_dynamic, for a more realistic (but more expensive) effect.