COMPUTER GRAPHICS COURSE Viewing and Projections Georgios - - PowerPoint PPT Presentation

computer graphics course
SMART_READER_LITE
LIVE PREVIEW

COMPUTER GRAPHICS COURSE Viewing and Projections Georgios - - PowerPoint PPT Presentation

COMPUTER GRAPHICS COURSE Viewing and Projections Georgios Papaioannou - 2014 VIEWING TRANSFORMATION The Virtual Camera All graphics pipelines perceive the virtual world Y through a virtual observer (camera), also positioned in the 3D


slide-1
SLIDE 1

COMPUTER GRAPHICS COURSE

Georgios Papaioannou - 2014

Viewing and Projections

slide-2
SLIDE 2

VIEWING TRANSFORMATION

slide-3
SLIDE 3

The Virtual Camera

Y

  • All graphics pipelines perceive the virtual world

through a virtual observer (camera), also positioned in the 3D environment

“eye” (virtual camera)

slide-4
SLIDE 4

Eye Coordinate System (1)

  • The virtual camera or “eye” also has its own

coordinate system, the eye coordinate system

Eye coordinate system (ECS) (WCS) eye Global (world) coordinate system X Y Z X Y Y Z

slide-5
SLIDE 5

Eye Coordinate System (2)

  • Expressing the scene’s geometry in the ECS is a

natural “egocentric” representation of the world:

– It is how we perceive the user’s relationship with the environment – It is usually a more convenient space to perform certain rendering tasks, since it is related to the ordering of the geometry in the final image

slide-6
SLIDE 6

Eye Coordinate System (3)

  • Coordinates as “seen” from the camera reference

frame

Y X ECS

slide-7
SLIDE 7

Eye Coordinate System (4)

  • What “egocentric” means in the context of

transformations?

– Whatever transformation produced the camera system  its inverse transformation expresses the world w.r.t. the camera

  • Example: If I move the camera “left”, objects appear

to move “right” in the camera frame:

WCS camera motion Eye-space object motion

slide-8
SLIDE 8

Moving to Eye Coordinates

  • Moving to ECS is a change of coordinates

transformation

  • The WCSECS transformation expresses the 3D

environment in the camera coordinate system

  • We can define the ECS transformation in two ways:

– A) Invert the transformations we applied to place the camera in a particular pose – B) Explicitly define the coordinate system by placing the camera at a specific location and setting up the camera vectors

slide-9
SLIDE 9

WCSECS: Version A (1)

  • Let us assume that we have an initial camera at the
  • rigin of the WCS
  • Then, we can move and rotate the “eye” to any pose

(rigid transformations only: No sense in scaling a camera): 𝐩𝑑, 𝐯, 𝐰, 𝐱 = 𝐒1𝐒2𝐔1𝐒𝟑 … . 𝐔𝑜𝐒𝑛 𝐩, ො 𝐟1, ො 𝐟2, ො 𝐟3

  • The eye space coordinates of shapes, given their

WCS coordinates can be simply obtained by: 𝐰𝐹𝐷𝑇 = 𝐍𝑑

−1𝐰𝑋𝐷𝑇

𝐍𝑑

slide-10
SLIDE 10

WCSECS: Version A (2)

  • This version of the WCSECS transformation

computation is useful in cases where:

– The camera system is dependent on (attached to) some moving geometry (e.g. a driver inside a car) – The camera motion is well-defined by a simple trajectory (e.g. an orbit around an object being inspected)

slide-11
SLIDE 11

WCSECS: Version B (“Look At”) (1)

  • Let us directly define a camera system by specifying

where the camera is, where does it point to and what is its roll (or usually, its “up” or “right” vector)

right up roll front look-at camera position

slide-12
SLIDE 12

WCSECS: Version B (“Look At”) (2)

  • The camera coordinate system offset is the eye

(camera) position 𝐩𝑑

  • Given the look-at position (the camera target) 𝐪𝑢𝑕𝑢

and 𝐩𝑑, we can determine the “front” direction:

Ԧ 𝐞𝑔𝑠𝑝𝑜𝑢 = 𝐪𝑢𝑕𝑢 − 𝐩𝑑 (normalized)

𝐪𝑢𝑕𝑢 𝐩𝑑

slide-13
SLIDE 13

WCSECS: Version B (“Look At”) (3)

  • The “up” or “right” vector need not be given

precisely, as we can infer the coordinate system indirectly

  • Let us provide an “upright” up vector: Ԧ

𝐞𝑣𝑞 =(0,1,0)

  • Provided that Ԧ

𝐞𝑣𝑞 is not parallel to Ԧ 𝐞𝑔𝑠𝑝𝑜𝑢:

𝐯 = Ԧ 𝐞𝑔𝑠𝑝𝑜𝑢 × Ԧ 𝐞𝑣𝑞, ෝ 𝐯 = 𝐯/ 𝐯 ෝ 𝐱 = − Ԧ 𝐞𝑔𝑠𝑝𝑜𝑢/ Ԧ 𝐞𝑔𝑠𝑝𝑜𝑢 ො 𝐰 = ෝ 𝐱 × ෝ 𝐯

Ԧ 𝐞𝑣𝑞 ො 𝐰 ෝ 𝐯 ෝ 𝐱 Ԧ 𝐞𝑔𝑠𝑝𝑜𝑢

slide-14
SLIDE 14

WCSECS: Version B (“Look At”) (4)

  • We can use the derived local camera coordinate

system to define the change of coordinates transformation (see 3D Transformations):

𝐪𝐹𝐷𝑇 = 𝑣𝑦 𝑣𝑧 𝑣𝑨 𝑤𝑦 𝑤𝑧 𝑤𝑨 𝑥𝑦 𝑥𝑧 𝑥𝑨 1 ∙ 𝐔−𝐏𝑑 ∙ 𝐪𝑋𝐷𝑇

slide-15
SLIDE 15

WCSECS: Version B (“Look At”) (5)

  • This version of the WCSECS transformation

computation is useful in cases where:

– There is a free roaming camera – The camera follows (observes) a certain target in space – The position (and target) are explicitly defined

slide-16
SLIDE 16

PROJECTIONS

slide-17
SLIDE 17

Projection

  • Is the process of transforming 3D coordinates of

shapes to points on the viewing plane

  • Viewing plane is the 2D flat surface that represents

an embedding of an image into the 3D space – We can define viewing systems where the “projection” surface is not planar (e.g. fish-eye lenses etc.)

  • (Planar) projections are define by a projection

(viewing) plane and a center of projection (eye)

slide-18
SLIDE 18

Taxonomy

  • Two main categories:

– Parallel projections: infinite distance between CoP and viewing plane – Perspective projections: Finite distance between CoP and viewing plane

slide-19
SLIDE 19

Where do We Perform the Projections?

  • Since in projections we “collapse” a 3D shape onto a

2D surface, we essentially want to loose one coordinate (say the depth z)

  • Therefore, it is convenient to perform the projection

when shapes are expressed in the ECS

slide-20
SLIDE 20

Orthographic Projection (1)

  • The simplest projection:
  • Collapse the coordinates on plane parallel to xy at

z=d (usually 0)

𝑧′ = 𝑧 𝑦′ = 𝑦

ECS y x z

𝐪 = (𝑦, 𝑧, 𝑨) 𝐪′ = (𝑦′, 𝑧′, 𝑒) 𝑒

𝑨′ = 𝑒

𝑨 = 𝑒 (view plane)

slide-21
SLIDE 21

Orthographic Projection (2)

  • Very simple matrix representation
  • Note that the rank of the matrix is less than its

dimension: This not a reversible transformation!

– This is also intuitively justified since we “loose” all information about depth 𝐐𝑃𝑆𝑈𝐼𝑃 = 1 1 𝑒 1

slide-22
SLIDE 22

The Pinhole Camera Model

  • It is an ideal camera (i.e. cannot exist in practice)
  • It is the simplest modeling of a camera:

photographic Image sensor For simplicity, graphics use a “front” symmetrical projection plane

slide-23
SLIDE 23

The Perspective Projection

  • From similar triangles, we have:

𝑧′ = 𝑒 ∙ 𝑧 𝑨 𝑦′ = 𝑒 ∙ 𝑦 𝑨

ECS y x z

𝐪 = (𝑦, 𝑧, 𝑨) 𝐪′ = (𝑦′, 𝑧′, 𝑒) 𝑧′ 𝑧 𝑒 𝑨

𝑨′ = 𝑒

𝑨 = 𝑒 (view plane)

slide-24
SLIDE 24

Matrix Form of Perspective Projection

  • The perspective projection is not a linear operation

(division by z) 

  • It cannot be completely represented by a linear
  • perator such as a matrix multiplication

𝐐𝑄𝐹𝑆 = 𝑒 𝑒 𝑒 1 𝐐𝑄𝐹𝑆 ∙ 𝐪𝑋𝐷𝑇 = 𝑦 ∙ 𝑒 𝑧 ∙ 𝑒 𝑨 ∙ 𝑒 𝑨 𝑦 ∙ 𝑒 𝑧 ∙ 𝑒 𝑨 ∙ 𝑒 𝑨 /𝑨 = 𝑦 ∙ 𝑒/𝑨 𝑧 ∙ 𝑒/𝑨 𝑒 1

Requires a division by the w coordinate to rectify the homogeneous coordinates

slide-25
SLIDE 25

Properties of the Perspective Projection

  • Lines are projected to lines
  • Distances are not preserved
  • Angles between lines are not preserved unless lines

are parallel to the view plane

  • Perspective foreshortening: The size of the

projected shape is inversely proportional to the distance to the plane

slide-26
SLIDE 26

The Impact of Focal Distance d

slide-27
SLIDE 27

What Happens After Projection? (1)

  • Coordinates are transformed to a “post-projective”

space

Y X ECS Y X Post-projective space

slide-28
SLIDE 28

What Happens After Projection? (2)

  • Remember also that “depth” is for now collapsed to

the focal distance

  • How then are we going to use the projected

coordinates to perform “depth” sorting in order to remove hidden surfaces?

  • Also, how do we define the extents of what we can

see?

slide-29
SLIDE 29

Preserving the Depth

  • Regardless of what the projection is, we also retain

the transformed z values

  • For numerical stability, representation accuracy and

plausibility of displayed image, we limit the z-range

  • 𝑜 ≤ 𝑨 ≤ 𝑔,

– 𝑜=near clipping value, – 𝑔=far clipping value,

slide-30
SLIDE 30
  • The boundaries (line segments) of the image, form

planes in space:

  • The intersection of the visible subspaces, defines

what we can see inside a view frustum

The View Frustum

slide-31
SLIDE 31

Z X Y

The Clipping Volume (1)

  • The viewing frustum, forms a clipping volume
  • It defines which parts of the 3D world are discarded, i.e. do

not contribute to the final rendering of the image

  • For many rendering architectures, this is a closed volume

(capped by the far plane)

Right clipping plane Near clipping plane Orthographic Clipping volume Perspective Clipping volume

slide-32
SLIDE 32

The Clipping Volume (2)

  • After projection, the contents of the clipping volume

are warped to match a rectangular paralepiped

  • This post-projective volume is usually considered

normalized and its local coordinate system is called Canonical Screen Space (CSS)

  • The respective device coordinates are also called

Normalized Device Coordinates (NDC)

slide-33
SLIDE 33

Orthographic Projection Revisited (1)

  • Let us now create an orthographic projection that

transforms a specific clipping box volume (left, right, bottom, top, near, far) to CSS:

Z X Y

slide-34
SLIDE 34

Orthographic Projection Revisited (2)

  • A simple translation  scaling transformation can

warp the clipping volume into NDC

Z X Y

(-1,-1,-1) (1, 1, 1) Notice the change of handedness here: (-1 corresponds to “near”, while “far” is 1)

slide-35
SLIDE 35

Orthographic Projection Revisited (3)

slide-36
SLIDE 36

Perspective Projection Revisited (1)

  • We want a similar transformation to warp the

contents of the perspective frustum into a normalized cube space (CSS)

  • Let us now see what happens to geometry when the

Cartesian coordinates are perspectively projected (warped) after the transformation:

slide-37
SLIDE 37

Perspective Projection Revisited (2)

  • In perspective projection, the clipping space is a

capped pyramid (frustum)

slide-38
SLIDE 38

Perspective Projection Revisited (3)

  • We still need to perform the perspective division
  • We also need to retain the depth information
  • Depth must obey the same transformation (division

by z)  retain straight lines

  • So it must be of the general form: zs=A+B/ze
  • Solving A and B for the boundary conditions:

f=A+B/f and n=A+B/n:

  • A=n+f
  • B=-nf 
  • zs=n+f-nf/ze
slide-39
SLIDE 39

Perspective Projection Revisited (4)

  • zs=n+f-nf/ze
slide-40
SLIDE 40

Perspective Projection Revisited (5)

Viewing frustum Post-projective (NDC) space

slide-41
SLIDE 41

Perspective Projection Revisited (6)

  • Next, we must normalize the result to bring it to the

CSS coordinates:

slide-42
SLIDE 42

Perspective Projection Revisited (7)

  • Of course, we still need to divide with the w

coordinate after the matrix multiplication

slide-43
SLIDE 43

Extended Perspective Projection (1)

  • In general, the frustum

axis is not aligned with the viewing direction

  • To bring this frustum to

the CSS normalized volume, we must first skew it

slide-44
SLIDE 44

Extended Perspective Projection (2)

  • Why do we need an off-axis projection?

Stereo Multi-view rendering Planar reflections

slide-45
SLIDE 45

Extended Perspective Projection (3)

  • The center of the near and

far cap must coincide with the z axis

  • Therefore, using the z-based

shear transformation:

  • We require:

𝑐0 + 𝑢𝑝 2 + 𝐶𝑜𝑝 = 0 𝑚0 + 𝑠𝑝 2 + 𝐵𝑜𝑝 = 0

slide-46
SLIDE 46

Perspective: Putting Everything Together (1)

  • The final extended perspective transformation matrix:
slide-47
SLIDE 47

Contributors

  • Georgios Papaioannou
  • Sources:

– T. Theoharis, G. Papaioannou, N. Platis, N. M. Patrikalakis, Graphics & Visualization: Principles and Algorithms, CRC Press