Deprecated
Hardware shaders are closely tied to the graphics hardware available. It is generally not possible to use a Cg shader that uses special NVIDIA hardware features for ATI hardware, and vice versa. The main classes are:
The main difference between software and hardware shaders to keep in mind is that hardware shading always proceeds triangle by triangle, not ray by ray. Each of the three vertices of the triangle pass through a vertex shader which may move vertices, alter normals, or set up other information tied to the vertex.
When all three vertices have been set up, the hardware rasterizes the triangle by picking points on the triangle that correspond to image pixels. For each of them, the vertex information stored by the vertex shader is interpolated, and the fragment shader is called to compute a pixel color value that is then stored or merged into the frame buffer.
For the shader writer, this means that there is no geometrical information except as stored by the vertex shader. There is no way to, for example, trace a ray, find a ray or volume length, or do other operations that involve other geometry. Reflections, shadows, and other features are available only through precomputed map images such as texture maps.
mental ray supports a large number of shader types. Only material and light shaders are directly supported. Since Cg supports shader graphs, subshaders including texture shaders are supported as well.
shader type | support |
---|---|
material | supported |
light | supported |
subshaders | supported in Cg1.2 |
texture | supported |
volume | not supported |
environment | supported for cameras but not materials |
lens | not supported; will never support ray bending |
output | not supported |
shadow | not applicable; shadow shaders are called during ray tracing only. Hardware rendering uses shadow maps instead. |
photon | not applicable; photon mapping is based on ray tracing and must be completed before hardware rendering begins. |
geometry | not applicable, geometry is built before rendering begins. |
displacement | not applicable for the same reason, although vertex shaders can be written that displace preexisting vertices. |
The next sections will show how to write a simple Phong shader and a point light shader.
Copyright © 1986-2009 by mental images GmbH