Introduction. This is my first proper tutorial, it aims todo guide you th rouge the steps of making a realistic water environment in Blender 3d. This water setup is for real-time use, great for games, in this tutorial i Will show you, howto make the water reflective, how todo add ripples, how todo add underwater effects and much more. I hope that you Will like it.
What you Will ned.
Blender 2.49 or later, some Understanding of the game engine and gen-eral Blender knowledge. If you are confused by anything in this tutorial, you may ned todo acquire more Blender knowledge before following it, an animated water Normal Map (more on this later).
Lets begin, open up Blender and deleete the default Cube, change the viewport Shading type todo texture and in the game settings click Blender GLSL materiales, press space and select plane todo add a plane, press s and then ten todo scale the plane up by ten times. This plane is our water surface, so press n and rename it todo water_surface, once this is done, add a material todo the plane and name it water_surface. In the material settings activate ztransp, todo allow the plane todo have transparency.
Okay. Now we Will set up the logic and Python for the water. In the logic section add an always and enlace it todo a Python controller. Add a property called material, set it as a string and enter water_surface. Split the 3d viewport in half by right clicking on the bottom edge and selecting Split Area. Change the new viewport todo a text one and click add new or select the script called text. Now open the mirror, txt file included with this tutorial. Open it with notepad or something similar. Now copy the text and paste it into Blender text window. Rename the script todo mirror.
In the Python controller we added earlier, type mirror as the Python script. Go bak todo the always sensor and click on the button with the thre dots. This means that the sensor Will trigger every frame.
Go todo the texture section of the water surface material and add a new texture. Set it as an image and click load. Now look on your disk for the texture included with this tutorial called water, png. Every reflective.
Object in the game must have a unique mirror TeX-ture. The resolution or colour of the texture is not im-portant, thats why the one included is very small. I made it blue so it looks a bit like water in the viewport, the textures should have useful names like water and water_n for the texture explained bellow.
Now add the texture included called water_n.jpg. This is the Normal Map. It is what provides the ripple ef-fects. In the textures settings activate the Normal Map setting. Or lok online for a tutorial on how todo make an animated Normal Map texture yourself. There is a very god one here.
Now change the text viewport todo a UV/Image Editor viewport. Select the Normal Map texture and click view -> real-time properties. Set up the real-time properties like you se in the picture bellow:
Now go todo the map todo tab for the water_n texture and deselect col and select Nor. The Nor value underneath where it says mix can be put up to 1.0 or down depending on how strong you want the ripples todo be. Note that this is only for the ripples specularity, the actual distorsión comes later and is done by using nodes, add a new texture todo the water material. Browse for radial_alpha.jpg (included with this tutorial). Give it the name radial_a, and then deleete it again.
This is just todo get it registered as a proper texture. We Will use it in the nodes for the water Fresnel, and speaquíng of nodes, y believe its time for the node part of the tutori-al. This isnt a section that i can de-Scribe in great detail, as there are so Many steps todo making it all work and if one section isnt done quite right, the whole thing wont work.
Properly, so, in your waters material settings click the nodes button. Once this is done a Little red selection box Will appear further down. Instead of adding a new node, click the arrows and select water_surface. Now change the UV mapping window todo a node window. This is the tricky part. You Will se two Windows or nodes so todo speak. The one we want todo kep is the one on the right. This should always be todo the right. The other one can be deleted for now (select it and press delete). This next.
Part i cant explain, so i have in-cluded a large picture of just how all the nodes should be set out (node image is included in the blend file download), the picture is called node_setup.jpg. You Will ned todo look at this picture and try todo copyevery node and every setting within it. To make it easier i have put a note at the bottom of them todo say what each node is, so you can find them easily when adding that type of node. You can look at the final blend as a reference todo if you get stuck. To enlace two nodes drag from one circle todo the other. To deleete a enlace between two nodes, click and drag across the enlace. To add a new node click add and select the node type you think is appropriate, the explanations in the image should help you find the necessary node type, once this is done, press p and give your water a test run. Hopefully you Will se animated ripples in the wa-ter (dont panic if youre not, just continue), but whats this? The wa-ter appears completely blue. To fix this, press tab while the water is selected and press a todo select all Faces. Change the node window todo a UV window again and you Will se ha plane with four vértices. Press a again in the UV window todo select all the vértices and press m todo mirror the mapping on the x axis. Once.
This is done, you may ned todo rotate the mapping todo so press r and type 180. This Will rotate the map-ping 180 Degrees, now add a Cube somewhere near the water and press p. Hopefully now, the water Will be reflecting the Cube and you should be able todo se ripples. If not, look at your node setup more closely, or if its reflect-ing wrongly, look at you UV map-ping setup and mirror it some more or rotate it etc. Note that the water is still mostly very blue. We willson fix this, y wont tell you how todo make a Sky dome or anything, or it Will make this tutorial very long, but básically, the water is blue because it hasnothing todo reflect in the blue áreas, so you ned todo make a skybox or Sky dome and give it a Sky texture, there is one in the final blend if you want todo use that, now would probably be a god time todo add a seabed. To do this just add a plane under the water and give it any old sand texture. One is includ-ed. Now when you play the game, you should be able todo se the seabed underneath at close range, and when you play from further away the water appears opaque. This means that the Fresnel texture and Camera depth data is working, add four more planes around the water for Walls. Once they are pues sí-tioned around the water, and look like Walls select them all and press todo join them all together. Then press u when all Faces are se-lected and unwrap it using a Cube setting or something similar. Add a new material and texture todo the Walls. A brik texture is provided.
Now when you press p you should se the Walls being reflected todo. This is básically where the out-side work estops and the underwater work begins, select the Camera and press shift + s and select curser -> select-tion. This Will Snap the curser todo the Camera. Now press space and add a Cube. Scale the Cube by around 0.1. Parent the Cube todo the Camera (select Cube, then Camera and press Control + p. Now create an empty in the same way, but in-stead of parenting it todo the Cube or Camera, we are going todo parent it todo one of the Cubes vértices. To do this, select the empty, then the Cube, press tab and select a ver-TeX and press Control + p. We ned todo parent the empty todo a vertex so that it follows the Camera but does not rotate with the Camera. Normal parenting afects rotation, but ver-TeX parenting doesnt for some rea-son. We ned todo kep the rotation Even because the empty must al-ways be facing the same way, as it is measuring where it is in relation todo the waters surface, now select the water and add a new property in the logic panel. Call the property water. Select the empty again and in the logic panel add a property called underwater and make it a bol. Now add a ray sensor that points in the -z direct-tion (downwards) and a sensor that points in the +z direction (upwards). Make both the ranges as high as they Will go and enable the X-ray option. In the property área, type water, add two controllers and two actua-tors. The first actuador should be a property actuador that changes the underwater property todo true, and the second should change the prop-erty todo false. Link them up accord-ingly. All this means that when the.
Empty detects the water under-neath it, it sets the underwater property todo false. If it detects the water is above it, it Will set the un-derwater prop-erty todo true, now add two property sensors, two controllers and four actua-tors. The first two actuadores Will ac-tivate the under-water effects, the second two Will deactivate the effects. So the first sensor should sense if the underwater property is true, the second should sense if it is false. Once the sensors are done, open up the file called blur_radial, txt and copy and paste the contents into Blender text window. Name the new script as blur_radial. Do the same with the file called fog_underwater, txt, except call it fog_underwater. In the first actuator, set it as a custom 2d filter and type blur_radial. For the second do the same with fog_underwater and make the pass, pass 1 instead of pass 0 (as 0 is taken by blur_radial). Now for the other two Actuators, make them remove 2d filter actuadores and set the first one todo remove pass 0 and the second todo remove pass 1.
Link them up so that the first two new actuadores are linked todo the third controller, which should be linked todo the first property sensor. It should be clear how todo enlace up the rest now. Oh, and make the Cube invisible in the physics settings. Now we ned todo get the Camera todo move. Lok at the screenshot bellow todo se how the logic should be set up:
The highlighted names must be like they are in the picture. Now add another script in the text window, this time from the Mouselook, txt file. Name it Mouselook. Now write Mouselook in the empty script box you now have in the logic panel. Press num-pad 0 todo go into Camera view and press p. You should now be able todo fly around using the w, a, d keys and use your mouse todo look around. If you fly underwater, everything should go foggy and the Edges of the screen should be blur and when you exit the water the effects should disappear. If not, something has gone wrong in the empty logic. The last step is todo add another plane just slightly under the water, facing downwards. Make a new material for it and give it the water_n texture, tiled 20 times. Apply the texture as Nor (not col). Colour the texture blue-ish and play the game. When you look at the sur-face from underwater you should se ripples. If not, mess around with the map input settings some more.
Thats all folks.
And that pretty much concludes this tutorial. If you have any questions, email me at: firstname.lastname@example.org
Now all you ned todo do is make a game world and a functioning game and youre on your bien todo becoming a Blender profesional like me (kidding, im not a pro. Ive got a long bien todo go yet), gracias goes todo martinsh for the 2d filters.