Projection (Part 2) : Derivation Created by Dr. Slim BECHIKH for - - PowerPoint PPT Presentation

projection part 2 derivation created by dr slim bechikh
SMART_READER_LITE
LIVE PREVIEW

Projection (Part 2) : Derivation Created by Dr. Slim BECHIKH for - - PowerPoint PPT Presentation

Projection (Part 2) : Derivation Created by Dr. Slim BECHIKH for SPSU course - CS4363 Computer Graphics and Multimedia Fall 2014 Parallel Projection normalization find 4x4 matrix to transform user


slide-1
SLIDE 1

Projection (Part 2): Derivation Created by Dr. Slim BECHIKH for SPSU course - CS4363 Computer Graphics and Multimedia Fall 2014

slide-2
SLIDE 2
slide-3
SLIDE 3

ParallelProjection

normalization find4x4matrixtotransformuserspecified

viewvolume tocanonicalviewvolume(cube)

glOrtho(left, right, bottom, top,near, far) Canonical ViewVolume Userspecified ViewVolume

slide-4
SLIDE 4

ParallelProjection:Ortho

Parallelprojection:2parts

1.

Translation: centersviewvolumeatorigin

slide-5
SLIDE 5

ParallelProjection:Ortho

2.

Scaling: reducesuserselectedcuboidtocanonical cube(dimension2,centeredatorigin)

slide-6
SLIDE 6

ParallelProjection:Ortho

  • Translationlinesupmidpoints:E.g. midpointofx=(right+left)/2
  • Thustranslationfactors:

(right+left)/2,(top+bottom)/2,(far+near)/2

Translationmatrix:

  • 1

2 / ) ( 1 2 / ) ( 1 2 / ) ( 1 near far bottom top left right

slide-7
SLIDE 7

ParallelProjection:Ortho

  • Scalingfactor:ratiooforthoviewvolumetocubedimensions
  • Scalingfactors:2/(right left),2/(top bottom),2/(far near)
  • ScalingMatrixM2:
  • 1

2 2 2 near far bottom top left right

slide-8
SLIDE 8

ParallelProjection:Ortho

Concatenating Translation x Scaling, we get Ortho Projection matrix

X

  • 1

2 2 2 near far bottom top left right

  • 1

2 / ) ( 1 2 / ) ( 1 2 / ) ( 1 near far bottom top left right

  • 1

2 2 2 near far near far far near bottom top bottom top bottom top left right left right left right

P = ST =

slide-9
SLIDE 9

FinalOrthoProjection

Setz =0 Equivalenttothehomogeneouscoordinate

transformation

Hence,generalorthogonalprojectionin4Dis

  • 1

1 1

Morth = P = MorthST

slide-10
SLIDE 10

PerspectiveProjection

Projection– maptheobjectfrom3Dspaceto

2Dscreen

x y z Perspective() Frustrum( )

slide-11
SLIDE 11

PerspectiveProjection:Classical

(0,0,0)

  • N

Projection plane Eye (COP) (x,y,z) (x’,y’,z’)

  • z
  • z

y Based on similar triangles: y’ N y -z N y’ = y x

  • z

=

VRP COP Object in 3 space Projectors Projected image

Near Plane (VOP) + z

slide-12
SLIDE 12

PerspectiveProjection:Classical

So(x*,y*)projectionofpoint,(x,y,z)untonearplaneNis

givenas:

Numericalexample:

Q.Whereontheviewplane doesP=(1,0.5,1.5)liefora nearplaneatN=1?

  • z

N y z N x y x , * *,

  • )

333 . , 666 . ( 5 . 1 1 5 . , 5 . 1 1 1 , * *,

  • z

N y z N x y x

VRP COP Object in 3 space Projectors Projected image

slide-13
SLIDE 13

Pseudodepth

Classicalperspectiveprojectionprojects(x,y)coordinatesto

(x*,y*),dropszcoordinates

Butweneedztofindclosestobject(depthtesting)!!!

VRP COP Object in 3 space Projectors Projected image

(0,0,0) z

Map to same (x*,y*) Compare their z values?

slide-14
SLIDE 14

PerspectiveTransformation

Perspectivetransformation mapsactualzdistanceof

perspectiveviewvolumetorange[–1to1](Pseudodepth) forcanonicalviewvolume

  • Near
  • Far
  • 1

1 Canonical view volume Actual view volume

Pseudodepth Actual depth

We want perspective Transformation and NOT classical projection!! Set scaling z Pseudodepth = az + b Next solve for a and b

slide-15
SLIDE 15

PerspectiveTransformation

Wewanttotransformviewingfrustum

volumeintocanonicalviewvolume

(-1, -1, 1) (1, 1, -1) Canonical View Volume x y z

slide-16
SLIDE 16

PerspectiveTransformationusing Pseudodepth

Choosea,bsoaszvariesfromNeartoFar,pseudodepth

variesfrom–1to 1(canonicalcube)

  • Boundaryconditions
  • z*=1whenz=N
  • z*=1whenz=F
  • z

b az z N y z N x z y x , , * *, *,

  • Near
  • Far

Canonical view volume Actual view volume

Pseudodepth Actual depth

1

  • 1

Z* Z

slide-17
SLIDE 17

Transformationofz:Solveforaandb

Solving: Useboundaryconditions

z*=1whenz=N………(1) z*=1whenz=F………..(2)

Setupsimultaneousequations

z b az z

  • *

) 1 ........( 1 b aN N N b aN

  • )

2 ........( 1 b aF F F b aF

slide-18
SLIDE 18

Transformationofz:Solveforaandb

Multiplybothsidesof(1)by1 Addeqns (2)and(3) Nowput(4)backinto(3)

) 1 ........( b aN N

  • )

2 ........( b aF F

  • )

3 ........( b aN N

  • aF

aN N F

  • )

4 .........( ) ( N F N F F N N F a

slide-19
SLIDE 19

Transformationofz:Solveforaandb

Putsolutionforabackintoeqn(3) So

b N F N F N N

  • )

( ) 3 ........( b aN N

  • N

F N F N N b

  • )

( N F NF N F N NF N NF N F N F N N F N b

  • 2

) ( ) (

2 2

N F N F a

  • )

( N F FN b

  • 2
slide-20
SLIDE 20

Whatdoesthismean?

Originalpointzinoriginalviewvolume,transformed

intoz*incanonicalviewvolume

where

  • Near
  • Far

Canonical view volume Actual view volume 1

  • 1

Original vertex z value Transformed vertex z* value

z b az z

  • *

N F N F a

  • )

(

N F FN b

  • 2
slide-21
SLIDE 21

HomogenousCoordinates

Wanttoexpressprojectiontransformas4x4matrix Previously,homogeneouscoordinatesof

P=(Px,Py,Pz)=>(Px,Py,Pz,1)

Introducearbitraryscalingfactor,w,sothat

P=(wPx,wPy,wPz,w)(Note:wisnonzero)

Forexample,thepointP=(2,4,6)canbeexpressedas (2,4,6,1)

  • r(4,8,12,2)wherew=2
  • r(6,12,18,3)wherew=3,or….

Toconvertfromhomogeneousbacktoordinarycoordinates,

firstdivideallfourtermsbyw anddiscard4th term

slide-22
SLIDE 22

PerspectiveProjectionMatrix

RecallPerspectiveTransform Wehave: Inmatrixform:

  • 1

) ( 1 z b az z N y z N x wz b az w wNy wNx w wz wy wx b a N N

  • z

b az z N y z N x z y x , , * *, *,

z N x x

  • *

z N y y

  • *

z b az z

  • *

Perspective Transform Matrix Original vertex Transformed Vertex Transformed Vertex after dividing by 4th term

slide-23
SLIDE 23

PerspectiveProjectionMatrix

Inperspectivetransformmatrix,alreadysolvedfora

andb:

So,wehavetransformmatrixtotransformz

values

  • 1

) ( 1 z b az z N y z N x wP b aP w wNP wNP w wP wP wP b a N N

z z y x z y x

N F N F a

  • )

(

N F FN b

  • 2
slide-24
SLIDE 24

PerspectiveProjection

  • Notdoneyet!!Cannowtransformz!
  • Alsoneedtotransformthex=(left,right)andy=(bottom,top)

rangesofviewingfrustumto[1,1]

  • SimilartoglOrtho,weneedtotranslateandscalepreviousmatrix

alongxandytogetfinalprojectiontransformmatrix

  • wetranslateby
  • –(right+left)/2inx
  • (top+bottom)/2iny
  • Scaleby:
  • 2/(right– left)inx
  • 2/(top– bottom)iny

1

  • 1

x y left right bottom top

slide-25
SLIDE 25

PerspectiveProjection

TranslatealongxandytolineupcenterwithoriginofCVV

  • –(right+left)/2inx
  • (top+bottom)/2iny

Multiplybytranslationmatrix:

1

  • 1

x y left right bottom top

  • 1

1 2 / ) ( 1 2 / ) ( 1 bottom top left right

Line up centers Along x and y

slide-26
SLIDE 26

PerspectiveProjection

  • TobringviewvolumesizedowntosizeofofCVV,scaleby
  • 2/(right– left)inx
  • 2/(top– bottom)iny

Multiplybyscalematrix:

1

  • 1

x y left right bottom top

Scale size down along x and y

  • 1

1 2 2 bottom top left right

slide-27
SLIDE 27

PerspectiveProjectionMatrix

glFrustum(left, right, bottom, top, N, F) N = near plane, F = far plane

  • 1

2 ) ( 2 min max 2 N F FN N F N F bottom top bottom top bottom top N left right left right x x N

  • 1

1 1 2 / ) ( 1 2 / ) ( 1 1 1 2 2 b a N N bottom top left right bottom top left right

Scale

Final Perspective Transform Matrix

Translate

Previous Perspective Transform Matrix

slide-28
SLIDE 28

PerspectiveTransformation

Afterperspectivetransformation,viewing

frustumvolumeistransformedintocanonical viewvolume

(-1, -1, 1) (1, 1, -1) Canonical View Volume x y z

slide-29
SLIDE 29

GeometricNatureofPerspective Transform

a)

Linesthrougheyemapintolinesparalleltozaxisaftertransform

b) Linesperpendiculartozaxismaptolinesperptozaxisaftertransform

slide-30
SLIDE 30

NormalizationTransformation

  • riginal clipping

volume

  • riginal object

new clipping volume distorted object projects correctly

slide-31
SLIDE 31

Implementation

Setmodelview andprojectionmatricesinapplicationprogram Passmatricestoshader

void display( ){ ..... model_view = LookAt(eye, at, up); projection = Ortho(left, right, bottom,top, near, far); // pass model_view and projection matrices to shader glUniformMatrix4fv(matrix_loc, 1, GL_TRUE, model_view); glUniformMatrix4fv(projection_loc, 1, GL_TRUE, projection);

..... }

Build 4x4 projection matrix

slide-32
SLIDE 32

Implementation

Andthecorrespondingshader

in vec4 vPosition; in vec4 vColor; Out vec4 color; uniform mat4 model_view; Uniform mat4 projection; void main( ) { gl_Position = projection*model_view*vPosition; color = vColor; }

slide-33
SLIDE 33

References

InteractiveComputerGraphics(6th edition),Angeland

Shreiner

ComputerGraphicsusingOpenGL(3rd edition),HillandKelley