Is there really a way to make a true toon shader material in Cycles?

Is there a way to make a true toon shader material in Cycles?

Here's, in order of importance, what would be ideal to find in such a shader:

1. Must use Cycles
2. Must be an actual shader
3. Must not rely on lighting
4. Must be independent of camera position
5. Must react directly to lighting rather than manually having to change it to emulate it
6. Should be easily made into a node-group
7. Should have the following configurability:
• Main color
• Darkness color
• Shadow depth (how far the shadow goes from the unlit side)

Below, I'll be listing some already-found methods and their flaws:

Cycles's Toon BDSF:

Source: Blender

Result:

Node setup:

Cons:

• Not a clear-cut two-color shading
• Reacts to diffusion of surrounding objects

Source: Blender StackExchange

Result:

Node setup (Compositor):

Cons:

• Very grainy
• Does not support colour textures
• Not easy to change shadow depth in a nodegroup
• Not a material, requires compositor
• Requires use of object indexes

Source: NixArt

Result:

Node setup:

Cons:

• Uses camera's direction
• Ignores lighting
• Not easy to change shadow depth in a nodegroup

Source: NixArt

Result:

Node setup:

Cons:

• Ignores lighting
• Direction of shadow is manually changed
• Not easy to change shadow depth in a nodegroup

However, this one is easily the best one. It's pretty great, and would work still images very well.

That's all I've got. Does anyone else have any methods that fall under most of the criteria I listed above? Also note that OSL is totally fine, if it works.

• – gandalf3 Jul 13 '15 at 6:32
• Any chance this osl shader meets your needs? You input a position that determines the mix of the two colours, so external lighting and camera position don't change the mix. – sambler Jul 13 '15 at 7:56
• Whenever I see these questions with all these limits, without any reason given for the limits, the questions seem to me to be like, "How do I cut down a tree using only a herring?" The answer is to not use a herring to cut down a tree. Figure out why these things-- like not using camera position, has to be a shader (as opposed to compositing?) -- are important, and talk about those reasons, rather than establishing hard limits. – Nathan Jun 21 '18 at 16:43

OSL + Solidify (Irie's Technique)

Results:

Pros:

• The toon shader has seven customizable parameters for creating many different looks
• Edge strokes taper off with a natural look, like hand-drawn strokes
• It renders quickly
• It responds to lighting (can be lit with lamps)

Cons:

• Some additional geometry must be generated to create the outlines
• It won't look right if you make the outlines too thick in the modifier
• The toon shader does not react to emitter meshes or other non-lamp light sources

This technique I found demonstrated on BlendSwap by Shinsuke Irie is pretty clever. It uses OSL to get the shading, so make sure you have OSL enabled if you append this into your blends. Also you will need to make one edit to the "toon.osl" script because Blender's code has changed since this file was published: speculartoon() closure has been renamed to glossytoon() so just find and replace that text, then refresh the Script node.

The outlines are generated by a Solidify modifier that has its normals flipped (is back-facing). This part is kind of hackish, but looks good because the strokes taper off to a nice sharp point. You can adjust the edge thickness by adjusting the Solidify modifier's Thickness slider, but only a little, as changing this too drastically gives strange results. The object uses both a "Skin" and "Edge" material to achieve the end result. The outline color can be changed in the "Edge" material.

Of course you can decide to use Freestyle instead of the Solidify technique, if you prefer.

Note that with the Solidify technique edge thickness is local to the object, but it could be linked to camera distance via a driver so that strokes remain the same thickness even in close-up shots. (This is the case for Freestyle as well.)

A look at the customizable parameters in Irie's toon shader:

Conclusion:

This technique can produce very pleasing results! The way edge strokes are generated is a bit unconventional, but it's worth taking a few minutes of studying the .blend to understand how it works. At first I had apprehensions about using a technique that requires a Solidify modifier since extra geometry must be generated, and I wasn't sure if it would cause issues with the deformations of rigged meshes. But then I found this video demonstrating this technique used in production on an animated character and I am convinced this is the best way to do toon shading in Cycles at this time.

• Two things: 1. the OSL shaders are pretty easy to convert to Cycles Nodes, which work with GPU rendering and the Material viewport shading, so there's little reason to use OSL. 2. Your lights need to be set to 0 radius to get the sharp shadows, which tripped me up when trying this technique. – Colonel Thirty Two May 14 '17 at 19:57
• @ColonelThirtyTwo 1. Good to know. If you've made a non-OSL Cycles nodes version would you mind sharing it with the community? (You can use Blend Exchange and post just the URL in a comment.) 2. Thanks for mentioning that. – Mentalist May 14 '17 at 23:57
• An updated version of this OSL toon shader (confirmed to work on 2.79) can be found here: blendswap.com/blends/view/89187 – Coby Randal Feb 27 at 20:55

Cycles's Toon BDSF + Hard Shadows + 0 Diffuse Bounces:

Result:

Process:

• Part one, two color shading

In order to avoid a non clear-cut two-color shading and at the same time make the material react directly to lighting i think the best compromise is to abandon soft shadows.

Setting a very low size of the lamp will make the toon shader react with a clear cut shading.

The following node setup allows to control the color of the "darkness color" with an emission shader (in blue), upon which we'll add a layer of diffuse toon (red):

In the first image, the two colors were substitute with two different shades of grey.

At the beginning you saw susanne lit by a sun lamp. Below that's a try with a point lamp:

• Part two, no reaction to diffuse

We now must face the diffusion part. Infact, by setting a small size of the lamp we actually achieve only this kind of result:

I added a red diffuse semisphere to the scene to control the interaction between susanne and other object. We see that susanne receives indirect light by both the sphere and the plane (and the environment) that ruin our shader's darkness color. We need that flat.

To avoid this interaction, we can set the maximum diffuse light bounces of the scene to 0 in the "light path" tab.This obiuvsly means that we'll lose a bit of realism to the scene. Now Cycles looks more similar to BI...but, at any rate, we keep all other features intact (see glossy blurry reflection in the second hemisphere).

To avoid diffuse interaction with the world background the only solution I came up with was to remove it (or set its strength to 0).

Summary:

1. Use that node sutup
2. Set all lamp size to a small value to obtain hard shadows and hard toon transition
3. Remove background
4. Set diffuse bounces in the "light path" tab to 0

Pros:

• Simple node setup
• React directly to lighting

Cons: