Blender 3D: Noob to Pro/Ray Tracing
|Applicable Blender version: 2.67.|
You previously learned about using diffuse and specular shaders to control the appearance of a material. These settings only affect how the material reflects direct light from lamps; but in the real world, objects are also illuminated by indirect light bouncing off other lit objects.
In particular, there is the important case of light bouncing off mirrors and other glossy or polished surfaces before travelling to the camera, and also of light passing through transparent objects and being refracted (bent).
In the real world, such light can illuminate other objects, and it can also do so after bouncing off non-mirrorlike surfaces. The general problem of modelling such indirect lighting is called global illumination, commonly abbreviated “GI”. Unfortunately, the Blender Internal renderer, which is what we have been working with so far, cannot deal with GI in its full generality; to cope with that, we would have to use the Cycles renderer, which is introduced later. So for now we will confine ourselves to mirrorlike reflections which do not illuminate other objects.
Setting The SceneEdit
Let’s create a very basic model we can use to experiment with various ray-tracing effects. Open a new Blender document. Make sure the default cube is selected. Go to the Modifiers context in the Properties window, and add an Array modifier to the cube.
The cube will immediately become two cubes, but so close together that they look like a single cuboid. This is because the default settings for the Array modifier are to use a Relative offset of (X, Y, Z) = (1.0, 0.0, 0.0). Change these offsets to (1.5, 1.5, 1.5), so the copies are more widely separated at a more interesting angle, and increase the repetition count to 5.
Now try rotating and repositioning the camera and the cubes to get them all in the view. If you hit F12 to render now, you should see something like at right. So far not very exciting. But since we are going to be dealing with reflections and refractions, it would be nice to have something in the surroundings to be reflected and refracted.
One easy thing to add is a world texture. Go to the Texture context in the Properties window. Make sure the World texture (the leftmost of the 3 buttons at the top of the topmost panel) is selected. Create a new texture, and change its type to “Magic”, which has a nice variety of different colours. Go to the Influence panel; by default the top-left checkbox (affect background progression) is checked; but this does nothing, because the default sky setting is not to have a progression at all. So uncheck that box, and check the second one on the left (affect horizon colour) instead.
Also under the “Size:” setting, set the X, Y and Z scaling all to 3.0; by shrinking the pattern, this will bring more detail into the view.
Now if you hit F12 , you should get an image with a slightly more interesting background.
OK, we are ready to start playing with the material settings...
In physics, refraction is what happens to light when it crosses the boundary from one material (e.g. air) into another (e.g. water); it slows down when it enters the denser material, and speeds back up when it leaves. The refractive index of a material is a measure of how much the speed changes relative to a vacuum (where light travels at full speed). As the speed changes, the light beam also changes direction, giving rise to well-known “bending” effects like you see when you put a teaspoon in a glass of water, or look down into a swimming pool (as at right).
Anyway, back to our tutorial model. Make sure the cubes are selected. Go to the Materials context in the Properties window. Find the Transparency panel, and check the box at the top to enable transparency. In the row of buttons for selecting the type of transparency just below that checkbox, titled “Mask”, “Z Transparency” and “Raytrace”, select “Raytrace”.
In the editable fields immediately below those transparency-type buttons, the one at the top left is titled “Alpha:”; you will have to reduce it below its default value of 1.0 in order to see any actual transparency effect. Try reducing it to 0.5.
Just a bit further down from the Alpha field, look for two more fields: “IOR:” (“Index Of Refraction”) and “Filter:”.
To simulate glass, set the IOR to 1.5 (other useful values are 1.33 for water, 2.4 for diamond etc). The Filter value controls how much of the diffuse colour of the material the light takes on as it passes through; set it to something like 0.5, though you probably won’t notice much effect from this unless you specify a strong colour in the diffuse shader settings.
The “Depth:” setting controls how many times the light passes across material boundaries before the renderer gives up keeping track. Larger values give more realistic results, at the usual cost of increased render times. In more complex scenes where you have transparent objects in front of other transparent objects, this value will have a definite effect; here it probably doesn’t matter too much.
Now if you hit F12 , you should see something like at right. The cubes still look a bit grey; if you set the alpha to 0, they will look much more transparent.
Also try playing with the “Amount:” slider under “Gloss:”: the default value of 1.0 gives perfectly smooth refraction, while values less than 1.0 give a “frosted glass” effect, blurring the light as it passes through the material.
The Fresnel FactorEdit
Real-life materials are never perfectly opaque or perfectly absorbent; even with something like a shiny metal which seems entirely opaque, light still manages to penetrate a little way into the surface, and even with the blackest of black soot, there is still some (tiny) amount of reflection going on.
The general behaviour is that a material is most transparent when its surface is viewed directly-on, and it is most reflective when it is viewed almost parallel to the surface (as usual, Wikipedia has all the gory details if you’re interested).
If you look back at that Transparency settings panel, you will see to the right of the Alpha field one labelled “Fresnel:”, and another one below that labelled “Blend:”, which comes to life when the Fresnel value is set to something greater than its default of 0.
The Fresnel (pronounced “fray-nel”) value is the power, which governs how sharply the transparency of the surface changes with viewing angle; 0 means the transparency stays unchanged at all angles, while higher values cause the transparency to fall off more rapidly towards the edges. The maximum value you can set for this field is 5.0.
Just below the Transparency panel in the material settings, you will see the Mirror panel. Check the box at the top to enable it. Note the “Reflectivity:” editable field just below the checkbox; you will need to set this to something other than its default of 0.0 in order to actually observe any mirror effect.
If you render now, you should see something like this.
See also the colour swatch specifying the colour of reflections: the default white means that reflections keep their colours unchanged, which is characteristic of reflections off glass, plastic or ceramics. Reflections off metal tend to take on the colour of the metal.
The Gloss setting governs how mirrorlike the reflections are: reducing this from its default of 1.0 adds blurring to the reflections, giving the effect of less-polished surfaces.
Note the Mirror panel has its own Fresnel settings. Go back to the Transparency panel, and set the Alpha to 0. That will disable the diffuse and specular shaders completely, giving us a pure ray-traced material, and also render the transparency Fresnel ineffective. Instead, we will control the Fresnel here in the Mirror panel. The behaviour for a nonzero Fresnel power is similar to before; however, instead of fading from transparent in surfaces viewed face-on to effects from the shaders when viewed edge-on, it will fade from transparent to mirrored.
Set the Fresnel value to something like 2.5. Compare the render to the previous one without Fresnel:
Finally, set the Reflectivity to 1.0, and the Fresnel to 0. Now if you render, you should get a completely opaque, mirror-reflective set of cubes.
Why Are My Shadows Black?Edit
Consider the render at right: this is a default document with a plane added; the cube has ray-trace transparency turned on with an IOR of 1.5, Filter of 0.5, Depth of 5 and Alpha of 0, other settings left at their default. The plane has a material with all settings at their default.
Light should be able to pass through the cube and illuminate the part of the plane directly behind; so why is the shadow completely black?
The problem is, by default, the Blender Internal renderer doesn’t bother to compute transparent shadows. Instead, it assumes that anything that blocks the light does so completely, presumably because it would slow things down too much to assume the opposite. To fix this, select the plane (not the cube), and in its Material settings, look for the Shadow panel. Note the two checkboxes at upper left: by default the “Receive” one is checked, the “Receive Transparent” one is not. Check the latter as well. Now any object surface with this material assigned will have proper non-transparent shadows computed as appropriate.
Now when you re-render, you should see a more accurate-looking transparent shadow.
Imagine if you had a scene with lots of non-transparent objects with different materials receiving shadows from lots of transparent objects: you have to check this “Receive Transparent” option on every single one of those materials that might be receiving transparent shadows! Yes, this can be a pain. Not to mention the issue of caustics, which the BI renderer doesn’t handle at all. If you want to render realistic scenes like this, then you will need to learn about Cycles...