# Lecture_003_Drawing_a_Triangle_and_an_Intro_to_Sampling

## 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:

1. Coverage: what pixel on screen does a triangle cover
2. Occlusion: if we have multiple triangles cover the same pixel, which one is closest to the camera Visibility Problem: Virtual Sensor needs to figure out the colors of pixels to draw. Notice the Virtual Sensor is mirrored with x-axis for convenience.

### Sampling

#### Sampling Coverage Sample Coverage Function: for all triangle, we sample its coverage function

### 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 Graph of z = \sin(x^2 + y^2)z = \sin(x^2 + y^2). The ring has higher frequency as the radius increase Graph of z = \sin(x^2 + y^2)z = \sin(x^2 + y^2) when viewed from above, colored z value as brightness. Notice as the frequency increse, sampled frequency does not always increase due to constant sampling rate.

#### 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.

There are two problems with $\text{sinc}$ filter

1. Encode a hard edge (piecewise discontinuity in the triangle edge) needs infinite series of frequencies.
2. If for each pixel we use a $\text{sinc}$, then every pixel can affect every other pixel, therefore computational power is to expensive. Resulting "Jaggies" in static image; "Roping" or "shimmering" in animated images; Moire patterns in high-frequency area of images;

#### Supersampling Analytic solution do exists in rendering checkerboard, but most things are not analytically solvable

### Implementation Details Coverage: check a point inside triangle by checking its relation to the boundary

Incremental Traversal: Check pixel near each other

Parallel Traversal:

1. bound a triangle by a box
2. check every pixel in the box in parallel

Coarse to Fine:

1. divide big box region into smaller boxes
2. check if the box overlaps with triangle
3. if overlap some, we subdivide more
4. if no overlap, all pixels in boxes are turned off
5. if all overlap, all pixels in boxes are turned on Recursive Coarse to Fine, but actual trade off depends on hardware (usually 1 coarse to fine level is good)

Note: Coarse to Fine can also be improved with Incremental Traversal since boxes near each other share similar pixel.

Table of Content