Showing posts with label Nodes. Show all posts
Showing posts with label Nodes. Show all posts

Lesson 13: Node Compositing: Depth of Field

Rearrange your Desktop

Let's move a few things around to get ready for our composite render. From the top (Numpad7) move things to look like this:
Try and get the camera located so your view is close to this (I am using a 50 MM lens on mine):

Changing Our Focus

In order to simulate depth of field in Blender, we need to establish a focal distance. Just as with a real camera, objects that fall within the depth of field area will be in sharp focus while those closer or father away will be blurred. We need to tell our camera where the focal distance is. We need an object to focus on.

We do this with an empty object. In Object Mode, add an empty (Add>Empty). Scale the empty up a bit.a In the Link and Materials tab, change the name in the 'OB:' box to 'FOCUS'. Move the empty to near where the label appears on the pencil. We want our label to be readable:
Now we need to tell our camera which object to focus on. In Object Mode, select the camera. In the Camera tab, in the box labeled 'DofOb:', type 'FOCUS'. Now our camera knows where our depth of field lies.

Compositing Nodes

Split the editing window and make one of the split a Node Editing window. A the bottom of the new window is a button with a face icon on it. Click it and then click the Use Nodes button. A Render Layer node and a Composite Node appear:
TIP:
At this point you can save yourself a lot of time by selecting the Scene button and in the Format tab, click the button labeled 'Preview'.

Press F12 to render your scene and select '1 RenderLayer' in the Render Layer Node (I grabbed the bottom right corner of the Composite Node and expanded it):
Now we'll add a Defocus Node (Add>Filter>Defocus). Place it between the other two nodes. Connect the Render Layer Image and Z outputs to the Defocus Image and Z inputs. Connect the Defocus Node Image output to the Composite Node Image input:
As shown above, deselect the 'No zbuffer' button and set the fStop to 1.20. Select the Scene button and in the Anim tab, select the 'Do Composite' button. Render your scene:
That's kind of cool, I guess, but the blurred parts are horribly fuzzy looking!Let's fix that. In the Defocus Node you will find a button labeled 'Preview'. De-select it and render again:
Whoa... now that looks like the real thing! Notice that the tip of the pencil and the eraser are out of focus while the label area is perfectly sharp. We can tweak the look of our rendered image using some of the other settings in the defocus node. We can set the depth of the area of focus by adjusting the fStop number. The larger the number, the deeper the area that is in focus. To demonstrate, change the fStop to 2.5 and re-render:
Now the depth of the sharp area of the camera range encompasses the entire pencil, while the cup is blurred. We can also force the blur to become stronger by using the Maxblur setting. Set the fStop to 1.20 again and set Maxblur to 20. The result:
Finally set the Maxblur back to 0. Let do a full-size, high quality render to we can see how our image is shaping up. Select the Scene button. In the Render tab, under the OSA button, click the button labeled 16. In the Format tab, click the 'FULL' button. Render your scene (this WILL be slow):

Lesson 10: More Nodes: The Pencil Label

Look for the Union Label

Now we are going to use nodes once again. To get started, split the Editing window and change one side to a UV/Imaging window (See Lesson 6).

Numpad7 to the top view and make sure your are not in perspective view (Numpad5 to toggle). Select the pencil and tab to edit mode. Select the top face of the pencil shaft and press 'u' to unwrap it and select 'Project from View' from the menu. A yellow box will appear over the grid in your UV window. Press 's' and scale it up until it fills the grid from top to bottom:
Select Image>New in the UV window to create a new map image. Even though our box is showing as a yellow outline in Blender, the image is blank. If we save the image now, it will be blank and we will have no way to know where our lettering should go when we open it in image editing software to add text. Blender provides a way to create a 2D image from a 3D image called Baking render meshes. We are going to do some baking, baby!

Baking Render Meshes

The process of mesh baking is easy to do and hard to understand. Since we have a surface unwrapped and an image to bake to, let's bake. From the 'Render' menu, choose 'Bake Render Meshes>Texture Only'. When blender is done working, it will have rendered your texture in the box in the UV window! Now we know where to put our text on our image:
How to Use a Baked Image

Now you can do an 'Image>Save as' and save this image outside Blender. From there you can do editing in any image editor that supports layers (Photoshop, GIMP, etc.) and add your label text. When you are finished with your image it should be white text over a black background. Kind of like on real baking shows, in the next section I am going to pull a 'finished cake' out of another oven.

Mapping the Label Image with Nodes

In the previous section we discussed baking and exporting an image to use as a map. Here is the map I came up with using that method (If you want to use it, click it and open the full size image and save that):
To use my image (or your own for that matter) in the UV Window, click Image>Open and browse to the image you want to use. I will appear under your yellow box. Scoot the box around until it fits well:
Nodes Again

No we can move on to our nodes. With same face selected, go select the Editor button and in the Links and Materials tab add a new material. Click the 'Assign' button.

Select to the Shading and Materials buttons. Rename the material 'PENCILMAP'. In the texture tab, clear all textures. Now click 'Add New' in the Texture tab and name the new texture 'PENCILMAP'.

Select the Texture button (leopard skin). Select image as the texture type and load the image of your label map.

Select the Materials button. In the Map Input tab, select the UV button.

Now we are going to edit the nodes. change the UV window to a Node Editor window. In the Links and Pipeline tab, click the 'Nodes' button. The node editor will show a Material and an Output node.

Set the Material Node material to 'YELLOW'. Press Shift + 'd' to duplicate the node. Set this new material node to material 'SILVER'. Here's how it should look:
Now add a Mix node (Add>Color>Mix). Connect the color outputs of the Material Nodes to the color inputs of the Mix node. Connect the color output of the Mix Node to the color input of the Output Node, like so:
Now add a Texture node (Add>Input>Texture). Select 'PENCILMAP' as the texture. Connect the color output to the Fac input on the Mix node:
Now add a Geometry node (Add>Input>Geometry). Connect the UV output to the Vector input of the Texture Node:
I can tell by looking at the Output Node preview that the materials are reversed, so swap the color inputs to the mix node. Also connect the Normal output of the Texture Node to the Normal input of the SILVER Material node:
Let's give her a render and see how she looks:

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.