Contour Shaders

The contour shaders compute contour color and width (and optionally object label, material tag, motion, and normal). Their input is two contour information blocks for two adjacent samples on each side of a contour (as stored by the contour store shader), the state, and shader parameters. Each material can have a separate contour shader. If no contour shader is specified for a material, that material does not get a contour.

The contour shader to call is selected based on which object is in front. If the difference in depth is small, the selection is based on which object faces the camera the most. (This is necessary to avoid "randomly" mixing contours along an edge between two different materials.)

As an example, consider the following very simple contour shader. It makes the contours white and half a percent (of the image X resolution) wide:

miBoolean my_first_contour_shader(
    miContour_endpoint  *result,
    MyInfo              *info_near,
    MyInfo              *info_far,
    miState             *state,
    void                *paras)
    result->color.r = result->color.g =
    result->color.b = result->color.a = 1.0;
    result->width = 0.5;

The type of the result is

typedef struct {
    miVector  point;
    miColor   color;
    float     width;
    miVector  motion;
    miVector  normal;
    miTag     material;
    int       label;
} miContour_endpoint;

The point is automatically filled in, the contour shader does not have to do that. point.x and point.y are in screen coordinates, while point.z is in camera coordinates.

An example of a slightly more complex shader, where the contour color is a factor of the material color and the width is a parameter, is

miBoolean my_colordependent_contour_shader(
    miContour_endpoint      *result,
    MyInfo                  *info_near,
    MyInfo                  *info_far,
    miState                 *state,
    Factorcolor_Parameters  *paras)
     * Set contour color to a factor times material color.
     * The opacity color->a is set to 1.0, otherwise the
     * material will shine through the contour.
    float f = paras->factor;
    result->color.r = f * info_near->color.r;
    result->color.g = f * info_near->color.g;
    result->color.b = f * info_near->color.b;
    result->color.a = 1.0;

     * Contour width given by a parameter
    result->width = paras->width;


An appropriate data type must be defined for a contour shader. In this case, the data type of the parameters, Factorcolor_Parameters, contains the fields factor and width.

Copyright © 1986, 2013 NVIDIA Corporation