In this recipe, we will create an underwater environment as shown in the following screenshot, looking especially at a fake caustic effect projected by the water's wavy surface and from an atmospheric perspective, obtained by a per material dedicated node group:
The underwater environment in the final rendering
Note that this atmospheric perspective effect is actually a fake and it is not obtained by a volume material. Volumetric shaders will be explained in Chapter 9, Special Materials, of this Cookbook.
Let's start by preparing the scene:
0.230
(press S, then press Z, enter .23
, and press Enter).4
both for the View and the Render levels.2
for both the View and the Render levels.20
, and Resolution to 12
.1.00
to 2.00
, and press I again to set a second key.Ocean_surface
as shown in the following screenshot:The Cube with the assigned Ocean modifier
16.80000
, Y to -2.64000
, and Z to 0.95000
. Then set the Rotation value of X to 92°
, Y to 0°
, and Z to 90°
. Next, go to the Camera view (press 0 on the numeric keypad).-3.22600
, Y as -2.79600
, and Z as -2.24463
. Enter Edit Mode and scale it 30 times bigger (press A to select all of the geometry, then press S, enter 30 and press Enter). Using the Specials menu (press W) divide the Plane five or six times. Activate the PET (Proportional Editing Tool), randomly select vertices, and move them up to model the dunes of the ocean bed. Exit Edit Mode, smooth it by the Tools tab under the Tool Shelf panel, and assign a Subdivision Surface modifier at level 2
. Disable the modifier visibility in the viewport by clicking on the eye icon. Rename it as Ocean_bed
.1.000
, G to 0.989
, and B to 0.700
). Change it to a Sun. Set the Size value to 0.010
and the Strength value to 2.500
. Then set the Rotation values of X to 22°
, Y to -7°
, and Z to 144°
. You might know that for a Sun Lamp, the location doesn't matter.1.00
. Then set the Samples to 25
for both Preview and Render. Under the Light Paths subpanel, disable both the Reflective Caustics and Refractive Caustics items.As an alternative, just open the 9931OS_05_underwater_start.blend
file and use the prepared scene.
First, let's perform the easy steps by appending the materials that are already made so that we can reuse them:
9931OS_03_Rock_procedurals.blend
file, append the Rock_proc01
material. Select the Rocks object and assign the newly appended material.9931OS_03_Ground.blend
file, append the Ground_01
material. Select the Ocean_bed object and assign the material.Now let's move on to the more complex steps:
9931OS_05_Ocean.blend
file, append the Ocean_surface
object, material. Select the Ocean_surface object and assign the material. Rename it as Ocean_surface_under
.Null
, and click on the Assign button. Now the Ocean_surface object has two different materials: the transparent water surface and the opaque sides and bottom (a simple white Diffuse BSDF material). Exit Edit Mode.caustics_tileable_low.png
texture and set the Color Space to Non-Color Data.Diffuse_Caustics
, Transparent_Caustics
, and Mix Shader_Caustics
.FAKE_CAUSTICS
as shown in the following screenshot:The FAKE_CAUSTICS frame mixed with the Ocean_Water node group on the ground of the Is Camera Ray output of the Light Path node
The following screenshot shows where we are so far:
The point where we are so far
What is missing now is the underwater atmospheric perspective effect. There are several ways to obtain this, for example, by compositing a Mist pass rendered in Blender Internal or by using a volumetric shader. However, we are going to do this with a simple node group added to every one of the different materials.
Mix Shader_Fog
.0.030
. Check the Clamp option. Connect the Multiply node output to the Fac input socket of the Mix Shader_Fog node.0.040
, G to 0.117
, and B to 0.124
.Fog_underwater
as shown in the following screenshot:The FOG_UNDERWATER node group in Edit Mode
The Fog_underwater node group pasted at the end of the shader
First of all, why should we choose a Cube for the ocean surface instead of the simpler Plane?
The reason is very simple: in Cycles, the World emits light, and the only way to avoid this is to set the color to pitch black (or by a combination of a Light Path node with the World materials, but this is another story). In our scene, the World is set to a bright blue sky color, and with a Plane, the underwater objects and the ocean bed would have been lit too much from the sides and the bottom the result look natural. A Cube, on the other hand, envelops all the underwater elements, limiting the lighting to the Sun Lamp passing through the surface, and projecting the image textured caustics. This gives a more natural-looking result.
The image texture we assigned to the water material is used to obtain a textured transparency effect. Right now, the water surface is actually opaque and transparent according to the black and white values of the textures, so as to allow the Sun Lamp light to pass through and project the caustics.
Thanks to the Is Camera Ray output of the Light Path node, the caustics image texture is not directly renderable on the ocean surface, but it nevertheless has some effect on the other materials. Because the value of Is Camera Ray is 1
, the rays starting from the Camera and directly hitting the ocean surface can render only the clean water material plugged into the second input socket of the Mix Shader node, while the transmitted caustics (plugged in the first Shader socket = 0) get rendered.
The Fog_underwater node group is simply an emitter material serving as the background (deep green in this case) and mapped on every underwater material according to the z depth of the Camera (it also works with the Camera frame, in the viewport). The density of the fog is set by the Multiply node's second Value. For the ocean body, a value of 0.030
is good enough.
Note that we didn't expose the values of the nodes in the Fog_underwater group. This is because in Edit Mode, we can tweak the internal values of just one node to automatically update all the fog group instances assigned to the other materials. Besides, we know that the values exposed on the group interface would overwrite the internal settings and work only for that single node instance.
The final underwater environment rendered from a different point of view