Adding Water

From Valve Developer Community
Revision as of 18:05, 26 April 2021 by GamerDude27 (talk | contribs) (Added "-")
Jump to: navigation, search
Русский 简体中文

Water is a very complex shader inside of the Source engine: it is animated, reflective, fogged, refractive, and bump mapped, and can also flow, depending on the engine branch. 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.

Note.png Note: Expensive water will only render correctly if the requirements are met.

"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.


To make it perform efficiently, water also has a collection of rules regarding its placement and usage inside of a map.

  • There may be only one water level height in a PVS if the water is expensive.
  • "Expensive" and "cheap" water may not be used simultaneously in the same PVS.
Note.png Note: Because the 3D Skybox is not considered part of the PVS, expensive water in the PVS does not prevent you from using cheap water in the skybox. Combining expensive and cheap waters in the skybox also seems feasible, though experimentation is needed.
Note.png Note: Because the 3D Skybox is not considered part of the PVS, seeing expensive water in the skybox without having expensive water in the PVS will cause reflections in the water to not appear accurately.
  • The water's surface should never slope in the Z-axis; it should always be parallel to the horizon line in a map.
  • Water is created by applying a water material to the top-most surface of a brush, while covering the remaining faces with the tools\toolsnodraw material.
  • The water_lod_control entity controls the distance at which expensive water transitions into cheap water.
  • An env_cubemap entity must be present for the water surface to render properly on sub-DX9 hardware.
  • Areaportals and Visclusters may never cross the water surface.
  • Water does not seal the map.

Water does not work with brush entities, and should not be attached to an entity. Water brushes included in any brush entity will not render correctly. The only exceptions are func_water_analog and func_water.

Note.png Note: Expensive water does not reflect the 3D Skybox, even if it is in the 3D skybox. Expensive water in the skybox will reflect the world. (However, reflections will not appear correctly if there is no expensive water in the PVS.)


To add a water volume to your level, follow these steps:

  1. Create a brush the size of the water volume using the Block Tool.
  2. Open the Texture Browser by clicking the Browse button on the Texture Bar.
  3. Double-click the tools\toolsnodraw material in the Texture Browser.
  4. With your water brush selected, click the Apply Current Texture button to assign the tool textures|tools\toolsnodraw material to the whole brush.
  5. Select the Texture Application tool, which opens the Face Edit mode.
  6. Left-Click the top face of the water brush in the 3D view to select it.
  7. Click Browse to bring up the Texture Browser again.
  8. Type water into the filter field. This will show you all materials with the keyword water in their name.
  9. Select a water material to apply by double-clicking it. One water material to try is nature/water_canals_water2.
  10. Click the Apply button on the Face Edit panel.
  11. The brush should have water correctly applied. Compile and run your map (with VVIS and VRAD enabled) to test it.

In order for water surfaces to render correctly, it is necessary for your map to have a skybox, and for the water brush itself to be rectangular. The brush can intersect other brushes, in order to hide unwanted areas. If the water hasn't been rendered correctly (you can't see it), it means you have a leak somewhere.

Game-specific caveats

  • Left 4 Dead 2 L4D2 maps also require an env_fog_controller.
  • Alien Swarm All water brushes in Alien Swarm must be attached to a func_brush called "structure_seal".
  • Portal To create the poison water in Portal, you must use the texture nature/hazard_liquid.

Cubemaps and water

Cubemaps are important to use with water surfaces. On lower than DX9 level video cards, it is not possible to render the real-time reflective water shader. For these cards, an env_cubemap entity provides the pre-calculated environment map use to render water on sub-DX9 cards.

Adding a env_cubemap to water surfaces:

  1. Add an env_cubemap entity using the Entity Tool.
  2. Place the env_cubemap above the top surface of the water, near the center.
  3. Double-click the env_cubemap in the 3D view to bring up the Object Properties dialog.
  4. Click on the Brush faces key in the Object Properties.
  5. Click the Pick... button. The mouse cursor will change to the eye dropper icon.
  6. Click the top water face to select it with the eyedropper. The face will highlight in red, to show it has been associated with the env_cubemap entity.
  7. Close the Object properties dialog.
  8. Compile and run your map. After the map is loaded, open the developers console and type buildcubemaps. The engine will calculate an environment map for each env_cubemap entity, and save the data into the BSP file.

See Also

External links