viewing - cg.tuwien.ac.at

44
Einführung in Visual Computing 186.822 Viewing Werner Purgathofer

Upload: others

Post on 26-May-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Viewing - cg.tuwien.ac.at

Einführung in Visual Computing186.822

Viewing

Werner Purgathofer

Page 2: Viewing - cg.tuwien.ac.at

Viewing in the Rendering Pipeline

Werner Purgathofer 2raster image in pixel coordinates

clipping + homogenization

object capture/creation

modelingviewing

projection

rasterizationviewport transformation

shading

vertex stage(„vertex shader“)

pixel stage(„fragment shader“)

scene in normalized device coordinates

transformed vertices in clip space

scene objects in object space

Page 3: Viewing - cg.tuwien.ac.at

From Object Space to Screen Space

Werner Purgathofer 3

object space world space camera space

clip space pixel space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

Page 4: Viewing - cg.tuwien.ac.at

Viewport Transformation

Page 5: Viewing - cg.tuwien.ac.at

From Object Space to Screen Space

Werner Purgathofer 5

object space world space camera space

clip space pixel space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

Page 6: Viewing - cg.tuwien.ac.at

Viewport Transformation

assumption: scene is in clip space !clip space = [–1,1] × [–1,1] × [–1,1]orthographic camera looking in –z directionscreen resolution nx × ny pixels

Werner Purgathofer / Einf. in Visual Computing 6

nx ny(–1,–1,–1)

(1,1,1)

(–1,–1) (0,0)(1,1) (nx,ny)

clip space:

z

Page 7: Viewing - cg.tuwien.ac.at

Viewport Transformation

can be done with the matrix

this ignores the z-coordinate, but…

(–1,–1) (0,0)(1,1) (nx,ny)

xscreenyscreen

nx/2 00 ny/2

nx/2ny/2

0 0 11

xy1

= ·

Werner Purgathofer / Einf. in Visual Computing

Page 8: Viewing - cg.tuwien.ac.at

Projection Transformation

Page 9: Viewing - cg.tuwien.ac.at

From Object Space to Screen Space

Werner Purgathofer 10

object space world space camera space

clip space pixel space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

Page 10: Viewing - cg.tuwien.ac.at

Parallel Projection (Orthographic Projection)

11

3 parallel-projection views of an object, showing relative proportions from different viewing positions

top side front

Werner Purgathofer / Einf. in Visual Computing

Page 11: Viewing - cg.tuwien.ac.at

Parallel vs. Perspective Projection

12Werner Purgathofer / Einf. in Visual Computing

Page 12: Viewing - cg.tuwien.ac.at

For Now: Parallel (Orthographic) Projection

Werner Purgathofer 13

object space world space camera space

clip space screen space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

Page 13: Viewing - cg.tuwien.ac.at

FB

Projection Transformation (Orthographic)

assumption: scene in box [L,R] × [B,T] × [F,N]orthographic camera looking in –z directiontransformation to clip space

14

L

(L,B,F) (–1,–1,–1)(R,T,N) (1,1,1)

clip space:

(–1,–1,–1)

(1,1,1)

z(L,B,F)

(R,T,N)z

orthographic view volumein camera space:

R

T

N

Werner Purgathofer / Einf. in Visual Computing

Page 14: Viewing - cg.tuwien.ac.at

Projection Transformation (Orthographic)

15

(L,B,F) (–1,–1,–1)(R,T,N) (1,1,1)

0 0 0 1

R – L2

T – B2

N – F2

R – LR + L

T – BT + B

N – FN + F

0 0

0 0

0 0

–Morth =

1

L

F

B

1

–1

–1

–1· =

Werner Purgathofer / Einf. in Visual Computing

Page 15: Viewing - cg.tuwien.ac.at

Parallel Projection Types

16

orthographicprojection

obliqueprojection

different orientation of the projection vector –g

–g

viewing plane

–g

viewing plane

Werner Purgathofer / Einf. in Visual Computing

Page 16: Viewing - cg.tuwien.ac.at

Camera Transformation

Page 17: Viewing - cg.tuwien.ac.at

For Now: Parallel (Orthographic) Projection

Werner Purgathofer 18

object space world space camera space

clip space pixel space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

Page 18: Viewing - cg.tuwien.ac.at

Viewing: Projection Plane

19

coordinate reference for obtaining a selected view of a 3D scene

displayplane

Werner Purgathofer / Einf. in Visual Computing

Page 19: Viewing - cg.tuwien.ac.at

Viewing: Camera Definitionsimilar to taking a photographinvolves selection of

camera positioncamera directioncamera orientation“window” (zoom) of camera

20

worldcoordinates

cameracoordinates

Werner Purgathofer / Einf. in Visual Computing

Page 20: Viewing - cg.tuwien.ac.at

Viewing: Camera Transformation (1)

view reference pointorigin of camera coordinate systemgaze direction or look-at point

21

right-handed camera-coordinate system, with axes u, v, w, relative to world-coordinate scene

y

zx

vw

u

eo

Werner Purgathofer / Einf. in Visual Computing

Page 21: Viewing - cg.tuwien.ac.at

Viewing: Camera Transformation (2)

22

eg

e … eye positiong … gaze direction (positive w-axis points to the viewer)t … view-up vector

wu

t

v = w × u

w = – g|g|

u =|t × w|t × w

Werner Purgathofer / Einf. in Visual Computing

Page 22: Viewing - cg.tuwien.ac.at

Viewing: Camera Transformation (2)

23

eg

e … eye positiong … gaze direction (positive w-axis points to the viewer)t … view-up vector

vw

ut

v = w × u

w = – g|g|

u =|t × w|t × w

Werner Purgathofer / Einf. in Visual Computing

Page 23: Viewing - cg.tuwien.ac.at

Viewing: Camera Transformation (3)

24

aligning viewing system with world-coordinate axes using translate-rotate transformations

Mcam = Rz· Ry· Rx·T

x

y

z

o

uvw

e

x

y

z

uv

wx

y

z

ouv

we

Werner Purgathofer / Einf. in Visual Computing

Page 24: Viewing - cg.tuwien.ac.at

For Now: Parallel (Orthographic) Projection

Werner Purgathofer 26

object space world space camera space

clip space pixel space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

Page 25: Viewing - cg.tuwien.ac.at

Viewing: Camera + Projection + Viewport

27

xscreenyscreen

z1

= Mvp·Morth·Mcam ·

xyz1

pixels onthe screen

world coordinates

( )

Werner Purgathofer / Einf. in Visual Computing

Page 26: Viewing - cg.tuwien.ac.at

For Now: Parallel (Orthographic) Projection

Werner Purgathofer 28

object space world space camera space

clip space pixel space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

Page 27: Viewing - cg.tuwien.ac.at

Perspective Projection

Page 28: Viewing - cg.tuwien.ac.at

Perspective Projection

30

perspective projection of equal-sized objects at different distances from the view plane

x

y

zview plane

projection reference

point

Werner Purgathofer / Einf. in Visual Computing

Page 29: Viewing - cg.tuwien.ac.at

Parallel vs. Perspective Projection

31

parallel projection: preserves relative proportions & parallel features (affine transform.)

perspective projection: center of projection, realistic views

Werner Purgathofer / Einf. in Visual Computing

Page 30: Viewing - cg.tuwien.ac.at

Perspective Transform

32

N F

T

B

O

Werner Purgathofer / Einf. in Visual Computing

Page 31: Viewing - cg.tuwien.ac.at

Perspective Transformation

33

fypO

view plane

yp = yfz

z

y

f … focal length

derivation of perspective

transformation

Werner Purgathofer / Einf. in Visual Computing

yp fzy =

Page 32: Viewing - cg.tuwien.ac.at

Perspective Transformation

34

fz

yp

y

view plane

yp = yfz

(z=N)

O(z=0)

N

N N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0

= P

xp = xdzNanalogous:

derivation of perspective

transformation

Werner Purgathofer / Einf. in Visual Computing

Page 33: Viewing - cg.tuwien.ac.at

Perspective Transformation

35

N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0

xyz1

· =

x·Ny·N

z·(N+F) –F·Nz

~>

x·N/zy·N/z

(N+F) –F·N/z1

homogenization: divide by z

yp = yz

xp = xzN

N

P =derivation of

perspective transformation

Werner Purgathofer / Einf. in Visual Computing

Page 34: Viewing - cg.tuwien.ac.at

Example: (Right) Top Near Corner

36

N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0

RTN1

· =

R·NT·N

N·(N+F) –F·NN

~>

RTN1

x (B or T or L or R)

view plane

NO

F

Werner Purgathofer / Einf. in Visual Computing

Page 35: Viewing - cg.tuwien.ac.at

Example: (Left) Top Far Corner

37

N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0

L·F/NT·F/N

F1

· =

L·FT·F

F·(N+F) –F·NF

~>

LTF1

x (B or T or L or R)

NO

F

view plane x·F/N

Werner Purgathofer / Einf. in Visual Computing

Page 36: Viewing - cg.tuwien.ac.at

Perspective Transform

38

N F

T

B

O

Werner Purgathofer / Einf. in Visual Computing

Page 37: Viewing - cg.tuwien.ac.at

Nonlinear z-Behaviour

39Werner Purgathofer / Einf. in Visual Computing

Page 38: Viewing - cg.tuwien.ac.at

Nonlinear z-Behaviour

40Werner Purgathofer / Einf. in Visual Computing

Page 39: Viewing - cg.tuwien.ac.at

From Object Space to Screen Space

Werner Purgathofer 41

object space world space camera space

clip space pixel space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

Page 40: Viewing - cg.tuwien.ac.at

Viewing: Camera + Projection + Viewport

42

xscreenyscreen

z´1

= Mvp·Morth·P·Mcam ·

xyz1

( )

Mper

pixels onthe screen

world coordinates

Werner Purgathofer / Einf. in Visual Computing

Page 41: Viewing - cg.tuwien.ac.at

From Object Space to Screen Space

Werner Purgathofer 43

object space world space camera space

clip space pixel space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

Page 42: Viewing - cg.tuwien.ac.at

z-Values Remain in Order

44Werner Purgathofer

N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0

xyz1

· ~>

x·N/zy·N/z

(N+F) –F·N/z1

z1, z2, N, F < 0z1 < z2

1/z1 > 1/z2 | · (–F·N) (<0)– F·N/z1 < – F·N/z2 | + (N+F)(N+F) – F·N/z1 < (N+F) – F·N/z2

Werner Purgathofer / Einf. in Visual Computing

Page 43: Viewing - cg.tuwien.ac.at

Perspective Projection Properties

parallel lines parallel to view plane ⇒ parallel linesparallel lines not parallel to view plane ⇒ converging lines (vanishing point)lines parallel to coordinate axis ⇒principal vanishing point (one, two or three)

45Werner Purgathofer / Einf. in Visual Computing

Page 44: Viewing - cg.tuwien.ac.at

Principle Vanishing Points

46

2-point perspectiveprojection

3-point perspectiveprojection

1-pointperspectiveprojection

vanishing point

Werner Purgathofer / Einf. in Visual Computing