程序代写代做代考 cse3431-lecture7

cse3431-lecture7

Transformations in the pipeline

Modeling
transformation

Viewing
transformation

Projection
transformation

Perspective
division

Viewport
transformation

OCS WCS VCS CCS

NDCS
DCS

(e.g. pixels)

lookAt()translate()…

ModelView Matrix
Vertex Shader

Projection transformations

Introduction to Projection
Transformations

Mapping: f : Rn à Rm
Projection: n > m
Planar Projection: Projection on

a plane.
R3àR2 or 


R4àR3 homogenous
coordinates.

Transformation: n = m

Basic projections
Parallel

Perspective

Taxonomy

Examples
• All defined with respect


to a unit cube

A basic orthographic projection
x’ = x
y’ = y
z’ = N

Matrix Form

Z

Y

I

N

A basic perspective projection

Note that d > 0

Similar triangles
x’/d = x/(-z) –> x’ = x d/(-z)
y’/d = y/(-z) –> y’ = y d/(-z)
z’ = -d

Matrix form?

(0,0,-z)

Reminder: Homogeneous
Coordinates

Canonical matrix form

Matrix form of
x’ = x d/(-z)
y’ = y d/(-z)
z’ = -d
d > 0

Moving from 4D to 3D

or

Things to notice

Projections in OpenGL
Projections in OpenGL are defined in the
camera coordinate system
• Although not advisable, with shaders you can actually

change that if you wish

• That means they are also applied in the camera
coordinate system, i.e. they are applied to a point or
vector given in camera coordinates

Camera coordinate system
• Camera at (0,0,0)
• Looking at –z
• Image plane is the near plane


z = -d, d > 0

Perspective projection of a
point

Point or vector in eye coordinates
Peye = (x,y,z)
Projected coordinates:
x’ = x d/(-z)
y’ = y d/(-z)
z’ = -d
d > 0

d

x0 = �d
x

z

y0 = �d
y

z
z0 = �d

Observations
• Perspective foreshortening
• Denominator becomes

undefined for z = 0
• If P is behind the eye z

changes sign
• Near plane just scales the

picture
• Straight line -> straight line

Perspective projection of a line

Perspective Division,
drop fourth coordinate

Is it a line?

Cont’d next slide

Is it a line? (cont’d)

So is there a difference?

Non-linearity of perspective
projection

How do points on lines project ?

Viewing space: R(g) = (1-g)A + gB

NDCS Coordinates: R’(f) = (1-f)A’ + fB’

What is the relationship between g and f?

A

BR

M, persp division

A’

B’
R’

NDCS and eventually
Screen Space

Viewing Space

Non-linearity of perspective
projection

Point goes through two stages

Viewing space: R(g) = (1-g)A + gB

Projected (4D) : r = MR

Projected cartesian: R’(f) = (1-f)A’ + fB’

What is the relationship between g and f?

A

BR

M
Perspective divisiona

b

r

A’

B’
R’

First step
Viewing to homogeneous space (4D)

A

BR

M
a

b

r

Second step
Perspective division

A

BR

M
a

b

r

Perspective division

A’

B’
R’

r = (1� g)a+ gb

r = (r1, r2, r3, r4)
a = (a1, a2, a3, a4)
b = (b1, b2, b3, b4)

9
>>>>=

>>>>;

! R01 =
r1
r4

=
(1� g)a1 + gb1
(1� g)a4 + gb4

Putting all together

A

BR

M
a

b

r

Perspective division

A’

B’
R’

Relation between the fractions

R can be texture coordinates, color etc.THAT MEANS: For a given f in screen space and A,B in viewing
space we can find the corresponding R (or g) in viewing space
using the above formula.

“A,B” can be texture coordinates, position, color, normal etc.

R01(g) =
lerp(a1,b1,g)
lerp(a4,b4,g)

R01(f) = lerp(
a1
a4
, b1
b4
, f)

9
>=

>;
! g =

f

lerp( b4
a4
, 1, f)

substituting this in R(g) = (1� g)A+ gB yields

R1 =
lerp(A1

a4
, B1
b4
, f)

lerp( 1
a4
, 1
b4
, f)

Effect of perspective projection
on lines

Equations

What happens to parallel lines?

Effect of perspective projection
on lines

Parallel lines

If parallel to view plane then:

Effect of perspective projection
on lines

Parallel lines

If not parallel to view plane then:

Vanishing point!

Summary
Forshortening
Non-linear
Lines go to lines
Parallel lines either intersect or remain
parallel
Inbetweeness (interpolation)

Screen space and viewing space are not
linearly related

Projections in the Graphics
Pipeline

View volumes
• Primarily two:

– Orthographic
– Perspective

• This stage also defines
the view window

• What is visible with each
projection?
– a cube
– a truncated pyramid

Projection Stage in Graphics
Pipeline

Open GL Canonical view
volume (left handed!)

Transforms the view volume into
a canonical one. The resulting
system is called:

Normalized Device Coordinate
System (NDCS)

Notice: z is reflected and NDCS
is a left-handed system)

Transformation vs Projection
We want to keep z
Why?
• Pseudodepth

I

-z0 z1 < z2 P1 P2 Derivation of the orthographic transformation Map each axis separately: • Scaling and translation Let’s look at y: • y’ = ay+b such that
 bottom à -1 
 top à 1 • Note:
 left,right,near,far,top,bottom>0

Derivation of the orthographic
transformation

Scaling and Translation

All three coordinates
Scaling and Translation

Matrix form

Alternative way
Scaling and translation of a cube

Note: r,l,b,t,n,f > 0

MO =

2

66
4

2
r�l 0 0 0
0 2

t�b 0 0
0 0 2

n�f 0
0 0 0 1

3

77
5

2

66
4

1 0 0 � l+r
2

0 1 0 � t+b
2

0 0 1 �n+f
2

0 0 0 1

3

77
5