Difference between revisions of "Water (shader)"

From Valve Developer Community
Jump to: navigation, search
(Flow: video)
(Flow)
Line 75: Line 75:
  
 
; {{l4d2 add|<code>$flowmap</code>}}
 
; {{l4d2 add|<code>$flowmap</code>}}
: This is a texture that defines flow velocity at about 4 [[texel]]s/meter. For the preservation of sanity Valve generate theirs with an unreleased [http://www.sidefx.com/index.php?option=com_content&task=view&id=1774&Itemid=343 Houdini] plugin.
+
: This is a texture that defines flow velocity by skewing and scrolling the $normalmap. For the preservation of sanity Valve generate theirs with an unreleased [http://www.sidefx.com/index.php?option=com_content&task=view&id=1774&Itemid=343 Houdini] plugin.
 
: [[File:L4d2 flowmap user.jpg|300px]] [[File:L4d2 flowmap tex.jpg|169px]] [[File:L4d2 flowmap dev.jpg|300px]]
 
: [[File:L4d2 flowmap user.jpg|300px]] [[File:L4d2 flowmap tex.jpg|169px]] [[File:L4d2 flowmap dev.jpg|300px]]
 
: [http://www.youtube.com/watch?v=iY6vkpQDcpU See a clip of the effect on YouTube.] For a detailed description of how it all works see [http://www.valvesoftware.com/publications/2010/siggraph2010_vlachos_waterflow.pdf Alex Vlachos' SIGGRAPH 2010 paper].
 
: [http://www.youtube.com/watch?v=iY6vkpQDcpU See a clip of the effect on YouTube.] For a detailed description of how it all works see [http://www.valvesoftware.com/publications/2010/siggraph2010_vlachos_waterflow.pdf Alex Vlachos' SIGGRAPH 2010 paper].
 +
; <code>$flow_normaluvscale</code>
 +
: The size of the normal map in relation to the flow map. Valve often use very high values (e.g. 800). {{todo|1 <nowiki>==</nowiki> one normal map repeat for every texel?}}
 +
; <code>$flow_worlduvscale</code>
 +
: {{todo|No apparent effect.}}
 +
; <code>$flow_timeintervalinseconds</code>
 +
: {{confirm|Time needed for one complete scroll of the normal map?}}
 +
; <code>$flow_uvscrolldistance</code>
 +
: {{todo}}
 +
; <code>$flow_bumpstrength</code>
 +
: How rough surface of the water is.
 +
; <code>$flow_timescale</code>
 +
: How fast the water flows over its specified distance.
 +
; <code>$flow_noise_texture</code>
 +
: A treatment texture used to break up repetition of the normal map.
 +
; <code>$flow_noise_scale</code>
 +
: {{todo|Has the same effect as $flow_normaluvscale?}}
 +
; <code>$flow_debug</code>
 +
: Replaces the water surface with a literal rendering of the $flowmap texture.
  
 
=== Other ===
 
=== Other ===

Revision as of 18:00, 26 June 2011

A custom Water material from Resistance And Liberation.
Real-time reflection of entities in Episode Two.

Water is one of the Source engine's most complex shaders. It creates animated, real-time reflective and refractive, fogged, normal-mapped water.

Special behaviour

Expensive and cheap
Water materials fall into two groups: expensive and cheap. Expensive water reflects and refracts the world in real-time, while cheap water uses an $envmap and does not refract. Users can disable expensive Water rendering through their video options, so always place env_cubemaps.
Above and below
Water actually requires two materials: one for above the surface and one for below. These materials are independent of each other, but of course for proper effect need to correlate in most areas.

Shader parameters

Textures

Tip:There is no $basetexture here. The surface is a combination of fog colour, animated bump map, and reflection.
$abovewater <bool>
Whether this material is used for above or below the water’s surface.
$bottommaterial <material>
Required field. This is the material (not texture) to use when underneath the water’s surface. The bottom material must have $reflecttexture and $abovewater disabled, but can otherwise do whatever it wants.
$underwateroverlay <material> (New with Half-Life 2: Episode Two / Source 2007)
Applies a screen overlay when the camera is underwater. Generally used with effects\water_warp01. Requires $abovewater to be 0.
$bumpmap <texture>
$normalmap <texture>
A Du/dv map for DirectX 8 rendering ($bumpmap), and a bump map for DirectX 9 and above ($normalmap). These should be animated unless the water is to be perfectly still.
Note:The $normalmap command is unique to the Water shader, and uses a normal map. A du/dv map is used for $bumpmap when using the Water shader. The $dudvmap command is obsolete.
Tip:Use $bumptransform with the TextureScroll proxy to move the normal map.
Size/angle of $scroll1 and $scroll2
$scroll1 "[<normal X> <normal Y>]" (New with Half-Life 2: Episode Two / Source 2007)
$scroll2 "[<normal X> <normal Y>]" (New with Half-Life 2: Episode Two / Source 2007)
If $scroll1 is defined and X is not zero, two more instances of the normal map will be drawn in such a way that they are merged together. The first layer is 7x larger and rotated 45°; the second is 2x larger and rotated 90°. The parameters specify the speed and direction that the extra layers will move. (Valve's materials usually contain a third number, but it doesn't have any apparent effect and is most likely obsolete.)
$dudvframe <int>
$bumpframe <int>
Frame to start the animated du/dv map and bump map on, respectively. Somewhat confusingly, $bumpframe affects $normalmap, which should be pointing to a bump map.

Fog

$fogcolor <RGB matrix>
This is the color of the water’s volumetric fog. Generally this value should match the color used in the bottom material.
$fogenable <bool>
Enable volumetric fog for the water.
$fogend <float>
This is the distance in inches from the eye at which water fog ends.
$fogstart <float>
This is the distance in inches from the eye at which water fog starts.
Warning: This must be 0 for edge fading to work properly.

Reflection/Refraction

$envmap <env_cubemap / texture>
Provides reflections for cheap water. See $envmap
$forcecheap <bool>
Make this water cheap regardless of the water_lod_control entity's or user's settings. This will disable real-time reflection and instead use $envmap. Refraction is assumed to be opaquely the water fog color.
$forceexpensive <bool>
This forces the water to render itself as expensive, regardless of the map's water_lod_control or the user's settings.
$reflectamount <float>
This is the amount of warp for the reflection. Higher values produce more visible reflections.
$reflectentities <bool>
Make the water reflect entities. By default, no entities are reflected.
$reflecttexture <texture>
Texture to use for reflection. For real-time reflections, use _rt_WaterReflection.
Tip:Specify $refracttexture without $reflecttexture to get real-time refraction on $envmap reflections.
$reflecttint <RGB matrix>
This is the color tint for the real-time reflection and environment map.
$refractamount <float>
This is the amount of warp for the refraction. Higher values produce more warping.
$refracttexture <texture>
Texture to use for refraction. For real-time refractions, use _rt_WaterRefraction.
Tip:Specify $refracttexture without $reflecttexture to get real-time refraction on $envmap reflections.
$refracttint <RGB matrix>
This is the color of the refraction.
Warning: It is recommended that you set this to white or something close to white so that edge transitions work properly on DX9.

Flow

$flowmap (New with Left 4 Dead 2)
This is a texture that defines flow velocity by skewing and scrolling the $normalmap. For the preservation of sanity Valve generate theirs with an unreleased Houdini plugin.
L4d2 flowmap user.jpg L4d2 flowmap tex.jpg L4d2 flowmap dev.jpg
See a clip of the effect on YouTube. For a detailed description of how it all works see Alex Vlachos' SIGGRAPH 2010 paper.
$flow_normaluvscale
The size of the normal map in relation to the flow map. Valve often use very high values (e.g. 800). To do: 1 == one normal map repeat for every texel?
$flow_worlduvscale
To do: No apparent effect.
$flow_timeintervalinseconds
Confirm:Time needed for one complete scroll of the normal map?
$flow_uvscrolldistance
To do
$flow_bumpstrength
How rough surface of the water is.
$flow_timescale
How fast the water flows over its specified distance.
$flow_noise_texture
A treatment texture used to break up repetition of the normal map.
$flow_noise_scale
To do: Has the same effect as $flow_normaluvscale?
$flow_debug
Replaces the water surface with a literal rendering of the $flowmap texture.

Other

%compilewater <bool>
This is needed to make a map using the material compile properly.
$surfaceprop water
Tells the physics system that the surface is water. See $surfaceprop.
%tooltexture <texture>
Defines the texture Hammer will display in the material browser.
WaterLOD proxy
This connects the water_lod_control entity in a level to the water’s internal parameters. This must be declared in the material for the LOD mechanisms to work properly.

See also