Water (shader)
Water is a very complex shader inside of the Source engine: it is animated, reflective, fogged, refractive, and bump mapped. With this complexity come rules and restrictions on how it is placed and what sort of water is used in different situations.
Expensive Water
This sort of water is the best looking, but also carries the most cost. This shader will reflect the world around it, refract and fog the world beneath it (based on the line integral through the water volume), and animate a bump mapped texture on the surface. While the results are photo-realistic, the cost can sometimes be too prohibitive for complex scenes.
Cheap Water
For situations where a more simplistic water solution is called for (normally for performance reasons), cheap water may be used. This version of water does not reflect the world around it, making it less realistic, but also much cheaper. Expensive water will fallback to cheap water on video cards that are unable to support the features necessary for it to render properly. It will also fallback to this material if the user overrides the visual quality setting for water’s appearance in the Video options in-game.
Water Volumes
See Adding Water for more information on how to create water volume brushes in your levels.
Creating Water Materials
Water materials are separated into two types: above and below the surface. The bottom material is specified via a parameter inside the above surface material. The above material is displayed when the view is outside of the water looking into it, and the bottom material is displayed when the view is underneath the water and looking out of it. Each material may define its own custom parameters to alter its appearance. Generally the coloration of the water materials should closely correlate. By altering the material parameters for either material type, you can change the opacity of the water, the amount of reflection, the amount of refraction, and the tinting of the water.
Water Material Parameters
Textures
$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
disabled and can have unique parameters for rendering the underwater scene. The bottom material should also set$abovewater
to 0. $bumpframe <int>
- Used for the texture animation proxy to declare the starting frame of the animated water surface.
$bumpmap <texture>
- This is the DU\DV map for the water. It is generated from a normal map.
$bumpmap
is used for DirectX 8 water, and$normalmap
is used for DX9. You should specify both so that you’ll get the correct results on both versions of the water shader. $normalmap <texture>
- This is the normal map for the water. It is used by the DX9 water shader.
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 water_lod_control entity’s setting. Todo: Or the user's?
$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.
Other
%compilewater <bool>
- This is needed to make a map using the material compile properly.
$surfaceprop water
- Used by the physics system to define the surface as being water.
%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.