Showing posts with label compositing. Show all posts
Showing posts with label compositing. Show all posts

Monday, May 17, 2010

2.49b Yafaray Tutorial



YafaRay is an external renderer (download it from www.yafaray.org) that is integrated with Blender 2.49 via Python scripts. You can add many dramatic features, such as global illumination, caustics, enhanced ray tracing, and self illuminated objects, to your renders, with YafaRay. YafaRay extends Blender's built in renderer with special types of lighting, new material options, and enhanced world settings.

Wednesday, December 23, 2009

Mix Node Part 1

Join my Blender 3D forum, where you can network with other Blender friends and get your Blender 3D questions answered.



One of the powerful reasons for using Blender is that it can do just all the steps in video production, from pre production right through post production, by itself. Although you might want to call on another product, such as an external renderer like Yafaray or an image editor such as the Gimp or Photoshop, for some specialized needs, in many cases Blender can do the job. The fewer pieces of software you have to juggle in your workflow, the better. Importing and exporting files between programs is a royal pain. Enhancing the quality of the color of images is one of these areas. When combined with Blender's composite node system, which I discussed in a basic way in a previous Youtube video, Blender can do just about everything a 2D image editor such as the Gimp or Photoshop can do.

In this tutorial, I will show how to use the Mix Node to blend two colors. This is a start to get you comfortable with tweaking 2D images entirely in Blender. This is just the tip of the iceberg. There is plenty of material, just in color processing, for many more tutorials. We'll spend the entire time in the Node Editor, pretending that Blender is really Photoshop in disguise. I will use Blender 2.49b.

Steps:
1) Start up Blender. One tiny bit of housekeeping before we go into the Node Editor. Press F10 to go to the Scene buttons. Press the Do Composite button in the Anim section, telling Blender's renderer to look at the composite nodes. Change the window type to Node Editor. That's where we'll stay. There are actually three types of node editing - Material, Composite, and Texture. We want the middle icon, the one with the face, the Composite Node. Click Use Nodes. Two nodes display, the input Render Layer and the output Composite. Delete the Render Layer node - we will ignore the 3D part of Blender. To do that, select the Render Layer node (Right Click just like you're selecting an object) and press the Delete key. We still need the Composite Node, however, because that is what ultimately renders. Move the Composite Node all the way to the right by selecting and dragging it.

2) We're going to start by mixing two RGB colors. The Mix node is the most important node in color editing. To add a Mix Node, press Shift-A (the Space Bar also works), then Add - Color - Mix. Note that there are 3 sockets on the left (the top one is grey and the bottom 2 are yellow), for input into the node, and one on the right, out from the Mix node after the node does its thing.

We'll concentrate on the bottom two yellow sockets. These are what the Mix Node is going to mix. To the left of each socket is a grey rectangle, along with the word Image. The grey rectangle represents a color. The word Image means that an Image can be mixed. Actually, you can mix one image with another, an image with a color, or one color with another color. We'll start by mixing one color with another. This is not really that common, but it works well for this tutorial, to explain how the Mix Node works.

3) Click on the top rectangle. Make it red (R=1, G=0, B=0). Then click on the bottom rectangle. Make it green (R=0, G=1, B=0). Connect the output image socket of the Mix node with the input image socket of the Composite Node. Press F12 to render. The result is a big square which is a light green. What did the Mix Node do? We can find out by positioning the cursor inside the render window, holding down the left mouse button, and dragging. There's a text display of the values of the particular pixel that the mouse is over. The display shows the pixel X and Y coordinates, the RGB color values, and the Alpha value. In this case, it doesn't matter because the color is the same no matter where you click. The RGB color is reported in two notations: R=128, G=128, and B=0, or R=.5, G=.5, and B=0. One is the decimal representation, the other the Blender representation of the color. What happened is that the Mix Node mixed half of the red with half of the green.

This result is actually misleading, because one might think that this "mix" is like mixing half of the red with half of the green as a result of the Fac setting. Fac., which is set at .5, or 50%, stands for Factor. But what is it actually factoring?

Let's find out. Set Factor to 1, or 100%. Press F12 to render. Now the result is all green (R=0, G=1, B=0). There's no red in the result at all.

Now set Factor to 0. Press F12 to render. Now the result is red, with no green at all.

What's happening is that for the Mix operation, the bottom color or image acts like the foreground, and the Factor is the percentage of the foreground's pixel values (each pixel being evaluated individually) that is used. Whatever percentage is not used is used by the top color. So, when Factor is 0, none of the green is used and all of the red. When Factor is .5 green and red are used equally, and when Factor is 1, all of the green is used and none of the red.

4) Now things get even more interesting. Click on the Mix dropdown list. Mix one of 16 possible ways that one image or color can be combined with another image or color. We can't possibly cover all of these in one 10 minute tutorial. But we can get a good start. Let's look at Add. Set the Factor to .5. Press F12 to render. Now we get an entirely different result: an orange square. What did Factor do this time? Clicking and dragging on the render square tells us that the result is R=1, G=.5, and B=0, all the red and 1/2 the green.

What did Factor do this time? Set Factor to 1 and press F12 to render. Now we get yellow (R=1, G=1, and B=0).

Set Factor to 0 and press F12 to render. Now we get Red (R=1, G=0, and B=0).

What happened? No matter what the factor, we always get all of the red. However, the amount of green is dependent on the Factor. On a pixel by pixel basis, the bottom color, multiplied by the factor, is added to the top color. Since the bottom color is green, the Factor controls, in effect, the amount of green in the result, with all of the red contributing.

5) Let's look at Subtract, which works a bit differently. With the Factor set to 0, press F12 to render. The result is red.

Set the Factor to .5. Press F12 to render. The result is still red.

Set the Factor to 1. Press F12 to render. The result is still red.

What's going on? If you look closely at the render text display, you'll see that while Red = 1, G actually equals -1. That's because Subtract subtracted the green (1) from the Red's green value (0), giving -1. Set Factor to .5. G now equals -.5 and R=1. That still means a red result because any number less than zero means no green.

This is just the tip of the iceberg. Experiment with the other Mix modes. In the next video, we'll look at what Mix is most commonly used for: combining two images. I hope you learned something. If you did, don't forget to hit the Subscribe button in Youtube. Happy Blendering!

Thursday, November 12, 2009

2.49b Vector Blur



Vector blur is a great way to add realism to your animation. Your eye naturally sees moving objects moving as a blur, because that is how your brain processes the motion. Without some sort of blurring, animated moving objects don't look as if they are realistically moving. Blender's animations are by default rendered as a sequence of perfectly still images. This is unrealistic, since fast moving objects do appear to be 'moving', that is, blurred by their own motion, both in a movie frame and in a photograph from a 'real world camera'.

To obtain such a blurring effect with moving objects, Blender can be made to render the current frame and some more frames, in between the real frames, and merge them all together to obtain an image where fast moving details are 'blurred'. The goal of this tutorial is to demonstrate how to blur moving objects in Blender.

First, we'll create a simple animation. We will animate the movement of the cube across the screen, over 50 frames. With an animation speed of 25 frames per second, that produces a 2 second video, one second going across the screen, the other second going back.

1) Go to the SR-1: Animation view.
2) Press the N key to bring up the Transform Properties window. Set the X location to -7, the Y location to 0, and the Z location to 0.
3) At Frame 1, press the I key and insert a Location key frame.
4) Go to Frame 25. Set the X location to 4, the Y location to 0, and the Z location to 0.
5) Press the I key and insert a Location key frame.
6) Go to Frame 50. Set the X location to -7, the Y location to 0, and the Z location to 0.
7) Press the I key and insert a Location key frame.

8) Go to the Scene buttons (F10), and set the animation to 50 frames.
9) In the Format panel, set the animation type to your favorite. I used the compressed AVI format with the CamStudio Lossless Codec, version 1.4, for compression.
The video will be created in the Output directory (/tmp by default), with a filename of 0001_0050.avi. Set the output directory to the folder where you want the video to be saved. If you chose a QuickTime movie, the filename would be 0001_0050.mov.

10) Hit the ANIM button. I will pause the video while the animation is being rendered, as I will do for the other animations in this video. The render took 1 minute, 10 seconds.

The animation does indeed have the cube move back and forth, but the motion of the cube is not realistic. The cube just moves in a straight line uniformly, without the blurring effect of motion.

With the help of the Node editor, we can introduce vector blur to this animation and compare. To do this,

1) Go to the Render Layers tab of the Scene button. Vector blur takes a special Vector (VEC) rendering pass, which is not rendered by default. Find the VEC button and enable it. Vector Blur requires the COMBINED, Z, and VEC passes. The others you may need to render the scene exactly as you need it.

2) Change the 3D view to the Node Editor. Press Control-Down Arrow to maximize te Node Editor. Click on the face, for composite nodes. Then click the USE NODES button. There are two default nodes, the input node (Render Layers) is the scene as rendered without compositing. The other node, the Composite node, is the final result of the compositing process.

3) Move the Composite Node all the way to the right, to make room for the Vector Blur.

4) Add the Vector Blur filter (Space - Add - Filter - Vector Blur). Accept the defaults. Connect the Image socket of the Render Layer to the Image input of the Vector Blur node. Connect the Z socket of the Render Layer node to the Z socket of the Vector Blur node. The Z socket stores the Z information - the distance of the cube from the camera. Connect the Speed socket of the Render Layer node to the Speed socket of the Vector Blur node. The Speed socket is really the key to blurring the cube's movement. You can play with the defaults. Increasing the number of samples, for example, makes the vector blur more realistic but slows down the rendering. Also, you can control which moving objects are blurred. A speeding sports car should be blurred, but bystanders should not.

5) Connect the Image output socket of the Vector Blur node with the Image socket of the Composite node.

The noodle (the node setup) is complete. Go back to the Scene buttons and click the Do Composite button. Press the Render button. Look at Frame 1. The monkey is blurred.

6) Time to animate. Click the ANIM button. Pause until the 50 frames are rendered. The render took 1 minute, 47 seconds.
Now you see the cube blurred while it is moving --- a much more realistic animation. Think of a fast sports car speeding by you.

Blender has another way to implement blurring a moving object: the Motion Blur option. To demonstrate that, click the MBLUR button in the Scene panel. Turn off Do Composite because motion blur doesn't rely on nodes. MBLUR is very slow because it renders each frame up to 16 times. The number of samples is controlled by the OSA setting, which is 8 on my computer. Eight renders per frame is mighty slow. The renderer calculates the position of each object and then averages the positions out. It is more accurate than Vector Blur, but at the cost of a LOT of time. Here is the cube animation with motion blur.

To summarize, Blender provides you with two options, Vector Blur and Motion Blur, for making your moving object look more realistically blurred as the object moves in the scene. For most applications, especially in the Game Engine, Vector Blur will work well. Happy Blendering!

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!