Lesson 6: Using Material Nodes - The Coffee Ring

A Stain on the Plane

When I was building this scene, I was looking around my desk for inspiration. The coffee cup is, of course, ubiquitous. And what respectable desk doesn't have a coffee ring? It just so happens that the coffee ring is a perfect lesson in material node editing.

Multiple Materials

Each object can have more than one material assigned to it. Right now, the plane that represents our desktop has the material "BEECH" assigned to it. We are about to assign a second material that represents coffee spills. Again, if you need a refresher in basic material assignment and texturing, see Lesson 2 in this series.

Let's assign a second material to our desktop plane. Select the desktop in object mode and follow these steps:
  1. Click the Editing button
  2. In the links and materials tab, click the new material button (highlighted below):
  3. You will notice that the material spinner above the new button now reads "2 Mat 2". This means that the object references two materials. Blender automatically named the new material "BEECH.001"
Now click on the Shaders and then the Materials buttons:
In the Link to Object tab, rename the new material "COFFEE". In the Texture tab, select each of the copies of "BEECH" and click the clear button. Now that our material doesn't look like beech wood anymore, let's try and make it look like coffee. Follow these steps:
  1. In the Materials tab, click the topmost color bar and set the color to Hex 4F3D11, brown.
  2. In the Shaders tab: Spec. = 1.2; Hard = 511
  3. In the Mirror Trans tab click the Ray Mirror button and set: RayMir = .35; Gloss=1
  4. Click the Ray Transp button and set: IOR:1.3
  5. Back in the Materials tab set the A (Alpha) slider to .790
We now have a brown, transparent, reflective material which will simulate coffee. To assign this material to the desktop and see how it looks, follow these steps:
  1. Click the Editing button:
  2. Press tab to enter Edit Mode.
  3. In the Link and Materials tab, press the Assign button (highlighted below):
Press F12 and we find our cup floating on a puddle of coffee (with cream I would say)!


Creating a Node Map Using the UV Editor

Now we have two materials associated with our desktop - beech wood and wet coffee. What we need is a way to tell the plane which parts are covered with beech and which parts are covered with coffee. That's where nodes come in.

The first thing we need to do is create a map that tells the coffee where we want it to be. I want there to be a coffee ring partially under the cup, so I have to find a way to make that happen. UV Unwrapping comes to the rescue!

To begin the UV Unwrap, we need to split the editing screen in half. Hover your mouse at the top of the editing window, just below the menu bar, until the cursor changes to an up-down arrow. Right-click and choose Split Area from the pop-up menu. Drag the new window to about 1/2 the width of the editing window. In the bottom left-hand corner of the new window, click the drop-down button and select UV/Image Editor. Your screen should look like this:


With the desktop plane selected, tab into edit mode. Press 'u', and select Unwrap from the menu. You will notice that the grid in the UV Editor window will be enclosed by a yellow box. The space within the grid represents the face of our plane! So what?

Now we need to make an image to place the map on. In the menu bar at the bottom of the UV Editing window, click on Image>New. For what we are doing, the default image size is OK, so just click OK. You will notice that you can no longer see the grid in the UV Editor - that's because it is covered by the image we just created.

Now we need to see in our model in real-time the changes we are making in the image editor. We need to be able to see where we are putting our coffee ring. Go to the viewport shading button and select textured:
Now you will notice that the desktop has turned black as well. That is because it is using the image in the UV Editor as a texture! Now we will use the built in image editor to help us locate the coffee ring on the desk. Near the bottom right corner of the image editing window is a button with a pencil icon on it called "Enable image painting" - click it. In the image editor window, click the View>Paint Tool. You are ready to start painting your desktop.

Start drawing circles using the brush tool in the Image Painter. Keep drawing circles until you get one in the spot you want, offset from the cup a little bit. You may have to keep trying for a little bit until you get it where you want it. Here's what it looked like when I tried it:
Once you get a circle roughly the right size and location, switch the brush function from 'Mix' to 'Subtract' and erase the circles you don't want. You now have two choices; you can either try to do the image editing in Blender, or select Image>Save as and save the image to be edited in an external editor. I saved the image and opened it in Photoshop, created a new layer and drew a more accurate circle in the correct location and saved the image again. Here's what mine looked like in the image editor after I reloaded it:
If you did your editing internal to blender, be sure to do an Image>Save as to save your image. We are now done with the UV Editor window, so we can close it up. You can also change the viewport shading back to solid (leaving it in textured mode slows down the redraws).

Assigning Our Image Map as a Material

This is going to get a bit rough, so hang with me here. Nodes are one of the hardest things to understand in Blender, but also one of the most powerful features.

As you will remember, we have two materials assigned to our desktop, and we are about to add a third. The third one will be the image map we just made. Here we go...

In Object Mode, with the plane selected, click the Editor button again to get to the Link and Materials tab. As we did before, click the new button for materials in Link and Materials and another material will be added to your plane ('3 Mat 3'). Once again click the Materials and then the Shaders buttons. Change the name of the material to 'COFFEEMAP' or something like that.

Go to the Texture tab and click Add New. Type a name like 'COFFEEIMGMAP' and click the Texture button (leopard skin). Select 'Image' from the Texture Type drop-down and in the Image tab, click 'Load' and browse to the map image we made in the previous section.

Click the Material Button again and in the Map Input tab, change sizeX, sizeY and sizeZ to 1. At the top of the box select the button labeled UV. Finally go back to the Editor button, tab into Edit Mode, select the new material (3 Mat 3) and assign it to the plane.

Let me briefly describe what we have done. We added another material to the plane and made the texture for that material the map image we just completed. We scaled it 1 to 1 and told Blender that the texture is to be mapped to the surface (UV). Finally we assigned it as the texture for the plane. Did you get all that? After you do it two or three times you will be able to remember.

Bring on the Nodes

Now that we have all of our materials assigned to the plane, we can start editing the nodes. To do so, we need to once again split the screen (or change the UV Editor window) and select the Node Editor window as our second window.

TIP:

To make connection between nodes, left-click on the output nodule you want to connect and with the mouse button down, drag the connection to the input nodule you want to connect to. To erase a connect, left-click near the connection you want to erase and drag a window over it. Release the mouse button and it will disappear.

With the desktop plane selected, click the Shaders and then the Materials buttons. To the right of the material name (which should be 'COFFEEMAP') is a button called Nodes - click it. The Node Editor comes to life with two nodes - a material node and an output node:
Click the material node and use the drop down to select the 'BEECH' material. Now press Shift + 'd' to duplicate it and drag it to the side. Change the material type in this second node to 'COFFEE'. It should look something like this:
Now we need to add a mix node. With your mouse over the Node Editor window, right-click and select Add>Color>Mix. Place the mix node between the material nodes and the output node. From the yellow color output of each Material node, drag a connection to the two color inputs of the Mix node. Form the yellow color output of the Mix Node, drag a connection to the color input of the Output Node. The nodes should now look like this:

Now right-click the Node Editor window once again and select Add>Input>Texture. Place the Texture Node to the left of the Material Nodes. Select the 'COFFEEMAP' texture in the drop- down. Drag a connection from the yellow color output of the Texture Node to the Fac Input Node of the Mix Node, like so:

Lastly, right-click in the Node Editor window one more time and select Add>Input>Geometry. Place the Geometry Node to the left of the Texture Node. Drag a connection from the UV output of the Geometry Node to the Vector input of the Texture Node. Your finished nodes should look like this:

Now press F12 to render your scene. If you find that your materials are mapped in reverse, meaning that the desktop looks like coffee with wood stains on it, simply swap the color inputs on the Mix Node. Your rendering should look something like this:

Viewed from another angle, it looks like this:

Now you have a rudimentary understanding of material nodes. Don't be afraid to play with things until you get it to look just the way you want it. Experimentation will lead to all kinds of discovery! In our next lesson, we will make the pencil.

No comments:

Post a Comment