underwater caustics and volumetric light

Upload: micmm

Post on 03-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Underwater Caustics and Volumetric Light

    1/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 linkbetween the two.

    Explains the problems around simulating volumetric light and caustics inBlender

    Provides a solution to simulating volumetric light in Blender.For a full treatise, which also includes caustics, see the Training section at theDNA Pixels web site.

    Before there was Blender, there was light: what isunderwater volumetric lighting ?

    Before jumping into Blender, let's talk underwater light. Any large body ofwater (dam, lake, sea, etc.) teems with small particles either organic orinorganic matter. They are so small that single particles may be nearly invisibleto the human eye. But there a billions of these particle in the water and butbright light still reflects off them, causing them to show up as a cloudinessunder the bright light. They therefore tend to be more visible where there isstrong light, as shown here:

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

    Example of underwater volumetric light

    http://www.dnapixels.com/tuts%20and%20tricks.htmlhttp://www.dnapixels.com/http://www.dnapixels.com/http://www.dnapixels.com/tuts%20and%20tricks.html
  • 7/28/2019 Underwater Caustics and Volumetric Light

    2/19

    In an underwater scene, these volumetric beams seem to move around. This isbecause the varying concentration of the beams are caused by the movementof the water and waves at the surface. Certain shapes of waves tend to focusthe sunlight more and others tend to disperse it more causing the continuousinterplay of moving light beams.

    What are caustics?

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

    In an underwater scene, light which is bent by the surface waves, show up ascaustic patterns when it hits the sea bed. These patterns are focused and de-focused 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 andcaustics always go together

    Where there are underwater light beams, there are caustics: they go hand-in-hand. (In veryclean water you may find caustics without light beams.)

    The waves on top of the water scatter the light beams: focusing and de-focusing them.

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

    Underwater caustics in the bottom of a

    pool of shallow water - as seen from abovethe water

    Caustic pattern of glassand static water

  • 7/28/2019 Underwater Caustics and Volumetric Light

    3/19

    As these light beams travelthrough the water, they reflect off

    small particles, causingvolumetric light beams to becomevisible in the water.

    When the light beams hitanything large in their path, thecaustic patterns show up: theseabed, bottom of the river, poolfloor, a fish, etc.

    The caustic patterns actually fallon the microscopic particles too,but the pattern does not show,because the particles are toosmall.

    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 onthe light itself)

    ...which should then show both the volumetric beams as well as simulate thecaustic 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 asit is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

    Underwater volumetric light and caustics

    go together

    Volumetric

    light beam

    Caustic

    pattern

    Sea bed

    Waves

    scatter light

  • 7/28/2019 Underwater Caustics and Volumetric Light

    4/19

    Before there was light, there was darkness

    The following test was done, consisting of:

    Blender can do volumetric lights, but there are certain limitations: The spot light with the ray-tracedbeams show through an alpha texture,

    but the volumetric light does not diminish where there are obstructionsin the light beam's way:

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

    Ground

    plane

    Plane with

    alpha texture

    Cubes

    Volumetric

    light

    Sun asbackgrond

    light

  • 7/28/2019 Underwater Caustics and Volumetric Light

    5/19

    The spot light with buffershadows renders an excellent volumetricshadow, but it can't see through the layer with transparent texture

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

    Some more issues with volumetric lights...

    I then thought I would adda few buffer-shadowed spotlights, each one represen-ting a beam of light, andmerely animate each one'sintensity over time there-by simulating a few lightbeams.

    But, alas, there were somemore problems...

    When one renders buffer-shadowed spot lights withvarying intensities in frontof each other, they turn outlike this:

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

    What is

    this black

    line?

    What is

    this black

    line?

  • 7/28/2019 Underwater Caustics and Volumetric Light

    6/19

    If one has a buffer-shadowed spot lights withzero intensity, it renders asfollows:

    DOUBLE-AAAAARRGGHH!!!! - More problems! This iswhere I started to seriously pull out my hair andwhy I am going bald

    But there HAS to be a way!

    I have seen other methods of simulating underwater light beams, but they aremore mechanical and do not lend themselves very well to animation.

    It then struck me! The buffer-shadowed spotlights seem to work fine when there is anobstacle 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 asit is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

    http://www.enricovalenza.com/makebongoenv.htmlhttp://www.enricovalenza.com/makebongoenv.html
  • 7/28/2019 Underwater Caustics and Volumetric Light

    7/19

    Simulating underwater volumetric light rays

    From top view (NUMKEY7), create a plane to simulate the seabed. Scale it todouble its default size by SKEY > 2 > ENTERKEY.

    Also from the top, create a sun lamp. Set its energy level to 0,5. This lamp willbe 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, itdoes 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 anotherplane object(make sure it is not amesh within the previous plane!).Subdivide it about 20-40 timeswhile in edit mode as shown (WKEY> Subdivide Multi).

    Exit edit mode (TABKEY)

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

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

  • 7/28/2019 Underwater Caustics and Volumetric Light

    8/19

    We are now going to turn thesubdivided plane into a circle:

    In object mode, first selectthe cylinder and then theplane.

    Create a boolean

    intersection between theplane and the cylinder bypressing the WKEY andselecting Intersect.

    Delete the cylinder and the square plane (just hit the DELKEY after your lastaction)

    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 asit is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

  • 7/28/2019 Underwater Caustics and Volumetric Light

    9/19

    Then, in edit mode, delete afew faces randomly (connectedand unconnected) from thecircular plane by going to face

    select mode (shortcut: CTRLTABKEY > FACES), selecting thefaces and deleting them (notthe vertices).

    Subsurf the object: F9, clickAdd Modifier, select Subsurf

    Go to object mode (TABKEY) Move the circular plane up by

    for example 2 Blender units.

    From the top, your circular planeshould now look something like theimage to the right.1

    With the 3D cursor still in the center of the Blender universe, create a defaultdisk (filled circle) with slats in it. Again, delete some face randomly in editmode.

    (The image below does not show any other objects.)

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

  • 7/28/2019 Underwater Caustics and Volumetric Light

    10/19

    In wireframe view, the two objectsshould resemble this from the top:

    Move the disk slightly (about 0,1Blender unit) above the plane inthe Z-direction, just to make iteasier for you to grab each onelater.

    A closer view looks like this:

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

  • 7/28/2019 Underwater Caustics and Volumetric Light

    11/19

    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 cando that by viewing the plane from the front (NUM1, orthogonalview) or the side (NUM3, orthogonal view) when you create the

    armature (Spacebar > Add > Armature). The bone's base shouldbe placed at the origin, with the bone pointing in the positive Z-direction, 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 asit is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

  • 7/28/2019 Underwater Caustics and Volumetric Light

    12/19

    Selecting the disk object Pressing SHIFTS-S, Cursor->Selection

    Now: 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 parent the disk to it's bone and parent the plane to its bone. Oneway to do it is:

    Make sure the armature is in pose mode (any selected bone shouldappear blue). If it is not, ensure the armature is selected, thenselect Pose Mode from the 3D window's header bar, or press CTRL-

    TAB. Parent the disk to it's associated bone by first selecting the disk,

    then selecting the disk's associated bone (the one you created inthe 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 asit is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

  • 7/28/2019 Underwater Caustics and Volumetric Light

    13/19

    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. PressEsc 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'srespective Z axis, but in opposite directions. We will do it via their bones. Thereason we do it that way, is because if you rotate the disk or plane around itslocalZ axis, but at an angle to any of the 3 globalaxes (X, Y or Z) it wobbleswhen it rotates. That is because objects are animated in 3 dimensions (X, Yand Z), while bones are animated in FOUR dimensions: W, X, Y and Z, usingquaternions. Let's not get stuck in the details here, but suffice it to say that itis 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 Yaxis by 90 degrees. (Shortcut:press RKEY, press YKEY [uses global Y axis], press YKEYagain [second YKEY causes it to use the local Y axis], type90, press ENTERKEY.) The reason we chose the bone's Yaxis, 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 asit is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

  • 7/28/2019 Underwater Caustics and Volumetric Light

    14/19

    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. Dothis at frames 81, 121 and 161.

    We will animate theplane'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 (stillin pose mode)

    Select allthe curves in the IPOcurve editor: with your mousecursor hovering over the IPOcurve editor, press the AKEYuntil all the dots on all thecurves turn white. (If they are

    yellow with handles you arein the curves' edit mode, whichyou can get out of by means ofTABKEY)

    Copythe top bone's IPO curvesby means of the down-arrow inthe IPO curve viewport'sheader bar - as indicated in theimage to the right.

    Paste the top bone's IPOcurves by clicking the up-arrowin the IPO curve viewport'sheader bar - as indicated in theimage to the right.

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

  • 7/28/2019 Underwater Caustics and Volumetric Light

    15/19

    If you now animate the bones (ALT AKEY), the disc and plane should rotate atthe same rate but in opposite directions for 161 frames (ESC to stopanimation).

    The reason they turn in opposite directions, is because they utilise the sameIPO curves, but the bones point in opposite directions.

    The rotation will be slow initially, pick up speed and then slow down to a halt atframe 161. We now want to ensure that the bones keep rotating beyond frame161, by doing the following:

    Ensuring all the IPO curves are selected, in the IPO curve window'sheader 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 asit is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

  • 7/28/2019 Underwater Caustics and Volumetric Light

    16/19

    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 beamangle) Set the SpotBl to 1

    From the front view, move the lamp upwards toabove the two disks until just before its rays arewider 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 firstrendering does not always look like thisimage for some reason. I sorted it out byrendering different Buf.Shadow types:Classical, Classical-Halfway and Irregular.Usually when I reverted back to Classicaland 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 greatstep forward!

    The shadow currently exactly showsthe shape of the holes through thedisk and circular plane. It may notseem like something, but havefaith we are on the right track andwill 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 asit is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

  • 7/28/2019 Underwater Caustics and Volumetric Light

    17/19

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

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

    (Don't worry about the fact that thethe disk and circular plane arevisible: the final image can becomposed in such a way that theywill be out of sight.)

    We are starting to be in business!

    These light rays are now starting to look like real underwater volumetric lightrays. With the soft value set to 100, the light spots on the seabed have notcompletely 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 weplay around with the softness value.

    Set the Soft value to 15...

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

    Samples=16

  • 7/28/2019 Underwater Caustics and Volumetric Light

    18/19

    With a reduced softness value,the light spots on the seabed startappearing.

    You can play around with the Softvalue until you get to a value that

    suits your needs.

    NOTE: the light spots on theseabed are not the causticsthemselves (which is the topic ofanother tutorial), but theyenhance the caustics. They dothat because, as the causticsmove around, these faint lightspots will also move around with

    the caustics and because theymove in unison with thevolumetric lights, they will lendmore 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 thoughthe halos still show beyond that.

    The rotation speed of the disks: by scaling all the IPO curves along theX-axis, the one can increase or decrease the rotation speed of the diskand circular plane causing the light beams to move faster or slowerwhen animated. At the moment they are moving too fast. You may wantto 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 asit is unchanged and credit is given to DNA Pixels (www.dnapixels.com)

    http://www.dnapixels.com/tuts%20and%20tricks.htmlhttp://www.dnapixels.com/tuts%20and%20tricks.html
  • 7/28/2019 Underwater Caustics and Volumetric Light

    19/19

    The sun lamp's colour: giving the sun lamp a bluish colour makes thewhole scene take on amuch moreunderwater look.

    Mist: if you play around

    with the environment'smist (F8), you cancause the seabed planeto disappear in thedistance.

    Feel free to play andexperiment. Here is whatmine looks like after a fewchanges:

    OK, what did we do in summary?

    We concluded in the beginning that neither ray shadows, nor buffer shadowson their own can provide a sufficiently realistic model for simulatingunderwater volumetric light rays.

    A better alternative was to use buffer shadows... but by using an obstacle infront of it. The obstacle does not cause the black rays that we saw if one setsa halo light's energy level to less than 1.

    The obstacle was created in a specific way (and there will be many other waysto do it): we created two counter-rotating disks. The one disk had randomly-situated radiating slats, while the circular plane had random holes. When theycounter-rotate, the resulting light that shines through the holes simulate theplay of underwater volumetric light rays. This method allows for the light raysto gradually become brighter over time and faint back to no light again. It alsoallows 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 playingaround with the spot lamp's parameters.

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

    Enjoy

    !