The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.
This shader does not work because the dot product never yields a value less than zero because N is in effect a front facing normal.
shader
sidemask(
color rearColor = color(0.7, 0.7, 0),
color frontColor = color(1,0,0),
output color resultRGB = 0)
{
vector i = normalize(-I);
vector n = normalize(N);
float angle = dot(i,n); // the cosine of the angle
// When the angle becomes negative we are shading
// the rear surface.
if(angle < 0)
resultRGB = rearColor;
else
resultRGB = frontColor;
}
In our implementation N in OSL corresponds to `Nf` in the C++ shader globals, meaning
the face-forward shading normal.
Ng corresponds to Ngf in the C++ shader globals, meaning the face-forward geometric normal.
To detect whether the shader is being executed on a back face, you would need to use the backfacing () function.