cs 586/480 class topics and objectives computer graphics iidavid/classes/cs586/... · class...

14
1 CS 586/480 Computer Graphics II Dr. David Breen Matheson 408 Thursday 6PM Æ 8:50PM Presentation 1 9/30/04 Class Topics and Objectives n Photo-realistic image generation n Ray Tracing! n Learn and implement the algorithms needed to create ray traced images n Serious numerical computing and programming class n Assumes you know CG I material n Go to web site Class Structure n Weekly lectures & reading assignments n 7 programming assignments n Post images and code on the web n Usually due Sunday 11:59 PM n Discuss problems/questions Thursday before n No tests n Grad students give presentations n Paper summary and one question Grading n Graduate Section n Programming Assignments - 80% n In-class Presentation - 10% n In-class Assignments - 10% n Undergraduate Section n Programming Assignments - 90% n In-class Assignments - 10% n Late policy n 1 week late Ÿ 1 letter grade down n 2 letter grades down after that

Upload: others

Post on 21-Sep-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

1

CS 586/480Computer Graphics II

Dr. David BreenMatheson 408Thursday 6PM Æ 8:50PM

Presentation 19/30/04

Class Topics and Objectivesn Photo-realistic image generationn Ray Tracing!n Learn and implement the algorithms

needed to create ray traced imagesn Serious numerical computing and

programming classn Assumes you know CG I materialn Go to web site

Class Structuren Weekly lectures & reading assignmentsn 7 programming assignmentsn Post images and code on the webn Usually due Sunday 11:59 PMn Discuss problems/questions Thursday before

n No testsn Grad students give presentationsn Paper summary and one question

Gradingn Graduate Section

n Programming Assignments - 80%n In-class Presentation - 10%n In-class Assignments - 10%

n Undergraduate Sectionn Programming Assignments - 90%n In-class Assignments - 10%

n Late policyn 1 week late Ÿ 1 letter grade downn 2 letter grades down after that

Page 2: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

2

Slide Credits

n Kevin Suffern - University of Technology,Sydney, Australia

n G. Drew Kessler & Larry Hodges - GeorgiaInstitute of Technology

n Fredo Durand & Barb Cutler - MITn Computer Graphics I

Ray Castingn Determines visible surfaces by tracing “light”

rays from the viewer’s eye to the objectsn View plane is divided by a pixel gridn The eye ray is fired from the center of projection

through each pixel

1994 Foley/VanDam/Finer/Huges/Phillips ICG

Ray Tracingn Extension of ray castingn Idea: Continue to

bounce the ray in thescene

n Shoot rays to lightsources

n Simple and powerfuln Reflections, shadows,

transparency andmultiple light sources

Ray Tracing Diagrams

Page 3: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

3

First Ray-Traced Image

Whitted 1980

Issuesn Ray-object intersectionsn Complex, hierarchical models (CSG?)n Transformationsn Camera modelsn Recursive algorithmsn Surface physics (shading models)n Color representationsn Light representationsn Sampling, anti-aliasing and filteringn Geometric opticsn Acceleration techniquesn Texture mapping

Page 4: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

4

sj

sk

Page 5: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

5

Calculating Primary Raysn Given (in world coordinates)n Camera (eye point) location On Camera view out direction (Zv)n Camera view up vector (Yv)n Distance to image plane (d)n Horizontal camera view angle (q)n Pixel resolution of image plane (hres, vres)

n Calculate set of rays (d) that equallysamples the image plane

Calculate Preliminary Valuesn Camera view side direction (Xv)n Zv ¥ Yv

n Horizontal length of image plane (sj)n Next slide

n Vertical length of image plane (sk)n sk = sj • (vres / hres)n Assume square pixels

n Calculating sjn h = d • tan(q/2)n sj = 2hn sj = 2d • tan(q/2)

Calculate Preliminary Valuesn Position of top left pixel (P0,0)n O + d * Zv - (Sj/2) * Xv + (Sk/2) * Yv

All in worldcoordinates!

Page 6: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

6

Calculate Those Rays!n P0,0 + a Xv - b Yv sweeps out image planen 0 £ a £ Sj; 0 £ b £ Sk

for (j=0; j++; j < hres)for (k=0; k++; k < vres) {

dj,k = (P0,0 + Sj*(j/(hres-1)) * Xv - Sk*(k/(vres-1)) * Yv) - O;

d’j,k = dj,k / | dj,k | ;Image[i,j] = ray_trace(d’j,k , Scene);

}

Page 7: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

7

Page 8: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

8

Parametersn X and Y resolution of imagen Camera location & directionn Distance between camera & image planen Camera view anglen Distance between pixelsn These are not independent!n Goal Æ Choose your independent

variables and calculate your d’s

Ray-Sphere Intersection

G. Drew KesslerLarry HodgesGeorgia Institute ofTechnology

Page 9: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

9

Ray/Sphere Intersection(Algebraic Solution)Ray is defined by R(t) = Ro + Rd*t where t > 0.

Ro = Origin of ray at (xo, yo, zo)Rd = Direction of ray [xd, yd, zd] (unit vector)

Sphere's surface is defined by the set of points{(xs, ys, zs)} satisfying the equation:

(xs - xc)2 + (ys - yc)2 + (zs - zc)2 - rs2 = 0

Center of sphere: (xc, yc, zc)Radius of sphere: rs

Possible Cases of Ray/SphereIntersection

1 2

34

5

1. Ray intersectssphere twice with t>0

2. Ray tangent tosphere

3. Ray intersectssphere with t<0

4. Ray originatesinside sphere

5. Ray does notintersect sphere

Solving For tSubstitute the basic ray equation:

x = xo + xd*ty = yo + yd*tz = zo + zd*t

into the equation of the sphere:(x0 + xdt - xc)2 + (y0 + ydt - yc)2 + (z0 + zdt - zc)2 - rs

2 = 0This is a quadratic equation in t: At2 + Bt + C = 0,

whereA = xd

2 + yd2 + zd

2

B = 2[xd(x0 - xc) + yd(y0 - yc) + zd(z0 - zc)]C = (x0 - xc)2 + (y0 - yc)2 + (z0 - zc)2 - rs

2

Note: A=1

Relation of t to IntersectionWe want the smallest positive t - call it ti

t0

t1

t1

t0Discriminant = 0

Discriminant < 0

t1

t0

˜˜

¯

ˆ

ÁÁ

Ë

Ê -+-=

˜˜

¯

ˆ

ÁÁ

Ë

Ê ---=

2

4

2

4

2

1

2

0

ACBBt

ACBBt

Page 10: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

10

Actual IntersectionIntersection point, (xi, yi, zi) = (xo+xd*ti, yo+yd*ti,

zo+zd*ti)Unit vector normal to the surface at this point is

N = [(xi - xc) / rs, (yi - yc) / rs, (zi - zc) / rs]If the ray originates inside the sphere, N should

be negated so that it points back toward thecenter.

N N

Summary (Algebraic Solution)1. Calculate A, B and C of the quadratic intersection equation2. Calculate discriminant (If < 0, then no intersection)3. Calculate t04. If t0 < 0, then calculate t1 (If t1 < 0, no intersection point on

ray)5. Calculate intersection point6. Calculate normal vector at point

Helpful pointers:n Precompute rs

2

n Precompute 1/rsn If computed t is very small then, due to rounding error, you

may not have a valid intersection

Ray-Triangle Intersection

Fredo DurandBarb CutlerMIT

Page 11: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

11

Page 12: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

12

Matrix A

|A| ’ determinant of matrix A

Page 13: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

13

Calculate Intersection Pointn Is b + g ≤ 1?n Are b and g both non-negative?n Is t non-negative?n If so, you’ve got an intersection!n P = R + tD

Design Your Ray Tracer!n “Novice programmers often neglect the design

phase, instead diving into coding without givingthought to the evolution of a piece of softwareover time. The result is a haphazard, poorlymodularized code which is difficult to maintainand modify. A few minutes of planning short-termand long-term goals at the beginning is time wellspent.”n Paul Heckbert, “Writing a Ray Tracer”

n Read this chapter!

Modular Functionalityn Read and write image filesn Create hierarchical geometric modelsn Support several geometric primitivesn Geometric calculations & parameters

n Ray-object intersectionsn Normalsn Bounding boxesn Color & surface propertiesn Texture maps

n Intersect arbitrary ray with scenen Stop at first intersection (shadow rays)

n Adaptive sampling of image planen Light properties

Page 14: CS 586/480 Class Topics and Objectives Computer Graphics IIdavid/Classes/CS586/... · Class Structure nWeekly lectures & reading assignments n7 programming assignments nPost images

14

Progression of Assignmentsn Basic ray tracer

n Triangle/sphere intersection. No shading.n Hierarchical geometric model

n Triangle mesh. Still no shading.n Simple shading and point light sourcesn Acceleration techniquesn Adaptive super-sampling/anti-aliasingn Shadows and reflectionsn 2D/3D texture mappingn No transparency/refraction :--(

Wrap Upn First programming assignmentn Due 10/10/04n Go to web page

n Grad students need to pick a presentationdate and paper for next week