Shader Declarations

Deprecated

Software and hardware shaders are both declared. A software shader declaration is little more than a list of the parameters accepted by the shader and their data types, without the actual values (they are defined later when the shader is used). Such a declaration might look like this, using mental ray's .mi scene definition syntax:

    declare shader
        color "mib_illum_lambert" (
            color           "ambience",
            color           "ambient",
            color           "diffuse",
            integer         "mode",
            array light     "lights"
        )
        version 2
    end declare

The declaration is the same for hardware and software shaders. This makes it simple to substitute a hardware shader for a software shader if both are written with the same interface parameters. Hardware shaders use the declaration to tell mental ray how the input parameters should be stored in uniform variables, just like software shaders use this information for building a stack frame for the C/C++ shader code.

The idea is that the declaration is the gateway between the shader and the hardware. Such a declaration may be fairly complex, but once written by the shader writer, the shader looks very similar to any other shader. The burden of writing the shader and declaring it is shifted to the programmer in a way that the artist, who later uses the shader, does not have to care about the complexities of hardware shader writing at all.

The only exception is that shaders might have built-in limitations not usually found in software shaders, such as accepting only a limited number of lights or textures; but these limitations are all in the domain of scene design and not in the domain of programming. Since the artist and the programmer require different skill sets, and are not normally the same person, mental ray maintains a strict separation of these two roles.

Hardware shaders come with additional information that is hidden behind the parameter declaration, in ways that only the programmer but not the artist needs to understand. A hardware shader declaration needs to contain the following information:

The following section describes an example based on NVIDIA's Cg language.

Copyright © 1986-2009 by mental images GmbH