Showing posts with label Freestyle. Show all posts
Showing posts with label Freestyle. Show all posts

Friday, May 15, 2015

Blender Tricks: Using Freestyle for Highlighting Objects Part 2 - Material Options

Summary

This article describes the creation of illustrations mixing elements with line art and "photorealistic" art in one image using Blender with the Cycles renderer and the options of the Freestyle line renderer. Here an example:

Background

This is a follow up to an earlier post of mine "Blender Tricks: Using Freestyle for Highlighting Objects Part 1 - Layer Options". In this article I explained how to use Blender with Cycles renderer to create illustrations with highlighted objects by assigning Freestyle line options per render layer and exploiting the "Alpha Over" render-layer node.
This layered technique is - from my point of view - a good choice for scenes with non-overlapping/interfering object, but has some drawbacks concerning artifacts of the per layer rendering process if object intersect.
Just recently (in the process of creating the image above) I discovered a better approach exploiting the Freestyle options on Material level. Similar to my previous example I want to put green lines around the red cube (only) in the image below:


All my examples here are based on Blender 2.74. So - let's get going...

Step 1: Enable Freestyle

To activate Freestyle line art rendering in Blender/Cycles tick on the "Freestyle" option on the "Render" menu:


Now all Freestyle options are available and without any changes Blender puts black lines around both cubes:


Step 2: Freestyle Line Settings in Material

With Freestyle enabled, a new Freestyle options tab becomes available in the "Materials" tab. There one can influence the line color and the line transparency/alpha:


To hide Freestyle lines in the output, put the alpha value (marked by the red ovals in screenshot above) in the Freestyle options of the corresponding material to zero.
In my example I put the Freestyle line color of the red material to green and alpha to 1. The blue material is adjusted to color = black (default) and alpha = 0.
However - this is where I struggled for quite some time - it is not enough to adjust the Freestyle settings in the material. If you only change color/alpha here, nothing will change in the output.

Step 3: Switching Freestyle Control from Global to Material

To put control of the Freestyle color/alpha options into the hand of the material one has to add two modifiers on the 
  • "Render Layers" -> "Freestyle Line Style" -> "Color" options AND (!) the
  • "Render Layers" -> "Freestyle Line Style" -> "Alpha" options:

for both option tabs add a "Material" modifier.
Now the Freestyle line color and visibility is controlled via the material. The result looks then like this - as desired:


Comparison to Layer-Approach

I presented two possible approaches to put differently colored lines around objects in Blender/Cycles. Which one is preferable now?
My opinion is the following: if you have scenes with separated objects casting not too many shadows onto each other, the layered approach is preferable. Furthermore it offers the possibility to control Freestyle for many objects/materials at once (= by layer). The drawback of the layer technique is that you have to have a scene with transparent background because object with lines have to be rendered in front of a transparent background. If you want more control over the lines, scenes where background transparency cannot be used and you want better results in your output the material based is the weapon of choice. Nevertheless material based is more time consuming as it requires adjusting Freestyle options for each of the materials in the scene individually.

This was it, I hope you liked this post and it helps you with your own project - keep on geekin'!

Cheers 
WolfiG



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