GAMES101 Lecture 09
GAMES101 Lecture 09
Lecture 9:
Shading 3 (Texture Mapping cont.)
http://www.cs.ucsb.edu/~lingqi/teaching/games101.html
Announcements
• About homework
- Homework 1 is being graded
- Homework 2
• Shading 1 & 2
- Blinn-Phong reflectance model
- Graphics Pipeline
- Texture mapping
- Texture queries
- Applications of textures
• Shadow mapping
How do we interpolate?
• Barycentric coordinates
(x, y) = ↵ A + B+ C
↵+ + =1
(x, y)
Inside the triangle if
B all three coordinates
are non-negative
A
(↵, , ) = (1, 0, 0)
(x, y) = ↵ A + B+ C
=A
A
(x, y)
GAMES101 8 Lingqi Yan, UC Santa Barbara
Barycentric Coordinates
AA
↵=
AA + AB + AC
AB
AB AA =
AA + AB + AC
AC
AC =
AA + AB + AC
B
1 1 1
(↵, , ) = 3, 3, 3
1 1 1
(x, y) = 3 A+ 3 B+ 3 C
(x, y)
B
A
GAMES101 10 Lingqi Yan, UC Santa Barbara
Barycentric Coordinates: Formulas
C
(x, y) = ↵ A + B+ C
↵+ + =1
(x, y) = ↵ A + B+ C
B
A
(x xB )(yC yB ) + (y yB )(xC xB )
↵=
(xA xB )(yC yB ) + (yA yB )(xC xB )
(x xC )(yA yC ) + (y yC )(xA xC )
=
(xB xC )(yA yC ) + (yB yC )(xA xC )
=1 ↵
V = ↵ VA + V B + VC
VA
However, barycentric coordinates are not invariant under projection!
GAMES101 12 Lingqi Yan, UC Santa Barbara
Applying Textures
Simple Texture Mapping: Diffuse Color
Want to sample
texture value f(x,y) at
red point
u01 u11
Take 4 nearest sample
locations, with texture
values as labeled.
u00 u10
u01 u11
And fractional offsets,
t (s,t) as shown
u00 s u10
lerp(x, v0 , v1 ) = v0 + x(v1 v0 )
u01 u11 u0 = lerp(s, u00 , u10)
u1 = lerp(s, u01 , u11)
u = lerp(t, u0 , u1)
t
u00 s u10
lerp(x, v0 , v1 ) = v0 + x(v1 v0 )
u01 u11 u0 = lerp(s, u00 , u10)
u = lerp(s, u01 , u11)
Two helper lerps (horizontal)
1
u0 = lerp(s,uu=00lerp(t,
, u10 ) u0 , u1)
t
u1 = lerp(s, u01 , u11 )
u00 s u10
f (x, y) = lerp(t, u0 , u1 )
u0
GAMES101 21 Lingqi Yan, UC Santa Barbara
Bilinear Interpolation
u1
lerp(x, v0 , v1 ) = v0 + x(v1 v0 )
u01 u11 u0 = lerp(s, u00 , u10)
u = lerp(s, u01 , u11)
Two helper lerps 1
u0 = lerp(s,uu=00lerp(t,
, u10 ) u0 , u1)
t
u1 = lerp(s, u01 , u11 )
u00 s u10 u0 = lerp(s, u00 , u10 )
f (x, y) = lerp(t, u0 , u1 )
u1 =lerp,
Final vertical lerp(s, u01 , u11 )
to get result:
f (x, y) = lerp(t, u0 , u1 )
u0
GAMES101 22 Lingqi Yan, UC Santa Barbara
Texture Magnification - Easy Case
Moire
Jaggies
Upsampling
upsampling Downsampling
downsampling
(Magnification)
magnification (Minification)
minification
512x supersampling
upsampling downsampling
magnification minification
D
D=2
D=1
v D=0
u
“Mip hierarchy”
level = D
What is the storage overhead of a mipmap?
u
Screen space (x,y) Texture space (u,v)
Estimate texture footprint using texture coordinates of
neighboring screen samples
(u,v)01
u
0s s 1
✓ ◆ 2 ✓ ◆2 ✓ ◆2 ✓ ◆ 2
du dv du dv A
D = log2 L L = max @ + , +
dx dx dy dy
(u,v)01
u
0s s 1
✓ ◆ 2 ✓ ◆2 ✓ ◆2 ✓ ◆ 2
du dv du dv A
D = log2 L L = max @ + , +
dx dx dy dy
Point sampling
Overblur
Why?
Anisotropic Filtering
WEIGHT = WTAB[floor(Q)]
This radius r is just the parameter needed when indexing 1* read and weight texture pixel */
a kernel, so Q can serve two purposes: inclusion testing NUM NUM+WEIGHT*texture[v,u]
-
•
kernel to use is the Gaussian f(r) = e-ar, shown in Figure
Can look up axis-aligned 9, for which WTAB[Q] = e-aQ. The Gaussian is preferred
to the theoretically optimal sinc kernel because it decays
much more quickly. By properly scaling A, B, C, and F, the
This implementation can be optimized further by re-
moving redundant calculations from the v loop and, with
rectangular zones length of the WTAB array can be controlled to minimize
quantization artifacts (several thousand entries have
proven sufficient). The parameters F and a can be tuned
proper checking, by using integer variables throughout.
The EWA filter computes the weighted average of
elliptical areas incrementally, requiring one floating-point
to adjust the filter cutoff radius and the degree of pixel multiply, four floating-point adds, one integerization, and
-
-
F Ux*Vy-Uy*Vx
-
•
F F*F
Can handle irregular footprints
-