Tips for water in Unity

October 7, 2011 in Rants & Raves, Technology

This post will show you how to create water with a custom mesh, adjust the settings and gain some artist insight into making water look nice. To keep up to date with the latest tech this post will primarily concentrate on new Pro water stuff, but later on there are some general tips which should be useful to all.

What elements make water?

Hydrogen & Oxygen

in Unity?

There are many different types of water you can create or use from prefabs. To take advantage of the latest water effects and scripts I will be concentrating on the Water4ExampleSimple assets which are essentially a couple of 3D meshes representing your water surface, with:

  • WaterTile script
  • Water shader

An empty object indicating the world space placement with:

  • A Water script which exposes the colours, normal texture and main parameters for the effect
  • A reflection script
  • An optional lighting script for specular effects
  • An optional displacement script

How can I make some water?

The simplest way is to drag the prefab into your scene, and assign your custom mesh:

  • Assets > Import Package > Water (pro only)
  • In the project window open the  Standard Assets > Water (Pro only) folder
  • Open up Water4 folder
  • Drag the Water4Example (Simple) Prefab into your scene
  • Position approximately where you need it
  • Select one of  the tile meshes, go to the mesh component in the inspector > select the round target icon on the right and choose your mesh (must be in your project)
  • Rotate the Water4ExampleSimple parent node 90 degrees, if your mesh comes in at the wrong angle (this can be caused when you export from a 3D app with a different co-ordinate system to Unity)
  • Place your mesh by moving the parent node
  • Remove the second tile mesh

Settings

Once you have your mesh as water you can begin to play with the settings. Select your Water4ExampleSimple node, and check the parameters in the inspector.

Water Base

Planar Reflection

This script is for enabling/disabling realtime planar reflections. Reflections are claculated in relation to the height of the parent mesh that has this script attached to. So the local Y transform of child meshes should be 0. Here you can also enable the reflections to include (or not) the skybox.

Specular Lighting

You can adjust the specular power from here and drag’n'drop any transform to indicate a specular light source. This can be your directional light transform or any other game object (doesn’t need to be a light).

Gerstner Displace

Here you can adjust the settings for the wave generation created by the Gerstner waves generation algorithm.

Water art tips

  • Go and check out some actual water – its always wise to get some visual ref for what you are trying to do. Make a video if you can.
  • Water absorbs red light from the spectrum reflecting back more green and blue rays, in additions to sky, which gives water the impression of being Blue in colour so:
    • You can’t make your surface blue (and you probably shouldn’t)  but if you use green and blue colours on the surfaces below the water such as a pool you can help with the illusion.
    • (I guess this is why Pool designers use green/blue/turquoise tiles).
    • The darker the blue, the deeper water appears – you can use a darker colour on the bottom and tint the refraction darker.

Using blues and greens on the tiles, vs using grey/pink
  • Moderate the effects, subtlety can help suspend disbelief, be sure to experiment but think about moderating:
    • Scrolling speed of normals
    • Reflection
    • Refraction
    • Fresnel and Normal strengths
    • Displacement
  • One useful tip is to turn practically everything off e.g. set sliders to zero and then build up the effects to get the desired impact.
  • If you have a convex mesh (such as water fall/pool lip) add poly detail to the curve to help the water ‘bend’.

Next time > Water 4 Advanced is the same tech but with foam and depth extinction.

Comments (15)

Subscribe to comments
  1. Vishmax

    December 9, 2011 at 7:23 am / 

    One thing is for sure. You did a lot of research on this. It’s either that or you just have the knowledge. This is impressive

  2. Martin

    November 10, 2011 at 3:37 am / 

    Nice tut but I use a GrabPass for reflection and, with the new version of Unity Player (3.4.2f3), it crashes on Mac OS browsers (except Camino) and works perfectly on Windows. Does somebody have the same problem?

  3. rea

    October 18, 2011 at 1:54 am / 

    @Jason : the only one that you always asking for…

  4. .Jason Amstrad.

    October 17, 2011 at 6:42 am / 

    @Alex

    What is DFS ?

  5. hippocoder

    October 16, 2011 at 4:30 pm / 

    can someone remove Jeringas post because it’s just spam for needles and drugs.

  6. Alex

    October 15, 2011 at 12:55 am / 

    Nice tut Olly.

    @ Jason : I can’t wait for DFS just to see what you will b**ch about next :D

  7. Rea

    October 13, 2011 at 7:18 am / 

    Speaking of the devil…..

  8. .Jason Amstrad.

    October 13, 2011 at 7:03 am / 

    This tutorial is not a dynamic fluid surface. It just looks like it.
    If a player walks on it,it will not generate waves automatically like natural water.

  9. Neodrop

    October 13, 2011 at 5:36 am / 

    Dynamic fluid surface ? Well, it’s possible : http://forum.unity3d.com/threads/59121-Visual-Logic-Editor-(Antares-VIZIO)-(video-amp-screens)?p=704126&viewfull=1#post704126

  10. Will

    October 13, 2011 at 5:00 am / 

    Nice work Olly! will promo this!

  11. Sam Hagelund

    October 13, 2011 at 2:54 am / 

    cowgaR – You were asking about dynamic fluid surfaces. A new Unity extension is available on the Unity Asset Store called FlowMachine. You can check it out here: http://inhouse.seriousgames.dk/flowmachine/

  12. JoeW

    October 12, 2011 at 4:43 pm / 

    Before I forget, what would REALLY be helpful is to include tips for optimizing water – it seems that even when it’s barely visible, it can kill performance, and I’d like to know how to make it a less expensive effect – even maybe somehow put some kind of LOD on it so that it’s not always grinding away in the background. Thanks again :)

  13. JoeW

    October 12, 2011 at 4:40 pm / 

    Thanks, Olly – good tips. I’d always wondered how to use my own mesh for the water – the big disc doesn’t always work so well :) I’m looking forward to the next one on Advanced Water, too.

  14. hippocoder

    October 12, 2011 at 4:35 pm / 

    Nice tut.

    Jason Amstrad’s wet dream.

  15. cowgaR

    October 12, 2011 at 2:04 pm / 

    what about dynamic fluid surfaces…. oh, wait a second ;)

Comments are closed.