Interpolants: Gouraud Shading and Specular Lighting

[Previous] [Next]

In Direct3D, the Gouraud shading technique, like all shading techniques, defines how lighting is interpolated between vertices. Lighting techniques, such as specular lighting, are used to incorporate the vector that runs from the object to the viewer's eye into the lighting computation. Therefore, unless you use flat shading, Direct3D interpolates the characteristics of a triangle's vertices across the triangle when it renders a face. The triangle interpolants are color, specular, fog, and alpha. Although it seems that texture coordinates would also be interpolants, they aren't affected by the shading model. (Chapter 8 covers texture coordinates in more detail.)

The current shade mode (the mode being used for the primitives being rendered) modifies the triangle interpolants. If you're using flat shading, Direct3D performs no interpolation; the renderer applies the color of the first vertex in the triangle to the entire face. If instead you use Gouraud shading, Direct3D applies linear interpolation using all three of the triangles' vertices. The final shading mode, Phong shading, which isn't yet implemented by the hardware on today's market, computes the color and lighting for every pixel. Direct3D is ready to use this feature when the appropriate hardware emerges.

Be aware that the color and specular interpolants are treated differently, depending on which color model you're using. If you're using the RGB color model, Direct3D uses the red, green, and blue color components in the interpolation. If you're using the monochromatic (ramp) model (which is obsolete in DirectX 7), Direct3D uses only the blue component of the vertex color. The alpha component of a color (the component that controls the color's transparency) is used as a separate interpolant since device drivers implement transparency in two different ways: through texture blending and through stippling.

To determine which forms of interpolation the current driver supports, check the dwShadeCaps member of the D3DPRIMCAPS structure. Direct3D assumes that if a primitive type is supported, at least the D3DSHADE_FLAT mode (as specified in the D3DSHADEMODE enumerated type) is available.

This dwShadeCaps member can have one or more of the following flags:

  • D3DPSHADECAPS_ALPHAFLATBLEND and D3DPSHADECAPS_ALPHAFLATSTIPPLED Indicate that the device can support an alpha component for flat-blended and flat-stippled transparency, respectively (the D3DSHADE_FLAT state as specified in the D3DSHADEMODE enumerated type). Applications provide the alpha color component for a primitive as part of the color for the first vertex of the primitive.
  • D3DPSHADECAPS_ALPHAGOURAUDBLEND and D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED Indicate that the device can support an alpha component for Gouraud-blended and Gouraud-stippled transparency, respectively (the D3DSHADE_GOURAUD state as defined in the D3DSHADEMODE enumerated type). Applications provide the alpha color component for a primitive at the vertices and the device interpolates the alpha component across a face along with the other color components.
  • D3DPSHADECAPS_COLORFLATMONO and D3DPSHADECAPS_COLORFLATRGB Indicate that the device can support colored flat shading in the D3DCOLOR_MONO and D3DCOLOR_RGB color modes, respectively. In these modes, the application provides the color component for a primitive as part of the color for the first vertex of the primitive. If you use a monochromatic lighting mode, the driver interpolates only the blue component of the color. If you use RGB lighting modes, the red, green, and blue components are interpolated.
  • D3DPSHADECAPS_COLORGOURAUDMONO and D3DPSHADECAPS_COLORGOURAUDRGB Indicate that the device can support colored Gouraud shading in the D3DCOLOR_MONO and D3DCOLOR_RGB color modes, respectively. In these modes, the application provides the color component for a primitive at the vertices and the driver interpolates the color component across a face. In monochromatic lighting modes, the driver interpolates only the blue component of the color. If you're using RGB lighting modes, the red, green, and blue components are interpolated.
  • D3DPSHADECAPS_FOGFLAT and D3DPSHADECAPS_FOGGOURAUD Indicate that the device can support fog in the flat and Gouraud shading models, respectively.
  • D3DPSHADECAPS_SPECULARFLATMONO and D3DPSHADECAPS_SPECULARFLATRGB Indicate that the device can support specular highlights in flat shading in the D3DCOLOR_MONO and D3DCOLOR_RGB color models, respectively.
  • D3DPSHADECAPS_SPECULARGOURAUDMONO and D3DPSHADECAPS_SPECULARGOURAUDRGB Indicate that the device can support specular highlights in Gouraud shading in the D3DCOLOR_MONO and D3DCOLOR_RGB color models, respectively.


Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net