cs 586/480 class topics and objectives computer graphics iidavid/classes/cs586/... · class...
TRANSCRIPT
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
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
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
4
sj
sk
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!
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);
}
7
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
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
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
11
12
Matrix A
|A| ’ determinant of matrix A
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
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