Rasterization: given geometry, render pixel
Ray Tracing: given pixel, render geometry
Primitives: whatever small things used to build big things that your graphic API supports.
Historically: it has actually taken the graphics community a long time to decide what the right building blocks for graphics should be. Two of my favorite diversions are swept spheres [which are both efficient to raytrace and can be rasterized reasonably efficiently as well] and implicit surfaces [which remain surprisingly relevant to this day]. (Jim McCann)
Implicit surface is used in Shader Toy but not popular because they are
- Non Local: can’t figure out where they are without solving equations
- hard to un-wrap/texture: surface not parameterize-able
Rasterization Pipeline
Why use triangle:
can approximate any shape
always planar, with well-defined normal vector
easy to interpolate data at corners (blend color using barycentric coordinates)
Two Questions:
Coverage: what pixel on screen does a triangle cover
Occlusion: if we have multiple triangles cover the same pixel, which one is closest to the camera
Sampling
Sampling Coverage
Breaking Ties
Reconstruction
Aliasing: When the frequency is higher than sampling rate, then reconstructed frequency can only be as high as sampling rate. (High frequencies in the original signal masquerade as low frequencies after reconstruction due to undersampling)
Image Reconstruction Example
Sinc Filter
Nyquist-Shannon Theorem: A band-limited signal (ie. no frequencies above threshold w_0) can be perfectly reconstructed if sampled with period T < \frac{1}{2} w_0 and reconstruct (interpolation) using \text{sinc} = \frac{1}{\pi x}\sin(\pi x) filter.
Usually for RGB pictures, we sample brightness and color in different frequency because brightness has higher frequency than color.
There are two problems with \text{sinc} filter
Encode a hard edge (piecewise discontinuity in the triangle edge) needs infinite series of frequencies.
If for each pixel we use a \text{sinc}, then every pixel can affect every other pixel, therefore computational power is to expensive.
Supersampling
Implementation Details
Incremental Traversal: Check pixel near each other
Parallel Traversal:
bound a triangle by a box
check every pixel in the box in parallel
Coarse to Fine:
divide big box region into smaller boxes
check if the box overlaps with triangle
if overlap some, we subdivide more
if no overlap, all pixels in boxes are turned off
if all overlap, all pixels in boxes are turned on
Note: Coarse to Fine can also be improved with Incremental Traversal since boxes near each other share similar pixel.
Diamond Exit Rule (for rasterizing line): Line is drawn if and only if it exit the diamond shape of a pixel. Any point in the line can only be exiting or entering the shape, not at the same time. This prevent redraw the same line when it is made up with 2 continuos segment. Specifically, a diamond will contain two opposite line and 2 points with inner area.
Top Left Rule (for rasterizing triangle): The top-left rule is that a pixel center is defined to lie inside of a triangle if it lies on the top edge or the left edge of a triangle.