Support

Dear reader, if you got someting out of my blog and if it helped you, it would be great if you supported me by clicking on the Google ads-banner at the right. This will not cost you anything but time but will generate a little bit of revenue for my time invested ;)
I'm as well happy if you LIKE or 1+ it and about comments that help to improve my articles.

Friday, April 3, 2015

Blender Tricks: Using Freestyle for Highlighting Objects Part 1 - Layer Options

Background

Currently I am creating a couple of illustrations of complex technical objects - detector assemblies for nuclear and particle physics. These detectors consist of multiple onion-like layers of specialized sub-components/detectors which I want to highlight in-situ to make clear which of the detectors I am talking about in the moment. Here an example:



The tool I am using is the 3D modeling and rendering software package Blender, which offers - to my knowledge - unprecedented functionality for free. Blender has been designed as tool for 3D computer artists rather than a tool to create technical/engineering CAD models, but in combination with a CAD modeling tool (e.g. CATIA, Autodesk inventor, or for hobbyists FreeCAD) it is a power-/wonderful tool do create stunning photorealistic graphics and illustrations.

Blender and Freestyle

Since release 2.69 (?) Blender incorporates the "Freestyle" package as rendering option, making it possible to add lines/strokes to the rendered objects. Freestyle offer many, sometimes too many options at several places to influence the look of the line strokes it creates and the impact on objects. However, it is a very strong tool to create cartoon-like characters on the one hand - this is what it has been made for - on the other hand as illustrator one can use it to highlight objects in your scene. I am using Freestyle in Blender for the latter intent.
Here an Example - say I created some "complex machine" consisting of several parts (the example was created using FreeCAD and exporting/importing a Wavefront obj-file to Blender). Here is a first image of the rendered scene without any object highlighted:


How can I highlight the little cube hidden among the cube and the cylinder? One option would be to give it a different color, but maybe I don't have this option.
In a first attempt one can switch on Freestyle in Blender:
  • Render Panel -> Freestyle Checkmark
The output of Blender looks like this with this option checked:


Already very edgy and sketchy, but still I did not manage to highlight only my little cube.

The Challenge

So I hope I made clear what I am up to. How do I put lines only around my little cube?

Solution

The solution I found uses the layer options of blender to create layer-dependent Freestyle output.

Step 1: Separate Objects by Layer

To be able to assign lines only to one object or a subset of objects, one has to move these to another layer than those which will be rendered "normally". To do so, select the object(s) and type "m" (move to layer) and click on the layer to
move the objects to:


You will know that you moved the object to the right layer by the little orange highlight in the layer overview indicating the layer with your currently selected object:


Step 2: Create A new Render Layer

We want to have only ONE object (or a subset of objects) showing lines as highlight., So we have to create a new render layer hosting the Freestyle line style whereas the objects on the "normal" layer will not have a specific line style:
  • "Render Layer" panel -> "add a render layer"

Make Sure: "Transparent" Film is Enabled

This option is required to be able to merge two images properly in a compositing step:

  • "Render" panel -> "Film" options

Step 3: Render Layer Depedent Freestyle Line Settings

In this step, we create one render layer with Freestyle LineSet (here named "HighlightLayer") and one without (here named "NormalLayer"):



Step 4: Line Set Tweaking

Freestyle offers various options to change the look and feel of the lines it creates. In my example I want the highlighted object to have a red line. This has to be set in
  • "Render Layers" panel -> "Freestyle Line Style"

Step 5: Activate Object Layer by Render Layer

  • "Render Layers" panel -> "Layer" options
By default, all object layers are included in the render layers:

Change this and include only those object layers in your "Highlight" layer (the one with the Freestyle LineSet) which shall have Freestyle lines. In my case:
  • object layer 1 in the "Hightlight" (Freestyle) layer - the one with the little cube:
  • object layer 2 in the "Normal" layer:
If you render with these settings, you will get the following:


Only the output of the "topmost" render layer is visible. Unfortunately this is not enough yet, still some compositing nodes have to be set.

Step 6: Compositing Node Settings

To merge the two images rendered by the two render layers, one has to do some compositing node magic. You will have to create two "Input" nodes, one for each render layer. The output of these nodes are merged via an "Alpha Over" node:
  • "Node Editor" -> "Compositing" Node Tree -> check "Use Nodes"

If you did everything right down to here (and if I described everything properly...) you will get the following result:





Well - the wrong shadow needs some work...
Update from May 2015: I described another approach in a follow-up post

I hope this blog helps you with your own project, keep on geekin', all the best your
WolfiG