Wednesday, April 7, 2010

shading normals

straight from Renderman pro server documentation,

P += normalize(N) * a * amplitude;t a;
P = transform("object", P);
N = transform("object", N + point "object" (0,0,0));
P = transform("object", "current", P);
N = calculatenormal(P);

with some errors in the above code, we can use this in a vector slbox to slightly alter the shading normal which we can then plug into a shading component(specular and reflection). say we want to break up the specular reflection of specular to make it look like water droplets on skin. we use the above code, use a fractal for "a", create our own point p and normal n, and normalize the final n. It'll look like this,

point p = transform("object", P);
normal n = transform("object", N + point "object" (0,0,0));
p += normalize(n) * a * amplitude;
p = transform("object", "current", p);
n = calculatenormal(p);
result = normalize(n);

The addition of point "shader" (0,0,0) in the second line accounts for the fact that N is really a vector (or normal), and thus should not transform in the same way as a point.
This is the old way of transforming vectors and normals. These days, we encourage you to use the following equivalent (but less confusing and cheaper!) construct:
normal Nsh; Nsh = ntransform ("shader", N); For vectors (as opposed to normals), one should use the vtransform function.


Post a Comment