Water (shader): Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (modified headline levels)
Line 20: Line 20:
==Water Material Parameters==
==Water Material Parameters==


{|
=== Textures ===
| <code>$abovewater (0,1)</code>
; <code>$abovewater <[[bool]]></code>
|-
: Whether this material is used for above or below the water’s surface.
| Whether this material is used for above or below the water’s surface.
; <code>$bottommaterial <material></code>
|-
: Required field. This is the material ('''not''' texture) to use when underneath the water’s surface. The bottom material must have <code>$reflecttexture</code> disabled and can have unique parameters for rendering the underwater scene. The bottom material should also set <code>$abovewater</code> to 0.
| <code>$bottommaterial (material name)</code>
; <code>$bumpframe <[[int]]></code>
|-
: Used for the texture animation proxy to declare the starting frame of the animated water surface.
|Required field. This is the material 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.
; <code>[[$bumpmap]] <texture></code>
|-
: This is the [[DU\DV]] map for the water. It is generated from a normal map. <code>$bumpmap</code> is used for DirectX 8 water, and <code>$normalmap</code> is used for DX9. You should specify both so that you’ll get the correct results on both versions of the water shader.
| <code>$bumpframe (integer)</code>
; <code>$normalmap <texture></code>
|-
: This is the normal map for the water. It is used by the DX9 water shader.
| Used for the texture animation proxy to declare the starting frame of the animated water surface.
 
|-
=== Fog ===
| <code>$bumpmap (texture name)</code>
 
|-
; <code>$fogcolor <[[RGB]] matrix></code>
|This is the DUDV map for the water. It is generated from a normal map. $bumpmap is used for dx8 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.
: This is the color of the water’s volumetric fog. Generally this value should match the color used in the bottom material.
|-
; <code>$fogenable <bool></code>
| <code>%compilewater(0,1)</code>
: Enable volumetric fog for the water.
|-
; <code>$fogend <[[float]]></code>
|This is needed for the compilation tools.
: This is the distance in inches from the eye at which water fog ends.
|-
; <code>$fogstart <float></code>
| <code>$envmap (texture name)</code>
: This is the distance in inches from the eye at which water fog starts.
|-
: {{warning|This must be <code>0</code> for edge fading to work properly.}}
|Texture to use for environment mapping (only for cheap water or water only refracts). Set this value to env_cubemap to use cubemaps placed in the map.
 
|-
=== Reflection/Refraction ===
| <code>$fogcolor { R, G, B }</code>
 
|-
; <code>[[$envmap]] <env_cubemap / texture></code>
|This is the color of the water’s volumetric fog. Generally this value should match the color used in the bottom material.
: Provides reflections for cheap water. See <code>[[$envmap]]</code>
|-
; <code>$forcecheap <bool></code>
| <code>$fogenable (0,1)</code>
: 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 <code>$envmap</code>. Refraction is assumed to be opaquely the water fog color.
|-
; <code>$forceexpensive <bool></code>
|Enable volumetric fog for the water.
: This forces the water to render itself as [[expensive]], regardless of the water_lod_control entity’s setting. {{todo|Or the user's?}}
|-
; <code>$reflectamount <float></code>
| <code>$fogend (float)</code>
: This is the amount of warp for the reflection. Higher values produce more visible reflections.
|-
; <code>$reflectentities <bool></code>
|This is the distance in inches from the eye at which water fog ends.
: Make the water reflect entities. By default, no entities are reflected.
|-
; <code>$reflecttexture <texture></code>
| <code>$fogstart (float)</code>
: Texture to use for reflection. For real-time reflections, use <code>[[_rt_WaterReflection]]</code>.
|-
: {{tip|Specify <code>$refracttexture</code> without <code>$reflecttexture</code> to get real-time refraction on <code>$envmap</code> reflections.}}
|This is the distance in inches from the eye at which water fog starts.
; <code>$reflecttint <RGB matrix></code>
{{Note|This must be 0.0 for edge fading to work properly.}}
: This is the color tint for the real-time reflection and environment map.
|-
; <code>$refractamount <float></code>
| <code>$forcecheap (0,1)</code>
: This is the amount of warp for the refraction. Higher values produce more warping.
|-
; <code>$refracttexture <texture></code>
|Make this water cheap regardless of the water_lod_control entity’s setting. This will ignore $reflecttexture and $refracttexture. Reflections will happen with $envmap and refraction is assumed to be opaquely the water fog color.
: Texture to use for refraction. For real-time refractions, use <code>[[_rt_WaterRefraction]]</code>.
|-
: {{tip|Specify <code>$refracttexture</code> without <code>$reflecttexture</code> to get real-time refraction on <code>$envmap</code> reflections.}}
| <code>$forceexpensive (0,1)</code>
; <code>$refracttint <RGB matrix></code>
|-
: This is the color of the refraction.
|This forces the water to render itself as expensive, regardless of the water_lod_control entity’s setting.
: {{warning|It is recommended that you set this to white or something close to white so that edge transitions work properly on DX9.}}
|-
 
| <code>$normalmap (texture name)</code>
=== Other ===
|-
 
|This is the normal map for the water. This is used by the dx9 water shader.
; <code>%compilewater <bool></code>
|-
: This is needed to make a map using the material compile properly.
| <code>$reflectamount (float)</code>
; <code>$surfaceprop water</code>
|-
: Used by the physics system to define the surface as being water.
|This is the amount of warp for the reflection. Higher values produce more visible reflections.
; <code>%tooltexture <texture></code>
|-
: Defines the texture Hammer will display in the material browser.
| <code>$reflectentities (0,1)</code>
; <code>WaterLOD proxy</code>
|-
: 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.
|Make the water reflect entities. By default, no entities are reflected.
|-
| <code>$reflecttexture (texture name)</code>
|-
|Texture to use for reflection. For real-time reflections, use _rt_WaterReflection.
{{Note|If you can specify $refracttexture without specying a $reflecttexture to get real-time refraction and cube map reflections.}}
|-
| <code>$reflecttint { R, G, B }</code>
|-
|This is the color tint for the real-time reflection and environment map.
|-
| <code>$refractamount (float)</code>
|-
|This is the amount of warp for the refraction. Higher values produce more warping.
|-
| <code>$refracttexture (texture name)</code>
|-
|Texture to use for refraction. For real-time refractions, use _rt_WaterRefraction.
{{Note|If you can specify $refracttexture without specying a $reflecttexture to get real-time refraction and cube map reflections.}}
|-
| <code>$refracttint { R, G, B }</code>
|-
|This is the color of the refraction.
{{Note|It is recommended that you set this to white or something close to white so that edge transitions work properly on dx9.}}
|-
| <code>$surfaceprop "water"</code>
|-
|Used by the physics system to define this surface as water.
|-
| <code>%tooltexture (texture name)</code>
|-
|Declares the texture to be used in Hammer when editing.
|-
| <code>WaterLOD proxy</code>
|-
|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.
|}

Revision as of 07:08, 15 July 2008

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.pngWarning: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.pngTip: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.pngTip:Specify $refracttexture without $reflecttexture to get real-time refraction on $envmap reflections.
$refracttint <RGB matrix>
This is the color of the refraction.
Warning.pngWarning: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.