cs g140 graduate computer graphics

59
June 15, 2022 1 College of Computer and Information Science, Northeastern University CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 3 - January 21, 2009

Upload: trey

Post on 23-Feb-2016

48 views

Category:

Documents


0 download

DESCRIPTION

CS G140 Graduate Computer Graphics. Prof. Harriet Fell Spring 2009 Lecture 3 - January 21, 2009. Today’s Topics. From 3D to 2D 2 Dimensional Viewing Transformation http://www.siggraph.org/education/materials/HyperGraph/viewing/view2d/2dview0.htm Viewing – from Shirley et al. Chapter 7 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS G140 Graduate Computer Graphics

April 22, 2023 1College of Computer and Information Science, Northeastern University

CS G140Graduate Computer Graphics

Prof. Harriet FellSpring 2009

Lecture 3 - January 21, 2009

Page 2: CS G140 Graduate Computer Graphics

April 22, 2023 2College of Computer and Information Science, Northeastern University

Today’s Topics

• From 3D to 2D• 2 Dimensional Viewing Transformation

http://www.siggraph.org/education/materials/HyperGraph/viewing/view2d/2dview0.htm • Viewing – from Shirley et al. Chapter 7• Recursive Ray Tracing

Reflection Refraction

Page 3: CS G140 Graduate Computer Graphics
Page 4: CS G140 Graduate Computer Graphics

Scene is from my photo of Estes Park – Harriet FellKitchen window from http://www.hoagy.org/cityscape/graphics/cityscapeAtNight.jpg

Page 5: CS G140 Graduate Computer Graphics

(-1, -1)

(1, 1)

Page 6: CS G140 Graduate Computer Graphics

April 22, 2023 6College of Computer and Information Science, Northeastern University

from a 3D World to a 2D Screen

When we define an image in some world coordinate system, to display that image we must somehow map the image to the physical output device.

1. Project 3D world down to a 2D window (WDC).2. Transform WDC to a Normalized Device

Coordinates Viewport (NDC).3. Transform (NDC) to 2D physical device

coordinates (PDC).

Page 7: CS G140 Graduate Computer Graphics

April 22, 2023 7College of Computer and Information Science, Northeastern University

2 Dimensional Viewing Transformationhttp://www.siggraph.org/education/materials/HyperGraph/viewing/view2d/2dview0.htm

• Window Example: Want to plot x vs. cos(x) for x between 0.0

and 2Pi. The values of cos x will be between -1.0 and +1.0. So we want the window as shown here.

Page 8: CS G140 Graduate Computer Graphics

April 22, 2023 8College of Computer and Information Science, Northeastern University

2D Viewing Transformation

World

Viewport

Device

Page 9: CS G140 Graduate Computer Graphics

April 22, 2023 9College of Computer and Information Science, Northeastern University

(3,2)

(0,0)

(0,3)

Pixel Coordinatesy

x

x = -0.5

y = 4.5

y = -03.5x = 4.5

Page 10: CS G140 Graduate Computer Graphics

April 22, 2023 10College of Computer and Information Science, Northeastern University

y

x

(-1,1)

(1,-1)

reflect

Canonical View to Pixelsy

x

(-1,-1)

(1,1)

x

(-nx/2,ny/2) y

(nx/2,-ny/2)

scale

y

x

(-0.5, ny--0.5)

(nx-0.5, -0.5)

translate

Page 11: CS G140 Graduate Computer Graphics

April 22, 2023 11College of Computer and Information Science, Northeastern University

2D Rectangle to Rectangle

(a, b)(c, d)

w1

w2

h1h2

T(-a, -b)S(w2/w1, h2/h1)T(c, d)

(0, 0)

Page 12: CS G140 Graduate Computer Graphics

April 22, 2023 12College of Computer and Information Science, Northeastern University

Canonical View Volume

(-1,-1,-1)

(1,1,1)

x

y

z

Page 13: CS G140 Graduate Computer Graphics

April 22, 2023 13College of Computer and Information Science, Northeastern University

Orthographic Projection

(l,b,n)

(r,t,f)

x

y

z

left bottom near right top far

Page 14: CS G140 Graduate Computer Graphics

April 22, 2023 14College of Computer and Information Science, Northeastern University

Orthographic Projection Math

2 0 0 0 1 0 0 -- 2

20 0 0 0 1 0 -- 2

20 0 0 0 0 1 -1 1- 20 0 0 10 0 0 1

canonical

canonical

canonical

l rr lx x

b ty yt b

z zn fn f

⎡ ⎤ +⎡ ⎤⎢ ⎥⎢ ⎥⎡ ⎤ ⎡ ⎤⎢ ⎥⎢ ⎥

+⎢ ⎥ ⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥ ⎢ ⎥⎢ ⎥⎢ ⎥=⎢ ⎥ ⎢ ⎥⎢ ⎥⎢ ⎥+⎢ ⎥ ⎢ ⎥⎢ ⎥⎢ ⎥⎣ ⎦ ⎣ ⎦⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎣ ⎦⎣ ⎦

Page 15: CS G140 Graduate Computer Graphics

April 22, 2023 15College of Computer and Information Science, Northeastern University

Orthographic Projection Math

2 0 0 0 1 0 0 -0 0 0 - 22 20 0 0 0 1 0 -0 0 0 - 22 20 0 0 0 0 1 -0 0 1 0- 2

0 0 0 1 0 0 0 10 0 0 1

x

yo

l rnr l

b tnt bM

n fn f

⎡ ⎤ +⎡ ⎤⎡ ⎤⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥ +⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥=⎢ ⎥⎢ ⎥⎢ ⎥+⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎣ ⎦⎢ ⎥⎢ ⎥⎣ ⎦⎣ ⎦

1 1

pixel

pixelo

canonical

x xy y

Mz z

⎡ ⎤ ⎡ ⎤⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥=⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎣ ⎦

Page 16: CS G140 Graduate Computer Graphics

April 22, 2023 16College of Computer and Information Science, Northeastern University

Arbitrary View Positions

gazethe view-up

eye

w = -g ||g||

u = t x w ||t x w||

v = w x u

Page 17: CS G140 Graduate Computer Graphics

April 22, 2023 17College of Computer and Information Science, Northeastern University

Arbitrary Position Geometry

e

v

u

w

(u=r,v=t,w=f)

(u=l,v=b,w=n)

o

z

yx

Page 18: CS G140 Graduate Computer Graphics

April 22, 2023 18College of Computer and Information Science, Northeastern University

Arbitrary Position Transformation

Move e to the origin and align (u, v, w) with (x, y, z).

0 1 0 00 0 1 00 0 0 1

0 0 0 1 0 0 0 1

u u u e

v v v ev

w w w e

x y z xx y z y

Mx y z z

−⎡ ⎤⎡ ⎤⎢ ⎥⎢ ⎥−⎢ ⎥⎢ ⎥=

−⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎥⎣ ⎦⎣ ⎦

Compute M = MoMv.

For each line segment (a,b)

p = Ma, q = Mb, drawline(p,q).

Page 19: CS G140 Graduate Computer Graphics

April 22, 2023 19College of Computer and Information Science, Northeastern University

Perspective Projection

(l,b,n) (r,t,f)

x

y

z

Page 20: CS G140 Graduate Computer Graphics

April 22, 2023 20College of Computer and Information Science, Northeastern University

Lines to Lines

Page 21: CS G140 Graduate Computer Graphics

April 22, 2023 21College of Computer and Information Science, Northeastern University

Perspective Geometry

gV

iew

pla

ne

y

ys

nz

ys = (n/z)y

e

Page 22: CS G140 Graduate Computer Graphics

April 22, 2023 22College of Computer and Information Science, Northeastern University

Perspective Transformation

The perspective transformation should take

( )

//

1 1

x nx zy ny zz p z

⎡ ⎤ ⎡ ⎤⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥→⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎣ ⎦

Where

p(n) = n

p(f) = f

and

n z1 > z2 f

implies p(z1) > p(z2).

P(z) = n + f – fn/z satisfies these requirements.

Page 23: CS G140 Graduate Computer Graphics

April 22, 2023 23College of Computer and Information Science, Northeastern University

Perspective Transformation

//

/1 1

x nx zy ny zz n f fn z

⎡ ⎤ ⎡ ⎤⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥→

+ −⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎣ ⎦

is not a linear transformation.

is a linear transformation.

1

x nxy nyz nz fz fn

z

⎡ ⎤ ⎡ ⎤⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥→

+ −⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎣ ⎦

Page 24: CS G140 Graduate Computer Graphics

April 22, 2023 24College of Computer and Information Science, Northeastern University

The Whole Truth about Homogeneous Coordinates

0

0

hxx

hy hy

h

hxx

hyy h

hzz

h

⎧ ⎫⎡ ⎤⎡ ⎤ ⎪ ⎪⎢ ⎥↔ ≠⎨ ⎬⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎪ ⎪⎢ ⎥⎣ ⎦⎩ ⎭⎧ ⎫⎡ ⎤⎡ ⎤ ⎪ ⎪⎢ ⎥⎪ ⎪⎢ ⎥ ⎢ ⎥↔ ≠⎨ ⎬⎢ ⎥ ⎢ ⎥⎪ ⎪⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎪ ⎪⎣ ⎦⎩ ⎭

A point in 2-space corresponds to a line through the origin in 3-space minus the origin itself.

A point in 3-space corresponds to a line through the origin in 4-space minus the origin itself.

Page 25: CS G140 Graduate Computer Graphics

April 22, 2023 25College of Computer and Information Science, Northeastern University

Homogenize

homogenize homogenize

homogenize

6 3 27 33 3

14 7 63 77 7

2 1 9 1

22 2 12

121 11 5.511

77 7 3.57

11 1 .5

⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎡ ⎤ ⎡ ⎤⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥→ ↔ → ↔⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎣ ⎦⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦

⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎡ ⎤⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ ⎥→ ↔ ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢⎣ ⎦⎣ ⎦ ⎣ ⎦ ⎣ ⎦

hom ogenize

22

1111

77

1

⎡ ⎤ ⎡ ⎤⎢ ⎥ ⎢ ⎥⎢ ⎥→ ↔ ⎢ ⎥⎥ ⎢ ⎥ ⎢ ⎥⎥ ⎢ ⎥ ⎣ ⎦⎣ ⎦

Page 26: CS G140 Graduate Computer Graphics

April 22, 2023 26College of Computer and Information Science, Northeastern University

Perspective Transformation Matrix

0 0 00 0 0

0 00 0 1 0 1

p p

n x nxn y ny

M Mn f fn z nz fz fn

z

⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ ⎥= →

+ − + −⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎣ ⎦ ⎣ ⎦

Compute M = MoMpMv.

For each line segment (a,b)

p = Ma, q = Mb, drawline(homogenize(p), homogenize(q)).

Page 27: CS G140 Graduate Computer Graphics

April 22, 2023 27College of Computer and Information Science, Northeastern University

Viewing for Ray-TracingSimplest Views

(0, 0, 0)

(wd, ht, 0)

screen

(wd/s, ht/2, d)

Page 28: CS G140 Graduate Computer Graphics

A Viewing System for Ray-Tracing

gaze

eye near distance = |g| (ex, ey, ez) =

w

hperp

(w/2, h/2, n)

(0, 0, 0)

(w, h, 0)

|p|j

-nk

You need a transformation that sends (ex, ey, ez) to (w/2, h/2, n) g to –nk p to |p|j

Page 29: CS G140 Graduate Computer Graphics

April 22, 2023 29College of Computer and Information Science, Northeastern University

Time for a Break

Page 30: CS G140 Graduate Computer Graphics

April 22, 2023 30College of Computer and Information Science, Northeastern University

Recursive Ray TracingAdventures of the 7 Rays - Watt

Specular Highlight on Outside of Shere

Page 31: CS G140 Graduate Computer Graphics

April 22, 2023 31College of Computer and Information Science, Northeastern University

Adventures of the 7 Rays - Watt

Specular Highlight on Inside of Sphere

Recursive Ray Tracing

Page 32: CS G140 Graduate Computer Graphics

April 22, 2023 32College of Computer and Information Science, Northeastern University

Adventures of the 7 Rays - Watt

Reflection and Refraction of Checkerboard

Recursive Ray Tracing

Page 33: CS G140 Graduate Computer Graphics

April 22, 2023 33College of Computer and Information Science, Northeastern University

Adventures of the 7 Rays - Watt

Refraction Hitting Background

Recursive Ray Tracing

Page 34: CS G140 Graduate Computer Graphics

April 22, 2023 34College of Computer and Information Science, Northeastern University

Adventures of the 7 Rays - Watt

Local Diffuse Plus Reflection from Checkerboard

Recursive Ray Tracing

Page 35: CS G140 Graduate Computer Graphics

April 22, 2023 35College of Computer and Information Science, Northeastern University

Adventures of the 7 Rays - Watt

Local Diffuse in Complete Shadow

Recursive Ray Tracing

Page 36: CS G140 Graduate Computer Graphics

April 22, 2023 36College of Computer and Information Science, Northeastern University

Adventures of the 7 Rays - Watt

Local Diffuse in Shadow from Transparent Sphere

Recursive Ray Tracing

Page 37: CS G140 Graduate Computer Graphics

April 22, 2023 37College of Computer and Information Science, Northeastern University

Recursive Ray-Tracing

• How do we know which rays to follow?• How do we compute those rays?• How do we organize code so we can

follow all those different rays?

Page 38: CS G140 Graduate Computer Graphics

select center of projection(cp) and window on view plane;for (each scan line in the image ) {

for (each pixel in scan line ) {determine ray from the cp through the pixel; pixel = RT_trace(ray, 1);}}

// intersect ray with objects; compute shade at closest intersection// depth is current depth in ray treeRT_color RT_trace (RT_ray ray; int depth){

determine closest intersection of ray with an object;if (object hit) {

compute normal at intersection;return RT_shade (closest object hit, ray, intersection, normal,

depth);}else

return BACKGROUND_VALUE;}

Page 39: CS G140 Graduate Computer Graphics

// Compute shade at point on object, // tracing rays for shadows, reflection, refraction. RT_color RT_shade (

RT_object object, // Object intersectedRT_ray ray, // Incident rayRT_point point, // Point of intersection to shadeRT_normal normal,// Normal at pointint depth ) // Depth in ray tree

{RT_color color; // Color of rayRT_ray rRay, tRay, sRay;// Reflected, refracted, and shadow ray

color = ambient term ;for ( each light ) {

sRay = ray from point to light ;if ( dot product of normal and direction to light is positive ){

compute how much light is blocked by opaque andtransparent surfaces, and use to scale diffuse and specular terms before adding them to color;}}

Page 40: CS G140 Graduate Computer Graphics

if ( depth < maxDepth ) { // return if depth is too deep if ( object is reflective ) {

rRay = ray in reflection direction from point;rColor = RT_trace(rRay, depth + 1);scale rColor by specular coefficient and add to color;

}if ( object is transparent ) {

tRay = ray in refraction direction from point;if ( total internal reflection does not occur ) {

tColor = RT_trace(tRay, depth + 1);scale tColor by transmission coefficient and add to color;

}}

}return color; // Return the color of the ray

}

Page 41: CS G140 Graduate Computer Graphics

April 22, 2023 41College of Computer and Information Science, Northeastern University

Computing R

V

N

R

VR

V+R

V + R = (2 VN) N

R = (2 VN) N - V

VN

VN

Page 42: CS G140 Graduate Computer Graphics

April 22, 2023 42College of Computer and Information Science, Northeastern University

Reflections, no Highlight

Page 43: CS G140 Graduate Computer Graphics

April 22, 2023 43College of Computer and Information Science, Northeastern University

Second Order Reflection

Page 44: CS G140 Graduate Computer Graphics

April 22, 2023 44College of Computer and Information Science, Northeastern University

Refelction with Highlight

Page 45: CS G140 Graduate Computer Graphics

April 22, 2023 45College of Computer and Information Science, Northeastern University

Nine Red Balls

Page 46: CS G140 Graduate Computer Graphics

April 22, 2023 46College of Computer and Information Science, Northeastern University

Refraction

( )( )

Snell's Lawsinsin

I T

T I

θ ηθ η

=

N

-N

I

TT

I

and are the

of the two mediums.

T I

indexes of refractionh h

Page 47: CS G140 Graduate Computer Graphics

April 22, 2023 47College of Computer and Information Science, Northeastern University

Refraction and Wavelength

N

-N

I

TT

I

( )( )

Snell's Lawsinsin

I T

T I

λ

λ

θ ηθ η

=

and are the

of the two mediums for the wavelength of light .

T I

indexes of refractionλ λh h

λ

Page 48: CS G140 Graduate Computer Graphics

April 22, 2023 48College of Computer and Information Science, Northeastern University

Computing T

N

-N

I

M

TT

I

sin(I)

cos(I)

I = - sin(I)M + cos(I)N

T = sin(T)M - cos(T)NHow do we compute M, sin(T), and cos(T)?

We look at this in more detail

Page 49: CS G140 Graduate Computer Graphics

April 22, 2023 49College of Computer and Information Science, Northeastern University

Computing T

( ) ( ) ( )( )

coscot

sin sinI

IT I

x θθ

θ θ= =

( ) ( )( ) ( )sin

cos cos by Snell's law.sin

T II I

I T

xθ ηθ θθ η

= =

-NT

T

Ix

sin(T)

cos(T)

( )cosI

I T

x ηθ η

= =

Page 50: CS G140 Graduate Computer Graphics

Computing T

( )cosII

T

η θη

( ) ( )T cos cosI IT I

T T

N Iη ηθ θη η

⎛ ⎞= − − −⎜ ⎟

⎝ ⎠

( ) ( ) ( )2

2 2cos 1 sin 1 sinIT T I

T

ηθ θ θη⎛ ⎞

= − = − ⎜ ⎟⎝ ⎠

-NT

T

I= x

sin(T)

cos(T)

I

T

hh

I

I

Parallel to I

( )( )2

21 1 cosII

T

η θη⎛ ⎞

= − −⎜ ⎟⎝ ⎠

( )( )2

21 1I

T

N Iηη⎛ ⎞

= − −⎜ ⎟⎝ ⎠

g

Page 51: CS G140 Graduate Computer Graphics

April 22, 2023 51College of Computer and Information Science, Northeastern University

Total Internal Reflection

( ) ( )( )2

2cos 1 1IT

T

N Iηθη⎛ ⎞

= − −⎜ ⎟⎝ ⎠

g

( )( )2

2When 1 1 0.I

T

N Iηη⎛ ⎞

− − ≥⎜ ⎟⎝ ⎠

g

When is cos(T) defined?

( )If and is close to 0, cos may not be defined.I T TN Iη η θ> gThen there is no transmitting ray and we have

total internal reflection.

Page 52: CS G140 Graduate Computer Graphics

April 22, 2023 52College of Computer and Information Science, Northeastern University

Index of RefractionThe speed of all electromagnetic radiation in vacuum is the same, approximately 3×108 meters per second, and is denoted by c. Therefore, if v is the phase velocity of radiation of a specific frequency in a specific material, the refractive index is given by

cv

h =

http://en.wikipedia.org/wiki/Refractive_index

Page 53: CS G140 Graduate Computer Graphics

April 22, 2023 53College of Computer and Information Science, Northeastern University

Indices of Refraction Material h at λ=589.3 nmvacuum 1 (exactly)

helium 1.000036

air at STP 1.0002926

water ice 1.31

liquid water (20°C) 1.333

ethanol 1.36

glycerine 1.4729

rock salt 1.516

glass (typical) 1.5 to 1.9

cubic zirconia 2.15 to 2.18

diamond 2.419http://en.wikipedia.org/wiki/List_of_indices_of_refraction

Page 54: CS G140 Graduate Computer Graphics

April 22, 2023 54College of Computer and Information Science, Northeastern University

One Glass Sphere

Page 55: CS G140 Graduate Computer Graphics

April 22, 2023 55College of Computer and Information Science, Northeastern University

Five Glass Balls

Page 56: CS G140 Graduate Computer Graphics

April 22, 2023 56College of Computer and Information Science, Northeastern University

A Familiar Scene

Page 57: CS G140 Graduate Computer Graphics

April 22, 2023 57College of Computer and Information Science, Northeastern University

Bubble

Page 58: CS G140 Graduate Computer Graphics

April 22, 2023 58College of Computer and Information Science, Northeastern University

Milky Sphere

Page 59: CS G140 Graduate Computer Graphics

April 22, 2023 59College of Computer and Information Science, Northeastern University

Lens - Carl Andrews 1999