Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Water has always been a tough one to tackle in computer generated art. It's not only a surface, but a volume. And because it's clear, yet seems to be so many colors, it's difficult to make the surface really look right, especially in the limited resources in a game. In Unity then, we've got two available waters to use. Basic water, that comes with Unity Free, and pro water, which comes with Unity Pro. If you're using Unity Free, import in the basic water. For pro users, make sure you import the water pro into the scene.
I'll right-click in the Assets folder, and choose Import package, and Water pro. It comes with quite a lot of things. A couple of prefabs, water scripts for different lighting, source materials, gradients and so on, and finally some custom shaders. I'll import the lot, and see what I get once those come in. The water imported in. And I got a shader warning down below, about a hidden screen space occlusion, GLSL vertex shader. There's something going on in there, it doesn't like in the syntax. But for now, I'll ignore it, as it's just a warning, not a show stopping error.
In my Standard Assets, I have a Water Pro-only folder. And in there, I've got prefabs for daylight and night time water. In there as well in Water Four, I've got examples of simple and advanced water, and sources for each of them. In the Sources then, we've got materials, objects, script shaders, and textures. What happens in a lot of water, is we'll start out with a fairly simple image, such as foam. Then we'll take it, and start to add in things into those materials. We'll use foam, for example, and distort it with gradients or procedural textures.
We'll then use other shaders that are custom defined to determine, reflection and so on. And build up this shader to get the richness of water. I'm going to replace that blue plane I've been using as a stand-in. But first, I'll turn off the terrain, and turn off my building in the inspector. With those off, I can see a little more clearly what I'm doing. I'll take the water I've got now, this plane, and copy the Y height by pressing Ctrl+C after I select that field. Now, drag in the daylight water. Dragging from the Standard Assets, into the scene. It starts out as a disk, and what I'll do in here is delete that plane and then size out this water.
I'll select my original plane, press delete, pick this new water, and paste in that Y height. It's a match and now I haven't disturbed the water level in my scene. What we've got going, when you look around at this, is what looks like a real-time reflection. It's coupled with a surface distortion, as well as some shine, and other factors going on. Here's what's happening in that shader. There's a scale of waves, and an amount of distortion in the reflection. It's governed by a Fresnel ramp, which shows it as more reflective as we're tangent to it.
Finally, there's a wave speed which is procedural, and a reflective color, in the Fresnel ramp, as an image. There is also a reflective cube, a horizon, as well as internal reflections and refractions. And these are actually the real time components. What's going on in here, if we click select, is that it's a water reflection of a render texture, which is a special image we can put on a camera, to render what the water is seeing. That's a Pro only feature, and that's what really what defines the Pro from the basic. Render to a texture what a camera is seeing, is unique to Pro.
And it's very useful for things like real time reflection but at the cost of extra draw calls in the performance hit. That's why we tend to limit down our reflections to cube maps wherever we can, and only use a reflection like this where, it's really necessary. Now what I'll do, is to scroll up in the water. And way up at the top is a scale. I'll bring out the scale, in the X and Z for this water circle, until it laps, into the lake shore. I'll try, 50 by 50, and turn back on the terrain to see what it looks like.
Well, so far, I've made a puddle. So I definitely need to bring out that water further. I'll try a scale of 200, by 200. And now, I'm getting my lake back. That may be too much, and I can go underneath and take a look, or turn on wire frame and see through the terrain. 200 by 200 is good, although maybe a little bit big. I'll make sure I pull this back as much as possible, so it's not reflecting the underside. I'll try 150 by 150.
And back here in a texture, just make sure it's catching the edge of the lake. We can continue to scale this down. 120 just seems to work. And this way I'm limiting down how much real time reflection I'm doing. I'll slide it over, just to make sure it catches all the edges, and I've got a lake in. Its got a good real time reflection of my clouds, and hopefully my buildings. Now in the water, I can custom tune the colour on it. In each of these it's got either, a cube map further a colour, or there is a gradient image we can adjust.
When we pick this ocean gradient for example, selecting the texture it's actually a very slim gradient. Selecting it then, or adjusting and changing, will change the overall color of that part of the water. I'll turn back on my building, and see how it looks. Turning on the building in the inspector, and pressing play. It takes a minute, but as we get outside, we can really see the surface of that water there. It's reflecting the sky, and has a lot of motion to it. Before I adjust the color, because the color is strongly biased by whatever is reflecting, I'm going to adjust the wave speed.
The lake is neat, but it's really got some flow to it, and I'd like it to be a little more tranquil. I'll select the water, and in that water, scrolling down. We have control over the wave speed. I'm going to pull these down here on all the factors, and see what they do. I'll try an X of six, a Y of two point five, a Z of negative five, and a W of negative one. Hopefully this will pull it down more. What I'll also do in here, is turn off my refraction. This water doesn't need to show the lake bed underneath. I don't really want to see through, and see the brown.
So in the refract layers, just like with lights, I'll drop down and choose nothing, and save on some computing power. Because its not refracting, essentially acting just as a reflective surface, in the game, I can see the water is definitely a bright blue. Even tinted though the windows. I'll definitely need to go take down that diffuse color. Pulling it back from that really screaming blue into almost a blue black. However, the slower speed is working much better. It's got a rippling in the reflection. And really gets the idea of a, very still lake with a little water ripple from the wind.
I like how it's looking, so once I go in and pull down the color in that gradient, and bring it back in, I should really have much dimmer water. I'm okay with not seeing through. I don't really need to show how shallow the lake is. But more that it's just opaque, as this complex is, perched on the water. We can keep adjusting things like speed, pulling it all the way down, and even keying those parameters to simulate wind kicking up or a sudden flow or gust. It's up to you how you'd like to use it. If you can get by with a simple water, do so.
Even if you're using the pro version, and a simple water looks good without doing a real time reflection, and gets you the idea of the water you want cheaper, use it. In an application like this though, where I want the serenity of these buildings perched on the lake, the Pro Water is the way to go, and the real-time reflection from the render to texture, really helps sell it.
Get unlimited access to all courses for just $25/month.Become a member
107 Video lessons · 34069 Viewers
94 Video lessons · 23786 Viewers
100 Video lessons · 4261 Viewers
83 Video lessons · 9302 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.