Perspective Projection
- What’s near plane’s l,r,b,t then?
- If explicitly specified, good
- Sometimes people prefer: vertical field-of-view (fovY) and aspect ratio (assume symmetry i.e. l=-r, b = -t)
- How to convert from fovY and aspect to l, r, b, t?
- Trivial
tan f o v Y 2 = t ∣ n ∣ \tan{\frac{fovY}{2}}=\frac{t}{\lvert n\rvert} tan2fovY=∣n∣t
a s p e c t = r t aspect=\frac{r}{t} aspect=tr
- Trivial
Canonical Cube to Screen
- What is a screen?
- An array of pixels
- Size of the array: resolution
- A typical kind of raster display
- Raster = screen in German
- Rasterize = drawing onto screen
- Pixel (FYI, short of ‘picture element’)
- For now: A pixel is a little square with uniform color
- Color is a mixture of (red, green, blue)
- Defining the screen space
- Slightly different from the ‘tiger book’
- Irrelevant to z
- Transform in xy plane: [ − 1 , 1 ] 2 [-1,1]^2 [−1,1]2 to [ 0 , width ] × [ 0 , height ] [0,\text{width}]\times[0,\text{height}] [0,width]×[0,height]
- Viewport transform matrix:
M v i e w p o r t = ( w i d t h 2 0 0 w i d t h 2 0 h e i g h t 2 0 h e i g h t 2 0 0 1 0 0 0 0 1 ) M_{viewport}=\begin{pmatrix}\frac{width}2&0&0&\frac{width}2\\0&\frac{height}2&0&\frac{height}2\\0&0&1&0\\0&0&0&1\end{pmatrix} Mviewport= 2width00002height0000102width2height01
Rasterization: Drawing to Raster Displays
Triangles - Fundamental Shape Primitives
Why triangles?
- Most basic polygon
- Break up other polygons
- Unique properties
- Guaranteed to be planar
- Well-defined interior
- Well-defined method for interpolating values at vertices over triangle (barycentric interpolation)
A Simple Approach: Sampling
Evaluating a function at a point is sampling.
We can discretize a function by sampling.
for (int x = 0; x < xmax; ++x) {
output[x] = f(x);
}
Sampling is a core idea in graphics.
We sample time (1D), area (2D), direction (2D), volume (3D)…
- Rasterization = Sampling A 2D Indicator Function
for (int x = 0; x < xmax; ++x) {
for (int y = 0; y < ymax; ++y) {
image[x][y] = inside(tri, x + 0.5, y + 0.5);
}
}
- Evaluating
inside(tri, x, y)