3D Graphics Programming with QuickDraw 3D
The application of surface-based shaders occurs within the QuickDraw3D shading architecture, an environment in which shaders can be applied at various stages in the imaging pipeline. This architecture provides well-defined entry points at specific locations along the imaging pipeline. At each such location, you can invoke a shader. This capability allows you to create both two-dimensional and three-dimensional visual effects.
The QuickDraw3D shading architecture is implemented using an object-based class hierarchy. For each location in the imaging pipeline at which a shader can be invoked, a subclass of the shader object has been defined. The following sections describe the available classes of shader objects.
Figure 14-1 Effects of the Lambert illumination shader
For a point on a surface, the Lambert illumination provided by i distinct lights is given by the following equation:
Here, Ia is the intensity of the ambient light, and ka is the ambient coefficient. Od is the diffuse color of the surface of the object being illuminated. N is the surface normal vector at the point whose illumination is being evaluated, and Li is a normalized vector indicating the direction to the ith light source. Notice that if the dot product (N × Li) is 0 for a particular light (that is, if N and Li are perpendicular), that light contributes nothing to the illumination of the point. Ii is the intensity of the ith light source, and kd is the diffuse coefficient of the surface being illuminated (that is, the level of diffuse reflection of the surface).
As you can see, the intensity of the light reflected by a point on a surface depends solely on the ambient light and the diffuse reflection of the surface
at that point.
QuickDraw3D does not currently provide a way to set the value of the diffuse coefficient of a surface directly. Instead, you must use the product kdOd as the surface's diffuse color. You specify a diffuse color by inserting an attribute of type kQ3AttributeTypeDiffuseColor into the surface's attribute set.<8bat>u
Figure 14-2 Effects of the Phong illumination shader
For a point on a surface, the Phong illumination provided by i distinct lights is given by the following equation:
Notice that the Phong illumination equation is simply the Lambert illumination equation with an additional summand to account for specular reflection. Here, R is the direction of reflection and V is the direction of viewing. The exponent n is the specular reflection exponent, and ks is the specular reflection coefficient. The specular reflection exponent determines how quickly the specular reflection diminishes as the viewing direction moves away from the direction of reflection. In other words, the specular reflection exponent determines the size of the specular highlight (a bright area on the surface of the object caused by specular reflection). When the value of n is small, the size of the specular highlight is large; as n increases, the size of the specular highlight shrinks.
The specular coefficient (or specular reflection coefficient), symbolized by ks in the equation above, indicates the level of the object's specular reflection. It controls the overall brightness of the specular highlight, independent of the brightness of the light sources and the direction of viewing.
Figure 14-3 shows an object illuminated using a variety of values for the specular reflection exponent and the specular coefficient. In this figure,
the specular reflection exponent increases from left to right, resulting in a smaller specular highlight. In addition, the specular coefficient increases
from top to bottom, resulting in a brighter specular highlight.
Figure 14-3 Phong illumination with various specular exponents and coefficients
A surface's specular reflection coefficient is also called
its specular control. You specify a specular reflection coefficient by inserting an attribute of type kQ3AttributeTypeSpecularControl
into the surface's attribute set.<8bat>u
Figure 14-4 Effects of the null illumination shader
For any point on a surface, the null illumination is given by the following equation:
Here, Od is the diffuse color of the surface of the object being illuminated. As you can see, when the null illumination shader is active, all facets of an object are drawn the same color (unless different facets have attribute sets that override the diffuse color of the object).
You create a texture shader by calling Q3TextureShader_New
, passing it a texture object (or, more briefly, a texture). QuickDraw3D provides a number of functions that you can use to create and manipulate texture objects. Currently QuickDraw3D supports one subclass of texture objects, pixmap texture objects, which are images defined by pixmaps. You call Q3PixmapTexture_New
to create a new texture object from a pixmap.
See the chapter "Geometric Objects" for information on pixmaps.<8bat>u
Once you've created a texture from a pixmap, you need to attach the texture to surfaces in your model. See "Using Texture Shaders" on page 14-11 for details.
Let us know what you think of these prototype pages.
Generated with Harlequin WebMaker