Table of contents
GDI
TOC
Collapse the table of content
Expand the table of content

Shading Requirements

Last Updated: 2/14/2017

The requirements for flat shading, Gouraud shading, specular highlighting, alpha blending, dithering, and color-key are as follows:

Flat Shading

The D3DPSHADECAPS_COLORFLATRGB bit in the dwShadeCap member of the D3DPRIMCAPS structure must be set for the appropriate primitive type (line or triangle) in order to indicate that flat shading is supported for that primitive type.

For all primitive types except triangle fans, the color, specular (if supported) and alpha data come from the first vertex of each primitive. For triangle fans, the second vertex is used. These colors remain constant across the entire triangle (that is, they are not interpolated).

Gouraud Shading

The dwShadeCaps member of the D3DPRIMCAPS structure must have the D3DPSHADECAPS_COLORGOURAUDRGB bit set for the appropriate primitive type (line or triangle) to indicate that Gouraud interpolation of colors is supported. The color and specular components are both linearly interpolated between vertices.

For all primitives, the color data must use linear interpolation between the vertices of the primitive, and must conform to an image generated by the reference rasterizer. Furthermore, all color and alpha components must be interpolated in the same fashion if they are present. For example, it is not valid to use Gouraud interpolation of the RGB components of a color while using flat shading for the alpha component. An exception is transmitting the fog component via the alpha component of the specular color, which should never be flat shaded.

Perspective correction of iterated color components is encouraged. Note that the reference rasterizer in the latest Direct X release already does perspective correction of color components. This is taken into account in current testing procedures.

Specular Highlighting

If specular highlighting support is exposed, then one or both of the following flags must be set in the dwShadeCaps member of the D3DPRIMCAPS structure for the appropriate primitive type (line or triangle):

  • D3DPSHADECAPS_SPECULARFLATRGB must be set if flat shading is supported.

  • D3DPSHADECAPS_SPECULARGOURAUDRGB must be set if Gouraud shading is supported.

Also, it must be possible to enable or disable specular highlighting by setting the appropriate value of the D3DRENDERSTATE_SPECULARENABLE render state.

Specular highlighting must be full color, and must be capable of producing the full range of colors available for the render target. Monochromatic specular highlighting is not sufficient to meet this requirement.

The D3DPSHADECAPS_SPECULARFLATMONO and D3DPSHADECAPS_SPECULARGOURAUDMONO flags are not to be used to indicate monochromatic specular highlighting. They indicate only that specular highlighting is supported in RAMP mode. There is no cap that can indicate that an adapter supports only monochromatic specular highlights in RGB mode. If your adapter supports only monochromatic specular highlights in RGB mode, you should not set the SPECULARFLATRGB or SPECULARGOURAUDRGB caps. With the monomodes, the hardware should just interpolate the blue channel of the specular components as a white intensity. This is controlled by the D3DRENDERSTATE_MONOENABLE render state.

To properly implement specular highlights, a second set of interpolants is required. However, hardware parts that support z-buffering and blending can often emulate specular highlights by doing a second blending pass over the triangle with the z comparison function set to D3DCMP_EQUAL (see the D3DCMPFUNC enumerated type in the DirectX SDK documentation). This second pass would do a blend to add the interpolated specular component to the pixel written during the first pass; values that exceed the maximum should saturate to white.

Alpha Blending

To expose support for alpha blending, the following flags must be set in the dwShadeCaps member of the D3DPRIMCAPS structure for the appropriate primitive type (line or triangle):

  • D3DPSHADECAPS_ALPHAFLATBLEND must be set if flat shading is supported with alpha.

  • D3DPSHADECAPS_ALPHAGOURAUDBLEND must be set if Gouraud shading is supported with alpha.

If alpha blending is supported, it must be possible to enable or disable it by setting the appropriate value of the D3DRENDERSTATE_ALPHABLENDENABLE render state.

Alpha blending, or true transparency (from the 3D space), is the process of modulating incoming color by the value of the data that is already located in the frame buffer. This render state has modes that can be set by the D3DRENDERSTATE_SRCBLEND and D3DRENDERSTATE_DESTBLEND render states.

When the alpha value for a blending operation is not available, it must be assumed to be 1.0 (opaque). An example of when this is possible is blending with textures that have no alpha channel.

If the target to which the resultant pixel is written contains an alpha channel, the alpha value resulting from any alpha blending operation must be written to that channel, allowing proper accumulation of transparency.

Dithering

If dithering is supported on a particular primitive type (line or triangle), the dwRasterCaps member of the D3DPRIMCAPS structure must have the D3DPRASTERCAPS_DITHER flag set. The feature must be controllable by means of the D3DRENDERSTATE_DITHERENABLE render state.

If dithering is supported, it may not default to always off or always on.

Color-key

Color-key is related to texture transparency and the D3DPTEXTURECAPS_TRANSPARENCY cap (see the dwTextureCaps member of the D3DPRIMCAPS structure).

Color-key transparency, which is used to create 2D sprites, replaces some colors of an object with the colors that are beneath them in the frame buffer. The driver should make it possible for an application to enable color-key for an entire scene, but only use the color-key on certain surfaces with the attached color-key values instead of turning the color-key on and off for each surface.

Colorkeying is enabled if the D3DRENDERSTATE_COLORKEYENABLE render state is set to TRUE and the texture surface has the DDRAWISURF_HASCKEYSRCBLT bit set

Color-key is enabled if the D3DRENDERSTATE_COLORKEYENABLE render state is set to TRUE and the texture surface has the DDRAWISURF_HASCKEYSRCBLT bit set. (See the dwFlags member of the DD_SURFACE_LOCAL structure for more information.) Applications create a texture surface that uses DDSD_CKSRCBLT and then call the IDirect3DDevice7::SetRenderState method with D3DRENDERSTATE_COLORKEYENABLE and TRUE. Both of these must be true for color-key to occur, and applications must be permitted to leave the render state TRUE all the time and still selectively use color-key for a subset of a frame's textures (that is, those that have the DDRAWISURF_HASCKEYSRCBLT bit set). It is up to the driver to correctly handle this behavior. For more information about IDirect3DDevice7::SetRenderState, see the Direct3D SDK documentation.

Send comments about this topic to Microsoft

© 2017 Microsoft