7. texture mapping - cgl.ethz.ch · 7. texture mapping 3 idea • add surface detail without...

40
7. Texture Mapping

Upload: others

Post on 13-Sep-2019

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g

Page 2: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 2

+ T

extu

re Ma

pp

ing

Mo

tivatio

n

Wire

fram

eM

od

el

+ Lig

htin

g &

Sh

ad

ing

http

://ww

w.3d

ren

de

r.com

/jbirn

/pro

du

ction

s.htm

l

tow

ard

s mo

re re

alism

Page 3: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 3

Idea

•A

dd

surfa

ce d

eta

ilw

itho

ut ra

ising

ge

om

etric co

mp

lex

ity

•T

ex

ture

s can

be

ima

ge

so

r pro

ced

ure

s

•T

ex

ture

s can

be

2Do

r 3D

Page 4: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 4

Exa

mp

les –Im

ag

e T

ex

ture

s

Flytastic

II (ww

w.e

nd

ox

on

.ch)

+

Page 5: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 5

Exa

mp

les –Im

ag

e T

ex

ture

s

Page 6: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 6

Exa

mp

les –B

um

p M

ap

Page 7: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 7

Exa

mp

les –B

um

p M

ap

in H

ard

wa

re

Page 8: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 8

Exa

mp

les –D

ispla

cem

en

t Ma

p

Page 9: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 9

Exa

mp

les –En

viron

me

nt M

ap

Page 10: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 10

Issues

•D

efin

ition

of te

xtu

re co

ord

ina

tes

•S

urfa

ce p

ara

me

trizatio

n

•A

nti a

liasin

g

•T

ex

ture

filterin

g

•Le

vel-o

f-De

tail

•H

ard

wa

re a

ccele

ratio

n

Page 11: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 11

Co

ncep

t of T

extu

re Ma

pp

ing

•Fin

d m

ap

pin

gs b

etw

ee

n d

iffere

nt co

ord

ina

te

system

s

•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

ates

Page 12: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 12

An

alytica

l 3D Su

fraces

1. Ke

y to te

xtu

re m

ap

pin

g: P

ara

metriza

tion

),

(

),

(

),

(

ts

z

ts

y

ts

x

t s

φθ

φφ

θ

φ θ

sincos cos sinsin

sph

ere

:

2. Ma

p p

ara

me

ters to

tex

ture

coo

rdin

ate

s

),

(

),

(

ts

v

ts

u

t s

)

,(

),

(

vut

vus

v uin

verse

:

Page 13: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 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

Page 14: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 14

Exa

mp

le

Page 15: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 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

s

Page 16: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 16

Pro

blem

s

Cra

ig G

otsm

an

et. al.

•O

verla

ps

•T

iny a

nd

larg

e tria

ng

les

–o

ptim

ize co

ord

ina

tes

by m

ovin

g ve

rtices o

n sp

he

re

–co

st fun

ction

(a

rea

, an

gles, o

verla

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 p

atch

es sep

ara

tely

Page 17: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 17

Tex

ture M

ap

Tim

We

yriche

t. al.

•T

ex

ture

ma

p co

rresp

on

ds to

pa

ram

etriza

tion

stretch

ed

at n

ose

tipco

mp

resse

d a

t no

se tip

Page 18: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 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

Te

xtu

re co

ord

ina

tes

No

rma

ls

Face

s (trian

gles)

coordNr/texNr/normalNr

OB

J Files:

Page 19: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 19

Ra

sterizatio

n

•Fro

m te

xtu

re co

ord

ina

tes o

f vertice

sto

tex

ture

coo

rdin

ate

s of p

ixe

ls

•Lin

ea

r inte

rpo

latio

n in

scree

n-sp

ace

(a

s in G

ou

rau

dsh

ad

ing

):

textu

re so

urce

wh

at w

e g

et

wh

at w

e w

an

t

Ima

ge

s by Fre

do

Du

ran

d

Page 20: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g

20

Persp

ective Interp

ola

tion

•Lin

ea

r varia

tion

in w

orld

coo

rdin

ate

s yield

s n

on

-line

ar 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 )

Page 21: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 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=

ne

are

st

]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

Page 22: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 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

==

Page 23: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 23

Enviro

nm

ent M

ap

•M

eth

od

to re

nd

er

refle

ctive o

bje

cts

•C

om

pu

te in

terse

ction

o

f refle

cted

ray w

ithsu

rrou

nd

ing

sph

ere

•T

ake

pa

ram

ete

r valu

es

of in

terse

ction

a

s tex

ture

coo

rdin

ate

s

n

(θ,φ)

Page 24: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 24

Exa

mp

les

•R

efle

ction

ma

pp

ing

usin

g O

pe

nG

L

Page 25: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 25

Cu

be M

ap

pin

g

•S

ph

ere

can

be

rep

lace

d b

y cub

e

•S

imp

lify com

pu

tatio

ns

Page 26: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g

26

Linea

r Ma

pp

ing

•U

ses o

bje

ct or e

ye co

ord

ina

tes

•(In

)de

pe

nd

en

t of tra

nsfo

rms

•C

an

be

use

d to

com

pu

te d

istan

ce fro

m o

bje

ctsy

x

-x

z-z

Page 27: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 27

An

Exa

mp

le

•M

ap

pin

g o

f dista

nce

s from

lase

r ran

ge

da

ta

Page 28: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 28

Pro

jective Tex

tures

•G

en

era

lize te

xtu

re co

ord

ina

tes to

a 4D

ho

mo

ge

ne

ou

s vecto

r (u, v, r, q

)

•T

ex

ture

ma

trix co

mp

ute

s full 4

x4

tran

sform

to

(up, v

p) use

d fo

r tex

ture

loo

kup

•T

ex

ture

ima

ge

can

be

pro

jecte

d in

de

pe

nd

en

t o

f view

ing

pro

jectio

n

•A

pp

licatio

ns:

–S

lide

pro

jecto

r

–S

po

tligh

t simu

latio

n

Page 29: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g

29

Pro

jection

Po

lyg

on

Screen

Eye

Tex

ture

Page 30: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g

30

Exa

mp

les

Page 31: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 31

Mip

-Ma

pp

ing

•M

inim

ized

tex

ture

sp

rod

uce

alia

sing

effe

cts

•S

tore

tex

ture

at m

ultip

le le

vels-o

f-de

tail

•U

se sm

alle

r versio

ns

wh

en

far fro

m ca

me

ra

•M

IPco

me

s from

the

Latin

multum

in parvo,

me

an

ing

am

ultitu

de

in a

sma

ll spa

ce.

with

ou

t mip

ma

pw

ith m

ipm

ap

mip

ma

p

Page 32: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 32

Tex

ture In

terpo

latio

n

•C

om

pu

te te

xtu

re va

lue

(R,G,B)

as fu

nctio

n o

f (u,v,z)

•T

ri-line

ar in

terp

ola

tion

u

v

u

v

u

v

zz

Page 33: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 33

Co

mp

uta

tion

of th

e Mip

Ma

p

•C

olo

r = w

eig

hte

d a

vera

ge

of n

ea

rby p

ixe

ls (filter)

•S

ee

gluBuild2DMipMaps()

Page 34: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 34

Bu

mp

Ma

pp

ing

•A

dd

ing

surfa

ce d

eta

il with

ou

t ad

din

g

ge

om

etry

•P

ertu

rba

tion

of su

rface

no

rma

l

•D

eta

ils inte

ract w

ith lig

ht

•B

um

ps a

re sm

all co

mp

are

d to

ge

om

etry

•B

um

p p

atte

rn is ta

ken

from

a (te

xtu

re-) m

ap

•C

an

also

be

pro

ced

ura

l (fracta

ls)

Page 35: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 35

Bu

mp

Ma

pp

ing

•G

iven

a su

rface

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 np

pb

'+

=

v '

u ''

∂ ∂×

∂ ∂=

pp

n

p

p’

Bu

mp

pa

ttern

b

Page 36: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 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

+=

Page 37: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 37

Bu

mp

Ma

pp

ing

•D

iscretiza

tion

usin

g Fin

ite D

iffere

nce

s

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 )

Page 38: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 38

Exa

mp

le: Mu

ltipa

ssB

um

p

Page 39: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g 39

Furth

er To

pics

•T

ex

ture

Pa

gin

g

•T

ex

ture

Ble

nd

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

Page 40: 7. Texture Mapping - cgl.ethz.ch · 7. Texture Mapping 3 Idea • Add surface detail without raising geometric complexity cns•Tae bur etxe images or procedures cns•Tae bur etxe

7. Tex

ture M

ap

pin

g

40

Exa

mp

les

Billo

ard

s: Xa

vier D

éco

retet a

l.

Alp

ha

Te

xtu

res