7. Texture Mapping Idea - CGL @ ETHZ · 7. Texture Mapping 13 Mapping a texture onto a sphere...
Transcript of 7. Texture Mapping Idea - CGL @ ETHZ · 7. Texture Mapping 13 Mapping a texture onto a sphere...
7. Tex
ture M
ap
pin
g
7. Textu
re Ma
pp
ing 2
+ T
ex
ture M
ap
pin
g
Mo
tivatio
n
Wirefra
me
Mo
del
+ Lig
htin
g &
Sha
din
g
http
://ww
w.3d
rend
er.com
/jbirn
/pro
du
ction
s.htm
l
tow
ard
s mo
re rea
lism
7. Textu
re Ma
pp
ing 3
Idea
•A
dd
surfa
ce d
eta
ilw
itho
ut ra
ising
geo
me
tric com
plex
ity
•T
ex
ture
s can
be
ima
ges
or p
roced
ures
•T
ex
ture
s can
be
2Do
r 3D
7. Textu
re Ma
pp
ing 4
Exa
mp
les –Im
ag
e T
ex
ture
s
Flytastic
II (ww
w.en
do
xo
n.ch
)
+
7. Textu
re Ma
pp
ing 5
Exa
mp
les –Im
ag
e T
ex
ture
s
7. Textu
re Ma
pp
ing 6
Exa
mp
les –B
um
p M
ap
7. Textu
re Ma
pp
ing 7
Exa
mp
les –B
um
p M
ap
in H
ard
wa
re
7. Textu
re Ma
pp
ing 8
Exa
mp
les –D
ispla
cem
en
t Ma
p
7. Textu
re Ma
pp
ing 9
Exa
mp
les –En
viron
me
nt M
ap
7. Textu
re Ma
pp
ing 10
Issues
•D
efinitio
n o
f tex
ture co
ord
ina
tes
•Su
rface
pa
ram
etrizatio
n
•A
nti a
liasin
g
•T
ex
ture
filterin
g
•Leve
l-of-D
eta
il
•H
ard
wa
re a
ccele
ratio
n
7. Textu
re Ma
pp
ing 11
Co
ncep
t of T
extu
re Ma
pp
ing
•Fin
d m
ap
pin
gs b
etwe
en
diffe
ren
t coo
rdin
ate
syste
ms
•In
vert tra
nsfo
rma
tion
from
tex
ture
co
ord
ina
tes to
ima
ge
pix
el
Tex
ture co
ord
ina
tes
surfa
ce coo
rdin
ates
w(u
,v)=
(x,y
,z)
Pix
el coo
rdin
ate
s
7. Textu
re Ma
pp
ing 12
An
alytica
l 3D Su
fraces
1. Key to
tex
ture
ma
pp
ing
: Pa
ram
etrizatio
n
→
),(
),
(
),(
ts
z
ts
y
ts
x
t s
→
φθ
φφ
θ
φ θ
sincos cos sinsin
sph
ere:
2. Ma
p p
ara
me
ters to
textu
re co
ord
ina
tes
→
),
(
),(
ts
v
ts
u
t s
→
)
,(
),
(
vut
vus
v uin
verse:
7. Textu
re Ma
pp
ing 13
Ma
pp
ing
a tex
ture o
nto
a sp
here
•U
se lin
ea
r ma
p
+ +=
D
Cv
BAu
φ θ
+
⋅−
⋅=
2/
4/
2/
ππ
πφ θ
v
u
7. Textu
re Ma
pp
ing 14
Exa
mp
le
7. Textu
re Ma
pp
ing 15
Pa
ram
etrizatio
no
f Tria
ng
le Mesh
es
•Fin
d te
xtu
re co
ord
ina
tes fo
r vertice
s
•T
ake
no
rma
l or ra
y from
cen
ter o
f gra
vity
Sph
erical co
ord
ina
tes (θ,φ
)
Tria
ng
le vertex
Cen
ter of G
ravity
Pro
ble
ms:
Mu
ltiple In
tersection
s7. T
exture M
ap
pin
g 16
Pro
blem
s
Cra
ig G
otsm
an
et. al.
•O
verlap
s
•T
iny a
nd
larg
e trian
gle
s–
op
timize co
ord
ina
tesb
y mo
ving
vertices o
n sp
he
re
–co
st fun
ction
(a
rea, a
ng
les, overla
p)
–fin
d m
inim
um
itera
tively
•T
op
olo
gica
lly no
t a sp
he
re–
cut m
esh
–o
ptim
ize pa
tches sep
ara
tely
7. Textu
re Ma
pp
ing 17
Tex
ture M
ap
Tim
Weyrich
et. al.
•T
extu
re m
ap
corresp
on
ds to
pa
ram
etrizatio
n
stretche
d a
t no
se tipco
mp
ressed a
t no
se tip
7. Textu
re Ma
pp
ing 18
Pa
ram
etrizedT
rian
gle M
esh
v 0.131171 -0.113469 0.178314
v 0.130945 -0.114951 0.182474
v 0.130916 -0.115792 0.185402
…vt
0.538446 0.4275
vt
0.550132 0.41427
vt
0.546491 0.427631
…vn
0.609697 0.486474 0.625789
vn
0.799934 0.334347 0.498315
vn
0.942394 0.131824 0.307435
…f 22/209/22 220/210/220 221/211/221
f 21/213/21 219/214/219 220/210/229
f 253/203/253 219/214/219 21/213/21
…
Ve
rtex
po
sition
s
Tex
ture co
ord
ina
tes
No
rma
ls
Face
s (trian
gle
s)coordNr/texNr/normalNr
OB
J Files:
7. Textu
re Ma
pp
ing 19
Ra
sterizatio
n
•Fro
m tex
ture
coo
rdin
ate
s of ve
rtices
to tex
ture
coo
rdin
ates o
f pix
els
•Lin
ear in
terp
ola
tion
in scre
en
-spa
ce
(as in
Go
ura
ud
sha
din
g):
textu
re sou
rcew
ha
t we g
et
wh
at w
e wa
nt
Ima
ges b
y Fredo
Du
ran
d
7. Textu
re Ma
pp
ing
20
Persp
ective Interp
ola
tion
•Lin
ear va
riatio
n in
wo
rld co
ord
ina
tes yie
lds
no
n-lin
ear va
riatio
n in
scree
n co
ord
ina
tes:
•P
ersp
ective
inte
rpo
latio
n im
ple
me
nte
d
in to
da
y’s gra
ph
ics card
s
projection plane
(u0 ,v
0 )
(u1 ,v
1 )
7. Textu
re Ma
pp
ing 21
Tex
ture Filterin
g
•(u,v)
are rea
l pix
el co
ord
ina
tes, e.g
. (6.4, 3.7):
]4,6[
map
color
=
nea
rest
]4,7[
]4,6[
]3,7
[]3,6
[
map
ts
map
ts
map
ts
map
ts
color
⋅⋅
+⋅
⋅+
⋅⋅
+⋅
⋅=
3
u
4
67
ss
tt
bi-lin
ear
u
3 4
67
7. Textu
re Ma
pp
ing 22
Tex
ture M
ap
pin
g in
Op
enG
L
loadImage(&texture_data);
glGenTextures(1, &texId);
glBindTexture(GL_TEXTURE_2D, texId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
w, h, 0, GL_RGB, GL_UNSIGNED_BYTE,
texture_data);
…glBindTexture(GL_TEXTURE_2D, texId);
glBegin(GL_TRIANGLES);
glTexCoord2f(u0 ,v0 ); glVertex(x0 ,y0 ,z0 );
glTexCoord2f(u1 ,v1 ); glVertex(x1 ,y1 ,z1 );
glTexCoord2f(u2 ,v2 ); glVertex(x2 ,y2 ,z2 );
glEnd();
→T
uto
r
]10[
,K
∈vu
mnh
w2
,2
==
7. Textu
re Ma
pp
ing 23
Enviro
nm
ent M
ap
•M
eth
od
to re
nd
er
reflective o
bje
cts
•C
om
pu
te in
terse
ction
o
f reflecte
d ra
y with
surro
un
din
g sp
he
re
•T
ake p
ara
meter va
lues
of in
terse
ction
a
s textu
re co
ord
ina
tes
n
(θ,φ)
7. Textu
re Ma
pp
ing 24
Exa
mp
les
•R
eflection
ma
pp
ing
usin
g O
pen
GL
7. Textu
re Ma
pp
ing 25
Cu
be M
ap
pin
g
•Sp
he
re ca
n b
e re
pla
ced
by cu
be
•S
imp
lify com
pu
tatio
ns
7. Textu
re Ma
pp
ing 26
Linea
r Ma
pp
ing
•U
ses o
bje
ct or eye co
ord
ina
tes
•(In
)de
pe
nd
ent o
f tran
sform
s
•C
an
be
use
d to
com
pu
te d
istan
ce fro
m o
bje
ctsy
x
-x
z-z
7. Textu
re Ma
pp
ing 27
An
Exa
mp
le
•M
ap
pin
g o
f dista
nces fro
m la
ser ra
ng
e d
ata
7. Textu
re Ma
pp
ing 28
Pro
jective Tex
tures
•G
enera
lize textu
re coo
rdin
ates to
a 4D
ho
mo
gen
eo
us ve
ctor (u
, v, r, q)
•T
ex
ture
ma
trix co
mp
ute
s full 4
x4
tran
sform
to
(up, v
p) used
for te
xtu
re loo
kup
•T
extu
re im
ag
e ca
n b
e p
roje
cted in
dep
en
de
nt
of vie
win
g p
roje
ction
•A
pp
licatio
ns:
–Slid
e pro
jector
–Sp
otlig
ht sim
ula
tion
7. Textu
re Ma
pp
ing 29
Pro
jection
Po
lygo
n
Screen
Eye
Tex
ture
7. Textu
re Ma
pp
ing
30
Exa
mp
les
7. Textu
re Ma
pp
ing 31
Mip
-Ma
pp
ing
•M
inim
ized te
xtu
res
pro
du
cea
liasin
g e
ffects
•Sto
re te
xtu
re a
t mu
ltiple
leve
ls-of-d
eta
il
•U
se sm
aller versio
ns
wh
en fa
r from
cam
era
•M
IPco
mes fro
m th
e La
tin m
ultumin parvo
, m
ea
nin
g a
mu
ltitud
e in
a sm
all sp
ace.
with
ou
t mip
ma
pw
ith m
ipm
ap
mip
ma
p7. T
exture M
ap
pin
g 32
Tex
ture In
terpo
latio
n
•C
om
pu
te textu
re valu
e (R,G,B)
as fu
nctio
n o
f (u,v,z)•
Tri-lin
ear in
terp
ola
tion
u
v
u
v
u
v
zz
7. Textu
re Ma
pp
ing 33
Co
mp
uta
tion
of th
e Mip
Ma
p
•C
olo
r = w
eigh
ted
ave
rag
e o
f ne
arb
y pix
els (filter)
•Se
e gluBuild2DMipMaps()
7. Textu
re Ma
pp
ing 34
Bu
mp
Ma
pp
ing
•A
dd
ing
surfa
ce d
eta
il with
ou
t ad
din
g
geo
me
try
•P
erturb
atio
n o
f surfa
ce n
orm
al
•D
etails in
tera
ct with
ligh
t
•B
um
ps a
re sma
ll com
pa
red to
ge
om
etry
•B
um
p p
attern
is taken
from
a (te
xtu
re-) ma
p
•C
an
also
be
pro
ced
ura
l (fracta
ls)
7. Textu
re Ma
pp
ing 35
Bu
mp
Ma
pp
ing
•G
iven a
surfa
ce p(u,v)
an
d
a p
ertu
rba
tion
valu
e b
(Jim Blinn
)
•P
oin
t p’o
n th
e b
um
py su
rface
•C
om
pu
te n
orm
al a
t Po
int p
’ vu
vu
pp
pp
n×
=∂ ∂
×∂ ∂
=
n np
pb
'+
=
v '
u ''
∂ ∂×
∂ ∂=
pp
n
p
p’
Bu
mp
pa
ttern
b
7. Textu
re Ma
pp
ing 36
Bu
mp
Ma
pp
ing
•P
artia
l de
rivative
s at p
oin
t p’
•P
ertu
rbe
d n
orm
al a
pp
rox
ima
ted
by (se
e B
linn
)
n np
p)
(b
uu
u '
∂ ∂+
∂ ∂=
∂ ∂
)(
b)
(b
'v
vu
up
np
nn
n×
+×
+=
7. Textu
re Ma
pp
ing 37
Bu
mp
Ma
pp
ing
•D
iscretiza
tion
usin
g Fin
ite Diffe
ren
ces
v
),v
b(u)
,vb(u
),v
b(u)
,vb(u
b
u
),v
b(u)
,vb(u
),v
b(u)
,vb(u
b
v u
2 2
12
22
11
21
21
22
11
12
−+
−=
−+
−=∆v
∆u
b(u1,v2 )
b(u2,v2 )
b(u2,v1 )
b(u1,v1 )
7. Textu
re Ma
pp
ing 38
Exa
mp
le: Mu
ltipa
ssB
um
p
7. Textu
re Ma
pp
ing 39
Furth
er To
pics
•T
extu
re P
ag
ing
•T
extu
re B
lend
ing
an
d co
mp
ositin
g (R
GB
A)
•M
ultip
le T
ex
ture
s
•D
yna
mic T
ex
ture
s
•B
ill bo
ard
ing
7. Textu
re Ma
pp
ing
40
Exa
mp
les
Billo
ard
s: Xa
vier Dé
coret
et a
l.
Alp
ha
Tex
tures