Computer Graphics Cheatsheet, Part 2
Computer Graphics Cheatsheet, Part 2
Recap Projection
Linear transformation A = T L
xe
xo
ye
= E −1 O yo
p̃ = f⃗t c = a⃗t A−1 c ⇒ a⃗t SA−1 c = f⃗t ASA−1 c: ze zo
1 1
p̃ is transformed by S with respect to a⃗t . 2n r+l
− r−l 0 0
xn xc r−l xe
2n t+b
kx2 v + c −
yn yc 0
kx ky v − kz s kx kz v + ky s = = t−b t−b 0 ye
ky kx v + kz s ky2 + c ky kz − kx s (v = 1 − c) zn zc 0 0 f +n
f −n − f2f−n
n
ze
kz kx v − ky s kz ky v + kx s kz2 v + c 1 wc 0 0 −1 0 1
xw W/2 0 0 (W − 1)/2 xn
ω1 ω2 ω1 ω2 − ĉ1 · ĉ2 yw 0 H/2 (H − 1)/2 yn
= =
ĉ2 ĉ2 ω1 ĉ2 + ω2 ĉ1 + ĉ1 × ĉ2
zw 0 0 1/2 1/2 zn
1 0 0 0 1 1
Clipping: because back vertices get flipped and go wrong
We do it after-multiplication-before-division, because
Normalized coord: divide-by-zero error!
Eye coord: we would need camera params
Backface Culling: calculate cross product
Varying Variables
v is affine in object ⇔ eye ⇔ clip coordinates
⇔ v/wn is affine in normalized device coordinates
−1
cos( θ2 ) cos( θ2 )
0 OpenGL interpolates v/wn , 1/wn to get v.
Rotation
sin( θ2 )k̂ ĉ sin( θ2 )k̂
Finding M s.t. qi = Mpi
Pn n i
F (t) = i=0 t (1 − t)n−i Pi
i
Materials
di = ci + 61 (ci+1 − ci−1 ), ei = ci+1 − 16 (ci+2 − ci ) Diffuse: equal brightness regardless of viewing angle: ⃗n · ⃗l
float diffuse = max(0.0, dot(normal, tolight));
vf =
P P P P P
v, ve = v+ vf , vv = n(n − 2)v + vf + ve
Specular: (⃗n · ⃗h)pow , where ⃗h = normalize(ṽ + l̃ )
vec3 refl = normalize(2.0 * normal * nDotL - tolight);
float specular = pow(max(0.0, dot(refl, viewDir)), 32.0);
Anisotropic: ⃗h · (⃗n × ⃗t), preferred tangent vector ⃗t
float v = dot(h, cross(normal, tangent));
float anisotropic = pow(1.0 - v*v, 16);
1
Texture Mapping Ray Tracing
Cast ray, test intersection with triangle, or sphere, or implicit
surface. Speed up using bounding volumes, grids or other spa-
tial partitioning, like KD-Tree, which recursively splits cells us-
ing axis-aligned planes, or object partitioning.
Sampling
Filter: I[i][j] ←
RR
Ωi,j
I(x, y)Fi,j (x, y)dxdy
in practice: super and multi-sampling
R 2π R π
steradians:
R
dω = 0 0
(sin θdθ)dϕ = 4π
Reconstruction
P
I(x, y) ← Bi,j (x, y)I[i][j] using some basis function Irradiance E(p) =
R R
dE(p, ω) =
Li (p, ω) cos θdω
R
from uniform hemispherical light: L sin θ cos θdθdϕ = Lπ
Color BRDF fr (p, ωi → ωr ) = dLr (p,ωr )
dEi (p,ωi ) = dLr (p,ωr )
Li (p,ωi ) cos θi dωi
Retinal, perceived, and object color. Cone cells at retina have BRDF is nonnegative, reciprocal, and energy-conserving
R
sensitivity functions. Lr (p, ωr ) = Le (p, ωr ) + fr (ωi → ωr )Li (p, ωi ) cos θi dωi
ρ
Diffusion: fr (ωi → ωr ) = π
Response to mixed light l(λ): L =
R
l(λ)kl (λ)dλ, M , S
Phong: fr (ωi → ωr ) = ks (ωr · mirror(ωi , ñ))α
R
R k436 (λ)l(λ)dλ
⃗c(l(λ)) = ⃗c436 ⃗c546
⃗c700 R k546 (λ)l(λ)dλ
k700 (λ)l(λ)dλ