Quick Reference: Using Normal Maps in BI and Cycles

[box color=”gray”]Normals and Material Masking Series – Part 1 | Part 2 | Part 3[/box]

QR-Baking-Normals-from-Bump_Heading-Image

In Part 1 of this series I covered how to bake a normal map from a bump map using Blender Internal’s texture baking abilities. This part demonstrates how to properly apply a normal map to a material in both Blender Internal and Cycles.

To quickly review, I have a simple subdivided cube, with some holding loops, unwrapped and the UVs arranged to maximize the sides of the cube facing the camera. I have also loaded the normal map image into the UV/Image Editor workspace.

QR-Using-Normal-Maps-In-BI-And-Cycles_Cube-And-UVs
Cube UV layout and normal map

Using a Normal Map in Blender Internal

To apply a normal map to a material in Blender Internal, first add a material to the cube then add a new texture to the material. Next, select “Image or Movie” and load in the normal map image. Under Image Sampling check the box next to Normal Map. It’s also a good idea to check Minimum Filter Size under Filter and set the Filter Size to 0.10 (the lowest setting possible). This will give a better quality result, especially if the normal map image is not particularly large. Set the Mapping to UV and, under Influence, check Normal and set the value to 1.

QR-Using-Normal-Maps-In-BI-And-Cycles_BI-Texture-Settings
Texture settings for normal map in Blender Internal (Click for larger view)

Using a Normal Map in Cycles

To apply the normal map to the cube in Cycles, first, add a material to the cube. Now bring up the Node Editor workspace (I generally split the window vertically with the Node Editor on the top and the 3D Viewport on the bottom.) By default, you will have a Diffuse BSDF shader node plugged into the “Surface” socket of a Material Output node. We’ll just use the diffuse shader, but give it a sexy color.

QR-Using-Normal-Maps-In-BI-And-Cycles_Default-Nodes
Default Cycles material nodes

Now we need to get the normal map image into the mix and we’ll do that with two nodes: Texture Coordinate and Image Texture. First, hit SHIFT+A to add a node and select Input -> Texture Coordinate, we’ll use this to map the image to the UV coordinates of the cube. Then add an Image Texture node (Texture -> Image Texture). Plug the “UV” output socket of the Texture Coordinate node into the “Vector” input socket of the Image Texture node. Also, change the drop-down box below the image file on the Image Texture node from “Color” to “Non-Color Data.”

QR-Using-Normal-Maps-In-BI-And-Cycles_TexCoord-ImageTex-Nodes
Texture Coordinate and Image Texture nodes (Click for larger view)

Now at this point, there are two things I’ve seen people do that are not the best way to apply a normal map:

[list icon=”busy”]

  •  Plugging the “Color” output socket of the Image Texture Node into the “Displacement” input socket of the Material Output node.
  •  Adding a Normal node, plugging the “Color” output socket of the Image Texture node into the “Normal” input socket of the Normal Node and the “Dot” output socket into the “Displacement” input socket of the Material Output node.

[/list]

Doing either of these is mismatching data types, which are indicated by the color of the sockets. Though in some circumstances this works fine, it is usually best practice to avoid plugging a socket into a socket of a different color. In this case, though you will get some displacement as a result, you are essentially turning the normal map back into a bump map by limiting the range of data being used. (For more info on data types, etc. keep an eye out for an upcoming post: Understanding the Node Interface.)

QR-Using-Normal-Maps-In-BI-And-Cycles_Incorrect-Nodes
How NOT to set up a normal map (Click for larger view)

The proper way to apply the normal map is to add – no surprise here – a Normal Map node (Vector -> Normal Map). Then plug the “Color” output from the Image Texture node into the “Color” input of the Normal Map node and the “Vector” output into the “Normal” input of the Diffuse BSDF node. This converts the color data from the image (yellow socket) into vector data (purple socket) and applies it to the normal of the shader node. Make sure the drop-down box is set to “Tangent Space” and the UV box is set to “UV Map” (or whatever the name is of your object’s UV map to which the normal map is aligned.) I’m not sure why this UV option is here; the Image Texture node vector is already set to UV, but best to do both.

QR-Using-Normal-Maps-In-BI-And-Cycles_Proper-Nodes
Using the Normal Map node (Click for larger view)
QR-Using-Normal-Maps-In-BI-And-Cycles_Cycles-Render
Cube render with normal map in Cycles

If you are building a material that mixes multiple shader nodes, simply plug the Normal Map “Vector” output socket into the “Normal” input socket of all the shader nodes. (Not all shader nodes have a “Normal” input, such as Emitter shader nodes.) As an example, I’ve mixed a Glossy shader with the Diffuse shader and applied the normal map to both. (I’ve collapsed some nodes in the image below to save space.)

QR-Using-Normal-Maps-In-BI-And-Cycles_Mixed-Shader-Niodes
Using a normal map in a material with multiple shaders (Click for larger view)
QR-Using-Normal-Maps-In-BI-And-Cycles_Cycles-Render-Glossy
Cube render in Cycles with mixed shader material

The next part of this series, Material Masking in Cycles, will demonstrate how to use mask images derived from the original bump map to mix several shaders, producing the result below with one material.

QR-Baking-Normals-from-Bump_Final-Box

<- Part 1: Baking Normals from a Bump MapPart 3: Material Masking in Cycles ->

Some textures used in creating models appearing in imagery on this post are from CGTextures.com, a most excellent source for photo textures.

Quick Reference: Using “Clamp” in Cycles

Being that my current machine isn’t nearly as meaty when it comes to processing as I’d like – and doesn’t have a graphics card that is compatible with Cycles GPU rendering – I’m always looking for ways to improve performance when rendering in Cycles. Blender Guru has a post worth checking out, 4 Easy Ways to Speed Up Cycles, but I’d like to mention a simple technique I’ve just recently discovered, using the Clamp setting.

RenderPanel_Clamp

Using Clamp

This example is still a work in progress, but is suitable for demonstrating the use of Clamp. (You can view the final image here in my portfolio.) The scene is lit by two emitter planes and a HDRI map. The bounces are already set to pretty conservative levels, but it’s till firefly city. Here’s a render after 2642 samples with Clamp set to 0, using progressive refine so the whole image renders at once (I won’t tell you how long it took on my computer, it’s a little embarassing.)

Banner-01_Test-06_2642-Samples_15h24m
2642 Samples, Clamp set to 0

In the Render panel, under Sampling, there is an option called Clamp (more on the particulars of what this does below.)  By setting the “Clamp” to 2, this is the result after 1363 samples.

1363 Samples, Clamp set to 2
1363 Samples, Clamp set to 2

You’ll notice that the image is a little dimmer and duller, the colors are less vibrant. That is easily fixed in the compositor with a simple Color Balance node. I essentially want to increase the contrast and brighten the image. Also, might as well do a little color correction while we’re at it.

With Color Balance node, reduce the value of the Lift and increase the value of the Gain
With Color Balance node, reduce the value of the Lift and increase the value of the Gain

With a little post-processing, an image that is less muddy. I’ve reversed the dimming effect of Clamp and added some flair to the image that I would have done anyway, at the same time. A bit more refinement of the image is a good idea, but this illustrates the basic point.

1363 Samples, Clamp set to 2, Color Balance adjusted
1363 Samples, Clamp set to 2, Color Balance adjusted

So, utilizing the Clamp setting, I was able to get a render that is virtually noise-free in about half the render time. You’ll have to experiment to find a Clamp value that balances render time and image quality for each scene. Remember that using clamp will dim the image (particularly the highlights) but that is usually fixed pretty easily with some post-processing. (You’ll notice the paper on the mini notebook has blown out a bit, this can be fixed by making the texture darker.)

Why Use Clamp

For more detail on Clamp, as well as other noise reduction techniques, explanations on how they work and what causes noise in the first place, I suggest checking out this page in the Blender Wiki. Briefly, Clamp caps the value of each sample, easing fluctuations from pixel to pixel. This obviously reduces the physical accuracy of the final image and dulls the brighter highlights, but these issues are usually either negligable or easily corrected.

I chose to use Clamp over using Filter Glossy or other techniques to reduce noise in this render for three main reasons:[list icon=”plus”]

  • It’s faster, easier and more effective at noise reduction over the entire image
  • Given the amount of glass and liquid as well as their prominence in the image, I wanted to preserve the accuracy of those light interactions as much as possible
  • It doesn’t involve making adjustments to individual elements or shaders

[/list]

Disabling caustics removes entirely a real physical effect of light (though it often doesn’t appreciably diminish the quality of the image and is a good idea to use in conjunction with setting a Clamp value), while Filter Glossy forces a reduction in sharpness. With Clamp, the inaccuracy is mostly in the intensity of highlights.