Creating a sand material using procedural textures

In this recipe, we will create a sand material that looks like what is shown in the following screenshot, which is good for both close and distant objects:

Creating a sand material using procedural textures

The sand material as it appears in the final rendering

Getting ready

Start Blender and switch to the Cycles Render engine. Then perform the following steps:

  1. Delete the default Cube and add a Plane (press Shift + A and navigate to Mesh | Plane).
  2. Press Tab to go to Edit Mode and scale it nine times bigger, with 18 units per side (press S, enter the digit 9, and press Enter). Go out of Edit Mode.
  3. Go to the World window and click on the Use Nodes button under the Surface subpanel in the Properties panel to the right of the screen. Then click on the little square with a dot on the right side of the Color slot. Select the Sky Texture item from the pop-up menu. Set the Strength value to 1.900.
  4. Select the Lamp, go to the Object data window, and click on the Use Nodes button. Then change the Type of Lamp to Sun and set Strength to 3.000. Change the color values to 1.000 for R, 0.935 for G, and 0.810 for B. In orthogonal top view, rotate the Sun lamp by 45°, as shown in the following screenshot:
    Getting ready

    The scene from the top with the Sun Lamp selected

  5. Add a Cube and a UV Sphere to the scene and place them leaning on the Plane.
  6. Select the Cube and click on the Smooth button in the Shading subpanel under the Tools tab to the left of the 3D window (press the T key to make it appear if it is not present).
  7. Select the UV Sphere and perform the same actions as given in step 6.
  8. Select the Cube, and in the Object modifiers window, add a Bevel modifier. Set Width to 0.1000, Segments to 2, and Profile to 0.15. Assign a Subdivision Surface modifier, set both the Subdivisions levels to 4, and check the Optimal Display item. Assign a Smooth modifier and set Factor to 1.000 and Repeat to 15.
  9. Select the UV Sphere and assign a Subdivision Surface modifier with Subdivisions levels set to 2 and the usual Optimal Display item checked.
  10. Select the Plane, click on the Smooth button, and then go to Edit Mode and press W. In the Specials pop-up menu, select the Subdivide item. Press the F6 key to call the Options pop-up menu (or go to the panel at the bottom of the Tool Shelf tabs) and set Number of Cuts to 10.
  11. Go out of Edit Mode, go to the Object modifiers window, and assign a Subdivision Surface modifier. Switch to the Simple subdivision algorithm and set both Subdivisions to 3. Check the Optimal Display item.
  12. Assign a Displace modifier and then click on the Show texture in texture tab button to the side of the New button. In the Texture window, click on the New button and switch the default Clouds texture with the Voronoi texture. Set the Size value to 5.00.
  13. Assign a new Displace modifier, click on the Show texture in texture tab button, and load a Voronoi texture again. Leave the Size value at 0.25.
  14. Assign a Smooth modifier and set Factor to 1.000 and the Repeat value to 5.
  15. Place the Camera to have a nice angle on the Plane and switch from the 3D view to a Camera view (by pressing the 0 key on the numeric keypad).
  16. Split the 3D window into two horizontal rows and change the upper row to a Node Editor window. Put the mouse cursor in the 3D view and press Shift + Z to set the Camera view mode to Rendered.
  17. Go to the Render window. Under the Sampling subpanel, set both the Clamp Direct and Clamp Indirect values to 1.000. Go to the Light Path subpanel and set the Filter Glossy value to 1.000.
  18. Set the Render samples to 25. The Rendered preview is shown in the following screenshot for your reference:
    Getting ready

    The prepared scene as it appears in the Rendered preview, with the rendering settings to the right

How to do it...

We have prepared the scene. Now let's start with the creation of the sand material using the following steps:

  1. Select the Plane and click on the New button in the Material window under the Properties panel or in the Node Editor toolbar. Rename the material Sand_01.
  2. Keeping the Shift key pressed, select the UV Sphere, the Cube, and for last one, the Plane (that is the active object of the multi-selection) by right-clicking on them. Press Ctrl + L, and in the Make Links pop-up menu, select the Material item to assign the same material to the other two objects. The Sand_01 material is now assigned to all three objects.
  3. In the Material window under the Properties panel to the right, switch the Diffuse BSDF shader with a Mix Shader node. In both the Shader slots, assign a Diffuse BSDF shader.
  4. In the Node Editor, add an RGB node (press Shift + A and navigate to Input | RGB) and an RGB Curves node (press Shift + A and navigate to Color | RGB Curves). Connect the output of the RGB node to the Color input socket of the first Diffuse BSDF shader and to the Color input socket of the RGB Curves node. Then connect the output of the RGB Curves node to the Color input socket of the second Diffuse BSDF shader node.
  5. Change the color values of the RGB node to 0.500 for R, 0.331 for G, and 0.143 for B. Click on the RGB Curves node window to create a new point, and set the coordinates to 0.48182 for X and 0.56875 for Y.
  6. Add a Noise Texture node (press Shift + A and navigate to Texture | Noise Texture), a Texture Coordinate node (press Shift + A and navigate to Input | Texture Coordinate), and a Mapping node (press Shift + A and navigate to Vector | Mapping).
  7. Connect the Object output of the Texture Coordinate node to the Vector input of the Mapping node, and then connect the Vector output to the Vector input of the Noise Texture node.
  8. Connect the Fac output of the Noise Texture node to the Fac input of the Mix Shader node. Increase the Detail value of the texture to 5.000.
  9. Press Shift + D to duplicate the Mix Shader node and paste it between the first Mix Shader node and the Material Output node. Add a Glossy BSDF shader node (press Shift + A and navigate to Shader | Glossy BSDF), set its Roughness to 0.700, and connect its output to the second Shader input socket of the second Mix Shader node. Set the Fac value to 0.100.
  10. Connect the Color output of the RGB node to the Color input socket of the Glossy BSDF shader node.
  11. Add a Frame (press Shift + A and navigate to Layout | Frame), press Shift and multi-select the RGB node, the RGB Curves node, the Noise Texture node, the two Diffuse BSDF nodes, the Glossy BSDF shader, the two Mix Shader nodes, and the Frame, and press Ctrl + P to parent them. In the Properties panel (press N key in the Node Editor window), label the Frame as SAND COLOR, as shown in the following screenshot:
    How to do it...

    The total vision of the SAND COLOR frame and the rendered effect on the objects

  12. Add a new Noise Texture node and a Wave Texture node (press Shift + A and navigate to Texture | ...). Select both and press Shift + D to duplicate them. Label them Wave Texture01, Wave Texture02, Noise Texture01, and Noise Texture02.
  13. Arrange the four texture nodes in a column like this: Wave Texture01, Noise Texture01, Noise Texture02, and Wave Texture02. Connect the Mapping output to the texture nodes' Vector input.
  14. Set the Scale value of Wave Texture01 to 3.000, Distortion to 25.000, and Detail to 10.000. Set the Detail value of Noise Texture01 to 10.000 and Distortion to 0.500. Set the Detail value of Noise Texture02 to 10.000 as well. Finally, set the Wave Texture02 node's Scale value to 25.000, Distortion to 15.000, and Detail Scale value to 5.000.
  15. Add a MixRGB node (press Shift + A and Color | MixRGB) and label it Mix01. Connect the Wave Texture01 node's Color output to the Color1 input and the Noise Texture01 node's Color output to the Color2 input.
  16. Select the MixRGB node and press Shift + D to duplicate it. Label it Mix02 and connect the Color output of the Mix01 node to the Color1 input of the Mix02 node. Then connect the Wave Texture02 node's Color output to its Color2 input.
  17. Connect the Color output of the Noise Texture02 node to the Fac input socket of the Mix02 node. Now the Node Editor window looks like what is shown in the following screenshot:
    How to do it...

    Building the bump pattern

  18. Add a Math node (press Shift + A and navigate to Converter | Math) and label it Bump_Strength. Change Operation to Multiply and connect the output of the Mix02 node to the first Value input socket. Set the second Value input socket's value to 1.000 and connect the node output to the Displacement input socket of the Material Output node, as shown in this screenshot:
    How to do it...

    The effect of the total output of the bump nodes connected to the Displacement input of the Material Output node

  19. Add a Hue/Saturation node (press Shift + A and navigate to Color | Hue/Saturation), label it Hue Saturation Value01, and drag it onto the link connecting the Noise Texture01 node to the Mix01 node to paste it in between. Set Value to 10.000.
  20. Press Shift + D to duplicate the Hue/Saturation node, label the duplicate Hue Saturation Value02, and drag it onto the link connecting the Wave Texture02 node to the Mix02 node. Set Value to 0.100.
  21. Press Shift + D to duplicate it again, name the duplicate Hue Saturation Value03, and drag it between the Mix02 node and the Bump Strength node. Set Value to 0.350. The following screenshot shows the effect of adding variation to the bump:
    How to do it...

    Adding variation to the bump pattern

  22. Add a Bright/Contrast node (press Shift + A and navigate to Color | Bright Contrast). Drag it so that it's pasted between the Noise Texture02 node and the Mix02 factor input. Set the Bright value to -0.250 and the Contrast value to 1.000.
  23. Add a Frame, press Shift (or box-select (press B key) these 11 nodes and then the Frame), and press Ctrl + P to parent them. Label the Frame SAND BUMP, as shown in the following screenshot:
    How to do it...

    The SAND BUMP frame containing all the bump nodes

  24. Select the Wave Texture02 node and press Shift + D to duplicate it twice (if the node is still parented to the SAND BUMP frame after duplication, press Alt + P to unparent it). Label them Wave Texture03 and Wave Texture04. Then duplicate the Bright/Contrast node twice and name the duplicates Bright/Contrast02 and Bright/Contrast03.
  25. Select one of the MixRGB nodes and press Shift + D to duplicate it. Set Blend Type (and the label) to Divide and the Factor to 1.000.
  26. Connect the Mapping vector output to the Vector input sockets of the two new wave textures.
  27. Connect each Color output of the two new wave textures to the respective Color input of the Bright/Contrast02 nodes. Then connect their color output to the Color1 and Color2 input of the Divide node.
  28. In the Wave Texture03 node, set Scale to 0.500, Distortion to 25.000, Detail to 10.000, and Detail Scale to 1.000. In the Bright/Contrast02 node, set the Bright value to 0.000 and the Contrast value to -0.800.
  29. In the Wave Texture04 node, set Scale to 1.000, Distortion to 10.000, Detail to 5.000, and Detail Scale to 1.000. In the respective Bright/Contrast03 node, set the Bright value to 0.000 and the Contrast value to -0.800.
  30. Add a Math node (press Shift + A and navigate to Converter | Math). Set Operation to Multiply, label it Multiply01, and leave the first Value as it is—the same as the Scale value of the Wave Texture03 node (0.500). Set the second Value to 1.000. Connect the Value output to the Scale input socket of the Wave Texture03 node.
  31. Press Shift + D to duplicate the Math node (label it Multiply02). Move it to the side of the Wave Texture04 node and set the first Value to be the same as the Scale value of the texture node (1.000). Set the second Value to 1.000 as well, and connect the Value output to the Scale input of the Wave Texture04 node.
  32. Add a Value node (press Shift + A and navigate to Input | Value). Connect the output to the second Value input sockets of both the Multiply-Math nodes. Label it Waves_size and set the input value to 1.000.
  33. Add a Frame, parent the last added nodes, and label it BIG WAVES, as shown in the following screenshot:
    How to do it...

    A new frame containing a new bump effect to be added to the previous one

  34. Duplicate the Bump_Strength node, unparent it from the SAND BUMP node, and set the Operation to Add. Drag it onto the link between the Bump_Strength node and the Material Output node, and label it Add_Bump01.
  35. Connect the Divide node output of BIG WAVES to the second Value input socket of the Add_Bump01 node, as shown in this screenshot:
    How to do it...

    The output of the two bump frames added together

  36. Duplicate a Noise Texture node (label it Noise Texture03), a Bright/Contrast node (label it Bright/Contrast04), and a Math node (label it Grain_Strength). Connect the Mapping output to the Vector input of the texture node. Then connect the Noise Texture node's Color output to the Bright/Contrast04 node's Color input and its output to the first Value input socket of the Grain_Strength node. Set its operation to Multiply and the second Value to 0.250.
  37. Set the texture Scale to 200.000, Detail to 1.000, and Distortion to 0.000. Set the Bright/Contrast04 node's Bright value to 0.000 and Contrast to 0.200.
  38. Add a Frame, parent the three nodes to it, and label it GRANULARITY, as shown in the following screenshot:
    How to do it...

    One more bump effect frame

  39. Duplicate the Add_Bump01 node, and label it Add_Bump02, and paste it between the Add_Bump01 node and the Material Output node. Connect the Grain_Strength output of the GRANULARITY frame to the second Value input socket of the Add_Bump02 node.
  40. Duplicate the Add_Bump02 node and paste it just before the Material Output node. label it TOTAL BUMP STRENGTH, set the node Operation to Multiply, and set the second Value to 0.500, as shown in this screenshot:
    How to do it...

    The GRANULARITY frame output added to the previous bump ones

So here we are now—the sand shader is complete, and this is how the nodes' network looks in the Node Editor window:

How to do it...

To obtain the image shown at the beginning of this recipe, we also added a few elements to the scene:

  • A new Cube primitive, with a simple diffuse pure white material, added just for reference to light intensity.
  • An Ico Sphere primitive, set as invisible and disabled for the rendering in Outliner. It works as target Object for a Boolean modifier assigned to the sand Cube and is placed in the stack between the Subdivision Surface and Smooth modifiers, as shown in the following screenshot:
    How to do it...

How it works...

The concept behind the structure of this material is basically the same as that for the procedural rock, and it can be subdivided into stages as well:

  • From step 1 to step 10, we built the color part of the shader, blending two differently colored Diffuse BSDF nodes on the ground of a Noise Texture factor, and building a basic shader with the Glossy BSDF component.
  • From step 12 to step 22, we built the main bump effect, this time piped directly as whole in the Displacement input of the Material Output node rather than to the Normal input sockets per shader.
  • From step 24 to step 32, we built a supplementary bump effect, this time to simulate the big waves you usually see on a desert's sand dunes. This effect was left apart from the main bump to be easily reduced or eliminated if required. Then we added two Math nodes set to Multiply and driven by a Value node to automatically set the size of the big sand waves. Actually, this is more a repeating effect, and the bigger the value, the smaller and closer the waves.
  • In steps 36 and 37, we built a last bump effect to add the sand grain if necessary, for example, for objects very close to the camera. In steps 39 and 40, we summed all the bump effects, to be driven by the last Math node value.

Every stage has been framed and properly labeled to make it more easily readable in the Node Editor window.

There's more...

One more thing we can do to improve this material is combine everything into a handy group node, at the same time leaving the fundamental values to be tweaked exposed on the node group interface. To do this follow these steps:

  1. Put the mouse cursor in the Node Editor window and press the B key. Two horizontal and a vertical lines appear at the location of the mouse cursor. Click and drag the mouse to encompass the framed nodes, leaving outside only the Texture Coordinate node, the Mapping node, and the Material Output nodes. After the mouse button is released, everything you encompassed is selected.
  2. Press Ctrl + G and create the group. Then press N in the Node Editor window to call the Properties panel on the right side.
    There's more...

    The previous sand material network inside a node group

  3. Press Tab to go out of Edit Mode. Then click on the little window on the interface to change the name from NodeGroup to Sand_Group.
    There's more...

    The closed node group

As you can see, inside the group, the Group Input node collects all the Vector sockets from which the various texture nodes take their mapping coordinates, so we now have eight Vector sockets in the outer interface, all connected to the same Object output of the Mapping node. However, we need only one Vector input to map all the textures inside the group, so let's perform the following steps:

  1. Press Tab to go to Edit Mode again and deselect everything by pressing the A key.
  2. Select the first bottom Vector output by clicking on the list of names in the little Inputs window under the Properties/Interface panel. Delete the corresponding Vector socket from the Group Input node by clicking on the X icon to the side of the newly appeared Name slot. Then click on the X icon again, and go on like this to delete all the Vector sockets except the last socket at the top of the list as shown in the following screenshot:
    There's more...
  3. Now press Shift, select the Group Input node and the first texture node, and press F to automatically connect them.
  4. Repeat to connect all the eight texture nodes to the Vector socket of the Group Input node.

Now we need to expose some of the values to modify the material from the interface, so let's perform the following steps:

  1. From the second Value socket of the Bump_Strength node inside the SAND BUMP frame, click and drag a link to the bottom free socket in the Group Input node. In the Input window under the Properties panel, double-click on the newly appeared input socket name, Value, and write Sand_strength.
    There's more...

    All the Vector input sockets of the nodes are connected to a single socket on the Group Input node, and the Bump Strength value is exposed by a new connection

  2. Repeat step 1 for the second Value socket of the Waves_Strength and the Grain_Strength nodes, and rename the respective input as Waves_strength and Granularity.
  3. Now click on the Waves_size node inside the BIG WAVES frame and delete it. Click and drag the second Value socket of the Multiply01 node to the Group Input node, and rename the new socket Waves_size. Click and drag a link from the second Value socket of the Multiply02 node, and connect it to the Waves_size socket as well.
  4. We also need to expose the second Value socket of the TOTAL BUMP STRENGTH frame. Rename the new socket on the interface as Total strength. This is in fact the value for the overall bump of the material.
  5. After this, we can do the following: expose the color input by deleting the RGB node in the SAND COLOR frame and connecting the Color input sockets of the Diffuse BSDF, RGB Curves, and Glossy BSDF shader node's to the Color socket on the Group Input node; expose the sand's grain size value, connecting the Scale input socket of the Noise Texture03 node to a Grain_size socket; and finally, by clicking on the arrows in the Properties panel, order the position of the input sockets on the Group Input node as shown in this screenshot:
    There's more...

    The sockets created on the Group Input node and reflected in the Interface subpanel

  6. Press Tab to close the group. On the interface, we now have the controls to increase or decrease the overall bump effect, the sand color and grain, the wave strength, and scale/repetition, as we can see in the following screenshot:
    There's more...

    The final Sand_Group node with all the exposed input on its interface

The group is now available under the Add menu, and its shortcut involves pressing Shift + A and navigating to Group | Sand_Group. It can be reused for other materials in the same scene and also with different interface values, or linked/appended from a library in other blend files.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.148.180