review: transformation matrices - cs csu homepagecs410/yr2015fa/more_progress/l25... · review:...

6
Texture Mapping Lecture #25 Tuesday, November 17 th 2015 Announcements PA3 grades being adjusted – Penalties for flipping dimensions to be removed PA4 handed out today – Due Tuesday, Dec. 8 th – See next slide for details 11/17/15 © Ross B everidge & B ruce Draper 2 PA4 Three additions over PA3 Specular Inter-reflection Recurse on reflection of viewing ray Multiple result by ks, add to reflection Base cases: Ray does not strike a polygon Product of ks terms < 1/512 Hard limit of 20 recursions (house of mirrors) – Translucency Materials now have translucency percentages Recurse on continuation of viewing ray Angle of refraction for infinitely thin planar surface Same base as above (ks & kt) – Anti-aliasing Five rays through every pixel Randomly positioned within pixel square 11/17/15 © Ross B everidge & B ruce Draper 3 Review: Transformation Matrices 11/17/15 © Ross B everidge & B ruce Draper 4 0 0 4 1 ! " # # # # $ % & & & & = 0 0 12 3 12 4 3 ! " # # # # # # $ % & & & & & & = 1 2 0 1 2 0 1 6 2 6 1 6 0 1 3 1 3 1 3 3 3 1 4 3 1 4 3 1 4 3 3 4 3 ! " # # # # # # # # # # $ % & & & & & & & & & & 5 5 5 1 ! " # # # # $ % & & & & The matrix above is an example projection matrix Q: What exactly is being projected/transformed? A: Coordinates Geometric Registration Registration is the proces of matching locations in one image to locations in another Does this matter? These two images have the same pixels! (But the mapping from left to right image is random) Image from CalTech256 data set Geometric Registration (II) Geometric registration finds a mapping that maps one image onto the other We will limit ourselves to linear transformation We should be able to register these…

Upload: phamthien

Post on 09-May-2018

216 views

Category:

Documents


1 download

TRANSCRIPT

Texture Mapping

Lecture #25Tuesday, November 17th 2015

Announcements

• PA3 grades being adjusted– Penalties for flipping dimensions to be

removed• PA4 handed out today

– Due Tuesday, Dec. 8th

– See next slide for details

11/17/15

© Ross Beveridge & Bruce Draper

2

PA4• Three additions over PA3

– Specular Inter-reflection• Recurse on reflection of viewing ray• Multiple result by ks, add to reflection• Base cases:

– Ray does not strike a polygon– Product of ks terms < 1/512– Hard limit of 20 recursions (house of mirrors)

– Translucency• Materials now have translucency percentages• Recurse on continuation of viewing ray

– Angle of refraction for infinitely thin planar surface– Same base as above (ks & k t)

– Anti-aliasing• Five rays through every pixel• Randomly positioned within pixel square

11/17/15

© Ross Beveridge & Bruce Draper

3

Review: Transformation Matrices

11/17/15

© Ross Beveridge & Bruce Draper

4

0041

!

"

####

$

%

&&&&

=

00

−123

−124 3

!

"

######

$

%

&&&&&&

=

12

0 −12

0

−16

26

−16

0

−13

−13

−13

33

−14 3

−14 3

−14 3

34 3

!

"

##########

$

%

&&&&&&&&&&

5551

!

"

####

$

%

&&&&

• The matrix above is an example projection matrix• Q: What exactly is being projected/transformed?

A:Coordinates

Geometric Registration• Registration is the proces of matching locations in one

image to locations in another• Does this matter?

These two images have the same pixels!(But the mapping from left to right image is random)

Imag

e fro

m C

alTe

ch25

6 da

ta s

et

Geometric Registration (II)• Geometric registration finds a mapping that maps

one image onto the other– We will limit ourselves to linear transformation

We should be able to register these…

Review: Image Transformations• The simplest set of transformations are translation,

rotation, and scale – Together these are called the similarity transform.– Similarity transforms have 4 degrees of freedom.

• In matrix form these are:

uv1

!

"

###

$

%

&&&=

s 0 00 s 00 0 1

!

"

###

$

%

&&&

xy1

!

"

###

$

%

&&&

uv1

!

"

###

$

%

&&&=

cos Θ( ) −sin Θ( ) 0

sin Θ( ) cos Θ( ) 0

0 0 1

!

"

####

$

%

&&&&

xy1

!

"

###

$

%

&&&

scale rotationand...

Similarity & Affine Transformations• All the similarity transforms can be combined into one

generic matrix:

• But! This matrix does more. What?– hint: two more transformation types included.– hint: 6 degrees of freedom (DOF)

• How can you specify this matrix?

!!!

"

#

$$$

%

&

!!!

"

#

$$$

%

&

=

!!!

"

#

$$$

%

&

11001yx

fedcba

vu Hint: diagonal

terms are not equal, and b ≠ -d.

This is equivalent to adding two shear parameters (or unequal scaling & one shear).

Similarity vs Affine Matrices• Similarity : 4 DOF

• Affine : 6 DOF

!!!

"

#

$$$

%

&

!!!

"

#

$$$

%

&

=

!!!

"

#

$$$

%

&

11001yx

fedcba

vu

uv1

!

"

###

$

%

&&&=

a b c−b a d0 0 1

!

"

###

$

%

&&&

xy1

!

"

###

$

%

&&&

Specifying Affine Transformations• There are six unknowns in the matrix (a through f)• If you specify one point in the source image and a

corresponding point in the target image, that yields two equations:

• So providing three point-to-point correspondences specifies an affine matrix

feydxvcbyaxu

iii

iii

++=

++=

Affine Specification: Example

There is one affine transformation that will map the green point on the right to the green point on the left, and align the red and blue points too.

Solving Affine TransformationsThese linear equations can be easily solved:

– WLOG, assume x1=y1=0– then u1= c and v1 = f– so:

( )

( )

( )( ) ( )

2323

123232

32

23

122

313

122

3133

2

23

3132

2123

2

212

1333

1222

xyyxuuxuux

yxyx

uuxxuu

b

uuxx

uubyxyx

byuux

byuuxxbyuu

a

ubyaxuubyaxu

−−

−−−=

−−

−−−=

−−−=""#

$%%&

'−

−−=−−

−−=

++=

++=

Calculation of a, b & cis independent of calculation of e, f & g.

Solving Affine (cont.)• This can be substituted in to solve for a• The same process with y’s solves for d,e,f• About the WLOG:

– It was true because you can translate the original coordinate system by (-x1, -y1)

– So what do you do to compensate?

• Alternatively, set up a system of linear equations and solve…

Solving Affine Transformations (III)

• Because u & v are independent:

• Therefore

• When does this have a solution?

11/17/15

© Ross Beveridge & Bruce Draper

14

𝑢"𝑢#𝑢$

=𝑥" 𝑦" 1𝑥# 𝑦# 1𝑥$ 𝑦$ 1

𝑎𝑏𝑐

𝑥" 𝑦" 1𝑥# 𝑦# 1𝑥$ 𝑦$ 1

," 𝑢"𝑢#𝑢$

=𝑎𝑏𝑐

Perspective Transformations• We can go beyond affine transformations.• We can do any perspective transformation of a plane

to a plane.• Therefore, we can model an image as a plane in

space, and project it onto any other image.– How does this differ from perspective projection?

Perspective Matrix

• Why does element [3,3] = 1?• How many points are needed to specify this matrix?

u'v 'w

"

#

$ $ $

%

&

' ' '

=

a b cd e fg h 1

"

#

$ $ $

%

&

' ' '

xy1

"

#

$ $ $

%

&

' ' '

u = u'w , v = v'

w

Solving for Perspective• Four corresponding points produce eight equations, eight

unknowns --- but we can’t observe w

• a,b, and c are no longer independent of d, e and f because they are linked by g and h.

1'

1'

++

++==

++

++==

ii

ii

i

ii

ii

ii

i

ii

hygxfeydx

wvv

hygxcbyax

wuu

Solving (cont.)• Multiply to get rid of the fraction…

• Now, remember that the u’s, v’s, x’s & y’s are known; group the unknown terms

( )( ) feydxhygxv

cbyaxhygxu

iiiii

iiiii

++=++

++=++

11

iiiiiii

iiiiiii

vhyvgxfeydxvuhyugxcbyaxu

−−++=

−−++=

Solving (III)• And express the result as a system of linear equations

!!!!!!!!!!!

"

#

$$$$$$$$$$$

%

&

!!!!!!!!!!!

"

#

$$$$$$$$$$$

%

&

−−

−−

−−

−−

−−

−−

−−

−−

=

!!!!!!!!!!!

"

#

$$$$$$$$$$$

%

&

hgfedcba

vyvxyxuyuxyxvyvxyxuyuxyxvyvxyxuyuxyxvyvxyxuyuxyx

vuvuvuvu

444444

444444

333333

333333

222222

222222

111111

111111

4

4

3

3

2

2

1

1

10000001100000011000000110000001

Solving (IV)• Finally, invert the constant matrix and solve

!!!!!!!!!!!

"

#

$$$$$$$$$$$

%

&

=

!!!!!!!!!!!

"

#

$$$$$$$$$$$

%

&

!!!!!!!!!!!

"

#

$$$$$$$$$$$

%

&

−−

−−

−−

−−

−−

−−

−−

−−−

hgfedcba

vuvuvuvu

vyvxyxuyuxyxvyvxyxuyuxyxvyvxyxuyuxyxvyvxyxuyuxyx

4

4

3

3

2

2

1

11

444444

444444

333333

333333

222222

222222

111111

111111

10000001100000011000000110000001

Now to Texture mapping

11/17/15

© Ross Beveridge & Bruce Draper, CS CSU

21

Image from http://www.minecraftercamp.com

Ubiquitous,andsometimesobvious

Adding surface detail• Surfaces in the world have appearance

– They are seldom one flat color.– They have true texture – repeating patterns.– They have structured markings.– They have tiny changes in surface height.

• Purists view (don’t try this!)– Use ever more even smaller uniform triangles.

• Pragmatists view– Paint surfaces with images – texture mapping.

11/17/15

© Ross Beveridge & Bruce Draper

22

Mapping • The underlying process is registration!

11/17/15

© Ross Beveridge & Bruce Draper

23

(0,0)

(1,1)t,s coordinates

(x,y,z)

(x,y,z)

Mapping (II)• Textures are color images

– Logical texture coords run from (0,0) to (1,1)

– Coordinates fixed regardless of image size

• Polygons are 2D surfaces in a 3D space

• The transformation from texture coordinates to surface coordinates is expressed as a matrix

11/17/15

© Ross Beveridge & Bruce Draper

24

Texture Matrices (OpenGL)

11/17/15

© Ross Beveridge & Bruce Draper

25

• Given vertices and the corresponding texture coordinates…

ts

!

"#

$

%&=

a b cd e f

!

"##

$

%&&

xyz

!

"

###

$

%

&&&

§ What type of transformation is this?§ How many correspondences are needed?

Texture Mapping in OpenGL• The fragment processor computes a

reflectance color for every pixel• When textures are enabled,

– The fragment processor also computes a texture value for every pixel

– Using the pixel to do texture mapping• These values are multiplied together to

produce the final value

11/17/15

© Ross Beveridge & Bruce Draper

26

Issue #1: Sampling• The mapping from surface points to

texture coordinates produces real values

11/17/15

© Ross Beveridge & Bruce Draper

27

X

Sampling• Nearest-neighbor:

– pick the closest texture pixel

• Bilinear:

– linearly interpolate in both dimensions

• Bicubic:

– fit a 3rd order surface to 16 surrounding points

– Not as expensive as it sounds

11/17/15

© Ross Beveridge & Bruce Draper

28

Sampling (III)

• A better solution is for the texture map to be roughly the same size as the surface projection.

• A MipMap is an image pyramid built from a texture map– Example: if the texture is 64x64, the pyramid

also includes 32x32, 16x16, etc.

11/17/15

© Ross Beveridge & Bruce Draper

29

Issue #2: Getting Textures

11/17/15

© Ross Beveridge & Bruce Drape

30

§ WEB!§ millions of textures – people use them for

backgrounds of web pages a lot! You can download them in bulk packages, etc..

§ Build your own§ Make them “seamless”

§ When tiled, you cannot see the edges of the tiles.

Just for example …

11/17/15

© Ross Beveridge & Bruce Draper

31

Texture Makers• There are tons of them.. Some examples:

– ftp://zdftp.zdnet.com/pub/private/sWlIB/graphics_multimedia_tools/graphics_tools/terltx32.zip

– http://www.backgroundmagic.com/software/BGM.zip

– http://www.metaworkshop.com/ftp/twinst.zip– http://216.156.212.112/photoseam.exe

11/17/15

© Ross Beveridge & Bruce Draper

32

More Examples

11/17/15

© Ross Beveridge & Bruce Draper

33

Surface Textures

11/17/15

© Ross Beveridge & Bruce Draper

34

Texture Map from Image

11/17/15

© Ross Beveridge & Bruce Draper

35