# 6 - Vertex Processing 2

# Outline

  • Projection Transformation
    • Orthographic Projection
    • Perspective Projection
  • Viewport Transformation

# Projection Transformation

  • View space โ†’ NDC (normalized device coordinate system)๋กœ ๋ณ€ํ™˜ $$ \mathbf{p_c=Pp_v} $$ ์—ฌ๊ธฐ์„œ
    • $\mathbf{p_v}$: view space ์ขŒํ‘œ
    • $\mathbf{P}$: projection matrix
    • $\mathbf{p_c}$: clip space (๋˜๋Š” NDC space) ์ขŒํ‘œ

# Recall that...

    1. ๊ฐ์ฒด ๋ฐฐ์น˜
      โ†’ Modeling transformation
    1. "์นด๋ฉ”๋ผ" ๋ฐฐ์น˜
      โ†’ Viewing transformation
    1. "๋ Œ์ฆˆ" ์„ ํƒ โ†’ Projection transformation
    1. "์Šคํฌ๋ฆฐ"์— ์ถœ๋ ฅ
      โ†’ Viewport transformation

# Recall: OpenGL Clip Space

  • Clip Space์—์„œ๋Š” $x, y, z$ ์ขŒํ‘œ๊ฐ€ $-1$์—์„œ $1$๊นŒ์ง€์ธ cube ๊ณต๊ฐ„ ์•ˆ์— ๊ฐ์ฒด๋ฅผ ๊ทธ๋ฆด ์ˆ˜ ์žˆ์Œ
  • ์ด ๊ณต๊ฐ„์˜ $xy$ ํ‰๋ฉด์ด 2D viewport ์—ญํ• ์„ ํ•จ
  • ์ด ์ขŒํ‘œ๊ณ„๋Š” normalized device coordinate (NDC) ๋ผ๊ณ  ๋ถˆ๋ฆผ

# Normalized Device Coordinates (NDC)

  • Normalized device coordinates (NDC)๋Š” ์žฅ์น˜์— ๋…๋ฆฝ์ ์ธ ๋””์Šคํ”Œ๋ ˆ์ด ์ขŒํ‘œ๊ณ„
    • ํ”ฝ์…€ ํฌ๊ธฐ, ํ•ด์ƒ๋„ ๋“ฑ์ด ๋‹ค๋ฅธ ๋‹ค์–‘ํ•œ ๋””์Šคํ”Œ๋ ˆ์ด ์žฅ์น˜์—์„œ๋„ ํ”„๋กœ๊ทธ๋žจ์ด ๋™์ผํ•˜๊ฒŒ ๋™์ž‘ํ•˜๊ฒŒ ํ•˜๋ ค๋ฉด ์ •๊ทœํ™”๋œ ์ขŒํ‘œ๊ณ„๊ฐ€ ํ•„์š”
  • ์ด ์ขŒํ‘œ๊ณ„์—์„œ์˜ ๊ณต๊ฐ„์„ clip space ๋˜๋Š” NDC space๋ผ๊ณ ๋„ ๋ถ€๋ฅธ๋‹ค
    • ๋‹จ, clip space์™€ NDC space๋Š” ์•ฝ๊ฐ„์˜ ์ฐจ์ด๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ
      ์ด๋Š” ์ด๋ฒˆ ๊ฐ•์˜์—์„œ ์ž์„ธํžˆ ๋‹ค๋ฃธ

# Canonical View Volume

  • Canonical view volume์€ NDC ๊ณต๊ฐ„ ๋‚ด์˜ 3์ฐจ์› ๋ณผ๋ฅจ์ด๋ฉฐ, ํ™”๋ฉด์— ํ‘œ์‹œ๋  ์ˆ˜ ์žˆ๋Š” ์žฅ๋ฉด์˜ ์˜์—ญ์„ ์ •์˜ํ•œ๋‹ค.
  • OpenGL ๊ธฐ์ค€: $[-1,~1]^3$ ๋ฒ”์œ„
  • Direct3D ๊ธฐ์ค€: $[0,~1]$ ๋ฒ”์œ„ ($z$์ถ•๋งŒ ๋‹ค๋ฆ„)
  • canonical view volume ์•ˆ์— ์žˆ๋Š” ๊ฐ์ฒด๋งŒ ๋ Œ๋”๋ง๋œ๋‹ค.
    • ์นด๋ฉ”๋ผ ๋ทฐ ์•ˆ์— ์žˆ๋Š” ๊ฐ์ฒด๋งŒ ๊ทธ๋ ค์ง
    • ๋„ˆ๋ฌด ๋ฉ€๊ฑฐ๋‚˜ ๋„ˆ๋ฌด ๊ฐ€๊นŒ์šด ๊ฐ์ฒด๋Š” ์ œ์™ธ๋จ

# Canonical View Volume

  • ๊ด€๋ก€์ ์œผ๋กœ NDC๋Š” left-handed ์ขŒํ‘œ๊ณ„์ž„ (OpenGL๊ณผ Direct3D ๋ชจ๋‘)
    • NDC์—์„œ $+z$ ๋ฐฉํ–ฅ์ด ํ™”๋ฉด ๋ฐฉํ–ฅ
  • OpenGL์˜ projection ํ•จ์ˆ˜๋Š” ์ž๋™์œผ๋กœ ์ขŒํ‘œ๊ณ„ ์†์žก์ด(handedness)๋ฅผ ๋ฐ”๊ฟ”์คŒ โ†’ world/model space๋Š” right-handed
    • View direction in view space: $-z$ ๋ฐฉํ–ฅ
    • Direct3D๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ left-handed system์„ ์‚ฌ์šฉํ•˜๋‚˜, ์ด ๋ณ€๊ฒฝ์„ ํ•˜์ง€ ์•Š์Œ

# View Volume

  • View space์—์„œ๋Š” ๊ฐ์ฒด๋ฅผ ๊ผญ $[-1, 1]$ ๋ฒ”์œ„ ์•ˆ์— ๋ฐฐ์น˜ํ•  ํ•„์š”๋Š” ์—†๋‹ค.
  • ๋Œ€์‹ , ์›ํ•˜๋Š” ํฌ๊ธฐ์˜ ์ง์œก๋ฉด์ฒด(cuboid)๋‚˜ frustum ํ˜•ํƒœ์˜ volume์„ ์„ค์ •ํ•˜๊ณ  ๊ทธ ์•ˆ์— ๊ฐ์ฒด๋ฅผ ๋ฐฐ์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์ด view volume (๋ฐ ๊ทธ ์•ˆ์˜ ๋ชจ๋“  ๊ฐ์ฒด)์€ canonical view volume in NDC space๋กœ ํˆฌ์˜๋œ๋‹ค.

โ†’ Projection transformation

# Projection Transformation

  • CG์—์„œ์˜ Projection์ด๋ž€: 3D ์ขŒํ‘œ๋ฅผ 2D ํ™”๋ฉด ์ขŒํ‘œ๋กœ ๋งคํ•‘ํ•˜๋Š” ๊ฒƒ
  • ์ˆ˜ํ–‰ ์ˆœ์„œ:
    • 3D ๊ณต๊ฐ„์ƒ์˜ arbitrary view volume โ†’ canonical view volume์œผ๋กœ ๋งคํ•‘
      โ†’ Projection transformation
    • canonical view volume์˜ z=1 ํ‰๋ฉด์— ํˆฌ์˜ (์‹ค์ œ๋กœ ๊ทธ๋ ‡๊ฒŒ ๋˜์ง„ ์•Š์ง€๋งŒ, ๊ฐœ๋…์ ์œผ๋กœ๋Š” ๊นŠ์ด(depth)๋ฅผ ๋”ฐ๋กœ ์œ ์ง€)
  • ํˆฌ์˜ ๋ณ€ํ™˜ ๋ฐฉ์‹์€ ํฌ๊ฒŒ 2๊ฐ€์ง€:
    • Orthographic projection
    • Perspective projection

# Orthographic (Orthogonal) Projection

  • View volume: ์ง์œก๋ฉด์ฒด (cuboid)
  • Orthographic projection: ์ง์œก๋ฉด์ฒด view volume์„ canonical view volume๋กœ ๋งคํ•‘
    • Scaling + Translation ์กฐํ•ฉ
    • โ†’ Windowing transformation

# Windowing Transformation

  • ์‚ฌ๊ฐํ˜• ๊ณต๊ฐ„ ๋‚ด ์  $(p_x,~p_y)$์„ ๋‹ค๋ฅธ ์‚ฌ๊ฐํ˜• ๊ณต๊ฐ„์˜ ๋Œ€์‘ ์  $(p_x',~p_y')$๋กœ ๋งคํ•‘ํ•˜๋Š” ๋ณ€ํ™˜
    • ์˜ˆ: $(x_l,~y_l)$ ~ $(x_r,~y_r)$ โ†’ $(x_l',~y_l')$ ~ $(x_r',~y_r')$ $$ p'_x = \left( \frac{p_x - x_l}{x_r - x_l} \right)(x_r' - x_l') + x_l' \\ p'_y = \left( \frac{p_y - y_l}{y_r - y_l} \right)(y_r' - y_l') + y_l' $$

# Orthographic Projection Matrix

  • 3D๊นŒ์ง€ ํ™•์žฅํ•˜๊ณ , ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋Œ€์ž…:

    $$ \begin{aligned} x_h &= \text{right},\quad x_l = \text{left},\quad x_h' = 1,\quad x_l' = -1 \\ y_h &= \text{top},\quad y_l = \text{bottom},\quad y_h' = 1,\quad y_l' = -1 \\ z_h &= -\text{far},\quad z_l = -\text{near},\quad z_h' = 1,\quad z_l' = -1 \end{aligned} $$

    $$ \mathbf{P}_{\text{orth}} = \begin{bmatrix} \frac{2}{\text{right} - \text{left}} & 0 & 0 & -\frac{\text{right} + \text{left}}{\text{right} - \text{left}} \\ 0 & \frac{2}{\text{top} - \text{bottom}} & 0 & -\frac{\text{top} + \text{bottom}}{\text{top} - \text{bottom}} \\ 0 & 0 & \frac{-2}{\text{far} - \text{near}} & -\frac{\text{far} + \text{near}}{\text{far} - \text{near}} \\ 0 & 0 & 0 & 1 \end{bmatrix} $$

# Examples of Orthographic Projection

  • Orthographic ๋ฐ ๋“ฑ๊ฐ(isometric) ํˆฌ์˜ ์˜ˆ์‹œ
  • ๊ฐ์ฒด๋Š” ์นด๋ฉ”๋ผ๋กœ๋ถ€ํ„ฐ์˜ ๊ฑฐ๋ฆฌ์™€ ๋ฌด๊ด€ํ•˜๊ฒŒ ํ•ญ์ƒ ๋™์ผํ•œ ํฌ๊ธฐ๋กœ ๋ณด์ž„

# Properties of Orthographic Projection

  • ์‚ฌ์‹ค์ ์œผ๋กœ ๋ณด์ด์ง€ ์•Š์Œ
  • ์ •ํ™•ํ•œ ์ธก์ •์— ์ ํ•ฉ
  • CAD, ๊ฑด์ถ• ๋„๋ฉด ๋“ฑ์—์„œ ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋จ
    • ์ •ํ™•ํ•œ ์ธก์ •์ด ์ค‘์š”ํ•œ ํ™˜๊ฒฝ
  • Scaling๊ณผ Translation์˜ ์กฐํ•ฉ
    โ†’ Affine transformation

# [Demo] Orthographic Projection

  • learnwebgl.brown37.net/08_projections/create_ortho/create_ortho.html (opens new window)
  • ์Šฌ๋ผ์ด๋”๋ฅผ ์›€์ง์ด๋ฉฐ ์™ผ์ชฝ(view volume)๊ณผ ์˜ค๋ฅธ์ชฝ(rendered view)์„ ๊ด€์ฐฐ
  • ์™ผ์ชฝ, ์˜ค๋ฅธ์ชฝ, ์•„๋ž˜, ์œ„, ๊ฐ€๊นŒ์›€, ๋ฉ€๋ฆฌ ์œ„์น˜๋ฅผ ์กฐ์ ˆ ๊ฐ€๋Šฅ

# Quiz 1

# Perspective Effects

  • ๋ฉ€๋ฆฌ ์žˆ๋Š” ๊ฐ์ฒด๋Š” ์ž‘๊ฒŒ ๋ณด์ž„
  • Vanishing point:
    • ํˆฌ์‹œ ๊ทธ๋ฆผ๋ฒ•์—์„œ ํ‰ํ–‰์„ ์ด ์ˆ˜๋ ดํ•ด ๋ณด์ด๋Š” ์ 
    • ํ‰๋ฉด ํˆฌ์‹œ์—์„œ ์›๊ทผ๊ฐ์„ ๋ถ€์—ฌํ•˜๋Š” ํ•ต์‹ฌ ์š”์†Œ

# Perspective Projection

  • View volume: Frustum (์ ˆ๋‘์ฒด) โ†’ "Viewing frustum"
  • Perspective projection: Viewing frustum์„ canonical view volume๋กœ ๋งคํ•‘
  • ์ •์ ๋“ค์„ canonical view volume๋กœ ๋น„์„ ํ˜•์ ์œผ๋กœ ๋งคํ•‘ โ†’ ๊นŠ์ด์— ๋”ฐ๋ฅธ ์™œ๊ณก ํšจ๊ณผ ์ƒ์„ฑ

# Why does this mapping generate a perspective effect?

  • ์›๋ž˜ 3D ์žฅ๋ฉด์—์„œ ์นด๋ฉ”๋ผ ๊ธฐ์ค€์œผ๋กœ ๋ฉ€์–ด์งˆ์ˆ˜๋ก z๊ฐ’ ์ฆ๊ฐ€
  • canonical ๊ณต๊ฐ„์œผ๋กœ ํˆฌ์˜ํ•  ๋•Œ z์— ๋”ฐ๋ผ ๋น„์„ ํ˜•์ ์œผ๋กœ ์ถ•์†Œ๋จ
  • ๊ฐ€๊นŒ์šด ๊ฐ์ฒด๋Š” ํฌ๊ฒŒ, ๋จผ ๊ฐ์ฒด๋Š” ์ž‘๊ฒŒ ํˆฌ์˜๋จ
    โ†’ ์ด๊ฒƒ์ด perspective ํšจ๊ณผ์˜ ๋ณธ์งˆ

# An Example of Perspective Projection

After perspective projection

  • Frustum ๋‚ด์— ์žˆ๋Š” ๊ฐ์ฒด๋“ค์ด canonical ๊ณต๊ฐ„์— ๋น„์„ ํ˜•์ ์œผ๋กœ ์••์ถ•๋จ
  • ์นด๋ฉ”๋ผ์— ๊ฐ€๊นŒ์šด ๊ฐ์ฒด๋Š” ๋” ํฌ๊ฒŒ, ๋ฉ€๋ฆฌ ์žˆ๋Š” ๊ฐ์ฒด๋Š” ๋” ์ž‘๊ฒŒ ๋ณด์ž„
  • Canonical ๊ณต๊ฐ„์˜ ๊ฒฐ๊ณผ๋ฅผ 2D ํ™”๋ฉด์— ํ‘œ์‹œ
  • ์ˆ˜ํ‰ ๋ฐฉํ–ฅ: 1024px
  • ์ˆ˜์ง ๋ฐฉํ–ฅ: 768px
  • ์นด๋ฉ”๋ผ์˜ viewport ๋‚ด์— ๊ฐ์ฒด๋“ค์ด ๊นŠ์ด์— ๋”ฐ๋ผ ๋‹ฌ๋ฆฌ ํ‘œํ˜„๋จ

# Let's first consider 3D View Frustum โ†’ 2D Projection Plane

  • 3D ์ ์„ ์นด๋ฉ”๋ผ ํ‰๋ฉด์— ํˆฌ์˜ํ•˜๋Š” ๊ณผ์ •์„ ๊ณ ๋ คํ•ด๋ณด์ž.

# Perspective projection

  • ํ™”๋ฉด ์œ„์˜ ๊ฐ์ฒด ํฌ๊ธฐ๋Š” ์นด๋ฉ”๋ผ๋กœ๋ถ€ํ„ฐ์˜ ๊ฑฐ๋ฆฌ์— ๋ฐ˜๋น„๋ก€ํ•จ

  • ์œ ์‚ฌํ•œ ์‚ผ๊ฐํ˜•์˜ ์„ฑ์งˆ: $$ \frac{y'}{d} = \frac{y}{-z} \\ \Rightarrow\quad y' = \frac{-d \cdot y}{z} $$

# Homogeneous coordinates revisited

  • Perspective๋Š” ๋‚˜๋ˆ—์…ˆ ์—ฐ์‚ฐ์ด ํ•„์š”ํ•จ
    • ์ด๋Š” Affine transformation์—๋Š” ํฌํ•จ๋˜์ง€ ์•Š์Œ
  • Affine์—์„œ๋Š” ํ‰ํ–‰์„ ์ด ํ‰ํ–‰ํ•˜๊ฒŒ ์œ ์ง€๋จ
    • ๋”ฐ๋ผ์„œ ์†Œ์‹ค์  ์—†์Œ
    • ๋ทฐํฌ์ธํŠธ๋กœ ์ˆ˜๋ ดํ•˜๋Š” ๊ด‘์„ ๋„ ์—†์Œ
  • Homogeneous coordinates์˜ ๋ณธ๋ž˜ ๋ชฉ์ ์€ ํˆฌ์˜ ๊ตฌํ˜„์— ์žˆ์Œ

# Homogeneous coordinates revisited

  • $w = 1$ ์ขŒํ‘œ๋ฅผ ์ž๋ฆฌ ํ‘œ์‹œ์ž๋กœ ๋„์ž…

    • translation์„ ์„ ํ˜• ๋ณ€ํ™˜๊ณผ ํ†ตํ•ฉํ•˜๋Š” ๋ฐ ํŽธ๋ฆฌ
  • ์ž„์˜์˜ $w$๋„ ํ—ˆ์šฉ ๊ฐ€๋Šฅ:

    $$ \begin{bmatrix} x \\ y \\ z \\ w \end{bmatrix} \sim \begin{bmatrix} kx \\ ky \\ kz \\ kw \end{bmatrix} $$

    • 4D ๋ฒกํ„ฐ์˜ ์Šค์นผ๋ผ ๋ฐฐ์ˆ˜๋Š” ๋™์ผํ•œ ์ขŒํ‘œ๋กœ ๊ฐ„์ฃผ

# Perspective projection

  • ํˆฌ์˜ ํ‰๋ฉด์— ํˆฌ์˜ํ•˜๋ ค๋ฉด, $z$๋ฅผ $w$๋กœ ์˜ฎ๊ฒจ์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€ํ™˜:

    $$ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} \frac{-d \cdot x}{z} \\ \frac{-d \cdot y}{z} \\ 1 \end{bmatrix} = \begin{bmatrix} d z & 0 & 0 & 0 \\ 0 & d z & 0 & 0 \\ 0 & 0 & 0 & -1 \\ 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$

# So far, 3D โ†’ 2D

  • ์ง€๊ธˆ๊นŒ์ง€๋Š” ๋‹จ์ง€
    3D View Frustum โ†’ 2D Projection Plane
    ๋กœ์˜ ํˆฌ์˜ ์ด์•ผ๊ธฐ์˜€์Œ

# Now, 3D โ†’ 3D

  • ๊ทธ๋Ÿฌ๋‚˜ ์‹ค์ œ๋กœ ์šฐ๋ฆฌ๊ฐ€ ๊ตฌํ˜„ํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ์€
    3D View Frustum โ†’ 3D Canonical View Volume

  • ์ฆ‰, ์›๊ทผ ํˆฌ์˜ ์ดํ›„์—๋„ $(x',~y',~z')$ ์ขŒํ‘œ๋Š” ์œ ์ง€๋˜์–ด์•ผ ํ•จ
    โ†’ clip space์˜ ๊นŠ์ด ์ •๋ณด๊ฐ€ ํ•„์š”

# First, 3D View Frustum โ†’ 3D Cuboid

  • ์šฐ์„ ์€ canonical volume์ด ์•„๋‹Œ, near, far ํ‰๋ฉด์ด ๊ฐ™์€ ์œ„์น˜์˜ cuboid๋ฅผ ๊ณ ๋ ค
  • x, y ์ขŒํ‘œ์— ๋Œ€ํ•ด ์ด์ „ ์Šฌ๋ผ์ด๋“œ์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ํˆฌ์˜ ๊ฐ€๋Šฅ:

$$ y' = \frac{-d \cdot y}{z} $$

$$ x' = \frac{-d \cdot x}{z} $$

  • near/far offset์ด ๋™์ผํ•œ cuboid๋ฅผ ๊ณ ๋ ค
  • ๋ฌธ์ œ๋Š” $z$ ์ขŒํ‘œ:
    • ๊นŠ์ด $z$๋Š” ๋ณด์กด๋˜์ง€ ์•Š์Œ (๋‚˜๋ˆ—์…ˆ ์—ฐ์‚ฐ ํฌํ•จ โ†’ ๋น„์„ ํ˜•)
    • ํ•ด๊ฒฐ: $z$ ๊ฐ’์„ ์ ์ ˆํžˆ ๋งคํ•‘ํ•˜์—ฌ near/far ํ‰๋ฉด์˜ ๊นŠ์ด ์ •๋ณด๋ฅผ ์œ ์ง€

# 3D View Frustum โ†’ 3D Cuboid

  • $z$ ๊ฐ’๊นŒ์ง€ ํฌํ•จํ•˜์—ฌ ์ „์ฒด๋ฅผ ํ–‰๋ ฌ๋กœ ํ‘œํ˜„:

    $$ \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} = \begin{bmatrix} \frac{-d x}{z} \\ \frac{-d y}{z} \\ \frac{-X}{z} \\ 1 \end{bmatrix} = \begin{bmatrix} d z & 0 & 0 & 0 \\ 0 & d z & 0 & 0 \\ 0 & 0 & a & b \\ 0 & 0 & -1 & 0 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$

  • $x$, $y$์—๋Š” ์˜ํ–ฅ ์—†์Œ โ†’ $z'$๋Š” $x$, $y$์™€ ๋ฌด๊ด€

    • ๋”ฐ๋ผ์„œ $c_0 = c_1 = 0$
  • ์›ํ•˜๋Š” ์กฐ๊ฑด:

    • $z'(-n) = n$
    • $z'(-f) = f$
  • ์„ ํ˜•์‹์œผ๋กœ $z'$ ์ •์˜:

    $$ z'(z) = \frac{a z + b}{-z} $$

  • ๋‘ ์กฐ๊ฑด์„ ๋Œ€์ž…ํ•˜์—ฌ ํ•ด ๊ตฌํ•จ:

    $$ a = f n,\quad b = f + n $$

# Final: 3D View Frustum โ†’ 3D Canonical View Volume

  • $\mathbf{P}_{\text{pers}} = \mathbf{P}_{\text{orth}} \cdot \mathbf{P}_{\text{dc}}$

  • $\mathbf{P}_{\text{dc}}$ ํ–‰๋ ฌ (near, far ๋ฐ˜์˜):

    $$ \mathbf{P}_{\text{dc}} = \begin{bmatrix} n & 0 & 0 & 0 \\ 0 & n & 0 & 0 \\ 0 & 0 & f + n & f n \\ 0 & 0 & -1 & 0 \end{bmatrix} $$

  • frustum โ†’ cuboid โ†’ canonical volume ์œผ๋กœ ๋ณ€ํ™˜

# Perspective Projection Matrix

  • ์ตœ์ข… perspective projection ํ–‰๋ ฌ:

    $$ \mathbf{P}_{\text{pers}} = \mathbf{P}_{\text{orth}} \cdot \mathbf{P}_{\text{dc}} = \begin{bmatrix} \frac{n}{r} & 0 & 0 & 0 \\ 0 & \frac{n}{t} & 0 & 0 \\ 0 & 0 & \frac{f + n}{n - f} & \frac{f n}{n - f} \\ 0 & 0 & -1 & 0 \end{bmatrix} $$

# Note on Mapped Depth (Z' value)

  • Perspective projection์€ ๊นŠ์ด $z$๊ฐ’์„ $(-1,~+1)$ ๋ฒ”์œ„๋กœ ๋น„์„ ํ˜• ๋งคํ•‘
  • ๊ฒฐ๊ณผ:
    • ์นด๋ฉ”๋ผ ๊ฐ€๊นŒ์ด์˜ ~z~๊ฐ’์ผ์ˆ˜๋ก ์ •๋ฐ€๋„๊ฐ€ ๋†’์Œ
    • ๋ฉ€์ˆ˜๋ก ์ •๋ฐ€๋„๊ฐ€ ๋‚ฎ์•„์ง
  • ๊ทธ๋ž˜ํ”„:
    • $X$์ถ•: $z$ ๊ฐ’ (์›๋ž˜ ๊นŠ์ด)
    • $Y$์ถ•: ๋งคํ•‘๋œ $z'$ ๊ฐ’

# Perspective Division, Clip / NDC Space

  • clip space: shader ์ดํ›„ ์žฅ๋ฉด ํ‘œํ˜„ (4D homogeneous)
  • NDC space: perspective division ์ดํ›„์˜ 3D ์ขŒํ‘œ๊ณ„
    • $w$๋กœ ๋‚˜๋ˆ ์„œ $[x/w,~y/w,~z/w]$ ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜๋จ
  • ์‹ค์ œ ํ‘œํ˜„๋˜๋Š” ๋ฒ”์œ„: $[-1,~1]$

# [Demo] Perspective Projection - frustum

# [Demo] Perspective Projection - perspective

# Quiz 2

# Viewport Transformation

  • Viewport transformation์€ NDC ๊ณต๊ฐ„์—์„œ ํ™”๋ฉด ๊ณต๊ฐ„(screen space)์œผ๋กœ ๋ณ€ํ™˜
  • ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„์˜ ๋ณ€ํ™˜: clip space โ†’ screen space
  • ์ขŒํ‘œ๊ณ„ ๋ฒ”์œ„:
    • NDC: $(-1,~-1,~-1)$ ~ $(1,~1,~1)$
    • Screen: $(0,~0,~0)$ ~ $(width,~height,~1)$

# Recall that...

    1. ๊ฐ์ฒด ๋ฐฐ์น˜ โ†’ Modeling transformation
    1. ์นด๋ฉ”๋ผ ๋ฐฐ์น˜ โ†’ Viewing transformation
    1. ๋ Œ์ฆˆ ์„ค์ • โ†’ Projection transformation
    1. ์Šคํฌ๋ฆฐ์— ์ถœ๋ ฅ โ†’ Viewport transformation

# Viewport Transformation

  • Canonical view volume (NDC)์—์„œ $z$๋ฐฉํ–ฅ +๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ ค๋‹ค๋ณธ๋‹ค๊ณ  ๊ฐ€์ •
  • Viewport๋Š” screen ์ƒ์˜ ์‚ฌ๊ฐํ˜• ์˜์—ญ
  • Viewport transformation๋„ ๊ฒฐ๊ตญ windowing transformation์˜ ์ผ์ข…
  • ๊นŠ์ด ๊ฐ’($z$)์€ $[0,~1]$ ๋ฒ”์œ„๋กœ ์žฌ๋งคํ•‘๋จ (default depth buffer)

# Viewport Transformation Matrix

  • windowing transformation matrix์—์„œ,

    • $x_p$, $x_l$, $x_h$ ... ๋Œ€์‹  viewport ๋ณ€์ˆ˜๋ฅผ ๋Œ€์ž…ํ•จ
  • ๋ณ€ํ™˜ ํ–‰๋ ฌ:

    $$ \mathbf{T}_{\text{vp}} = \begin{bmatrix} \frac{\text{width}}{2} & 0 & 0 & \frac{\text{width}}{2} + x_{\min} \\ 0 & \frac{\text{height}}{2} & 0 & \frac{\text{height}}{2} + y_{\min} \\ 0 & 0 & \frac{1}{2} & \frac{1}{2} \\ 0 & 0 & 0 & 1 \end{bmatrix} $$

  • $(x_{\min},\ y_{\min})$๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ
    $(\text{width},\ \text{height})$ ํฌ๊ธฐ์˜ ํ™”๋ฉด ์ขŒํ‘œ๋กœ ์ด๋™