Simple Phong shader via PyNodes

i was trying to implement a phong shader via pynodes for learing purposes, and it did´nt quite worked… see for yourself:
video --> http://vimeo.com/12810083

here is the code for the pynode

from Blender import Scene,Lamp, Node
from Blender.Mathutils import *
import Blender
import math

class Shader(Node.Scripted):

def __init__(self, sockets):
    col = Node.Socket('Color', val = 4*[1.0])
    loc = Node.Socket('Coords', val = 3*[1.0])
    nor = Node.Socket('Normal', val = 3*[1.0])
    rought = Node.Socket('Rought', val = 1.0, max = 100.0, min = 0.0001)
    
    sockets.input = [col, loc, nor, rought]
    sockets.output = [col]
       
def __call__(self):
    col = self.input.Color
    rought = self.input.Rought
    lamp = Blender.Object.Get("Lamp")
    cam = Blender.Object.Get("Camera")
    
    P = Vector(self.input.Coords)
    N = Vector(self.input.Normal).normalize()
    
    L = Vector(lamp.getLocation('worldspace')).normalize()
    I = (P-L).normalize()
    
    R = L.reflect(N)
    R = R.normalize()
    
    
    intensity = DotVecs(R,I)
    if intensity < 0:
         intensity = 0
    intensity = intensity**1/rought
    self.output.Color = [intensity,intensity,intensity,1]

node = Shader

can anyone help me finding the error and fixing it?

IIRC (which I probably don’t) you can access the shadeinput struct variables to get the surface normal, light vector and the rest of the stuff you need to do a proper shader.

That way you wouldn’t need create sockets to get those values.

Don’t remember how to get at it though.

IIRC?
i dont think the problem is in the socket input, but in the calculation part…

the normal input is necessary because if i use a (self.shi.normal, i think is something like this) you get a result with a “flat shade” turned on…

Ok, yeah, self.shi sounds about right – too lazy to look it up though.

But what I’m saying is blender gives you the light vector (so you don’t have to lookup Blender.Object.Get(“Lamp”)), view vector (Blender.Object.Get(“Camera”)), etc… for every point and (I believe) runs the shader calculation for every lamp separately so you can automagically have it work with multiple lamps.

You also have to run a diffuse and specular pass if you want it to look like a built-in shader because that’s what they do.

Oh, i see, i will try that…

Yes, I know, i alredy did a larbertian shader based on this tutorial.