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 and OpenGL. 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.

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 minus left. The height is defined as bottom minus top.

In the top-left filling convention, the word "top" refers to the vertical location of horizontal spans, and the word "left" refers to the horizontal location of pixels within a span. 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.

If, for example, you define a rectangle 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 the Direct3D rasterizer tessellates this rectangle, the center of each pixel would be unambiguously inside each of the four triangles, and the top-left filling convention would not be needed. The following drawing illustrates this. The pixels in the rectangle are labeled according to the triangle in which Direct3D includes them.

If you move the rectangle in the previous example so that its upper-left corner is at (1.0, 1.0), its lower-right corner at (3.0, 5.0), and its center point at (2.0, 3.0), Direct3D applies the top-left filling convention. Most of the pixels in this rectangle would straddle the border between two or more triangles, as the next illustration shows.

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