Tuesday, April 3, 2012

Rasterization Rules

People who have experience in graphics programming using graphics APIs such as DirectX, OpenGL, and OpenGL ES, must have been familiar with the term, "Rasterization". However, how many of you have heard about "rasterization RULES"? In other words, who do you know how hardware determines that a specific pixel on shared edge between two triangles belongs to which triangle? This could be a point of view from graphics hardware rather than programmer's because it is processed in driver software. Thereby, driver softwares should follow the rules up. As a result, programmers who develop the drivers should know how rasterization works. However, regardless that you are a graphics driver programmer or graphics software engineer using APIs, I believe that "understanding the basic theory" is always helpful and useful to learn other concepts as well as work in various environments. Today, I would like to go over "rasterization rules" in graphics.  As I briefly mentioned before, 1) two polygons could share their edges (i.e., a rectangle consisting of two triangles). Another case is that 2) two lines could share the point (i.e., a set of line segments). These are two cases for the rasterization rules.

1. Top-left rule:
A triangle rasterization rule (in Direct3D, OpenGL, GDI) defines how vector data is mapped into raster data. The raster data is snapped to integer locations that are then culled and clipped, and per-pixel attributes are interpolated before being passed to a pixel shader. Top-left rule ensures that adjacent triangles are drawn once.

The shared edge is the left edge of the Triangle (0,0, 5,0, 5,5). Thus pixels on the shared edge are included into the right triangle.  If we consider antialiasing or multisampling , it will be more complicated.


2. Diamond-exit rule:
This is a rasterization rule for line segments that share the end point. OpenGL uses a this rule to determine those fragments that are produce by rasterizing a line segment.
Hence, when rasterizing a series of connected line segments, shared end points will be produced only once. Then, the diamond regions where line segment exits cause rasterization to produce fragments. In the figure, two line segments share the end point that belongs to the green line based on the diamond-exit rule.

No comments: