eecs 487: interactive computer graphics n n- · eecs 487: interactive computer graphics ......

10
EECS 487: Interactive Computer Graphics Lecture 13: Planar Geometric Projections Orthographic projection Perspective projection Projections in OpenGL Planar Geometric Projections Planar project onto a plane (vs. planetarium, e.g.) Geometric projectors are straight lines (vs. curved lines in cartography, e.g.) Projection map from n to n-1 dimensions Euclidean geometry describes shapes “as they areproperties of objects that are unchanged by rigid motions: lengths, angles, parallel lines Projective geometry describes objects “as they appearlengths, angles, parallel lines become “distorted” when we look at objects Projection System Common elements: Center of Projection (COP) (for perspective projection)/ Direction of Projection (DOP) (for parallel projection, COP at ) Projection/view/picture/image plane (PP) Projectors/sightlines Parallel Perspective Lozano-Perez01 Perspective Parallel Taxonomy of Planar Geometric Projections top, bottom, front, back, left, right One-point Two-point Three-point Perspective Projection Cavalier Cabinet General Oblique Isometric Dimetric Trimetric Axonometric Multiview Orthographic Parallel Projection Planar Geometric Projections

Upload: vuongngoc

Post on 06-Apr-2018

245 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

EECS487:Interactive

ComputerGraphics

Lecture13:•  PlanarGeometricProjections

•  Orthographicprojection

•  Perspectiveprojection•  ProjectionsinOpenGL

PlanarGeometricProjections

Planar⩴projectontoaplane(vs.planetarium,e.g.)

Geometric⩴projectorsarestraightlines

(vs.curvedlinesincartography,e.g.)

Projection⩴mapfromnton-1dimensions

Euclideangeometrydescribesshapes“astheyare”

• propertiesofobjectsthatareunchangedbyrigidmotions:lengths,angles,parallellines

Projectivegeometrydescribesobjects“astheyappear”

•  lengths,angles,parallellinesbecome

“distorted”whenwelookatobjects

ProjectionSystem

Commonelements:

• CenterofProjection(COP)

(forperspectiveprojection)/

DirectionofProjection(DOP)

(forparallelprojection,≈COPat∞)

• Projection/view/picture/imageplane(PP)

• Projectors/sightlines

ParallelPerspective

Lozano-Perez01 Perspective

Parallel

Taxonomyof

PlanarGeometricProjections

top, bottom,

front, back,

left, right

One-point

Two-point

Three-point

Perspective

Projection

Cavalier

Cabinet

General

Oblique

Isometric

Dimetric

Trimetric

Axonometric Multiview

Orthographic

Parallel

Projection

Planar Geometric Projections

Page 2: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

Multiview

Orthographic

• preservesratios,butnotangles(�notvisible)

• parallellinesremainparallel

�isconsidered

anaffinetransform

James07

• projectionplaneparalleltoonecoordinateplane(projectonto

planebydroppingcoordinate

perpendiculartoplane)

• projectiondirectionperpendiculartoprojectionplane

• goodforexactmeasurements

(CAD,architecture)

AxonometricOrthographic

Axonometric:

• projectionplaneisnotparalleltoanycoordinateplane• projectiondirectionperpendiculartoprojectionplane

Isometric:

• preserveslengthsalong3principalaxes• principalaxesmake

thesameanglewith

eachother(120º)

120º

120º

120º

ParallelOrthographicProjections

Arewedone?

P =1 0 00 1 00 0 0

⎢⎢⎢

⎥⎥⎥

Yes,butwe’velostdepth(z)information,can’tdo:

• hiddensurfaceremoval

•  lighting,etc.Needtopreservezdimension!

�mapviewvolumetocanonicalviewvolume

Akenine-Möller&Haines02

OrthographicProjection

Viewvolumedefinedby

left,right,bottom,top,near,andfarplanes:

Mapittocvv:

Shirley02

Page 3: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

Simplecase:viewvolumeaxis-alignedwithworld

coordinatesystem

•  theviewvolumeisinnegativez,n > f

Moregenerally,theview

volumeisnotaxis-aligned

withworldCS(itwillalways

beaxis-alignedwitheyeCS):

OrthographicProjectionSetup

Shirley02

Fromanarbitraryaxis-aligned

boundingboxtocanonicalviewvolume

•  translateandscale:

WhatwouldtheTandSmatricesbe?

OrthographicProjection

T =

1 0 0 − l + r2

0 1 0 − b + t2

0 0 1 − n + f2

0 0 0 1

⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥⎥

S =

2r − l

0 0 0

0 2t − b

0 0

0 0 2n − f

0

0 0 0 1

⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥⎥⎥

Po = ST =

2r − l

0 0 − l + rr − l

0 2t − b

0 − b + tt − b

0 0 2n − f

− n + fn − f

0 0 0 1

⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥⎥⎥

RTR3

OrthographicProjectionand

ViewingTransform

Fromanarbitraryviewing

volumetocanonicalviewvolume

•  translateeyetoorigin•  transformtoeyecoordinatesystem

•  applyorthographicprojection

2r − l

0 0 − l + rr − l

0 2t − b

0 − b + tt − b

0 0 2n − f

− n + fn − f

0 0 0 1

⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥⎥⎥

Shirley02

ux uy uz 0

vx vy vz 0

wx wy wz 0

0 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

1 0 0 −ex0 1 0 −ey0 0 1 −ez0 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

Mworld−>canonical =

Meye→canonical Mworld→eye

PerspectiveProjection

Objectsappearsmallerasdistancefrom

centerofprojection(eyeofobserver)increases

(perspectiveforeshortening)⇒looksmorerealistic

(humaneyesnaturallyseethingsinperspective)

Preserves:

•  lines(collinearity)•  incidence(“lieson”,intersects)

• crossratio

Doesnotalwayspreserveparallellines:

•  linesparalleltoprojectionplaneremainparallel

•  linesnotparalleltoprojectionplaneconvergetoasinglepointonthehorizoncalledthevanishingpoint(vp)

Page 4: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

TheCrossRatio

Forthe4setsof4 collinearpointsinthefigure,thecross-ratioforcorrespondingpointshasthesamevalue(canpermutethepoint

ordering)

p3 − p1 p4 − p2p3 − p2 p4 − p1

p1 − p3 p4 − p2p1 − p2 p4 − p3

p2 − p1 p4 − p3p4 − p1 p3 − p2p1 p2

p3

p4

pi =

xi

yizi1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

deMenthon

Seitz08

ClassesofPerspectiveProjection

one-point:projectionplaneparalleltoonecoordinateplane(�totwocoordinateaxes,

onecoordinateaxiscutsprojectionplane)

two-point:projectionplaneparalleltoone

coordinateaxis(twocoordinateaxescut

projectionplane)

James07

ClassesofPerspectiveProjection

three-point:projectionplanenotparalleltoanycoordinate

axis(threecoordinateaxescut

projectionplane)

Duell

James07Hulsey

ProjectiveGeometryin2D ConsiderlinesandpointsinPWeextendto3Dtosimplifydealingwithinfinity

•  originooutofP,atadistance= 1fromP

ToeachpointminPwecanassociateasinglerayp = (x1, x2, x3)

ToeachlinelinPwecanassociateasingleplane(A, B, C)•  theequationoflineLinprojectivegeometryis Ax1 + Bx2 + Cx3 = 0

deMenthon

o

p = (x1, x2, x3)

x1x2

x3(A, B, C ) = L

Pm

l

Page 5: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

HomogeneousCoordinates

Therayp = (x1, x2, x3)and (λx1, λx2, λx3)arethesameandaremappedtothesamepointminP•  pisthecoordinatevectorofm,

(x1, x2, x3)itshomogeneouscoordinates

Theplanes(A, B, C) and(λA, λB, λC)arethesame

andaremappedtothesamelinelinP•  Listhecoordinatevectorofl,

(A, B, C)itshomogeneouscoordinates

Pointp’isonlineLifL•p’ = 0

deMenthon

o

p = (x1, x2, x3)

x1x2

x3L = (A, B, C)

Pm

l

(A, B, C)

p’

PerspectiveDivide

Howdowe“land”backfromtheprojectiveworldto

the2DCartesianworldoftheplane?

•  forpoint,considertheintersectionofrayp = (λx1, λx2, λx3)withtheplanex3 = 1�λ = 1/x3,m = (x1 / x3, x2 / x3, 1)

•  forline,intersectionofplaneAx1 + Bx2 + Cx3 = 0withthe

planex3 = 1islinel = Ax1 + Bx2 + C = 0

Called“perspectivedivide”

Forthemathematically

inclined,orstudying

computervision:what’s

thegeometricinterpretation

ofx3 = 0?deMenthon

o

p = (x1, x2, x3)

x1x2

x3L = (A, B, C)

Pm

l

(A, B, C )

ProjectiveGeometry

Twolinesalwaysmeetata

singlepoint,andtwopoints

alwayslieonasingleline

Projectivegeometrydoes

notdifferentiatebetween

parallelandnon-parallellines

Pointsandlinesaredualof

eachother

Toreturnfromhomogeneous

coordinatestoCartesian

coordinates,dividebyx3(w)

deMenthon,Durand08

w = 1

w = 2

(0, 0, 1) = (0, 0, 2) = … (7, 1, 1) = (14, 2, 2) = … (4, 5, 1) = (8, 10, 2) = …

3DProjectiveGeometry

Theseconceptsgeneralizenaturallyto3D

Homogeneouscoordinates

•  projective3Dpointshavefourcoordinates:p = (x, y, z, w)

Projectivetransformations

•  representedby4×4matrices

Seitz08

Page 6: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

VanishingPoints

Whathappenstotwoparallellinesthatarenot

paralleltotheprojectionplane?

Theparametricequationfor

alineis:

Afterperspectivetransform:

Atthelimit,witht�∞,weget

apoint![(vx/vz)d, (vy/vz)d, 1]T

Eachsetofparallellines

intersectatavanishingpoint

l = p + tv =

pxpypz1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

+ t

vxvyvz0

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

!

px'

p 'yw

⎢⎢⎢

⎥⎥⎥=

px + tvx

py + tvy(pz + tvz ) / d

⎢⎢⎢⎢

⎥⎥⎥⎥

afterperspective

divide

⎯ →⎯⎯⎯

px + tvx

pz + tvzd

py + tvypz + tvz

d

1

⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥

PerspectiveProjection

Giventhecoordinatesoftheorangepoint

findthecoordinatesofthegreenpoint

Isperspectiveprojectionsimply:

(x,y,z, 1)�(xd/z,yd/z,d, 1),thenmaptoscreenbythrowing

awaythez-coordinate:(xd/z,yd/z, 1)?

tanθ = y 'd= yz

y ' = yd zy

y’

d

z

view plane

e

y

z gθ

Projecting(x,y,z, 1)�(xd/z,yd/z,d, 1)andthrowing

awayddoesnotpreservethedepthinformation

InsteadwantPsuchthat:

Justlikeorthographicprojection,weneedtomap

theviewvolumetoaCVVinsteadofa2Dplane

PerspectiveProjectionMatrix

P

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

xdz

y dzz '1

⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥

perspective

divide

preservetherelative

depthinformationof

eachpoint

ProjectionSystemSetup

Thecoordinatesystem

Theeye(e)•  actsasthefocalpointandCOP

•  placedattheorigin•  lookingdown(g)alongthenegativez-axis(axisofprojection)

Thescreen

•  liesintheprojectionplane• ⟘tothez-axis,�tothex-yplane•  locatedatdistancedfromtheeye

•  d isa.k.a.thefocallength

(x, y, z, 1)(x’, y’, d, 1)

e g

Whatdoesitmeanforw=1?Whatdoesitmeanforw>1?Whatisthehomogeneous

coordinate(HC)when

projectingfrom3Dto2D?

Page 7: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

PerspectiveProjectionViewFrustum

Viewvolume(frustum:truncatedpyramid):

• definedby(left,right,top,bottom,near,far)clippingplanes

• near(n)andfar( f )distancesalong–z-axis,bothnegativenumbers,n > f

• nothingnearerthannwillbedrawn

�  avoidnumericalproblemsduring

rendering,suchasdivideby0• nothingfurtherthanfwillbedrawn

�  avoidlowdepthprecisionfordistantobjects

Topreserverelativedepthinformation,

wemustmapthefrustumtoaCVVinsteadofa2Dplane

View volume

FromFrustumtoCVV

perspective

projection,

including

perspective

divide

RTR3

orthographic

projection

WantprojectionmatrixPsuchthat:

WhatshouldPbe?• we’reprojectingfrom3Dto2D (not4Dto3D),

usetheHCoftheprojectedpointtostoreitsdepth

info(i.e.,the“real”HCin3Dto2Dprojection)

• firstattempt:

Anyproblem?

PerspectiveProjectionMatrix

P

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

x d zyd zz '1

⎢⎢⎢⎢

⎥⎥⎥⎥

!

Pp =

d 0 0 00 d 0 00 0 d 00 0 0 z

⎢⎢⎢⎢

⎥⎥⎥⎥

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

=

xdydzdz

⎢⎢⎢⎢

⎥⎥⎥⎥

afterperspective

divide

⎯ →⎯⎯⎯

x d zyd zd1

⎢⎢⎢⎢

⎥⎥⎥⎥

Secondattempt:foramoregenericmatrix,

grabthedepthinfofromthepointitself:

Arewedone?

• theprojectedx-,y-,andHCarecorrectalready,butafterperspectivedivide,alldepthsmappedtod!• 3rdrowofmatrixmustbetweakedtopreserverelative

depthinfo(z’)

!

Pp =

d 0 0 00 d 0 00 0 d 00 0 1 0

⎢⎢⎢⎢

⎥⎥⎥⎥

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

=

xdydzdz

⎢⎢⎢⎢

⎥⎥⎥⎥

afterperspective

divide

⎯ →⎯⎯⎯

x d zyd zd1

⎢⎢⎢⎢

⎥⎥⎥⎥

PerspectiveProjectionMatrix

Page 8: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

PerspectiveProjectionMatrix

Letd = n

The1stand2ndrowsofParecorrect

already,forthe3rdrow(thirdattempt):

• thecomputationofz’doesnotrelyonxandy,setthefirsttwonumbersoftherowto0• wecanusetheremainingtwonumbersto

computez’,letthembeunknownsaandbfornow:

!

Want:!P

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

x n zyn zz '1

⎢⎢⎢⎢

⎥⎥⎥⎥

!

Frustum Rectangularbox

!

Pp =

n 0 0 00 n 0 00 0 a b0 0 1 0

⎢⎢⎢⎢

⎥⎥⎥⎥

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

=

xnyn

az + bz

⎢⎢⎢⎢

⎥⎥⎥⎥

afterperspective

divide

⎯ →⎯⎯⎯

x n zyn za + b z1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

Forthe3rdrowofP:• wantaandbsuchthat:

• or,forz=n, a+b/z = nandforz=f, a+b/z = f

PerspectiveProjectionMatrix

!

P

xyn1

⎢⎢⎢⎢

⎥⎥⎥⎥

xyn1

⎢⎢⎢⎢

⎥⎥⎥⎥

!and!P

xyf1

⎢⎢⎢⎢

⎥⎥⎥⎥

x n fyn ff1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

!

for!z = n : !a + b n = n, !a = n − b nfor!z = f : !a + b f = f ,

substituting!for!a:! n − b n( ) + b f = fb n − f( ) = f − n( )nf , !b = −nf

substituting!for!b:!a = n − −nf( ) n , !a = n + f

nf

PerspectiveDivide

Thendividebythehomogenouscoordinate

�squeezingthefrustumintoarectangularbox

Shirley02

Notehown/zconvenientlycancels

thenegativesignsout

n 0 0 00 n 0 00 0 n + f −nf0 0 1 0

⎢⎢⎢⎢

⎥⎥⎥⎥

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

=

nxny

(n + f )z − nfz

⎢⎢⎢⎢

⎥⎥⎥⎥

perspectivedivide⎯ →⎯⎯⎯

xn zyn z

n + f − nfz

1

⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥

PerspectiveForeshortening

Whatistheeffectofperspectivedivide

ontheshapeofobjects?

�Afterperspectivedivide,anobjectfurtheraway

appearstobesmallerthananequal-sizeobjectnearby

Curless08

Page 9: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

FromFrustumtoCVV

Nowrepositionandscaletherectangularbox

Assumeviewingtransformhasbeen

done,soafterperspectivedivide

(notshown)we’reonlydealingwith

axis-alignedviewingvolume

Pp = STP = PoP =

2r − l

0 0 − r + lr − l

0 2t − b

0 − t + bt − b

0 0 2n − f

− n + fn − f

0 0 0 1

⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥⎥⎥

n 0 0 00 n 0 00 0 n + f −nf0 0 1 0

⎢⎢⎢⎢

⎥⎥⎥⎥

=

2nr − l

0 l + rl − r

0

0 2nt − b

b + tb − t

0

0 0 n + fn − f

2nff − n

0 0 1 0

⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥⎥⎥

Seealsohttp://www.songho.ca/opengl/gl_projectionmatrix.html

Recallthatafterperspectivedividewehave:

Asaconsequenceofperspectiveforeshortening,

z’isnotlinearlyrelatedtoz:

LosingDepthPrecision

x 'y 'z '1

⎢⎢⎢⎢

⎥⎥⎥⎥

=

nx zny z

n + f − fnz

1

⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥

!

z ' = n + f − nfz

Δz ' ≈ nfΔzz2

; !Δz ≈ z2

fnΔz '

max !Δz !is!when!z = f

At!z = f ,!Δz = fnΔz ', !as!n→ 0,

near!the!far!plane!(f ),!Δz→∞!but!must!be!covered!by

the!same!Δz ' !as!smaller!Δz !that!are!closer!to!n

Redbook10

n → 0

Asaconsequenceofperspectiveforeshortening,

z’isnotlinearlyrelatedtoz:aszgetsclosertof,thesameamountofΔz’mustrepresentlargerΔz

Forexample:letn = 10, f = 90,forz1 = 10, z’1 = 10 Δz1 = 1forz2 = 11, z’2 = 18.182 Δz’1= 8.182...

forzk-1 = 89, z’k-1 = 89.888 Δzk-1 = 1forzk = 90, z’k = 90 Δz’k-1= 0.112

LosingDepthPrecision

Implicationofthenon-linearmapping:

•  informationonthefarplanelosesprecision

�z-bufferpunchthroughorz-fighting•  distancesclosertooriginareexaggerated

Effectisamelioratedifnsetfurtherfromorigin

LosingDepthPrecision

far=100

RTR3

Akeley07

Δz1 Δz2

Δz’1, n

Δz’2, f

Δz’1, n

Δz’2, f

Page 10: EECS 487: Interactive Computer Graphics n n- · EECS 487: Interactive Computer Graphics ... projectors are straight lines ... to projection plane remain parallel •lines not parallel

z-BufferQuantization

z-valuesstoredasnon-negativeintegers

Integersarerepresentedinb(=16or32)bits,givingarangeofB(= 2b)values{0, 1, 2, . . . , B-1}

Floatingpointz’-valuesarediscretizedintointegerbins:Δz’= (f−n)/B,soforexampleforn = 10,f = 90,bothz1 = 89,z’1 = 100−(900/89) = 89.888 andz2 = 90, z’2 = 100−(900/90) = 90arebothdiscretizedtoz’ = 90

Moralofthestory:choosenasfarawayfromoriginas

possibleandfasnearaspossible(toreduceΔz’)