From BlenderWiki

Jump to: navigation, search

Back to index

[edit] Ideas

  • Add your idea here.

[edit] Recipes

[edit] Toon 1

Example output of Toon 1 node.[.blend]

This script produces simple toony surface. Adjust zmax and zmin for interesting results. Note that zmax > zmin. Else they are swapped.

from math import log, sqrt
from Blender import Node

def swap(a, b):
    return b, a

class Toon1Node(Node.Scripted):
    def __init__(self, sockets):
        zmax = Node.Socket('Zmax', val=1.0, min=0.01, max=10.0)
        zmin = Node.Socket('Zmin', val=0.5, min=0.01, max=10.0)
        
        col = Node.Socket('Color', val = 4*[1.0])
        
        sockets.input = [col, zmax, zmin]
        sockets.output = [col]

    def __call__(self):
        view_normal = self.shi.viewNormal
        max = self.input.Zmax
        min = self.input.Zmin
        
        if min >= max: min, max = swap(min, max)
        
        # Basic idea from X-Toon. See http://artis.inrialpes.fr/Publications/2006/BTM06a/ .
        D = 1.0- log(sqrt(view_normal[0]**2 + view_normal[1]**2)/min) / log(max/min)
        self.output.Color = map(lambda x: x * D, self.input.Color)

__node__ = Toon1Node

[edit] Toon 2

Example output of Toon 2 node.[.blend]

Another toon shader. This is focused more on detecting sharp edges in a rudimentary way.

from Blender import Node

def swap(a, b):
    return b, a

class Toon2Node(Node.Scripted):
    def __init__(self, sockets):
        col1 = Node.Socket('Color1', val = 4*[1.0])
        col2 = Node.Socket('Color2', val = 4*[1.0])
        threshold = Node.Socket('Threshold', val=0.5, min=0.0, max=1.0)
        
        col = Node.Socket('Color', val = 4*[1.0])
        
        sockets.input = [col1, col2, threshold]
        sockets.output = [col]

    def __call__(self):
        self.output.Color = self.input.Color1
        
        if self.shi.surfaceNormal[2] * self.shi.viewNormal[2] > self.input.Threshold:
            self.output.Color = self.input.Color2

__node__ = Toon2Node