利用者:N t/SummerOfCode2005/Fluid Animation/Tutorial 2
Fluid Simulation - Tutorial 2 (the Next Step)
This tutorial should give you on overview over the settings commonly used for doing fluid animations with Blender. It assumes you're familiar with the user interface and you at least read through tutorial1. This is how it should look in the end this time: [1].
Important
The Blender GUI changed a bit after these
tutorials were made. So if you are using a newer build please check the tutorial changes page before going on. |
This tutorial will deal with a simple version of the standard free surface animation test case - the glass filling animation. Btw. - don't forget to save your file (best with different names) once in a while...
Part 1: Making a Simple Glass
ファイル:Http://graphics.ethz.ch/~thuereyn/download/blender/tut2p1.png
Step 1) In the following we will model a very simple glass (more of a mug, actually) by using one of the cool new modifiers. We'll start with this standard box you get in the beginning. Start off by saving the file with some reasonable name like "tut2.blend".
http://graphics.ethz.ch/~thuereyn/download/blender/tut2p2.png
Step 2) Switch to front view (1 NumPad), enter edit mode (⇆ Tab) and rename the object to "Glass".
http://graphics.ethz.ch/~thuereyn/download/blender/tut2p3.png
Step 3) Switch of the visible selection mode and select the upper row of vertices with the B. Rotate the view a bit to get a better view
http://graphics.ethz.ch/~thuereyn/download/blender/tut2p4.png
Step 4) Extrude the upper face by pressing the E, select region and immediatly press enter to place the new face at the same position as the old one. Now with the new face selected press the S and scale the new face inwards a bit.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2p5.png
Step 5) Press E again, again with region, to extrude the face again, and move it downwards a bit. Switch to side view and move the new face down until you have an even distance on all sides of the cube.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2p6.png
Step 6) Leave edit mode with ⇆ Tab, you should now have a nice hollow cube.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2p7.png
Step 7) In the modifiers panel, add a subsurf modifier.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2p8.png
Step 8) Increase the Levels setting to 2, and the Render Levels to 4. Also set the face display mode to Smooth. This has to do as a glass, it would surely fall over in reality, but you can definitely fill in something.
Part 2: Setting up the Fluid Simulation
http://graphics.ethz.ch/~thuereyn/download/blender/tut2p9.png
Step 9) Enable the fluid simulation obstacle setting for the glass and add a plane mesh below the glass object (best do this in top mode 7 NumPad to have it aligned correctly). Dont forget to put the red-white marker in the correct place to simplify things, and name it e.g. "Floor".
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pa.png
Step 10) Switch of the shaded mode with the Z, and add a cube around the center of the glass. Scale it up to be four units on each side. In side view align the bottom of the cube with the floor plane, and name it "Domain". Finally enable fluid simulation and make the cube a domain, and set it to Smooth shading in the Editing buttons right away. (Note that the domain box is cubic in this case, but in general it doesn't have to be.)
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pb.png
Step 11) In top view add a sphere in the lower left corner of the domain object. Enable the object transform properties (N) and scale it to something between 0.4 and 0.5 in each dimension.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pc.png
Step 12) Name the sphere "Drop" and make it fluid in the fluid sim settings tab. The drop should end up in the glass, let's try an initial velocity around 0.1 for X and Y (not Z, it will fall down due to gravity anyway).
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pd.png
Step 13) Now we're ready to start simulating: first reduce the number of frames to e.g. 50. Then select the domain object again, and just hit bake for a low-res test simulation to check if the drop really hits the glass the way we want. Playback the animation (AltA) and view it from different angles. It's probably a bit to slow - I ended up with a initial velocity for the drop of (0.2, 0.15, 0). Change and re-simulate until you think it's good. You might also want to reduce the simulation end time to 0.2.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pe.png
Step 14) Once it's ok, increase the simulation =Resolution= to 128 (this will need around 300MB of main memory), and perhaps also the =Preview Resolution= to 30 or 35 to get a more detailed preview. Now the simulation will take significantly more time (several minutes probably). Playback the animation again. Switch to shaded view again (Z), and go to some frame inbetween, e.g. 20, by pressing the →. Switch the GUI Display setting of the domain object to "Final" to check how it will look while rendering. Make sure smooth shading is switched on for the fluid domain object in the Editing buttons. Check some other frames, then set the mode to "Preview" again. If you dont like the result, better reduce the resolution again, e.g. change the form of the drop and its initial velocity, and do some more test simulations until you happy with the result. (Don't worry about the original drop mesh that's still visible in this picture - it won't be visible in the end anyway.)
Part 3: Materials Setup
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pf.png
Step 16) For the following, leave the =Frame= setting somewhere in the middle to see both the fluid and the glass (e.g. 20). If you rendered the scene now, it would all look pretty grey and boring. Select the floor, go to the Shading buttons (F5), click on add new material, and change the diffuse color to (0.8, 0.4, 0).
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pg.png
Step 17) Let's make the background brighter by changing to the world buttons, and changing the background color to (0.4, 0.7, 1.0).
http://graphics.ethz.ch/~thuereyn/download/blender/tut2ph.png
Step 18) Now select the glass object, switch back to material buttons and rename its material to "Glass". Activate Ray Mirror , set the Ray Mir value to 0.15 and increase the Depth to 7. Then activate Ray Transp set the IOR to 1.5 (this is the correct physical value for normal glass) and set the Alpha slider to 0. Btw. - comparing the pictures you'll see that I forgot to switch the domain object GUI display to preview before this one.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pi.png
Step 19) For the fluid it's almost the same - create a new material named "Water", and set the same values as for the glass, except for IOR, which is 1.3 this time, and you could set Ray Mir to 0.1 instead.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pj.png
Step 20) From top view, duplicate the light two times (⇧ ShiftD), rotate the view a bit, and distribute them around the glass as shown in the picture. Then enable Ray Shado for each one in the Lamp buttons.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pk.png
Step 21) Select the camera with the 0 NumPad key, and right click the black border to select the camera. Zoom in on the glass by setting the Lens value to 90 in the Editing buttons (shift click the field to enter a numerical value), and use G to move the camera until you have a good view of the glass, and the original drop mesh isnt visible anymore.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pl.png
Step 22) Finally ready to render! Just press F12 to render or switch to the Render buttons, adjust the anti-aliasing and resolution as you like and click the RENDER button. If you like the result, use Save Image... (or F3) to save the rendered picture. With the ANIM button there you could also render the whole animation (for this you might want to reduce the rendering resolution).
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pl2.png
Step 22b) Optional - to enhance realism a bit, you can change the point lamps to area lights. Aim them at the glass by rotating them, increase the size to 1 or 2, and decrease the engergy until the scene is properly lit (check this by doing low-res test renderings, the GUI display will not correctly show the scene brightness). Finally increase the number of samples for each light, to create nice soft shadow edges. Now rendering takes much longer of course :) ...
Part 4: Changing the Simulation Settings
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pm.png
Step 23) Let's say you decided at some point, that a square glass and mud are more interesting than this standard glass of water. To do this, first select the glass and disable the subsurf modifier for realtime and rendering display. Also switch back to solid instead of smooth shading. Now the original square shape is visible. If you play the animation again it will look strange, as the fluid does ignore the changed shape until you bake it again.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pn.png
Step 24) To keep the original water-like fluid, a new surface data set will be created for the mud. Select the fluid domain object, and click on the BakeDir button. Select the directory to put the surface meshes, and enter "tut2mud" in the filename field, then press ↵ Enter or click Select Directory. Now change the viscosity to the honey preset, and click BAKE. The prefix "tut2mud" will now be used for the simulation meshes, and the old ones will not be overwritten. Note - it might be a good idea to create a directory for fluid simulation data somewhere near your .blend files.
http://graphics.ethz.ch/~thuereyn/download/blender/tut2po.png
Step 26) To make the fluid look muddy, change to the Material settings, create a new "Mud" material using the drop down menu, and give it some mud color. Make sure to switch off alpha, ray mirror and ray transparence in case they're still on. You can also set the shaders as shown in the picture to create a dull brown. Now you could render the animation again... It should like roughly like this: [2](DivX).
http://graphics.ethz.ch/~thuereyn/download/blender/tut2pp.png
Step 27) If you wanted to change to the old water sim at some point, simply select the fluid domain object, click the Bake Dir button and select any of the original surface or preview meshes. These are probably named such as "tut2.blend_OBCube_surface_...bobj.gz", or "tut2.blend_OBCube_preview_...bobj.gz". Selecting any of these will extract the correct prefix from the filename, and after clicking Select Directory the original simulation result should be visible again. To make it look as it should, you of course have to enable the subsurf modifier for the glass again.
Part 5: Where to go from here...
- An important effect that's missing are visible caustics. If you have a working Yafray installation, you can add photon light sources to generate caustics.
- Yafray also has more realistic surface reflection settings, in combination with interesting backgrounds scenes or HDR images this gives a nice appearance.
- Try setups with more complex obstacle and fluid geometry - the maximum simulation resolution is currently limited to prevent crashes due to high memory usage, but with the highest setting fairly complex simulations are possible.
- Set the drop object to Inflow instead of Fluid a run the simulation again (maybe you have to scale down the drop a bit to prevent the domain from overflowing).
PS: If you find errors in the tutorial (or in the fluid simulator) - please let me know after checking the FAQ on the main page.
Back to the Fluid Simulation chapter...