# 5 - Vertex Processing 1
# Outline
- Rasterization Pipeline & Vertex Processing
- Modeling Transformation
- Viewing Transformation
# Recall: Rasterization Pipeline
(3D ์ฅ๋ฉด์ ๊ธฐํ ์ ๋ณด๋ฅผ ํฝ์ ๋จ์์ 2D ์ด๋ฏธ์ง๋ก ๋ณํํ๋ ์ผ๋ จ์ ์ฒ๋ฆฌ ๊ณผ์ )
- Vertex Processing
- vertex๋ฅผ screen space๋ก ๋ณํ
- Primitive Processing
- vertex๋ค์ polygon์ผ๋ก ๊ตฌ์ฑ
- Scan Conversion
- polygon์ fragment ์งํฉ์ผ๋ก ๋ณํ
- Fragment Processing
- ๊ฐ fragment์ ์์ ๊ฒฐ์ (ํ ์ค์ฒ, ์กฐ๋ช ๋ชจ๋ธ ๋ฑ ๊ณ ๋ ค)
- Per-sample Operations
- depth test, alpha blending ๋ฑ ์ํ
- Vertex Processing:
- ์ ์ ๋ค์ ํ๋ฉด ์ขํ๊ณ๋ก ๋ณํ
- ์ผ๋ จ์ ์ ์ ๋ณํ ์ํ์ค๋ฅผ ์ ์ฉ
- ์ฐ๋ฆฌ๊ฐ ์ง๊ธ๊น์ง ํ์ตํ ๋ฒ์๋:
- Primitive Processing ~ Per-sample Operations
- ์ค๋๊ณผ ๋ค์ ์๊ฐ์ ๋ณผ ๋ด์ฉ:
- Vertex Processing
# Vertex Processing
๊ฐ ๊ฐ์ฒด์ body frame์์์ ์ ์ ์์น:
$$ \mathbf{p}_1,\quad \mathbf{p}_2,\quad \mathbf{p}_3 $$
World frame์ผ๋ก์ ๋ณํ:
$$ \mathbf{M} \mathbf{p}_1,\quad \mathbf{M} \mathbf{p}_2,\quad \mathbf{M} \mathbf{p}_3 $$
โ ํ์ง๋ง ์์ง ํ๋ฉด์ ํ์ํ๊ธฐ ์ํด์ ์ถ๊ฐ ๊ฐ๋ ์ด ํ์ํจ
โ์นด๋ฉ๋ผโ๊ฐ ์ฅ๋ฉด์ ๋ฐ๋ผ๋ณธ๋ค๋ ๊ฐ๋ ๋์ ํ์
์ด์ด์ง๋ ๋จ๊ณ:
- โ์นด๋ฉ๋ผโ ๋ฐฐ์น
- โ๋ ์ฆโ ์ ํ
- โ์คํฌ๋ฆฐโ์ ํฌ์ฌ
# In Terms of CG Transformation,
- ๊ฐ์ฒด ๋ฐฐ์น
โ Modeling Transformation - ์นด๋ฉ๋ผ ๋ฐฐ์น
โ Viewing Transformation - ๋ ์ฆ ์ ํ
โ Projection Transformation - ํ๋ฉด์ ์ถ๋ ฅ
โ Viewport Transformation
- ์ ๋ชจ๋ ๋ณํ๋ค์ ํ๋ ฌ ๊ณฑ์ ์ผ๋ก ๊ตฌ์ฑ๋จ
# Vertex Processing (Transformation Pipeline)
- Object space (body frame):
- ๊ฐ์ฒด ๊ธฐ์ค ์ขํ๊ณ
- World space (world frame):
- ์ ์ฒด ์ฅ๋ฉด ๊ธฐ์ค ์ขํ๊ณ
- ์ํํ ์์
:
- ์ด๋(translate), ํ์ (rotate), ํฌ๊ธฐ ์กฐ์ (scale) ๋ฑ
- ์ด์ ๊ฐ์์์ ๋ค๋ฃฌ ๋ชจ๋ affine ๋ณํ ํฌํจ
# Modeling transformation
- ๊ฐ์ฒด ์ขํ๊ณ (object space) โ world ์ขํ๊ณ๋ก ๋ณํ
- ์ด์ ๊ฐ์์์ ๋ฐฐ์ด affine transformation์ ์ ์ฉํจ
# Placing a โcameraโ
- world ์ขํ๊ณ ์์์ ์นด๋ฉ๋ผ๋ฅผ ๋ฐฐ์นํจ
- view space (๋๋ camera space) ์ ์๋จ
# Viewing transformation
- world space โ camera space๋ก ๋ณํ
- ์ฆ, world ๊ธฐ์ค ์ฅ๋ฉด์ ์นด๋ฉ๋ผ ๊ธฐ์ค์ผ๋ก ์ฌ๋ฐฐ์ด
# Selecting its โlensโ
- ํฌ์ ๋ฐฉ์์ ์ ์ํจ (์: perspective, orthographic ๋ฑ)
- view space โ Clip space / NDC (normalized device coordinate) space
# Projection transformation
- ์์ผ๊ฐ(FOV), ์ข
ํก๋น, near/far plane ๋ฑ์ ๊ณ ๋ คํ์ฌ
3D ๊ณต๊ฐ์ ์ ๊ทํ๋ ์ฅ์น ์ขํ๊ณ(NDC) ๋ก ๋ณํ - ์ขํ ๋ฒ์: $(-1,~-1,~-1)$ ~ $(1,~1,~1)$
# Displaying on a โcinema screenโ
- NDC ๊ณต๊ฐ์ ์ด๋ฏธ์ง ๊ณต๊ฐ์ผ๋ก ๋ณํ
- ์ฆ, ํฝ์ ์ขํ๊ณ ์์ ํ๋ฉด ์ถ๋ ฅ
# Viewport transformation
- NDC ์ขํ๋ฅผ ์ค์ ํ๋ฉด ํด์๋์ ๋ง๊ฒ ์ค์ผ์ผ ์กฐ์
- ์ขํ๊ณ๋ฅผ ์ ๊ทํ ๊ณต๊ฐ โ ์คํฌ๋ฆฐ ๊ณต๊ฐ์ผ๋ก ๋ณํ
# Transformation Pipeline ์ ์ฒด ์์ฝ
Object space โ View space โ Clip space โ Screen space
- Modeling transformation
- Viewing transformation
- Projection transformation
- Viewport transformation
โ ๋ชจ๋ ๊ณผ์ ์ ํ๋ ฌ๊ณฑ(Matrix Multiplication) ์ผ๋ก ๊ตฌ์ฑ๋จ
- Modeling, Viewing, Projection, Viewport ๋ณํ์
4x4 ํ๋ ฌ ๊ณฑ์ ์ผ๋ก ์ฒ๋ฆฌ๋จ
MVP Matrix ์ ์ฉ
- ํ๋์ ์ $\mathbf{p}_o$๊ฐ
- ๋ชจ๋ธ๋ง ๋ณํ: $\mathbf{M}$
- ๋ทฐ์ ๋ณํ: $\mathbf{V}$
- ํฌ์ ๋ณํ: $\mathbf{P}$
- ๋ทฐํฌํธ ๋ณํ: $\mathbf{T}_{\mathbf{vp}}$
์ ๊ฑฐ์ณ์ - ์ต์ข ์์น $\mathbf{p}_s$๋ก ๋ณํ๋จ
$$ \mathbf{p}_s=\mathbf{{T}_{vp} PVMp_o} $$
# Modeling Transformation
- object space์์ world space๋ก์ ๋ณํ
$$ \mathbf{p}_w = \mathbf{M} \mathbf{p}_o $$ - ์ด๋ $\mathbf{M}$์ affine transformation๋ค์ ์กฐํฉ
- ์: ์ด๋, ํ์ , ์ค์ผ์ผ ๋ฑ
# Recall: Directions of the "arrow"
- $$ \mathbf{p}_w = \mathbf{M} \mathbf{p}^{\{1\}} $$
- 1๋ฒ์งธ ์๋ฏธ: geometry ๋ณํ ๋ฐฉํฅ
- 3๋ฒ์งธ ์๋ฏธ: frame์ด ๋ฐ๋๋ ๊ด์ ์์ โ ๋ฐฉํฅ ๋ฐ๋๊ฐ ๋๋ ๊ฒ์ฒ๋ผ ๋ณด์ผ ์ ์์
# Modeling Transformation
- ๊ฐ์ฒด๋ object์ ๊ณ ์ ์ขํ๊ณ (body frame) ์ ์ ์๋จ
- object โ world ๋ณํ์ modeling transformation์ด๋ผ ํ๋ฉฐ
ํ๋ ฌ $\mathbf{M}$์ผ๋ก ํํ๋จ - ์ด ํ๋ ฌ $\mathbf{M}$์ ์ง๊ธ๊น์ง ๋ฐฐ์ด affine ๋ณํ (์ด๋, ํ์ , ์ค์ผ์ผ ๋ฑ)์ ์กฐํฉ
์์: ๋ค์ค ๋ถํ์ modeling
- ๋ฐํด, ์บ๋น, ์ปจํ
์ด๋ ๊ฐ๊ฐ์ object frame์์
- modeling matrix $\mathbf{M}_{\text{wheel}},\ \mathbf{M}_{\text{cab}},\ \mathbf{M}_{\text{container}}$๋ฅผ ์ ์ฉ
- ์ต์ข ์ ์ผ๋ก world frame ์์ ์ ์ฒด ํธ๋ญ ์์น๊ฐ ๊ตฌ์ฑ๋จ
# Quiz 1
# Viewing Transformation
- Viewing transformation์ world space์์ camera space(view space)๋ก ๋ณํํ๋ ์ฐ์ฐ์ด๋ค.
- ๋ณํ๋ ๊ฒฐ๊ณผ๋ ๊ฒฐ๊ตญ ํ๋ฉด์์ 2D ์ด๋ฏธ์ง(screen space)์ ๋ํ๋๋ค.
- ์ด ๊ณผ์ ์ ๋ค์๊ณผ ๊ฐ์ ์์์ ๋ฐ๋ฅธ๋ค:
$$ \mathbf{p}_\mathbf{v} = \mathbf{V} \mathbf{p}_\mathbf{w} $$
# Recall that...
- ๊ฐ์ฒด ๋ฐฐ์น
โ Modeling transformation
- ๊ฐ์ฒด ๋ฐฐ์น
- "์นด๋ฉ๋ผ" ๋ฐฐ์น
โ Viewing transformation
- "์นด๋ฉ๋ผ" ๋ฐฐ์น
- "๋ ์ฆ" ์ ํ
โ Projection transformation
- "๋ ์ฆ" ์ ํ
- "์คํฌ๋ฆฐ"์ ํ์
โ Viewport transformation
- "์คํฌ๋ฆฐ"์ ํ์
# Viewing Transformation
- Viewing transformation์ rigid transformation์ผ๋ก์, ํ์ ๊ณผ ์ด๋์ ํฌํจํ๋ค.
- world space์์ view space๋ก ๋ณํํ๋ ๋ฐ ์ฌ์ฉ๋๋ฉฐ, ๋ณํ ํ๋ ฌ์ viewing matrix V์ด๋ค.
- ๋ชฉ์ : camera frame ์์์ ๋ชจ๋ ๊ฐ์ฒด์ vertex๋ค์ ํํํ๋ ๊ฒ
- ์ด๋ฅผ ์ํด camera frame์ ์ ์ํด์ผ ํจ (world frame ๊ธฐ์ค)
- camera frame์ ์ ์ํ๋ค๋ ๊ฒ์ ๊ณง ์นด๋ฉ๋ผ์ ์์น์ ๋ฐฉํฅ์ ๊ฒฐ์ ํ๋ ๊ฒ๊ณผ ๊ฐ๋ค.
# Defining Camera Frame 1 - "LookAt"
- ์นด๋ฉ๋ผ์ ์์น์ ๋ฐฉํฅ์ ์ ์ํ๋ ์ฌ๋ฌ ๋ฐฉ์์ด ์๋ค.
- ๊ทธ ์ค ์ง๊ด์ ์ธ ๋ฐฉ์์ผ๋ก lookat ํจ์๋ฅผ ์๊ฐ:
- Eye point: ์นด๋ฉ๋ผ ์์น
- Look-at point: ์นด๋ฉ๋ผ๊ฐ ๋ฐ๋ผ๋ณด๋ ์ง์
- Up vector: ์ด๋ ๋ฐฉํฅ์ด ์๋ฅผ ๋ํ๋ด๋์ง ์ค๋ช
# [Demo] LookAt Function
- learnwebgl.brown37.net/07_cameras/camera_lookat/camera_lookat.html (opens new window)
- ์ฌ๋ผ์ด๋๋ฅผ ์์ง์ด๋ฉฐ eye, center, up ๊ฐ์ ๋ฐ๊ฟ๋ณด๋ฉด, 3D ์ฅ๋ฉด์ ๋ทฐ๊ฐ ์ด๋ป๊ฒ ๋ณํ๋์ง ๊ด์ฐฐํ ์ ์๋ค.
# Defining Camera Frame 1 - "LookAt"
- eye point, look-at point, up vector๊ฐ ์ฃผ์ด์ง๋ฉด, camera frame์ ๊ณ์ฐํ ์ ์๋ค.
- ์นด๋ฉ๋ผ ์ขํ์ถ์ผ๋ก๋ ์ผ๋ฐ์ ์ผ๋ก $\mathbf{u},\ \mathbf{v},\ \mathbf{w}$ ๋ฒกํฐ๋ฅผ ์ฌ์ฉํ๋ฉฐ, ์ด๋ ๊ฐ๊ฐ ๋ค์์ ๋ํ๋:
- $\mathbf{u}$: ์ค๋ฅธ์ชฝ ๋ฐฉํฅ
- $\mathbf{v}$: ์์ชฝ ๋ฐฉํฅ
- $\mathbf{w}$: ๋ค์ชฝ ๋ฐฉํฅ
- camera frame์ ์ ์ํ๋ ค๋ฉด $\mathbf{u},\ \mathbf{v},\ \mathbf{w}$ ๋ฒกํฐ์ ์์ ์ ๊ตฌํด์ผ ํจ
# Given Eye point, Look-at point, Up vector
- Eye point, Look-at point, Up vector๋ฅผ ์ด์ฉํ์ฌ ์นด๋ฉ๋ผ ์ขํ๊ณ๋ฅผ ์ ์ํ๋ค.
# Getting origin point
Eye point ์์ฒด๊ฐ ์นด๋ฉ๋ผ ์ขํ๊ณ์ ์์ ์ด ๋๋ค.
$$ \text{origin of camera frame} = \mathbf{P}_{\text{eye}} $$
# Getting "w" axis vector
Look-at point๋ฅผ ๋ฐ๋ผ๋ณด๋ ๋ฐฉํฅ์ $\mathbf{w}$์ถ์ผ๋ก ์ ์ํ๋ค.
$$ \mathbf{w} = \frac{\mathbf{P}_{\text{eye}} - \mathbf{P}_{\text{ref}}}{|| \mathbf{P}_{\text{eye}} - \mathbf{P}_{\text{ref}} ||} $$
# Getting "u" axis vector
up ๋ฐฉํฅ ๋ฒกํฐ์ $\mathbf{w}$ ๋ฒกํฐ์ ์ธ์ ์ ํตํด $\mathbf{u}$ ์ถ์ ๊ณ์ฐํ๋ค.
$$ \mathbf{u} = \frac{\mathbf{V}_{\text{up}} \times \mathbf{w}}{|| \mathbf{V}_{\text{up}} \times \mathbf{w} ||} $$
# Getting "v" axis vector
์ง๊ต์ขํ๊ณ๋ฅผ ๋ง๋ค๊ธฐ ์ํด ๋ค์๊ณผ ๊ฐ์ด ์ ์ํ๋ค.
$$ \mathbf{v} = \mathbf{w} \times \mathbf{u} $$
# Recall: 2) Affine Transformation Matrix defines an Affine Frame w.r.t. World Frame
Affine ๋ณํ ํ๋ ฌ M์ ์ขํ๊ณ(ํ๋ ์)๋ฅผ ๋ณํํ๋๋ฐ ์ฌ์ฉ๋๋ค.
ํ๋ ์ $\{1\}$์ ํ๋ ์ $\{0\}$ ๊ธฐ์ค์ผ๋ก ์ ์๋๋ค.
์ขํ๊ณ ์ถ $(x,~y,~z)$๊ณผ ์์ ์ขํ๊ฐ ํ๋ ฌ์ ์ด(column)๋ก ๊ตฌ์ฑ๋๋ค:
$$ \text{Frame } \{1\} \text{ in } \{0\} = \begin{bmatrix} \mathbf{x}_1 & \mathbf{y}_1 & \mathbf{z}_1 & \mathbf{p}_1 \end{bmatrix} $$
๋๋ 4ร4 homogeneous form์ผ๋ก ํํํ๋ฉด:
$$ \begin{bmatrix} x_{1x} & y_{1x} & z_{1x} & p_{1x} \\ x_{1y} & y_{1y} & z_{1y} & p_{1y} \\ x_{1z} & y_{1z} & z_{1z} & p_{1z} \\ 0 & 0 & 0 & 1 \end{bmatrix} $$
# Thus, the Camera Frame is defined by
$$ \mathbf{v=wxu}$$
$$ \begin{bmatrix} u_x & v_x & w_x & P_{\text{eye},x} \\ u_y & v_y & w_y & P_{\text{eye},y} \\ u_z & v_z & w_z & P_{\text{eye},z} \\ 0 & 0 & 0 & 1 \end{bmatrix} $$
# How can we get viewing matrix $\mathbf{V}$ from the camera frame?
๋ชจ๋ธ๋ง ๋ณํ์ ๋ฐฉ์๊ณผ ์ ์ฌํ๊ฒ viewing matrix $\mathbf{V}$๋ฅผ ๊ตฌํ ์ ์๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก, ๊ฐ์ฒด์ body frame์์์ ์ขํ๋ฅผ world frame์ผ๋ก ๋ณํํ๋ affine matrix์ ์ญํ๋ ฌ์ด ๋ฐ๋ก viewing matrix๊ฐ ๋๋ค.
๊ฐ์ฒด ๊ณต๊ฐ(Object space)์ ์นด๋ฉ๋ผ ๊ณต๊ฐ(Camera space)์ผ๋ก ๋ฐ๊พธ๋ฉด, ์ด๋ค ๋ณํ ํ๋ ฌ์ด ํ์ํ ๊น?
๋ทฐ ๊ณต๊ฐ(View space) โ ์๋ ๊ณต๊ฐ(World space) ๋ฐฉํฅ์ผ๋ก ๋ณํํ๋ค๋ฉด?
์นด๋ฉ๋ผ ํ๋ ์์์์ ์ถ ๋ฒกํฐ $\mathbf{u},\ \mathbf{v},\ \mathbf{w}$์ ์์ $\mathbf{P}_{\text{eye}}$๋ฅผ ์ฌ์ฉํด ๋ณํ ํ๋ ฌ์ ๊ตฌ์ฑํ ์ ์๋ค.
์ด ํ๋ ฌ์ด ๋ฐ๋ก Rigid transformation matrix์ด๋ค.
$$ \begin{bmatrix} u_x & v_x & w_x & P_{\text{eye},x} \\ u_y & v_y & w_y & P_{\text{eye},y} \\ u_z & v_z & w_z & P_{\text{eye},z} \\ 0 & 0 & 0 & 1 \end{bmatrix} $$
# Viewing Transformation is the Opposite Direction
Viewing matrix $\mathbf{V}$๋ ์์ ํ๋ ฌ์ ์ญํ๋ ฌ๋ก ์ ์๋๋ค.
์ฆ, ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก์ ๋ณํ์ด๋ค.
$$ \mathbf{V} = \begin{bmatrix} \mathbf{R} & \mathbf{t} \\ \mathbf{0} & 1 \end{bmatrix}^{-1} = \begin{bmatrix} \mathbf{R}^\top & -\mathbf{R}^\top \mathbf{t} \\ \mathbf{0} & 1 \end{bmatrix} $$
# Inverting Rigid Transformation Matrix
3ร3 ํ์ ํ๋ ฌ $\mathbf{R}$๊ณผ 3ร1 ์ด๋ ๋ฒกํฐ $\mathbf{t}$๋ฅผ ํฌํจํ rigid ๋ณํ ํ๋ ฌ $\mathbf{T}$์ ์ญํ๋ ฌ์ ๋ค์๊ณผ ๊ฐ๋ค:
$$ \mathbf{T} = \begin{bmatrix} \mathbf{R} & \mathbf{t} \\ \mathbf{0} & 1 \end{bmatrix} \quad \Rightarrow \quad \mathbf{T}^{-1} = \begin{bmatrix} \mathbf{R}^\top & -\mathbf{R}^\top \mathbf{t} \\ \mathbf{0} & 1 \end{bmatrix} $$
์นด๋ฉ๋ผ ํ๋ ์ ํ๋ ฌ์ ๊ฒฝ์ฐ, $\mathbf{R}$์ $\mathbf{u},\ \mathbf{v},\ \mathbf{w}$ ๋ฐฉํฅ ๋ฒกํฐ๋ก ์ด๋ฃจ์ด์ง๋ค.
# Viewing Transformation is the Opposite Direction
$\mathbf{V}$๋ ๋ค์๊ณผ ๊ฐ์ด ๋ช ์์ ์ผ๋ก ๊ตฌ์ฑ๋๋ค:
$$ \mathbf{V} = \begin{bmatrix} u_x & v_x & w_x & -\mathbf{u} \cdot \mathbf{P}_{\text{eye}} \\ u_y & v_y & w_y & -\mathbf{v} \cdot \mathbf{P}_{\text{eye}} \\ u_z & v_z & w_z & -\mathbf{w} \cdot \mathbf{P}_{\text{eye}} \\ 0 & 0 & 0 & 1 \end{bmatrix} $$
# Defining Camera Frame 2 - Translate & Rotate
LookAt
ํจ์ ์ธ์๋, ์นด๋ฉ๋ผ์ ์์น์ ๋ฐฉํฅ์ ์ ์ํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์๋ค.- ๋จ์ํ translateํ๊ณ rotateํ๋ฉด rigid transformation ํ๋ ฌ๋ก ์ ์ ๊ฐ๋ฅํ๋ค.
# [Demo] Translate & Rotate Camera
- learnwebgl.brown37.net/07_cameras/camera_trunk_axes/camera_trunk_axes.html (opens new window)
- ์ฌ๋ผ์ด๋๋ก eye ์์น๋ฅผ ๋ฐ๊พธ๊ฑฐ๋ ์ถ ๋ฐฉํฅ ๋ฐ ๊ฐ๋๋ฅผ ์ง์ ํด ํ์ ํ๋ ์นด๋ฉ๋ผ ์์ง์์ ์๊ฐ์ ์ผ๋ก ๊ด์ฐฐํ ์ ์๋ค.
# Moving Camera vs Moving World
- ์ฌ์ค, ์ด ๋์ ๋๋ฑํ ์ฐ์ฐ์ด๋ค.
- ์นด๋ฉ๋ผ๋ฅผ $(1,~0,~2)$๋งํผ ์ด๋์ํค๋ ๊ฒ์
== ์๋๋ฅผ $(-1,~0,~-2)$๋งํผ ์ด๋์ํค๋ ๊ฒ๊ณผ ๊ฐ๋ค. - ์นด๋ฉ๋ผ๋ฅผ $y$์ถ ๊ธฐ์ค์ผ๋ก $60\degree$ ํ์ ์ํค๋ ๊ฒ์
== ์๋๋ฅผ $y$์ถ ๊ธฐ์ค์ผ๋ก $-60\degree$ ํ์ ์ํค๋ ๊ฒ๊ณผ ๊ฐ๋ค.