Join my Blender 3D forum, where you can network with other Blender friends and get your Blender 3D questions answered.
Hi. The eye naturally focuses on sharper objects in a scene and tends to overlook blurred objects. Depth of Field (DOF) is a technique in which you highlight objects in focus, giving them the illusion of being closer to the camera, and blur out the parts of the scene that are not as important. You can use this to force your viewers to focus on the objects you consider important. Using Blender's composite nodes, with some mathematical trickery, you can set up Depth of Field.
So let's get started. Fire up Blender, delete the default cube (Right Click, Delete key, and Enter to confirm). Add the monkey mesh (Space - Add - Mesh - Monkey). Let's make the monkey green. Press F5 (Shading). Then click Add New to add a new material. Set R=0, G=1, and B=0. Go to the Edit buttons (F9). Press the Set Smooth button to make Suzanne more presentable.
Let's make more Suzannes. Click the Modifier button, at the extreme right. Add an Array Modifier. Make sure Relative Offset is clicked. Set X= -1, Y=0, and Z=0. Set Count = 8. Press F12 to render. We now have 8 monkeys, each a bit farther away from the camera than the previous one. The last two monkeys are out of camera range. To fix this, press N to bring up the Transform Properties window. Set LocX to 3. Now there are 8 monkeys in camera range.
Suppose we want our viewers to focus on the first monkey and gradually blur the rest of them as they get further from the camera. We can achieve this effect with Composite Nodes. To do this, change the window type of the 3D Viewport to Node Editor. We start out with two nodes. The input Render Layers node is our original scene before the composite node magic is applied. The output Composite node is the final, composited result. Move the Composite node all the way to the right.
Add a Map Value node (Space - Add - Vector - Map Value). Map Value takes information and maps it into a range of values. Map Value can also add a number (the Offset), as well as multiply by a number (the Scale) from the input. We're going to play with the offset and scale in a minute. In this case, we are going to map the Z value, which is the distance, in Blender Units, of each pixel, from the camera. Connect the Z socket of the Render Layers node to the Value socket of the Map Value node.
Next, add a Color Ramp node (Space - Add - Converter - ColorRamp). The color ramp gives us a visual representation of the Z values, with values from 0 (black) to 1 (white), Connect the Map Value's Value socket to the Factor socket of the Color Ramp node. Then, connect the ColorRamp image socket to the Composite Node image socket.
Right now the compositor shows all white. That's because all the monkeys map to a value of 1 or greater. The first monkey is about 5 Blender Units from the camera. With this mapping, the monkeys all map to white.
However, if we adjust the offset to -6 and the Size to .1, we get an interesting falloff from black to white. What happens is that for distances between 6 and 16 Blender units, we map a value between 0 and 1. Here's an example. Take a pixel at 10 Blender Units from the camera. First subtract 6, to get 4, then multiply 4 by .1, yielding a value of .4, which maps to a grayish color 40% between black and white. Any Z distance less than 6 produces black. A value greater than 16 produces white. We can translate this falloff into a gradual blurring.
To do this, add a Blur node (Space - Add - Filter - Blur). Connect the Image socket of the Render Layer node to the Image socket of the Blur node. That will feed the original scene to the blur node. Then, connect the Image socket of the ColorRamp node to the Size socket of the Blur node, feeding the adjusted Z values to the Blur node. Connect the Image socket of the Blur node to the Image socket of the Composite node.
You need to fiddle around with the X and Y values in the blur node to set up the exact amount of blur falloff. I found that X=6 and Y=6 worked well for focusing on the first monkey and gradually fading out the others.
We're ready to render. Go to the scene buttons (F10). Press the Do Composite button to tell the Renderer that we are using composite nodes. Press F12 to render. You should get the depth of field effect we're aiming for.
That's it. I hope this gives you some interesting ideas for highlighting objects in your scene using depth of field. Happy Blendering!
This blog contains the scripts for my Blender 3D YouTube videos. They're published as follows:
Buy The Blender 3D Cookbook as a book!
Buy the Blender 3D Cookbook for your iPad!
Buy the Blender 3D Cookbook for your Kindle!
Showing posts with label composite. Show all posts
Showing posts with label composite. Show all posts
Thursday, November 12, 2009
Friday, November 6, 2009
2.49b Composite Nodes
Nodes are a powerful Blender feature, allowing you to change how your scene renders, to combine images and videos, and to do many types of special effects. Compositing is a critical part of the video production process. The purpose of this video is to make you comfortable moving around in the Node Editor and to introduce a some basic image effects.
Let's delete the default cube and have fun with Suzanne. So highlight the cube (right click), press X to delete and Enter to confirm. Then add Suzanne (space-add-mesh-monkey). Press F9 to go to the Edit buttons. Press the Set Smooth button to make her look a bit more presentable. Add a red material by pressing F5 (Shading), then the Add New button to add a new material. Set the R to 1, the G to 0, and the B to 0.
To set up node based rendering, press F10 to go to the Scene buttons. In the Anim panel, press the Do Composite button. When you do this, instead of the scene rendering, the result of your composite node processing renders when you press F12.

To go to the Node Editor, change the View type to Node Editor. Blender supports material nodes and texture nodes as well as composite nodes. To enable Composite Nodes, click the Face icon. Then, click on the Use Nodes button.

Two puzzling rectangular objects display. On the left is the Render Layers node. On the right is the Composite node. You can resize a node by clicking on the lower right part of the node and dragging. The nodes are connected by a black wire, from the yellow Image button on the right side of the Render Layer node to the yellow Image button on the left side of the Composite node. What's going on?
Composite nodes really have three types, Input, Output, and different types of things you might do to the input before you render the output. Think of compositing as similar to going to the barber shop. Your head, before you get your haircut, with unshaven and with unkempt hair, is the input. The barber can do a number of things - give you a shave, wash your hair, cut it short, and so on. These are like processing nodes. The end result - the output - ends up in the Composite Node. The first big rule of compositing is: There Can Only Be One Composite Node.
The Render Layers node is the input - your scene before anything is done with it. The Composite node is the result. Node setups can get very confusing. The easiest way to set them up is to place the input nodes (there can be more than one, because we might combine things, such as a scene with an image), on the far left, and the output node, the Composite node, to the right. The processing nodes are in the middle, best placed in logical order from left to right.
Move the Composite node all the way to the right. Moving is similar to moving in the 3D window. Press the Right arrow key to select the Composite node, then drag it all the way to the right. The wire follows along.

Press F12 to render. Suzanne renders as if there was no compositing active. You also see a thumbnail of the rendered scene both in the Render Layers node and the Composite node. That's because this is like walking into the barber shop, seeing the long line, and walking out. Nothing was done.
OK. Let's do some stuff to Suzanne. How about making her 3 times bigger? Easy. Instead of going back to the 3D view and scaling her up, you can do it in the Node editor. Add a Scale Node (Space - Add - Distort - Scale). Nothing happens yet. You need to connect the wires. To do this, connect the Image socket (that's the yellow Image dot) on the right side of the Render Layers node to the Image socket on the left side of the Scale node. This tells the Node editor to pump the scene, with Suzanne, into the Scale node. Set the X and Y values to 3, to indicate how large to scale Suzanne.
Next, connect the Image socket on the right side of the Scale node to the Image socket on the left side of the Composite node. This tells the Node editor to take the new, larger Suzanne, and add it as input to the Composite node. Look at the image on the Composite node. It already shows the bigger Suzanne. If you press F12 to render, Suzanne also renders larger.

That's a good start. How about flipping her upside down? Easy. Add a Flip node (Space - Add - Distort - Flip). Connect the Image socket on the right side of the Scale node to the Image socket on the left side of the Flip node. From the dropdown, select Flip X & Y. Now connect the Image socket on the right side of the Flip node with the Image socket on the left side of the Composite node.

The path is clear. Suzanne is scaled and then flipped. You can see each step. By the way, the 3D view hasn't changed. Suzanne is still her old self. Change to 3D view, look, and change back to the Node editor.
The Viewer node, another type of output node, lets you view Suzanne's progress. To add a Viewer node, press Space - Add - Output - Viewer. Automatically, the Viewer node is connected, via the Image socket, to the last node selected. A handy button is the Use Backdrop button, which displays the most recently selected Viewer node. You see Suzanne both scaled and flipped.

We can see Suzanne after she was scaled but before she was flipped. To do that, cut the connection between the Flip node and the Viewer node by pressing the left mouse button and dragging across the wire. Then, connect the output Image socket of the Scale node to the input Image socket of the Viewer node. Now Suzanne is scaled but unflipped.

Click the Backdrop button to get the regular background. Let's blur Suzanne, giving the illusion of fuzziness. Blur is a filter node. So press Space - Add - Filter - Blur. Connect the Image socket on the right side of the Flip node to the Image socket on the left side of the Blur node. Set X and Y to 10, specifying the blur amounts. Then connect the Image socket on the right side of the Blur node with the Composite node's image socket. Click the Backdrop button.

Now let's make Suzanne black and white. Add a Converter node to do that (Space - Add - Converter - RGB to BW). Convert the Image socket on the right of the Blur node to the Composite Node image socket.

Many of the keys you are familiar with in navigating the 3D window work in the node editor. Right click selects a node. Shift Right click on another node extends it. X deletes the selected nodes. Control-Z corrects your error.
You can group nodes when you have a lot of them. Let's say you really like to scale, flip, blur, and make objects black and white. You can create a group out of these nodes. Select all of them press Control-G. You've created a nice node group, cleaning up the diagram a lot. Node groups can be copied and even exported to another blend file, which is nice because you won't have to redo all those steps each time. The tab key shows the nodes in the group. If you change your mind, Alt-G undoes the grouping.

To summarize, we've enlarged Suzanne 3 times, flipped her over, blurred her, and got rid of her red color - all without touching the underlying 3D view, which you can see in the Render Layers node. This just scratches the surface. I hope this gives you a good start on compositing nodes in Blender. Happy Blendering!
Labels:
2.49b,
3d,
blender,
cg,
composite,
compositing,
computer graphics,
nodes,
Video Tutorial
Subscribe to:
Posts (Atom)