Sunteți pe pagina 1din 19

Tutorial: Simulating underwater volumetric lighting in Blender

Skill level required: Intermediate

What is this tutorial about?


This tutorial:

Describes what volumetric light and caustics are, as well as the link between the two. Explains the problems around simulating volumetric light and caustics in Blender Provides a solution to simulating volumetric light in Blender.

For a full treatise, which also includes caustics, see the Training section at the DNA Pixels web site.

Before there was Blender, there was light: what is underwater volumetric lighting ?
Before jumping into Blender, let's talk underwater light. Any large body of water (dam, lake, sea, etc.) teems with small particles either organic or inorganic matter. They are so small that single particles may be nearly invisible to the human eye. But there a billions of these particle in the water and but bright light still reflects off them, causing them to show up as a cloudiness under the bright light. They therefore tend to be more visible where there is strong light, as shown here:

Example of underwater volumetric light


DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

In an underwater scene, these volumetric beams seem to move around. This is because the varying concentration of the beams are caused by the movement of the water and waves at the surface. Certain shapes of waves tend to focus the sunlight more and others tend to disperse it more causing the continuous interplay of moving light beams.

What are caustics?


In non-technical terms, caustics occur when light rays are bent as they go through transparent objects (such as glass or water). It is also caused when light reflects off very reflective (curvy) surfaces.

Caustic pattern of glass and static water

Underwater caustics in the bottom of a pool of shallow water - as seen from above the water

In an underwater scene, light which is bent by the surface waves, show up as caustic patterns when it hits the sea bed. These patterns are focused and defocused beams of light, which make patterns on anything in their path, whether it is a fish, a plant of the sea bed.

Like ham and eggs, underwater volumetric light and caustics always go together
Where there are underwater light beams, there are caustics: they go hand-inhand. (In very clean water you may find caustics without light beams.) The waves on top of the water scatter the light beams: focusing and defocusing them.

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

As these light beams travel through the water, they reflect off small particles, causing volumetric light beams to become visible in the water. When the light beams hit anything large in their path, the caustic patterns show up: the seabed, bottom of the river, pool floor, a fish, etc. The caustic patterns actually fall on the microscopic particles too, but the pattern does not show, because the particles are too small.

Waves scatter light Volumetric light beam

Caustic pattern

Sea bed

Underwater volumetric light and caustics go together

Enter Blender
What I hoped to do, was to use Blender's volumetric halo effect (F5) to: 1. Show the volumetric light beams 2. Create a texture with alpha transparency settings to simulate the caustics 3. Shine the light through the caustic texture (or create the texture on the light itself) ...which should then show both the volumetric beams as well as simulate the caustic pattern on anything the light falls on. But, things are never as easy as you hope for...

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

Before there was light, there was darkness


The following test was done, consisting of:

Sun as backgrond light

Volumetric light

Cubes

Plane with alpha texture

Ground plane

Blender can do volumetric lights, but there are certain limitations: The spot light with the ray-traced beams show through an alpha texture, but the volumetric light does not diminish where there are obstructions in the light beam's way:

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

The spot light with buffer shadows renders an excellent volumetric shadow, but it can't see through the layer with transparent texture

Aaaargghh!!! What works with the one lamp does not work in the other! What are we to do?!

Some more issues with volumetric lights... I then thought I would add a few buffer-shadowed spot lights, each one representing a beam of light, and merely animate each one's intensity over time thereby simulating a few light beams. But, alas, there were some more problems... When one renders buffershadowed spot lights with varying intensities in front of each other, they turn out like this:

What is this black line?

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

If one has a buffer-shadowed spot lights with zero intensity, it renders as follows:

DOUBLE-AAAAARRGGHH!!!! - More problems! This is where I started to seriously pull out my hair and why I am going bald

But there HAS to be a way!


I have seen other methods of simulating underwater light beams, but they are more mechanical and do not lend themselves very well to animation. It then struck me! The buffer-shadowed spot lights seem to work fine when there is an obstacle in the way. Remember this one? But a few tricks were necessary...

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

Simulating underwater volumetric light rays


From top view (NUMKEY7), create a plane to simulate the seabed. Scale it to double its default size by SKEY > 2 > ENTERKEY. Also from the top, create a sun lamp. Set its energy level to 0,5. This lamp will be used to provide ambient light. Move it upwards and away from the centre. Because the sun lamp's rays are parallel and of equal energy over distance, it does not really matter where the lamp is: it illuminates everything equally. DEselect its Ray shadow button to ensure it does not cast a (sharp) shadow. Now, instead of a transparent texture, we are going to create an obstacle:

From the top view, create another plane object (make sure it is not a mesh within the previous plane!). Subdivide it about 20-40 times while in edit mode as shown (WKEY > Subdivide Multi). Exit edit mode (TABKEY)

Still in top view, create a cylinder with capped ends of default size (this view is from the side).

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

We are now going to turn the subdivided plane into a circle: In object mode, first select the cylinder and then the plane. Create a boolean intersection between the plane and the cylinder by pressing the WKEY and selecting Intersect.

Delete the cylinder and the square plane (just hit the DELKEY after your last action) Select the newly-created (half) cylinder and go to edit mode (TABKEY) Go the front view (NUM1) With all the vertices DEselected, now select all the vertices at the bottom of the cylinder and delete them

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

Then, in edit mode, delete a few faces randomly (connected and unconnected) from the circular plane by going to face select mode (shortcut: CTRL TABKEY > FACES), selecting the faces and deleting them (not the vertices). Subsurf the object: F9, click Add Modifier, select Subsurf Go to object mode (TABKEY) Move the circular plane up by for example 2 Blender units.

From the top, your circular plane should now look something like the image to the right.1

With the 3D cursor still in the center of the Blender universe, create a default disk (filled circle) with slats in it. Again, delete some face randomly in edit mode. (The image below does not show any other objects.)

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

In wireframe view, the two objects should resemble this from the top:

Move the disk slightly (about 0,1 Blender unit) above the plane in the Z-direction, just to make it easier for you to grab each one later.

A closer view looks like this:

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

Create an armature with bones for the disk and the plane, as follows: From the front view (NUM1), create an armature for the circular plane: snap the cursor to the plane by means of SHIFT-S:

Create an armature (bone) perpendicular from the plane. You can do that by viewing the plane from the front (NUM1, orthogonal view) or the side (NUM3, orthogonal view) when you create the armature (Spacebar > Add > Armature). The bone's base should be placed at the origin, with the bone pointing in the positive Zdirection, i.e. orthogonal to the plane

Move (GKEY) the bone downwards along the Z-axis (ZKEY).

Press TABKEY to exit armature edit mode Place the 3D cursor exactly in the midpoint of the disk (which is slightly offset above the circular plane in the Z-direction) by:

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

Selecting the disk object Pressing SHIFTS-S, Cursor->Selection Select the previous bone and go into armature edit mode (TABKEY) Wile in orthogonal front of side view, add a new bone in the positive Z-direction at the new location of the 3D cursor: SPACEBAR > Add > Bone. Press TABKEY to go back to object mode.

Now:

Now parent the disk to it's bone and parent the plane to its bone. One way to do it is: Make sure the armature is in pose mode (any selected bone should appear blue). If it is not, ensure the armature is selected, then select Pose Mode from the 3D window's header bar, or press CTRLTAB. Parent the disk to it's associated bone by first selecting the disk, then selecting the disk's associated bone (the one you created in the centre of the disk) and pressing CTRL-PKEY > Make Parent To > Bone.

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

In the same way, parent the plane to it's associated bone. Verify that the parenting is correct by selecting a bone (in pose mode) and moving it. The child object should move with it. Press Esc to release the bone. Test both bones.

Let's get some motion going


We want to animate the disk and the plane to rotate around each one's respective Z axis, but in opposite directions. We will do it via their bones. The reason we do it that way, is because if you rotate the disk or plane around its local Z axis, but at an angle to any of the 3 global axes (X, Y or Z) it wobbles when it rotates. That is because objects are animated in 3 dimensions (X, Y and Z), while bones are animated in FOUR dimensions: W, X, Y and Z, using quaternions. Let's not get stuck in the details here, but suffice it to say that it is better to use bones for rotation in this application.

We will now animate the disk's bone to rotate once every 160 frames. This will be done by setting rotation keys at every 90 degrees: Ensure you are on the first frame (shortcut: SHIFT-LEFTARROW) Select the top bone and insert a rotation key: Press IKEY > Select Insert key > Rot Go to frame 41 (UPARROW 4 times): Rotate the bone around its Y axis by 90 degrees. (Shortcut: press RKEY, press YKEY [uses global Y axis], press YKEY again [second YKEY causes it to use the local Y axis], type 90, press ENTERKEY.) The reason we chose the bone's Y axis, is because it is the bone's axis along the length of the
DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

bone which lines up with the disk's Z-axis. Insert a rotation key on this frame, as before. Repeat the above steps by first going to the correct frame number, then rotating the bone 90 degrees and then keying the bone. Do this at frames 81, 121 and 161. We will animate the plane's bone by copying the disk bone's IPO curves: Near the top of the Blender window, go to the IPO curve editor in the Animation screen, i.e. Screen 1:

In the IPO curve's header, make sure the IPO type is Pose: Go back to frame 1 (SHIFT-LEFTARROW) Select the bottom bone, ensuring that it is in pose mode (blue). Insert a rotation key for the bottom bone. This is done just to create an IPO curve for it, as we will now replace it.

Select the top bone again (still in pose mode) Select all the curves in the IPO curve editor: with your mouse cursor hovering over the IPO curve editor, press the AKEY until all the dots on all the curves turn white. (If they are yellow with handles you are in the curves' edit mode, which you can get out of by means of TABKEY) Copy the top bone's IPO curves by means of the down-arrow in the IPO curve viewport's header bar - as indicated in the image to the right.

Paste the top bone's IPO curves by clicking the up-arrow in the IPO curve viewport's header bar - as indicated in the image to the right.

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

If you now animate the bones (ALT AKEY), the disc and plane should rotate at the same rate but in opposite directions for 161 frames (ESC to stop animation). The reason they turn in opposite directions, is because they utilise the same IPO curves, but the bones point in opposite directions. The rotation will be slow initially, pick up speed and then slow down to a halt at frame 161. We now want to ensure that the bones keep rotating beyond frame 161, by doing the following: Ensuring all the IPO curves are selected, in the IPO curve window's header bar, select Curve > Extend Mode > Cyclic Do the same for the other bone

If you now play the animation beyond frame 161, the bones will keep rotating.

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

Let's shed some volumetric light


Create another light as follows: First, place the 3D cursor at the center of our Blender universe by pressing SHIFT CKEY. Go to top view (NUM7) and add a spot light (SPACEBAR > Add > Lamp > Spot) Set the light's properties as follows (F5 should get you to the correct panel): Energy: 1,5 Enable the Halo button Set the HaloInt to 1,5 Ensure that the Halo step is on 1 Select Buf.Shadow (Ensure it is Classic) Set the SpotSi to 30 (i.e. the spot light's beam angle) Set the SpotBl to 1

From the front view, move the lamp upwards to above the two disks until just before its rays are wider than the disks, as shown to the right.

If we render it, it looks something like the image below. (Npte: I have found that the first rendering does not always look like this image for some reason. I sorted it out by rendering different Buf.Shadow types: Classical, Classical-Halfway and Irregular. Usually when I reverted back to Classical and rendered, the problem disappeared) What is important is that: The halo light shining through the disk and circular plane nearly looks like volumetric lights! That's a great step forward! The shadow currently exactly shows the shape of the holes through the disk and circular plane. It may not seem like something, but have faith we are on the right track and will soon do something about that. Let's now address the above points...
DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

Firstly, we'll soften the shadow: set the light's Soft value to the maximum of 100...

The sharp-edged light spots on the plane don't look right. Fix that by adjusting the Samples value to 16:

Sam pl e

s= 16

(Don't worry about the fact that the the disk and circular plane are visible: the final image can be composed in such a way that they will be out of sight.) We are starting to be in business! These light rays are now starting to look like real underwater volumetric light rays. With the soft value set to 100, the light spots on the seabed have not completely disappeared, but they are so soft that they are nearly not visible. We may want to see a bit of them, so let's next see what happens when we play around with the softness value. Set the Soft value to 15...
DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

With a reduced softness value, the light spots on the seabed start appearing. You can play around with the Soft value until you get to a value that suits your needs. NOTE: the light spots on the seabed are not the caustics themselves (which is the topic of another tutorial), but they enhance the caustics. They do that because, as the caustics move around, these faint light spots will also move around with the caustics and because they move in unison with the volumetric lights, they will lend more credibility to the caustics.

Parameters you may want to play around with


I would suggest you can play around with the following: The buffer shadow light: Its halo intensity Its softness value Its Dist and ClipEnd values: Larger Dist values make the end of the halo brighter close to the seabed. If the ClipEnd value ends above the seabed, the light (and therefore shadows) stop short of the seabed - even though the halos still show beyond that.

The rotation speed of the disks: by scaling all the IPO curves along the X-axis, the one can increase or decrease the rotation speed of the disk and circular plane causing the light beams to move faster or slower when animated. At the moment they are moving too fast. You may want to scale them so that they rotate 90 degrees about every 200 frames.
DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

The sun lamp's colour: giving the sun lamp a bluish colour makes the whole scene take on a much more underwater look. Mist: if you play around with the environment's mist (F8), you can cause the seabed plane to disappear in the distance.

Feel free to play and experiment. Here is what mine looks like after a few changes:

OK, what did we do in summary?


We concluded in the beginning that neither ray shadows, nor buffer shadows on their own can provide a sufficiently realistic model for simulating underwater volumetric light rays. A better alternative was to use buffer shadows... but by using an obstacle in front of it. The obstacle does not cause the black rays that we saw if one sets a halo light's energy level to less than 1. The obstacle was created in a specific way (and there will be many other ways to do it): we created two counter-rotating disks. The one disk had randomlysituated radiating slats, while the circular plane had random holes. When they counter-rotate, the resulting light that shines through the holes simulate the play of underwater volumetric light rays. This method allows for the light rays to gradually become brighter over time and faint back to no light again. It also allows for the varied width of the rays, as well as a level of randomness in one rotation that would not easily be detected by the human eye. The consistency of the light rays can also be quite well controlled by playing around with the spot lamp's parameters.

j n E

! y o

DNA Pixels: you are free to use and distribute this material as long as it is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

S-ar putea să vă placă și