All pastes #253960 Raw Edit

jesterKing

public python v1 · immutable
#253960 ·published 2006-11-21 09:23 UTC
rendered paste body
import Blenderimport Blender.Nodeimport mathfrom Blender import Noisefrom Blender import Mathutilsclass LambertPhong(Blender.Node.node):    def __init__(self, ins, outs):        colout = (Blender.Node.RGBA, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)                colin = (Blender.Node.RGBA, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0)        ambin = (Blender.Node.RGBA, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0)        specin = (Blender.Node.RGBA, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0)        ref = (Blender.Node.VALUE, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0)        spec = (Blender.Node.VALUE, 1.0, 1.0, 1.0, 1.0, 0.0, 2.0)        hard = (Blender.Node.VALUE, 1.0, 1.0, 1.0, 1.0, 0.0, 200.0)                outs.definitions ={'color':colout}        ins.definitions  ={  'diff':colin,                            'specular':specin,                            'amb': ambin,                            'ref': ref,                            'spec': spec,                            'hard': hard	                                }            def __call__(self, shi, ins, outs):        coords = shi.tex_coord        viewnorm = shi.view_normal        surfnorms = shi.surface_normal                    l = [1.0,1.0,1.0]       #light col        a = ins['amb']          #ambient col        d = ins['diff']         #diffuse col        #print a        s = ins['specular']     #specular col        ka = 0.5                #ambient coeff        kd = ins['ref']         #diffuse coeff        ks = ins['spec']        #specular coeff        katt = 1.0              #attenuation -> not needed        kn = ins['hard']        #hardness coeff                LOC = Mathutils.Vector(-1.0, 0.0, -10.0)        T = Mathutils.Vector(coords)        N = Mathutils.Vector(surfnorms)        L = LOC - T        L.normalize()        R = 2 * N * Mathutils.DotVecs(N, L) - L        V = Mathutils.Vector(viewnorm)        ix = [a[i]*ka*d[i] + katt * l[i] * (kd * d[i] * Mathutils.DotVecs(N, L) + ks * s[i] * Mathutils.DotVecs(R, V) ** kn) for i in xrange(3)]                outs['color'] = (ix[0],ix[1],ix[2], 1.0)