David McMahon
12-08-2008, 02:27 PM
Dabu asked me to make this tutorial on making an ocean animate in Maya's viewport. Why make your own ocean when Maya can do it for you? Maya's prefabricated oceans are very cool, but they can't run in the viewport, and have to be rendered out. So this tutorial shows you how to make an ocean that will run realtime in Maya's viewport. Here is a screenshot of mine:http://www.gamestepper.com/forums/attachment.php?attachmentid=14446&d=1228774504
First, make a picture of your ocean from above. You could paint yours, but I went to Maya's Window/General Editors/Visor, which Galena showed me the other day:http://www.gamestepper.com/forums/attachment.php?attachmentid=14447&d=1228774602
Click on the Ocean Examples tab at the top of the visor, and middle-mouse-click and drag it into an empty file:http://www.gamestepper.com/forums/attachment.php?attachmentid=14448&d=1228774774There are many pre-made examples, or you can fiddle with the attributes and make your own custom one. I chose the whitecaps, because I was going for a fresh and windy blown-out look. Go to the TOP view, and take a screen shot, and then make a tiling texture out of it. Mine looks like this:http://www.gamestepper.com/forums/attachment.php?attachmentid=14449&d=1228774956Get another picture of water for the wind waves, making sure to pick one with high contrast. You want high contrast, because you are eventually use this second picture as a multiply layer. My high-contrast water shot looks like this:http://www.gamestepper.com/forums/attachment.php?attachmentid=14451&d=1228775163
David McMahon
12-08-2008, 03:17 PM
It is the animation AND interaction of these two water images that is going to give a nice wavey motion effect. You achieve this by making a layered texture. DON"T be scared if you have never made a layered texture before. The following several pictures will step you through it, and you'll be well on your way in a few minutes. First make a Lambert for each of the two images that will eventually go into the layered texture, just like any other Lambert:[attachment=4:3v1fosf6]Tutorial_5.jpg[/attachment:3v1fosf6]Right click/hold/Graph the Network on your new Lambert, then double click on the place2dTexture node, which should turn yellow:[attachment=3:3v1fosf6]Tutorial_5a.jpg[/attachment:3v1fosf6]Adjust the repeat uv attributes. I used 5 and 5 for the x and y repeats for mine, but this is something you will come back to later and re-adjust for the images, your ocean planes and your scene later on. You will probably want different values for each of your images. This repeat uv attribute tiles your tiling texture for you. You will see the preview in the pink texture node change your texture to indicate that the tiling is happening. If you noticed the pink boxes in the attribute panel in my screenshot, ignore them for now. Later on we are going to come back to these and animate them. Once you set keys on that attribute, they turn pink too.
Next we build the Layered Texture, which is going to do most of the work for us. Go to the Create Maya Nodes in the Hypershade window, and scroll down to Other Textures. Click it, or middle-mouse-click and drag it into your window. Graph the network again. It should look something like this, a little plain green box, because there is no nework yet:[attachment=2:3v1fosf6]Tutorial_6.jpg[/attachment:3v1fosf6]This part is a little tricky, but as long as you don't go clicking a bunch of buttons and follow the instructions carefully, it should work. Go to the Texture tab in your hypershade window:[attachment=1:3v1fosf6]Tutorial_7.jpg[/attachment:3v1fosf6]This isn't the Material tab where you get green Materials boxes, but the Texture tab, and you should end up with pink texture nodes. Middle-mouse the texture nodes (that Maya created for your two new Lamberts) over to the Layered Texture Attributes panel, and drop it right next to the green box with white around it. The green box is the temporary node. Once you have middle-mouse at least one of the texture nodes over, you can delete the temporary node by clicking the little white X in the tiny box just beneath it. This is where you have to be careful, because if you click in the panel instead, you are creating a new node, which you don't want. If this happens, click the little white box under the new nodes to delete them. When you are done middle mousing the texture nodes over and deleting the temporary node, it should look like this:[attachment=0:3v1fosf6]Tutorial_8.jpg[/attachment:3v1fosf6]
David McMahon
12-08-2008, 04:12 PM
You want your multiply layer on the left, so if it isn't already there, middle-mouse it to the left. Set the Blend mode for your multiply layer to Multiply. Click on the blue wave texture node, and make sure that its Blend Mode is set to Over. Go right-mouse-Graph the Network of your Layered Texture in the Hypershade window. Now the network should look almost like this:
http://gamestepper.com/forums/attachment.php?attachmentid=14457&d=1228778484
Notice that the green Materials box is missing? You have to middle mouse drag a Lambert into the window and connect the texture node. You do this by middle-mouse dragging the texture node over the new Lambert. A box will open up to ask you how you want them connected. Choose Default. Select your new Lambert and right-mouse Graph the Network, and it should look something like the one above, where you have the pink Layered Texture node feeding into the green Materials Lambert node, and your two wave textures feeding into the Layered Texture. Now sit back in your chair and say Ah...because you are done with the hardest part.
After you have stretched and congratulated yourself, maybe had a drink of water too, go back and animate the textures. You do this by double clicking the Place2dTexture node for one of the two water textures, which should turn yellow again. Put some values in the Translate Frame x and y boxes, and key them by right mouse clicking over the words Translate Frame, and select Set Key. The little Translate Frame boxes will turn pink so you know they have animation recorded on the timeline. Go to your time line to a new key frame, and put some new numbers in the Translate Frame boxes, and Set Key them too. Do this again for the other wave texture place2dTexture node, but CHOOSE DIFFERENT VALUES in the Translate Frame boxes. Right mouse/Graph the Network again, and it should look something like this:
http://gamestepper.com/forums/attachment.php?attachmentid=14458&stc=1&d=1234946700
Next apply this texture to a plane in your scene. Test how well you guessed on your Translate Frame values by playing your animation. Both of your textures should move, but because you set the Translate Frame values for each of them differently, they SHOULD NOT move together. If so adjust the values for one of them, and/or the Repeat UV attributes until you get something that looks good to you. What you want is the multiply layer forming moving shadows across the top of the whitecaps layer, and both moving sorta together in the direction of the waves and wind happening in your scene. They should do this at a leisurely pace, about the pace of real waves.
Do your waves move together instead of criss-crossing each other? Then there is one other important step you might need to do: make a second set of uvs for your ocean plane. Having a second set of uvs allows you to move your wave image on one path, and your multiply image on a separate path, which produces the nice wave interactions you are looking for.
Warning: you are at the precipice of uv hell. I think I crossed this threshold by accident in my Maya I class, and despite warnings by many others, like, "I never use anything but the default uvs, Map 1; just use CUBO" I kept going. Mostly because I didn't know how to get out of it.
So before you go too far, learn how to backtrack back to the precipice, where there is a nice view. Here is the threshold: instead of using the CUBO or other automatic mapping perspective, you check the dreaded option box:
http://gamestepper.com/forums/attachment.php?attachmentid=14480&d=1228842619
See that little checked box, Create New UV Set? At one point in time I checked that box, and named my first uv set, and entered uv hell. I probably named my uv sets because someone told me it was a good habit to name everything you make in Maya so you would be able to identify it later. What they didn't tell me was that you didn't need to name anything you didn't make. While naming things in Maya is a good habit, most people never find a need to check that box, and always use Map 1, the default map. Which is okay, but those fearful ones are stuck with only one uv set per object.
But you think you want two uv sets for one object. And you think that you are brave. So if you are going to cross this threshold, the first new thing to learn is to uncheck that box, probably right away. Why? Because if you leave it checked, the next time you make uvs, say by going to Create UVs Based on Camera but without opening the option box, and making uvs say for an entirely different object, Maya will create yet another uv set with the same name. And worse yet, Maya thinks it is smart, and will save the name you put in that box, even if you open up an entirely different scene. ACH. UV HELL. Actually Maya is too smart to let you use the exact same name. Say you called your new uv set "Daves_uv_hell_threshold," the next time you created uvs it would be called "Daves_uv_hell_threshold1." Now imagine you take more than one shot of your uvs to create a nice efficient uv map. Most of us take many, many shots, especially on a complicated object. You could easily end up with many, many uv sets, all of which have the wrong name.
Some of you might have already done this. So if you have, the next thing to learn to make it back to the uv hell threshold is how to get rid of uv sets you don't want. This is a menu trick that Jeremy Parish showed me one day, and it was a halleluja moment for me, and he was pretty excited about it too, because he had discovered it while exploring. Kind of like finding a pot of gold at the end of the rainbow. I was so excited because by the time he found it, I was deep into uv hell. Here is the trick: With your cursed object highlighted in object mode and your cursor in your scene window, right-mouse-click-and-hold, and pull the cursor down to UV Set/UV Set Editor. Now here is a point that begs for a screenshot, but when you try to do it, the only thing that comes up is the box that appears after you click. So I would like you to appreciate that in order to get the following image, I had to actually take a photograph of my screen. And, since I was right-mouse-and-holding and taking a picture at the same time, it was an excercise in coordination. And this operation required new batteries for my camera:
http://gamestepper.com/forums/attachment.php?attachmentid=14481&d=1228844308
See all those uv sets that you named? When you click the UV Set Editor, a golden pot box shows up. Now you can control select (or more likely shift select) the ones you don't want and delete them. So now you know how to get out of uv hell, and you can make two (and only two) uv sets with different names. Once you have made two uv sets for your ocean plane, you can go back to the Place2dTexture nodes, and put different numbers in the two nodes, and get your waves interacting.
But wait, you may need to dive into the relationship editor to straighten out which map goes to which uv set. You get there by going to Window/Relationship Editors/UV Linking/Texture Centric or UV Centric. This will allow you to control which map goes to which uv set. Sometimes Texture Centric won't work because you have confused Maya, and if so, try the UV Centric. And vice versa.
If you have made it this far, I am guessing that you have a nice simple ocean scene, with two wave images interacting nicely. Or will soon.
If your scene has islands, shores boats, currents, etc., you will need other layers of ocean waves. Here are a couple of screen shots of some of the things I have added to mine to get more waves interacting and a more realistic effect:
http://gamestepper.com/forums/attachment.php?attachmentid=14463&stc=1&d=1234946700
Getting some ideas now? Here are some of mine:
1. Add refelected waves from shorelines and objects. Put alpha on wave images so that you have waves breaking over other ocean textures.
2. Add a wave shadow or highlight by making a white-striped shader placed over the layered texture.
3. Add a round soft-brush dot texture to another plane, and color the vertices with dark green. Animate the dot. The outside vertices of the plane should be pure alpha, so the green dot fades in and out. This mimics the light and dark green colors that happen on oceans that tend to show up on the crests or tops of waves, where you are looking down into the water.
4. Add a lattice deformer and animate it to make your geo deform like waves. Key the wave and lattice speeds to match, so the shadow follows your geometry.
5. Add spray.
I could go on and on here, but you have some ideas of your own, so Dive in. When your ocean is done, put the sunlamp on, plug in some cool tunes, and bask on the shores of your new ocean, all playing live in your Maya window.
Record it as a background screensaver, so you can vacation anytime you want.
Have fun,
Dave
David McMahon
12-08-2008, 04:19 PM
If you liked this ocean tutorial, you can contact Dave McMahon at DMcMahon@Pacbell.net, or by calling (510)527-6677.
Sixcolors
03-31-2010, 12:44 PM
I found this when searching for something completely unrelated. This was such a cool project! I remember everyone being amazed when they saw the water moving in the viewport. :D