Lecture_003_Drawing_a_Triangle_and_an_Intro_to_Sampling

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)

Swept Spheres

Swept Spheres

Implicit Surface (https://www.wikiwand.com/en/Implicit_surface)

Implicit Surface (https://www.wikiwand.com/en/Implicit_surface)
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

Rasterization Pipeline

Rasterization Pipeline

Why use triangle:

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.

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.

Different situation a pixel can be covered by triangles. Getting analytical answer is too difficult.

Different situation a pixel can be covered by triangles. Getting analytical answer is too difficult.

Sampling

Sampling the Original Signal

Sampling the Original Signal

Sampling Coverage

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

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

Coverage Sampling Result

Coverage Sampling Result

Breaking Ties

Ties can appear through sampling

Ties can appear through sampling

Tie Breaking Implementation: OpenGL, Direct3D implementation

Tie Breaking Implementation: OpenGL, Direct3D implementation

Reconstruction

Constant Reconstruction of Original Signal

Constant Reconstruction of Original Signal

Piecewise Linear Reconstruction of Original Signal

Piecewise Linear Reconstruction of Original Signal

Reconstruction in 2D

Reconstruction in 2D

Sampling and Reconstruction

Sampling and 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)

Aliasing Visualization

Aliasing Visualization

Image Reconstruction Example

Left: Original Signal; Right: Frequency Spectrum

Left: Original Signal; Right: Frequency Spectrum

Left: Reconstructed Signal; Right: Keep only low frequency

Left: Reconstructed Signal; Right: Keep only low frequency

Left: Reconstructed Signal; Right: Keep only mid frequency

Left: Reconstructed Signal; Right: Keep only mid frequency

Left: Reconstructed Signal; Right: Keep only high frequency

Left: Reconstructed Signal; Right: Keep only high frequency

Graph of klzzwxh:0017. The ring has higher frequency as the radius increase

Graph of z = \sin(x^2 + y^2). The ring has higher frequency as the radius increase

Graph of klzzwxh:0019 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.

Graph of 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.

Usually for RGB pictures, we sample brightness and color in different frequency because brightness has higher frequency than color.

klzzwxh:0024

\text{sinc} = \frac{1}{\pi x}\sin(\pi x)

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.

Two issues why we can't use klzzwxh:0027

Two issues why we can't use \text{sinc}

Resulting "Jaggies" in static image; "Roping" or "shimmering" in animated images; Moire patterns in high-frequency area of images;

Resulting "Jaggies" in static image; "Roping" or "shimmering" in animated images; Moire patterns in high-frequency area of images;

Supersampling

Supersampling: taking multiple random samples for each pixel

Supersampling: taking multiple random samples for each pixel

Turning supersampling into pixel

Turning supersampling into pixel

But error persists in supersampling

But error persists in supersampling

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

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

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

Incremental Traversal

Incremental Traversal

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

Sticky Situration: parallel traversal will waste a lot of power

Sticky Situration: parallel traversal will waste a lot of power

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)

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.

Line Rasterization Rule

Line Rasterization Rule

Line Rasterization Rules (Antialiased, Without Multisampling)

Line Rasterization Rules (Antialiased, Without Multisampling)

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.

Triangle Rasterization Rule

Triangle Rasterization Rule

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.

Point Rasterization Rule

Point Rasterization Rule

Multisample Anti-Aliasing Rasterization Rules

Multisample Anti-Aliasing Rasterization Rules

For more specification: read Microsoft Rasterization, OpenGL, Vulkan Line Rasterization

OpenGL vs Vulkan

OpenGL vs Vulkan

Table of Content