We're making a movie with some swimming sharks; they've
been modeled as polygons; and I'd like to add a texture
to them. The sharks are deformed in the animation system,
so I pass in the original coordinates of each polygon as
well as the deformed coordinates, as follows:
RiDeclare("PreDef", "varying point");
...
RiPolygon(nvert, RI_P, pos, RI_N, normal, RI_ST, uv, "PreDef", predef,
RI_NULL);
Where 'pos' is the deformed points, and 'predef' is the undeformed
points.
Then, in the shader, I want to add some bumpy texture based on
the 3D undeformed points. The problem that I had originally
was that the model became faceted, because 'calculatenormal'
generates a new normal based strictly on the geometery.
The trick here is that you first have
to find the difference between the shading normal and the
geometric normal, and add that back into the normal at the end.
displacement
bumpy_texture(
float freq=200, depth=0.05;
varying point PreDef = point(0,0,0))
{
float d;
normal sN, nNg, diff;
point PP, PDP;
PDP = transform("object", PreDef) * freq;
d = noise(PDP) - .5;
PP = transform("shader",P);
sN = normalize(ntransform("shader",N));
nNg = normalize(Ng);
diff = N - nNg;
P = transform("shader", "current", PP + sN*depth*d);
N = normalize(calculatenormal(P)) + diff;
}
Anyway, this looks great. I'm sure I'll be looking this
message up in dejanews myself in a few months :)
-- Thaddeus Beier th...@hammerhead.com
Technology Development 818) 762-8643
Hammerhead Productions http://www.hammerhead.com