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

Water (shader): Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (clean up, replaced: {{ModernWarning| → {{warning| (7))
Line 20: Line 20:


{{MatParam|$basetexture|texture|Usually referred to as a "sludge-layer", acts as a layer on top of the surface of the $AboveWater Material.
{{MatParam|$basetexture|texture|Usually referred to as a "sludge-layer", acts as a layer on top of the surface of the $AboveWater Material.
{{ModernWarning|The $BaseTexture will only be lightmapped if there is no $FlowMap!}}
{{warning|The $BaseTexture will only be lightmapped if there is no $FlowMap!}}
{{ModernWarning|When not using a $FlowMap, this parameter does not work with projected textures or $LightMapWaterFog!}}
{{warning|When not using a $FlowMap, this parameter does not work with projected textures or $LightMapWaterFog!}}
{{note|In games before {{As}}, the surface is a combination of fog color, animated bump map, reflection and refraction.<br>{{tip|If a BaseTexture is necessary in earlier games, and real-time reflections are not necessary, then the [[Refract]] shader could be used instead.}}}}
{{note|In games before {{As}}, the surface is a combination of fog color, animated bump map, reflection and refraction.<br>{{tip|If a BaseTexture is necessary in earlier games, and real-time reflections are not necessary, then the [[Refract]] shader could be used instead.}}}}
|since={{as}}}}
|since={{as}}}}
Line 53: Line 53:
{{MatParam|$fogcolor|RGB matrix|Color of the water’s volumetric fog. Generally this value should match the color used in the bottom material.<br>
{{MatParam|$fogcolor|RGB matrix|Color of the water’s volumetric fog. Generally this value should match the color used in the bottom material.<br>
{{Important| If this parameter is not defined in a VMT, the shader will force its value to <code>"[1 0 0]"</code> and spew an error message saying <code>Material x needs to have a $fogcolor.</code>}}
{{Important| If this parameter is not defined in a VMT, the shader will force its value to <code>"[1 0 0]"</code> and spew an error message saying <code>Material x needs to have a $fogcolor.</code>}}
{{ModernWarning|
{{warning|
Cheap water treats this parameters as a linear value where 0.0 is 0% and 1.0 is 100%.<br>
Cheap water treats this parameters as a linear value where 0.0 is 0% and 1.0 is 100%.<br>
Expensive water treats this parameter as a Gamma value,<br>
Expensive water treats this parameter as a Gamma value,<br>
Line 64: Line 64:
{{MatParam|$lightmapwaterfog|bool|Allows the fog to receive [[lightmap]]s, so that static objects can cast shadows onto the water. This must be enabled when the map is compiled. <br>
{{MatParam|$lightmapwaterfog|bool|Allows the fog to receive [[lightmap]]s, so that static objects can cast shadows onto the water. This must be enabled when the map is compiled. <br>
{{note| Bumped Lightmaps are only enabled when a $BaseTexture has been defined, without it, a regular Lightmap will be used instead.}}
{{note| Bumped Lightmaps are only enabled when a $BaseTexture has been defined, without it, a regular Lightmap will be used instead.}}
{{ModernWarning|This feature does not exist for cheap water.}}
{{warning|This feature does not exist for cheap water.}}
|since={{l4d2}}}}
|since={{l4d2}}}}


Line 72: Line 72:
{{MatParam|$reflectamount|float|Amount of warp for the reflection. Higher values produce more visible reflections.}}
{{MatParam|$reflectamount|float|Amount of warp for the reflection. Higher values produce more visible reflections.}}
{{MatParam|$reflecttint|RGB matrix|Color tint for both expensive and cheap reflections.<br>
{{MatParam|$reflecttint|RGB matrix|Color tint for both expensive and cheap reflections.<br>
{{ModernWarning|
{{warning|
This parameter is in Gamma space on expensive water, meaning it will be converted to linear before being sent to the shader.<br>
This parameter is in Gamma space on expensive water, meaning it will be converted to linear before being sent to the shader.<br>
To calculate the eventual linear value that the shader is supplied with, apply the formula <code>x^(1/2.2)</code>}}}}
To calculate the eventual linear value that the shader is supplied with, apply the formula <code>x^(1/2.2)</code>}}}}
Line 104: Line 104:
{{MatParam|$refracttint|RGB matrix|Color of the refraction.<br>
{{MatParam|$refracttint|RGB matrix|Color of the refraction.<br>
{{warning|It is recommended that you set this to white or something close to white so that edge transitions work properly on DX9.}}
{{warning|It is recommended that you set this to white or something close to white so that edge transitions work properly on DX9.}}
{{ModernWarning| This parameter is in Gamma space, meaning it will be converted to linear before being sent to the shader.<br>
{{warning| This parameter is in Gamma space, meaning it will be converted to linear before being sent to the shader.<br>
To calculate the eventual linear value that the shader is supplied with, apply the formula <code>x^(1/2.2)</code>}}}}
To calculate the eventual linear value that the shader is supplied with, apply the formula <code>x^(1/2.2)</code>}}}}
{{MatParam|$blurrefract|bool|Blurs the refraction when underwater.
{{MatParam|$blurrefract|bool|Blurs the refraction when underwater.
Line 121: Line 121:
{{MatParam|$flowmap|texture|Texture that defines flow velocity by skewing and scrolling the <code>$normalmap</code>. Valve generates their flowmaps with [https://www.sidefx.com/products/houdini/ Houdini].
{{MatParam|$flowmap|texture|Texture that defines flow velocity by skewing and scrolling the <code>$normalmap</code>. Valve generates their flowmaps with [https://www.sidefx.com/products/houdini/ Houdini].
: [http://www.youtube.com/watch?v{{=}}iY6vkpQDcpU Video of the effect.] For technical details, see [https://steamcdn-a.akamaihd.net/apps/valve/2010/siggraph2010_vlachos_waterflow.pdf Alex Vlachos' SIGGRAPH 2010 paper] and [https://steamcdn-a.akamaihd.net/apps/valve/2011/gdc_2011_grimes_nonstandard_textures.pdf Valve's GDC 2011 paper].<br>
: [http://www.youtube.com/watch?v{{=}}iY6vkpQDcpU Video of the effect.] For technical details, see [https://steamcdn-a.akamaihd.net/apps/valve/2010/siggraph2010_vlachos_waterflow.pdf Alex Vlachos' SIGGRAPH 2010 paper] and [https://steamcdn-a.akamaihd.net/apps/valve/2011/gdc_2011_grimes_nonstandard_textures.pdf Valve's GDC 2011 paper].<br>
{{ModernWarning|Using this parameter with $BaseTexture will make the $BaseTexture not be affected by lighting.}}|since={{l4d2}}}}
{{warning|Using this parameter with $BaseTexture will make the $BaseTexture not be affected by lighting.}}|since={{l4d2}}}}
{{MatParam|$flow_normaluvscale|float|The number of world units covered by the normal map before it repeats. Typically in the 100s.|since={{l4d2}}}}
{{MatParam|$flow_normaluvscale|float|The number of world units covered by the normal map before it repeats. Typically in the 100s.|since={{l4d2}}}}
{{MatParam|$flow_worlduvscale|float|The number of times the flow map fits into the material. Face texture scale affects this.|since={{l4d2}}}}
{{MatParam|$flow_worlduvscale|float|The number of times the flow map fits into the material. Face texture scale affects this.|since={{l4d2}}}}

Revision as of 00:44, 4 January 2024

English (en)Français (fr)中文 (zh)Translate (Translate)
Water reflecting entities in real-time in Episode Two.

Water is a Pixel shader available in all Source Source games. It creates water that realistically reflects and refracts the world, and that can flow throughout a map.

Tip.pngTip:Water does not need to use the Water shader! If a less realistic effect is desired, or the water volume is oddly shaped, other shaders can be used, such as LightmappedGeneric or Refract. The method for creating the materials is the same.

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_cubemap entities throughout a map.
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 for proper effect need to correlate in most areas.
Flow Mapping
Water can flow in arbitrary directions. It's very tricky to create a flow map by hand however, and the tool Valve used internally hasn't been released.

Shader parameters

Textures

$basetexture

$abovewater $bottommaterial $underwateroverlay $bumpmap $normalmap $dudvframe $bumpframe $bumptransform $scale $flashlighttint $waterdepth $depth_feather

Fog

$fogenable $fogcolor

$fogstart $fogend $lightmapwaterfog

Reflection

$reflecttexture $reflectamount $reflecttint $envmap $envmapframe $forceenvmap $forcecheap $forceexpensive $cheapwaterstartdistance $cheapwaterenddistance $reflectentities $reflectonlymarkedentities $reflectskyboxonly $reflect2dskybox $reflect3dskybox $reflectblendfactor $nofresnel $forcefresnel $basereflectance $maxreflectance

Refraction

$refract $refracttexture $refractamount $refracttint $blurrefract $pseudotranslucent $waterblendfactor

Size/angle of $scroll1 and $scroll2

Flowing water

$scroll1 "[<normal X> <normal Y>]" (in all games since Source 2006)
$scroll2 "[<normal X> <normal Y>]" (in all games since Source 2006)
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.)

Flow maps

A flow map texture.
The flow map texture in-engine, shown with $flow_debug 1.
The result in-engine.

$flowmap $flow_normaluvscale $flow_worlduvscale $flow_uvscrolldistance $flow_timeintervalinseconds $flow_timescale $flow_bumpstrength $flow_noise_texture $flow_noise_scale $flow_debug

Basetexture Flow

$basetexture $color_flow_uvscale $color_flow_timescale $color_flow_timeintervalinseconds $color_flow_uvscrolldistance $color_flow_lerpexp $color_flow_displacebynormalstrength

Authoring a flow map

Directions of water flow depend on the red and green channels of the flow map.

Overall, trying to create a flow map manually is a nightmare. Painting the flow map, fitting it into the world, and painting foam, is extremely difficult.

But if you do want to give it a try, flow direction is read from the red and green channels of the flow map. 50% tone means no movement.

The texture scale of any faces using a water texture with a flow map appear to have a direct correlation on the flow map. The fewer water faces or planes you use the easier the process of authoring a custom flow map will be (selecting all of your water faces and using 'treat as one' when using the fit scaling may also be an option)

Red channel
X axis
Green channel
Y axis
Alpha channel
Controls $basetexture blending from Portal 2 onwards.
There are now tools to assist in painting flowmaps.
Flow field editor from algoholic.eu : http://algoholic.eu/another-flow-field-editor-update/ [dead link]
Flowmap generator (paid): http://www.superpositiongames.com/products/flowmap-generator
Creating flowmaps using Houdini (UDK) : https://www.dropbox.com/s/ii2x077vj64lyhl/Water%20Flow%20For%20UDK.pdf [dead link]

Other

%compilewater $surfaceprop %tooltexture

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