The graphics pipeline is another approach to rendering: drawing objects one by one onto the screen, or object-order rendering
. Unlike in ray tracing, where we consider each pixel in turn and find the objects that influence its color, we will instead consider each geometric object in turn and find the pixels that it could have an effect on. The process of finding all the pixels in an image that are occupied by a geometric primitive is called rasterization
. So object-order rendering can also be called rendering by rasterization. The sequence of operations is starting with objects and ending by updating pixels in the image, namely graphics pipeline
.
Hardware pipelines must run fast enough to react in real time for games, visualizations, and user interfaces. Production pipelines must render the highest quality animation and visual effects possible and scale to enormous scenes, but may take much more time.
The work that needs to be done in object-order rendering can be organized into the task of rasterization itself, the operations that are done to geometry before rasterization, and the operations that are done to pixels after rasterization. The most common geometric operation is applying matrix transformations to map the points that define the geometry from object space to screen space, so that the input to the rasterizer is expressed in pixel coordinates, or screen space. The most common pixelwise operation is hidden surface removal
which arranges for surfaces closer to the viewer to appear in front of surfaces farther from the viewer. Geometric objects
are fed into the pipeline from an interactive application or from a scene description file, and they are always described by sets of vertices
. The vertices are operated on in the vertex-procssing stage
, then the primitives using those vertices are sent to the rasterization stage
. The rasterizer breaks each primitive into a number of fragments, one for each pixel covered by the primitive. The fragments are processed in the fragment processing stage, and then the various fragments corresponding to each pixel are combined in the fragment blending stage.
Rasterization
For each primitive that comes in, the rasterizer has two jobs:
- enumerating the pixels that are covered by the primitive;
- then, interpolating values, called
attributes
, across the primitive.
The output of the rasterizer is a set of fragments
, one for each pixel covered by the primitive. Each fragment lives at a particular pixel and carries its own set of attribute values.
Line Drawing
For general screen coordinate endpoints , , the routine should draw some reasonable set of pixels that approximate a line between them.
Line drawing using implicit line equations
The most common way is the midpoint
algorithm. The midpoint algorithm ends up drawing the same lines as the Bresenham alogithm, but more straight forward.
The first thing is to find the implicit equation for the line as discussed in .
Nexy, we assume the slop of the line where the line is moving faster in than in . The key assumption of the midpoint algorithm is that we draw thinnest line possible that has no gaps. A diagonal connection between two pixels is not considered a gap.
The midpoint algorithm for first estabilishes the left most point.
Triangle Rasterization
Barycentric coordinates -> color redering.
Another subtlety of rasterizing trangles is that we are usually rasterizing triangles that share vertices and edges.