graphics pipeline : geometric operations

38
University of Calgary GraphicsJungle Project CPSC 587 2005 CPSC 587/687 page 1 Graphics Pipeline : Geometric Operations

Upload: others

Post on 02-Jun-2022

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 1

Graphics Pipeline : Geometric Operations

Page 2: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 2

•• Tools for creating and manipulating a “camera” Tools for creating and manipulating a “camera” that produces pictures of a 3D scenethat produces pictures of a 3D scene

•• Viewing transformationsViewing transformations and and projectionsprojections

•• Perform Perform cullingculling or backor back--face eliminationface elimination

Viewing transformation

Page 3: Graphics Pipeline : Geometric Operations

3D Rendering Pipeline3D Rendering Pipeline

Object definitionObject definition

Compose sceneCompose sceneDefine view referenceDefine view referenceDefine lightingDefine lighting

CullCullClip to 3D view volumeClip to 3D view volume

Hidden surface removalHidden surface removalRasterizationRasterizationShadingShading

Local coordinate space

World coordinate space

View space

3D screen space

Display space

Modeling transformation

View transformation

Projection

Projection divide

Page 4: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 4

Yw

Zw

Xw

Compose sceneCompose sceneDefine view referenceDefine view reference

World coordinate space

View space

Modeling transformation

View transformation

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

=

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

11w

w

w

viewv

v

v

zyx

Tzyx

( )vvv zyx

( )www zyx

Page 5: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 5

View plane eye

VU

-N

RTTview = ⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

⋅−⋅−⋅−

=

1000100010001

NeVecVeVecUeVec

T

( )( )000−= eyeeVec

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

=

1000000

zyx

zyx

zyx

NNNVVVUUU

R

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

=

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

11w

w

w

viewv

v

v

zyx

Tzyx

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 5

Viewing transformation

Page 6: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 6

Viewing Transforms

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

=

1000000

zyx

zyx

zyx

NNNVVVUUU

RLemma:Where does thismatrix come from:

U

V

Nt

ge

e = Eye Positiong = gaze directiont = view up vector

N= ||g||g

U= ||t x N||t x N

V= N x U

N

Page 7: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 7

Special Orthogonal Matrics

See 453 slides

Page 8: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 8

Taxonomy of ProjectionsTaxonomy of Projections

Parallel Perspective

Page 9: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 9

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

==

1/100010000100001

d

TT persproj

obs: d is N in the picture

Perspective ProjectionsPerspective Projections

dzwzZyYxX

v

v

v

v

====

Page 10: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 10

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

==

1000000000100001

ortproj TT

Parallel Projections (orthographic)Parallel Projections (orthographic)

Page 11: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 11

Yw

Zw

Xw

Compose sceneCompose sceneDefine view Define view referencereference

World coordinate space

View space

Modeling transformation

View transformation( )vvv zyx

( )www zyx

ProjectionProjection

3D screen space( )WZYX

Projection DivideProjection Divide

( )sss zyx

Perspective DividePerspective Divide

Page 12: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 12

PerspectivePerspective

wZz

wYy

wXx

s

s

s

=

=

=

dzwzZyYxX

v

v

v

v

====

where

Parallel Parallel (orthographic)(orthographic)

0===

s

vs

vs

zyyxx

Perspective DividePerspective Divide

Page 13: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 13

See 453 slides for ramifications of divide by W

Perspective DividePerspective Divide

Page 14: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 14

View VolumeView Volume

Page 15: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 15

Xw

eye

VU

View planewindow

eye

Yw

Zw

View volume

We specify it!

-NWhat appears on the screen: projection of part of the scene contained within the view volume

Page 16: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 16

View planewindow

eye

View volume

Page 17: Graphics Pipeline : Geometric Operations

dhzx v

v −=

h

d

dhzx v

v =

dhzy v

vol =

dhzy v

v −=

dzv =

fzv =f

Page 18: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 18

( )

( ) ⎟⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜⎜

−−

−⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

=

000

10000100001

10000100000

000

dffd

dffh

dh

d

Tpers

Scaling (d/h in x and y)Truncated pyramid into a

Regular pyramid

Regular pyramid into a box

Perspective MatrixPerspective Matrix

Page 19: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 19

( )

( ) ⎟⎟⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜⎜⎜

−−

−=

000

100

100

000

dffd

dff

hd

hd

Tpers

Page 20: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 20

wZz

wYy

wXx

s

s

s

=

=

=

( ) ( )v

v

v

v

zwdf

dfdf

fzZ

yhdY

xhdX

=−

−−

=

=

=where

( )

( ) ⎟⎟⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜⎜⎜

−−

−=

000

100

100

000

dffd

dff

hd

hd

Tpers

Page 21: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 21

OpenGL: Viewing Process, Graphics PipelineOpenGL: Viewing Process, Graphics Pipeline

Scales and shifts each vertex so that all of them that lie inside the view volume will lie inside a standard cube

Provides the CTCombines two effects: Modeling transformations applied to objects +Transformation that orients and positions the camera in space

Page 22: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 22

Page 23: Graphics Pipeline : Geometric Operations
Page 24: Graphics Pipeline : Geometric Operations

OpenGL: Positioning and Aiming the CameraOpenGL: Positioning and Aiming the Camera

View plane

eye

VU

-N

glMatrixMode (GL_MODELVIEW)glLoadIdentity();

glLookAtglLookAt (eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.(eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.z);z);

Page 25: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 25

OpenGL: Setting the Camera OpenGL: Setting the Camera

(Parallel Projection)(Parallel Projection)

glMatrixMode (GL_PROJECTION)glLoadIdentity();

glOrthoglOrtho (left, right, bottom, top, near, far);(left, right, bottom, top, near, far);

Page 26: Graphics Pipeline : Geometric Operations

University of Calgary GraphicsJungle Project CPSC 587 2005

CPSC 587/687

page 26

OpenGL: Setting the Camera OpenGL: Setting the Camera (Perspective Projection)(Perspective Projection)

glMatrixMode (GL_PROJECTION)glLoadIdentity();

glFrustumglFrustum (left, right, bottom, top, near, far);(left, right, bottom, top, near, far);

gluPerspectivegluPerspective ((viewAngleviewAngle, aspect, near, far);, aspect, near, far);

or

more intuitive

Page 27: Graphics Pipeline : Geometric Operations

3D Rendering Pipeline3D Rendering Pipeline

1. INTRODUCTION

2. IMAGING

3. 3D RENDERING OVERVIEW

4. MODELING (1)shapes and transformations

5. RENDERING (1, 2, 3, 4)

1. Graphics Pipeline : Geometric Operations

6. MODELING (2)Representation and Modeling

7. ANIMATION

8. TOPICS

Object definitionObject definition

Compose sceneCompose sceneDefine view referenceDefine view referenceDefine lightingDefine lighting

CullCullClip to 3D view volumeClip to 3D view volume

Hidden surface removalHidden surface removalRasterizationRasterizationShadingShading

Local coordinate space

World coordinate space

View space

3D screen space

Display space

Modeling transformation

View transformation

Projection

Projection divide

Page 28: Graphics Pipeline : Geometric Operations

Yw

Zw

Xw

Compose sceneCompose sceneDefine view referenceDefine view reference

World coordinate space

View space

Modeling transformation

View transformation

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

=

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

11w

w

w

viewv

v

v

zyx

Tzyx

( )vvv zyx

( )www zyx

Page 29: Graphics Pipeline : Geometric Operations

( ) 0>− FmdoteyeP

Culling (backCulling (back--face removal)face removal)View plane

eye

VU

-N

F is F is back faceback face ifif

Page 30: Graphics Pipeline : Geometric Operations

Dot ProductDot Product

Angle between Two Vectors

∑=

=⋅=n

iiiwvwvd

1

Sign and Perpendicularity

( )∧∧

⋅= cbθcos

“perpendicular”orthogonalnormal

Page 31: Graphics Pipeline : Geometric Operations

Normal to a PlaneNormal to a Plane

Page 32: Graphics Pipeline : Geometric Operations

Finding the Normal VectorsFinding the Normal Vectors

Flat Face:1V

2V 3Vm

( ) ( )2321 VVVVm −×−=

Two Problems:

1V

2V

3V

Vectors nearly parallel, the cross product will be very small,Numerical inaccuracies may result

Polygon is not perfect planar

Page 33: Graphics Pipeline : Geometric Operations

Finding the Normal VectorsFinding the Normal Vectors

Robust Method (Newell): 1V

2V 3Vm

( )( ) ( )( )

( )( ) ( )( )

( )( ) ( )( )∑

=

=

=

+−=

+−=

+−=

1

0

1

0

1

0

N

iinextiinextiz

N

iinextiinextiy

N

iinextiinextix

yyxxm

xxzzm

zzyym

Page 34: Graphics Pipeline : Geometric Operations

Vertex and Face TableVertex and Face Table

Shared vertices

Still no topology information

Each face lists vertex references

( )111 ,, zyx

( )222 ,, zyx

( )333 ,, zyx

( )444 ,, zyx

( )555 ,, zyx

F1F2

F3

VERTEX TABLE

V1

V2

V3

V4

V5

( )111 ,, zyx

( )222 ,, zyx

( )333 ,, zyx

( )444 ,, zyx

( )555 ,, zyx

FACE TABLE

V1 V2 V3

V3 V2 V4

V3 V4 V5

F1

F2

F2

Page 35: Graphics Pipeline : Geometric Operations

Mesh

pt

norm

face

Point3

x, y, zVector3

dx, dy, dz

VertexID

vertIndexnormIndex

numVerts

numNormals

numFacesnVerts

Face

vert

Page 36: Graphics Pipeline : Geometric Operations

( ) 0>− FmdoteyeP

Culling (backCulling (back--face removal)face removal)View plane

eye

VU

-N

F is F is back faceback face ifif

Page 37: Graphics Pipeline : Geometric Operations

void Mesh :: draw ()

{

for (int f = 0; f < numFaces; f++)

{

glBegin (GL_POLYGON)

for (int v = 0; v < face[f].nVerts; v++)

{

int iv = face[f].vert[v].vertIndex;

glVertex3f(pt[iv].x, pt[iv].y, pt[iv].z);

}

glEnd();

}

}

Page 38: Graphics Pipeline : Geometric Operations

void Mesh :: draw ()

{

for (int f = 0; f < numFaces; f++)

{

If ( isBackFace ( f, eye ) ) continue;glBegin (GL_POLYGON)

for (int v = 0; v < face[f].nVerts; v++)

{

int iv = face[f].vert[v].vertIndex;

glVertex3f(pt[iv].x, pt[iv].y, pt[iv].z);

}

glEnd();

}

}