RixPatterns
|
Notes on the Code
The basic code for CutrSideMask.cpp was generated from the .args file shown below.
Refer to the tutorial, |
|
Listing 1 (CutrSideMask.args)
|
|
Once the .args script had been created
and it UI had been previewed
a .cpp document was generated by Cutter.
Most of the code generated by Cutter does not require editing, however, lines (112 to 133) were deleted, ----snip----snip----snip----snip----snip----snip----
// Access the primitive variables that will be needed for the
// calculation of the output values. For example, 'st' texture
// values.
RtFloat2 const *st, st_default(0, 0);
sctx->GetPrimVar("st", st_default, &st);
// Assign values to each point.
for(int n = 0; n < sctx->numPts; n++) {
// For example, assign values based on the value of 's'...
if(st[n].x > 0.5) {
resultC[n].r = input_outsideRGB->r;
resultC[n].g = input_outsideRGB->g;
resultC[n].b = input_outsideRGB->b;
}
else
{
resultC[n].r = 1;
resultC[n].g = 1;
resultC[n].b = 1;
}
----snip----snip----snip----snip----snip----snip----
and replaced by the following code. // Access the primitive variables that will be needed for the
// calculation of the output values.
RtNormal3 const *Ngn; // normalized geometric normal
RtVector3 const *Vn; // normalized view vector
sctx->GetBuiltinVar(RixShadingContext::k_Ngn, &Ngn);
sctx->GetBuiltinVar(RixShadingContext::k_Vn, &Vn);
// Assign values to each point.
for(int i = 0; i < sctx->numPts; i++) {
// Calculate the dot product and use it to determine if the
// point being shaded is facing the camera.
float NdotV = Dot(Ngn[i], Vn[i]);
if (NdotV > 0.f) {
resultRGB[i] = input_outsideRGB[i];
}
else
{
resultRGB[i] = input_insideRGB[i];
}
}
|
|
No other edits were made. The final code for plugin can be viewed here. |
© 2002- Malcolm Kesson. All rights reserved.