Contour Contrast Function

The contour contrast shader decides where the contours should be. For example, it might decide that there should be a contour when the difference in depth or orientation is large. The decision is based on the contour information for two points (the information saved by the contour store shader), the reflection or refraction level of the two points, the state, and the parameters of the contour contrast function. Note that the state does not contain intersection information because the contrast function is comparing two intersections, described solely by the information stored by the two contour store functions. This means that state variables such as point or tex_list are undefined in a contrast function.

The output is a Boolean value indicating whether there should be a contour between the two points. If the returned value is miTRUE, one of two things can happen: If the distance between the two points corresponds to max samples, a contour will be placed between the two points (getting contour width, color, etc. by calling the material's contour shader). If not, mental ray will take some additional samples to get a more precise position of the contour. There is only one contour contrast shader for the scene.

As an example of a user-defined contour contrast shader, consider the following function with parameters zdelta and ndelta:

miBoolean my_contour_contrast_function(
    MyInfo                          *info1,
    MyInfo                          *info2,
    int                              level,
    miState                         *state,
    My_Contour_Contrast_Parameters  *paras)
{
    /*
     * Contour if one ray intersected an object and one
     * ray hit background
     */
    if (!info1 || !info2)
           return(miTRUE);

    /*
     * Contour if sufficiently large difference in depth
     */
    if (fabs(info1->point.z - info2->point.z) >
                                          paras->zdelta)
           return(miTRUE);

    /*
     * Contour if sufficiently large change in normal
     */
    if (mi_vector_dot(&info1->normal, &info2->normal) <
                        cos(paras->ndelta * M_PI/180.0))
           return(miTRUE);

    /*
     * No contour otherwise
     */
    return(miFALSE);
}

Copyright © 1986, 2013 NVIDIA Corporation