Legacy Documentation: Version 2018.1 (Go to current version)
How do I fix the rotation of an imported model?
Art Asset best practice guide
Other Versions

Water in Unity

Unity includes several water Prefabs (including the necessary Shaders, scripts and art Assets) within the Standard Assets packages. Separate daylight and nighttime water Prefabs are provided.

Note that the water reflections described in this document do not work in VR.

Reflective daylight water
Reflective daylight water
Reflective/Refractive daylight water
Reflective/Refractive daylight water

Setting up water

Place one of the existing water Prefabs into your Scene. Make sure you have the Standard Assets installed:

  • Simple Daylight Simple Water and Nighttime Simple Water in Standard Assets > Water.
  • Fancier water - Daylight Water and Nighttime Water in Pro Standard Assets > Water (this needs some Assets from Standard Assets > Water as well). Water mode (Simple, Reflective, Refractive) can be set in the Inspector.

The Prefab uses an oval-shaped Mesh for the water. If you need to use a different Mesh, change it in the Mesh Filter of the water GameObject:

Creating water from scratch (Advanced)

Simple water requires attaching a script to a plane-like mesh and using the water shader:

  1. Have mesh for the water. This should be a flat mesh, oriented horizontally. UV coordinates are not required. The water GameObject should use the Water Layer, which you can set in the Inspector.
  2. Attach the WaterSimple script (from Standard Assets/Water/Sources) to the GameObject.
  3. Use the FX/Water (simple) Shader in the Material, or tweak one of the provided water Materials (Daylight Simple Water or Nighttime Simple Water).

Reflective/refractive water requires similar steps to set up from scratch:

  1. Create a Mesh for the water. This should be a flat Mesh, oriented horizontally. UV coordinates are not required. The water GameObject should use the water Layer, which you can set in the Inspector.
  2. Attach the Water script (from Pro Standard Assets/Water/Sources) to the GameObject (Water rendering mode can be set in the Inspector: Simple, Reflective or Refractive.)
  3. Use the FX/Water Shader in the Material, or tweak one of the provided water Materials (Daylight Water or Nighttime Water).

Properties in water Materials

These properties are used in the Reflective and Refractive water Shaders. Most of them are used in the Simple water Shader as well.

Property: Function:
Wave scale Scaling of waves normal map. The smaller the value, the larger water waves.
Reflection/refraction distort How much reflection/refraction is distorted by the waves normal map.
Refraction color Additional tint for refraction.
Environment reflection/refraction Render textures for real-time reflection and refraction.
Normalmap Defines the shape of the waves. The final waves are produced by combining these two normal maps, each scrolling at different direction, scale and speed. The second normal map is half as large as the first one.
Wave speed Scrolling speed for first normal map (1st and 2nd numbers) and the second normal map (3rd and 4th numbers).
Fresnel A texture with alpha channel controlling the Fresnel effect - how much reflection vs. refraction is visible, based on viewing angle.

The rest of the properties are not used by the Reflective and Refractive Shaders, but need to be set up in case the user’s video card does not support it and must fallback to the simpler shader:

Property: Function:
Reflective color/cube and fresnel A texture that defines water color (RGB) and Fresnel effect (A) based on viewing angle.
Horizon color The color of the water at horizon. `this is only used in the Simple water Shader.
Fallback texture Define the fallback Texture used to represent the water on really old video cards, if none of the better looking Shaders can run.
对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答