abouton z ARCHIVE resumeoff   logo vfx


electron microscope Shader Project

Concept / Updates / Breakdown

The original idea for the shader was to simply adjust the facing ratio of the polygons.

The beginning part of the code sets a variable to a forward facing normal causing the normals to face the camera.

normal n = normalize(N);
normal nf = faceforward(n, I, n);

Next we reverse the viewing vector set as “i”. Using a “dot” product or in other words finding the cosine between our reversed viewing vector and our normal. We can reverse the diffuse color with a simple subtraction of 1.

Next we can change the rim with a smooth step function to the apparent opacity.

vector i = normalize(-I);
float dot = 1 - i.nf;

Finally we can change the color of the rim by multiplying a color back into the final equation.

Ci = Oi * Cs * diffusecolor * coloredge * Kd;

A hairy Ant

The second shader on this project creates the hairs on the surface even if a displacement is used. It would be too difficult to explain the code verbatim but the general idea is simple.

First a new function within the RSL needs to be declared. This function can define three points, a base, a mid point, and a tip. This was done in a “C” script provided by Prof. Malcom Kesson.

The shader will randomly select micro polygons based on a percentage defined by the artist. This is called by an “if” statement that checks if the random number is greater than the density percentage. If so a curve will be defined.

if(random() > density && ribname != "")

Next the shader will figure out a U and V position in relation to a normal and find an average between them. This will cause a hair to tip to one side.

vector uBias = normalize(transform(spacename, dPdu));
vector vBias = normalize(transform(spacename, dPdv));
vector bias = vector( (uBias[0] + vBias[0])/2,
(uBias[1] + vBias[1])/2,
(uBias[2] + vBias[2])/2);


Next the shader figures the base and then the tip based on a predefined length. After that the midpoint is calculated but really it is 2/3’s of the length. This midpoint is then combined with noise to give a bend to the hair. This is how the defined curve is then drawn out.

point base = transform(spacename, P);
point tip = base + nn * len; // Wiggle the mid point
float ns = noise(transform(spacename, P) * Kf);
ns = ns - 0.5; ns = ns * Kn;
point mid = base + (nn * len)/3 + ns;

After that a the curves are saved out into a rib file where the a “ReadArchive” function can call them back into play.

facehair(ribname, base, mid + bias/3, tip + bias, basewidth, tipwidth);

Bringing it together

The last part of code was a rib file that brings in my geometry to generate the curves then using another frame to bring the hair ribs and the geometry ribs together under the facing ratio shader.