Triangle Rasterization Rules

Often the points specified for vertices do not precisely match the pixels on the screen. When this happens, Direct3D applies triangle rasterization rules to decide which pixels apply to a given triangle.

Direct3D uses a top-left filling convention for filling geometry. This is the same convention that is used for rectangles in GDI, the Windows NT polygon rasterizer, and OpenGL. Also, in Direct3D the center of the pixel is the point at which decisions are made; if the center is inside a triangle, the pixel is part of the triangle. Pixel centers are at integer coordinates.

This description of triangle-rasterization rules used by Direct3D does not necessarily apply to all available hardware. Your testing may uncover minor variations in the implementation of these rules. In the future, nearly all manufacturers will implement these rules as they are described in this section.

The following illustration shows a rectangle whose upper-left corner is at [0, 0] and whose lower-right corner is at [5, 5]. This rectangle fills 25 pixels, just as you would expect. The width of the rectangle is defined as right-left. The height is defined as bottom-top.

In the top-left filling convention, the word "top" refers to horizontal spans, and the word "left" refers to pixels in spans. An edge cannot be a top edge unless it is horizontalžin the general case, most triangles will have only left and right edges.

The top-left filling convention determines the action taken by Direct3D when a triangle passes through the center of a pixel. The following illustration shows two triangles, one at [0, 0], [5, 0], and [5, 5], and the other at [0, 5], [0, 0], and [5, 5]. The first triangle in this case gets 15 pixels, whereas the second gets only 10, because the shared edge is the left edge of the first triangle.

Suppose that a rectangle were defined with its upper-left corner at [0.5, 0.5] and its lower-right corner at [2.5, 4.5]. The center point of this rectangle would be at [1.5, 2.5]. When this rectangle was tessellated, the center of each pixel would be unambiguously inside each of the four triangles, and the top-left filling convention would not be needed.

If a rectangle with the same dimensions were moved slightly, so that its upper-left corner were at [1.0, 1.0], its lower-right corner at [3.0, 5.0], and its center point at [2.0, 3.0], the top-left filling convention would be required. Most of the pixels in this new rectangle would straddle the border between two or more triangles.

Notice that for both rectangles, the same pixels are affected.