RixPatterns
CutrVelvet Node


return to main index

Code:
    CutrVelvet.args
    CutrVelvet.cpp



Introduction

This tutorial presents a custom RIS pattern node based on the RSL code used in the tutorial,
    RSL: Edge Effects
and elaborated in the tutorial,
    RfM Reyes: HyperShade cutrVelvet Node

The node colorises the silhouette edge of a curved surface based on the dot product of the viewing vector and the surface normal. The node interface in HyperShade is shown below - figure 1.



Figure 1


The Main CPP Code

Mose of the CutrVelvet.cpp code handles the declaration of variables and the connections of it's input and outputs - the "plumbing" if you will! However, lines 115 to 129 (ComputeOutputParams() method) are responsible for performing the calcuations that define CutrVelvet's "edge effect".


CutrVelvet lines 115 to 129


    // Assign an array of normalized shading normals to Nn.
    RtNormal3 const  *Nn;
    ctx->GetBuiltinVar(RixShadingContext::k_Nn, &Nn);    
  
    // Assign an array of normalized view vectors to Vn.
    RtVector3 const  *Vn;
    ctx->GetBuiltinVar(RixShadingContext::k_Vn, &Vn);
        
    // Assign values to the outputs.
    RtFloat dot;
    for(int i = 0; i < ctx->numPts; i++) {
        dot = 1.0 - Vn[i].Dot(Nn[i]);
        dot = RixSmoothStep(1.0 - edge_width[i], 1.0, dot);
        resultRGB[i] = RixMix(base_color[i] * base_brightness[i], edge_color[i] * edge_brightness[i], dot);
        }







© 2002- Malcolm Kesson. All rights reserved.