Creating tree shaders – the bark

There are several different ways to make trees in a 3D package: starting from the simpler low-poly objects, such as the billboards used in video games (simple planes mapped with tree images on a transparent background), to middle complex objects where a trunk mesh is attached to a foliage mass made of little alpha textured planes, each one representing a leaf or even a twig, to more complex and heavy meshes, where every little branch and leaf is actually modeled.

In case you need them, you can find several free tree models in the Blender format and also their billboard versions at http://yorik.uncreated.net/greenhouse.html.

For this two-part tree shader recipe, we will instead use a model coming from the many environment assets of the CG short Big Buck Bunny, the second open movie produced by the Blender Foundation. All the movie assets are free to be downloaded, distributed, and reused even for commercial projects because the short is licensed under the Creative Commons Attribution 3.0 license (refer to its official website at http://creativecommons.org/licenses/by/3.0/).

The general shape of the tree and the leaves is pretty toyish. This is because they are elements that have been drawn to match the toon style of the furry characters, but it's actually perfectly suited for our demonstration purposes. The final rendered tree from Big Buck Bunny is shown in the following screenshot for your reference:

Creating tree shaders – the bark

The final rendered tree from Big Buck Bunny

The tree model is composed of several parts: on the first layer, there are the tree_trunk, the tree_branch, and the tree_branches meshes, and on the second layer are the leaves, made by a single leaf object dupliverted on the tiny faces of the leaves_dupli object. (That is, the leaf_tobeswitched object is parented to the leaves_dupli object, and then, in the Object window and under the Duplication subpanel, the Faces duplication method has been selected, the Scale item checked, and the Inherit Scale value set to 1110.000. This way, the leaf_tobeswitched object is instanced on the leaves_dupli object's many faces according to their location, rotation, and scale.)

On the 11th layer, there are three leaf objects with three different levels of detail: a simple flat Plane, a subdivided and curved Plane, and a modeled leaf. Their presence is only to supply the low, middle, and high resolution mesh data. By selecting the leaf_tobeswitched object and by going to the Object data window, it is possible to switch between the leaf_generic_low, leaf_generic_mid, and leaf_generic_hi foliage levels of detail.

In the first part of this two-part recipe, we will create the material for the bark, as shown in the following screenshot:

Creating tree shaders – the bark

The bark material

Getting ready

Start Blender and open the 9931OS_08_tree_start.blend file. For this recipe, deactivate the second layer, and in Outliner, select the tree_trunk object.

How to do it...

Let's start by creating the bark material using the following steps:

  1. Click on the New button in the Node Editor window toolbar or in the Material window, and rename the material as bark.
  2. Still in the Material window, switch the Diffuse BSDF shader with a Mix Shader node, and label it as Mix Shader_bark1. In the first Shader slot, select a Diffuse BSDF shader node, and in the second one, select a Glossy BSDF shader node; then, label them as Diffuse_bark1 and Glossy_bark1. Set the Glossy_bark distribution to Beckmann, the Roughness value to 0.800, and the Mix Shader_bark1 node's Fac value to 0.200.
  3. Add a Texture Coordinate node (press Shift + A and navigate to Input | Texture Coordinate), a Mapping node (press Shift + A and navigate to Vector | Mapping), and an Image Texture node (press Shift + A and navigate to Texture | Image Texture); label the last two as Mapping1 and Bark_color1.
  4. Connect the UV output of the Texture Coordinate node to the Vector input socket of the Mapping1 node, and the output of this node to the Vector input socket of the Bark_color1 node. Connect the Color output of the Bark_color1 node to the Color input sockets of both the Diffuse_bark1 and Glossy_bark1 shader nodes.
  5. Click on the Open button of the Bark_color1 node, browse to the textures folder, and load the bark_color_tile.png image.
  6. Press Shift + D to duplicate the Bark_color1 node, label it as Bark_normal1, and connect the Mapping1 node output to its Vector input socket. Make the image datablock single-user by clicking on 2, which appears on the right side of the image name. Click on the Open Image button (the one with the folder icon), browse again to the textures folder, and load the bark_norm_tile.png image. Set Color Space to Non-Color Data.
  7. Add a Normal Map node (press Shift + A and navigate to Vector | Normal Map), label it as Normal Map1, and connect the Color output of the Bark_normal1 node to the Color input socket of the Normal Map1 node, and then set the Strength value to 2.000. Click on the UV Map for tangent space maps button upwards of the Strength one and select UVMap (the trunk mesh has two different sets of UV coordinates, which we'll see later).
  8. Connect the Normal output of the Normal Map1 node to the Normal input sockets of both the Diffuse_bark1 and the Glossy_bark1 shader nodes, as shown in the following screenshot:
    How to do it...

    The basic bark material that uses a normal map

  9. Now, box-select (press the B key and then draw a rectangle) all the nodes except for the Texture Coordinate and Material Output nodes and press Shift + D duplicate them. Move them down and change their labels by substituting the 1 suffix with 2. Connect the UV output of the Texture Coordinate node to the Vector input socket of the duplicated Mapping2 node, and set the Scale of this node to 0.350 for all three axes.
  10. Add a Mix Shader node (press Shift + A and navigate to Shader | Mix Shader), label it as Mix Shader_bark3, and paste it right before the Material Output node. Connect the output of the Mix Shader_bark2 node to the second Shader input socket of the Mix Shader_bark3 node.
  11. Add a Noise Texture node (press Shift + A and navigate to Texture | Noise Texture), connect the UV output of the Texture Coordinate node to the Vector input socket of the Noise Texture node, and connect the Fac output of this node to the Fac input socket of the Mix Shader_bark3 node.
  12. Set the Noise Texture node's Scale value to 15.000, as shown in the following screenshot:
    How to do it...

    Making the bark material a bit more complex

  13. Now, press Shift and select the tree_branch and tree_branches meshes, and as the last one, reselect the tree_trunk mesh to make it the active object; then, press Ctrl + L. In the Make Links pop-up menu, select the Materials item to assign the bark material to the other two meshes.

How it works...

  • For this material, we built a simple shader using two tileable image maps, a color one for the Diffuse and the Glossy components, and a normal map for the bump.
  • Then, we duplicated everything and mixed the second material copy with different scale values to the first one by the factor of a Noise procedural texture, to add variety to the bark pattern and to avoid that unpleasant repeating effect that often shows up with tileable image textures.

There's more...

At this point, if you look carefully at the Rendered view of the tree trunk, you'll see that sadly, there are ugly seams where the trunk's main body joins the big low branches as shown in the following screenshot:

There's more...

The visible seams at the branches joining

This is due to the fact that the unwrap of the mesh has separated the branches' UV islands from the main trunk ones. Although the effect can be barely visible, let's say that you absolutely want to avoid this; that's why we are now going to see a solution for the problem, by using a second set of UV coordinates and a Vertex Color layer.

This is what we are going to do:

  1. Select the trunk mesh and go into the Vertex Paint mode; the mesh turns totally white, because that is the color assigned to the vertexes by default. Start to paint with pure black on the vertexes located at the joining of the low branches with the trunk, achieving this result:
    There's more...

    The trunk model seen in the Vertex Paint mode

  2. As you can see, the joining vertices edge loops are black but are smoothly blending into the white of the default mesh vertex color. This will be used as a stencil map to blend two different instances of the same bark material mapped on different UV coordinates. Go to the Object data window and rename the Vertex Color layer as Join_branches.
  3. Switch to Edit Mode and select all the faces including the necessary vertices' edge loops; in the Object data window, under the UV Maps subpanel, click on the + icon (add UV Map) and rename the new UV coordinates layer as UVMap2. Place the mouse cursor on the 3D viewport, press U, and select Unwrap in the UV Mapping pop-up menu, as shown in the following screenshot:
    There's more...

    The trunk model in Edit Mode and the UV islands in the UV/Image Editor window

  4. Go out of Edit Mode. Click on the user number to the right of the material data block in the Node Editor window toolbar and rename the new material as bark_seamless.

    Now, by looking at the following screenshot, it is clear what we have to do:

    There's more...

    Two identical bark materials mapped on different UV layers and mixed on the ground of the Vertex Paint output

  5. Make a duplicate of the bark material and blend the two shaders (inside the BARK_A and BARK_B frames respectively) using a Mix Shader node, modulated by the Join_branches vertex color stencil. Use an Attribute node both for the Vertex Color layer output and to set the UVMap2 coordinates layer for the copy of the bark material. Now, the output looks similar to what is shown in the following screenshot:
    There's more...

    The final result: no more seams

As you can see in the preceding screenshot, there are no more visible seams; the two differently UV mapped materials smoothly blend together.

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

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