CSE4203: Computer Graphics Chapter 7 (part - A) Viewing

41
CSE4203: Computer Graphics Chapter – 7 (part - A) Viewing Mohammad Imrul Jubair M. I. Jubair 1

Transcript of CSE4203: Computer Graphics Chapter 7 (part - A) Viewing

CSE4203: Computer Graphics

Chapter – 7 (part - A)

Viewing

Mohammad Imrul Jubair

M. I. Jubair 1

Outline

– Image-order and object-render rendering

– Viewing transformation

– Viewport transformation

– Orthographic projection transformation

M. I. Jubair 2

Credit

M. I. Jubair 3

CS4620: Introduction to Computer GraphicsCornell UniversityInstructor: Steve Marschnerhttp://www.cs.cornell.edu/courses/cs4620/2019fa/

Rendering Techniques (1/2)

• One of the basic tasks of computer graphics is rendering 3D objects:

– taking a scene, or model, composed of many geometric objects arranged in 3D space

– producing a 2D image that shows the objects as viewed

– from a particular viewpoint.

M. I. Jubair 4

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Rendering Techniques (2/2)

1. Image-order rendering: iterate over the pixels in the image to be produced, rather than the elements in the scene to be rendered.

2. object-order rendering: that iterate over the elements in the scene to be rendered, rather than the pixels in the image to be produced.

M. I. Jubair 5

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Image-order Rendering (1/2)

• Image-order rendering:

– Ray-tracing:

Each pixel is considered in turn, and for each pixel

• All the objects that influence it are found

• and the pixel value is computed.

– in Chapter 4

M. I. Jubair 6

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Object-order Rendering (1/2)

• Object-order rendering:

– Viewing Transformation:

Each object is considered in turn, and for each object:

• All the pixels that it influences are found and updated

M. I. Jubair 7

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Object-order Rendering (2/2)

• Viewing Transformation (this chapter):

– The inverse of the previous process.

– How to use matrix transformations to express any parallel or perspective view.

– These transformations:

• Project 3D points in the scene (world space) to 2D points in the image (image space)

M. I. Jubair 8

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Object space vs World space vs Camera space

– Object space

– World space

– Camera space

M. I. Jubair 9

M. I. Jubair 10

Viewing Transformation Sequences (1/1)

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Viewport Transformation (1/19)

M. I. Jubair 11

A3d(3,3,2)

A2d(3,3)

x

z

y

x

y

• Projection: Ignoring the z-coordinate

Viewport Transformation (2/19)

M. I. Jubair 12

(x,y,z) є [-1, 1]3

• Canonical View Volume: (x,y,z) є [-1, 1]3

– We will assume that the model to be drawn are completely inside the canonical view vol.

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

z

Viewport Transformation (4/19)

M. I. Jubair 13

(-1, -1, -1)

(1, 1, 1)

(-1, -1)

(1, 1)(-1, 1)

(1, -1)

(x,y) є [-1, 1]2

(x,y,z) є [-1, 1]3

unit image rectangle

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Viewport Transformation (5/19)

M. I. Jubair 14

(-1, -1, -1)

(1, 1, 1)

(-1, -1)

(1, 1)(-1, 1)

(1, -1)

ny

nx

(x,y) є [-1, 1]2

(x,y,z) є [-1, 1]3

screen (pixel coord.)

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Viewport Transformation (7/19)

M. I. Jubair 15

(-1, -1)

(1, 1)(-1, 1)

(1, -1)

(0, 0)

(nx-1, ny-1)

[-1, 1]2→ [-0.5, nx-0.5] × [-0.5, ny-0.5]

(x,y) є [-1, 1]2

Each pixel “owns” a unit square centered at integer coordinates; the image boundaries have a half unit overshoot from the pixel centers; and the smallest pixel center coordinates are (0, 0).

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Viewport Transformation (8/19)

M. I. Jubair 16

(-1, -1)

(1, 1)(-1, 1)

(1, -1)(-1/2, -1/2)

(nx-1/2, ny-1/2)

Windowing Transform.

(Chap - 6)

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Viewport Transformation (9/19)

M. I. Jubair 17

(-1/2, -1/2)

(nx-1/2, ny-1/2)

T(1, 1)

(0, 0)

Viewport Transformation (10/19)

M. I. Jubair 18

(-1/2, -1/2)

(nx-1/2, ny-1/2)

T(1, 1) → S(nx/2, ny/2)

Viewport Transformation (11/19)

M. I. Jubair 19

(-1/2, -1/2)

(nx-1/2, ny-1/2)

T(1, 1) → S(nx/2, ny/2) → T(-1/2, -1/2)

Viewport Transformation (12/19)

M. I. Jubair 20

(-1/2, -1/2)

(nx-1/2, ny-1/2)

T(1, 1) → S(nx/2, ny/2) → T(-1/2, -1/2)

Mvp = T(-1/2, -1/2) * S(nx/2, ny/2) * T(1,1)

Viewport Transformation (15/19)

M. I. Jubair 21

Mvp = T(-1/2, -1/2) * S(nx/2, ny/2) * T(1, 1)

Q: Do matrix multiplication and check

Viewport Transformation (16/19)

M. I. Jubair 22

Mvp = T(-1/2, -1/2) * S(nx/2, ny/2) * T(1, 1)

(-1, -1)

(1, 1)(-1, 1)

(1, -1)

(-1/2, -1/2)

(nx-1/2, ny-1/2)

Canonical Screen

(xpixel, ypixel)(xcanonical, ycanonical)

This is similar to windowing

transform.(Chap - 6)

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Viewport Transformation (18/19)

M. I. Jubair 23

Viewport Transformation (19/19)

M. I. Jubair 24

(-1/2, -1/2)

(nx-1/2, ny-1/2)

Canonical Screen

(-1, -1, 1)

(1, 1, 1)(-1, 1,1 )

(1, -1, 1)

(xpixel, ypixel, zcanonical)(xcanonical, ycanonical, zcanonical)

[carry along the z-coordinate without changing it]

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Orthographic Projection Transformation (1/1)

• What if we want to render geometry in some region other than canonical view vol.?

M. I. Jubair 25

+y

+z

Orthographic View Volume (1/3)

• We’ll name the coordinates of its sides so that the view volume is [l, r] ×[b, t] × [f, n]– View direction: looking along −z

– Orientation: +y up

• x = l ≡ left plane,

• x = r ≡ right plane,

• y = b ≡ bottom plane,

• y = t ≡ top plane,

• z = n ≡ near plane,

• z = f ≡ far plane.

M. I. Jubair 26

+y

+z-z

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Orthographic View Volume (2/3)

• Looking along the minus z-axis with his head pointing in the positive y-direction.– View direction: looking along −z

– Orientation: +y up

• But, this is unintuitive!

M. I. Jubair 27

+y

+z-z

up

view dir.

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Orthographic View Volume (3/3)

• If entire orthographic view volume has negative z then n > f.

• z = n plane is closer

M. I. Jubair 28

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Orthographic to Canonical View Volume (1/3)

• Transform from orthographic view volume to the canonical view volume– We need to apply windowing transformation (just like before!)

M. I. Jubair 29

+y

+z

+y

+z -z

orthographic view volume

Canonical view volume

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Orthographic to Canonical View Volume (2/3)

M. I. Jubair 30

+y

+z

(l, b, n)

(r, t, f)

(1, 1, 1)

(-1, -1, -1)

orthographic view volume

Canonical view volume

+y

+z -z

Orthographic to Canonical View Volume (3/3)

M. I. Jubair 31

+y

+z

(l, b, n)

(r, t, f)

(1, 1, 1)

(-1, -1, -1)

Q: How can we get this matrix?Help: Chap 6 (Windowing Transformation) and Mvp

orthographic view volume

Canonical view volume

+y

+z -z

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner | http://www.cs.cornell.edu/courses/cs4620/2019fa/

Orthographic → Canonical → Screen (1/5)

M. I. Jubair 32

+y

+z

Canonical View Vol.

Screen

(xpixel, ypixel, zcanonical)

(xcanonical, ycanonical, zcanonical)

Orthographic → Canonical → Screen (2/5)

M. I. Jubair 33

+y

+z+y

+z

Canonical View Vol.

Screen

Orth. View Vol.

(xpixel, ypixel, zcanonical)

(xcanonical, ycanonical, zcanonical)

(x, y, z)

Orthographic → Canonical → Screen (3/5)

M. I. Jubair 34

+y

+z+y

+z

Canonical View Vol.

Screen

Orth. View Vol.

(xpixel, ypixel, zcanonical)

(xcanonical, ycanonical, zcanonical)

(x, y, z)

Orthographic → Canonical → Screen (4/5)

M. I. Jubair 35

+y

+z+y

+z

Canonical View Vol.

Screen

Orth. View Vol.

(xpixel, ypixel, zcanonical)

(xcanonical, ycanonical, zcanonical)

(x, y, z)

Orthographic → Canonical → Screen (5/5)

M. I. Jubair 36

Screen

Orth. View Vol.

(xpixel, ypixel, zcanonical)

(x, y, z)

Code: Orthographic to Screen (1/1)

Drawing many 3D lines with endpoints ai and bi:

Construct Mvp

Construct Morth

M = Mvp*Morth

for each line segment (ai, bi) do:

p = M*ai

q = M*bi

drawline (xp, yp, xq, yq)

M. I. Jubair 37

Practice Problem - 1

Transform a 3D line AB from an orthographic view volume to a viewport of size 128 x 96. Vertices of the line are A(-1, -3, -5) and B(2, 4, -6). The orthographic view volume has the following setup:

l = - 4, r = 4, b = - 4, t = 4, n = - 4, f = - 8

You must -

a. Determine the transformation matrix M.

b. Multiply M with the vertices of the line and determine the position of vertices on viewport.

M. I. Jubair 38

Practice Problem – 1 (Sol.)

M. I. Jubair 39

nx = 128ny = 96

l = - 4, r = 4,b = - 4, t = 4,n = - 4, f = - 8

Practice Problem – 1 (Sol.)

M = Mvp*Morth

M. I. Jubair 40

M A =A’

M B=B’

Additional Reading

• Wireframe renderings

• Derive Morth

M. I. Jubair 41