Creating a fake immersion effect material

In this recipe, we will create a material to give the effect of an object immersed in a substance becoming more and more opaque as the depth increases, for example, murky water.

Creating a fake immersion effect material

The murky water effect as it appears in the final rendering

Start Blender and open the 9931OS_09_start.blend file. Then follow these steps:

Let's go ahead and create the different materials:

  1. Go to the Material window and select the Suzanne_unwrapped mesh. In the Node Editor window toolbar, click on the New button, and rename the material as (simply) Suzanne. In the Material window under the main Properties panel, switch the Diffuse BSDF shader with a Mix Shader node. In the first Shader slot, select a Diffuse BSDF shader node, and in the second Shader slot, select a Glossy BSDF shader node.
  2. Set the Glossy distribution to Beckmann and the Roughness value to 0.100. Then set the Fac value of the Mix Shader node to 0.600.
  3. Select the bed Plane and click on the New button in the Node Editor window toolbar. Rename the material as bed.
  4. In the Material window, switch the Diffuse BSDF shader with an Emission shader node. Set the Color values for R to 0.800, G to 0.659, and B to 0.264. Then set the Strength value to 0.100.
  5. Select the water Plane and click on the New button in the Node Editor window toolbar. Rename the material as water.
  6. In the Material window, switch the Diffuse BSDF shader with a Mix Shader node. In the first Shader slot, select a Glass BSDF shader node, and in the second Shader slot, select a Transparent BSDF node.
  7. Set the Glass BSDF node's Roughness value to 0.600 and the IOR to value 1.333. Then set the Color values for R to 0.185, G to 0.611, and B to 0.800.
  8. Add a Light Path node (press Shift + A and navigate to Input | Light Path) and a ColorRamp node (press Shift + A and navigate to Converter | ColorRamp). Connect the Ray Length output to the Fac input socket of the ColorRamp and invert the position of the black-and-white color stops (that is, move the black color stop to the extreme right and the white color stop to the extreme left of the slider).
  9. Connect the ColorRamp output to the Fac input socket of the Mix Shader node.
    How to do it...

    The murky water material network

The effect happening on the water material is due to the Ray Length output, which returns the length of the light rays passing through an object, thus giving the thickness of that object. In our case, the distance from the water mesh surface to the far distance (from the Camera point of view, because the light rays originate from the Camera).

The gradient of the ColorRamp is mapped on the length of this Ray Length output (also clamped and inverted by the same ColorRamp node), connected to the Fac input socket of the Mix Shader node in order to work as a stencil map to smoothly blend the amount of the Glass shader with the amount of the Transparent BSDF shader node.

Thus, the transition from the Transparent shader to the Glass shader returns the impression of a volume of water becoming murkier as the distance of the object from the surface increases.