# Discussion 2

## Bullets

• Transforms
• Basic transforms
• Scaling
• Reflection
• Shear
• Rotation in 2D
• Affine transformation
• Homogenous coordinates
• Coordinate system transform
• Combining transforms: Order of transformation
• Rotation in 3D
• Spaces
• World space
• Camera space
• View matrix
• Projection space
• Projection matrix
• Texture mapping
• Linear interpolation across a triangle
• Barycentric coordinates
• Perspective projection & interpolation
• Texture sampling
• Sampling rate
• Texture antialiasing
• Texture filtering
• Magnification
• Bilinear filtering
• Minification
• Trilinear filtering
• Rasterization pipeline (covered in discussion 3)
• Vertex processing
• Triangle processing
• Rasterization
• Fragment processing
• Simple shading: Blinn-Phong Reflection Model
• Framebuffer operations

## Transforms

📖 There's nothing I can say that's better than Songho's notes for transforms on OpenGL.

## Sampling

Reducing a continuous-time signal to a discrete-time signal. Think of it as recording sounds in a digital sound studio.

🤔 Some intuition: The continuous-time signal may be some sound picked up by the microphone, some image, some sine wave!?

🍿 If time permits: Demo differently sampled audio tracks (in Adobe Audition)

### Nyquist theorem

Nyquist frequency: Half the sampling frequency
We get no aliasing from frequencies less than the Nyquist frequency.

As an example, for an image of stripes (black & white), if we're sampling at every 16px, stripes at cycle every 32px or more will result in no aliasing.

Also, if there are stripes that cycle at every 8px (4px black, then 4px white), we'd want to sample at every 4px to avoid aliasing.

## Texture mapping

### Barycentric coordinates

\begin{align} (\alpha, \beta, \gamma), \alpha + \beta + \gamma = 1 \\ P = \alpha A + \beta B + \gamma C \\ \end{align}

We're only concering $R^2$ for this section

Point in triangle test demo

🤔 Do we really need to describe a point with all $\alpha$, $\beta$ and $\gamma$? What if we drop $\alpha$?

\begin{align} P & = \alpha A + \beta B + \gamma C \\ P & = (1 - \beta - \gamma) A + \beta B + \gamma C \\ P & = A - \beta A - \gamma A + \beta B + \gamma C \\ P - A & = \beta (B - A) + \gamma (C - A) \end{align}

Now we can see it with $A$ as the origin, with $(B - A)$ and $(C - A)$ as two independent vectors.

This can lead us to another point-in-triangle test (that doesn't worry about winding). For any $P$, how can we tell its Barycentric coordinates? It's a change in frame of reference.

\begin{align} P - A & = \beta (B - A) + \gamma (C - A) \\ \begin{bmatrix}B - A & C - A\end{bmatrix} \begin{bmatrix}\beta \\ \gamma\end{bmatrix} & = P - A \\ \begin{bmatrix}\beta \\ \gamma\end{bmatrix} & = \begin{bmatrix}B - A & C - A\end{bmatrix}^{-1} (P - A) \end{align}

This may look rather troublesome, but it lends to an approach for finding ray-triangle intersection in $R^3$ (more later).

🍿 If time permits: Demo Suzanne model (in Blender)

### Mipmaps

🤔 Why would you want mipmaps?