assignment 5 (ray casting) extensiongroups.csail.mit.edu/graphics/classes/6.837/f02/... ·...
TRANSCRIPT
Lecture 12: Thursday, 17 October 2002
Assignment 5 (Ray Casting) extensionEye ray generation; ray-primitive intersectionNew due date is Monday, 21 October at 5pm
Assignment 6 (Ray Tracing) extensionShadows, reflection, refraction, super-samplingNew due date is Monday, 28 October at 5pm
Adjusted office hours:Thursday (today):
Addy, 4-7pm, W20 Linux ClusterProf. Durand, 4-6pm, Bldg. 4 SGI Cluster
Friday:Prof. Teller, 3-5pm, W20 Linux Cluster
Monday:Addy, 10am-Noon, NE43-256Prof. Durand, 2-4pm, NE43-254
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 1
Today
Planning for the second half of the termGetting started on your final team projects
Lecture: Ray TracingContrast scan-conversion, ray casting, ray tracingAppropriate physical units for ray tracingRay tracing pseudocode (Assignments 5 & 6)Ray tracing extensions
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 2
Final Projects
Start thinking about what you’d like to do!Animation? Game? Visualization? Algorithm? Interaction method? Etc.Representative final project reports linked from F99 course page
Team-building page, with list of past project titles, athttp://graphics.lcs.mit.edu/classes/6.837/F02/projects/teams.htm
Enter a brief description of your project idea or interests(along with your contact info, relevant background/skills, etc.) there
Next Thursday, in class:Brain-storming and team-building sessionCome with project ideas in mind; we’ll discuss as a groupStudents watching off-line: come to Prof.s’ office hours
Teams formed, project proposals due by November 1That’s two weeks from tomorrow !
Thereafter, weekly meetings with TA through end of term
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 3
Scan Conversion: Visibility Resolution
“Feed-forward” rendering method, one polygon at a timePolygons issued in “immediate mode” to graphics pipelineFull-frame, single raster, or single-pixel depth bufferVisibility (depth) information computed many times at each pixel
Limitations of scan-conversion method for visibility:Restricted to scan-convertable primitives (simple surface types)Requires polygonalization (& tessellation choice) for all primitivesCauses faceting (geometric) artifacts at silhouettes, interior
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 4
Scan Conversion: Shading Computation
Shading computed with a constant amount of stateTypically, small number of hardware-supported light sources
Local shading computation f (position, material, light, viewer)Evaluated at polygon vertices, Gouraud interpolated
Limitations of local shading computation & interpolation:Cartoonish look; incorrect highlights; no
shadows (occlusion of light sources)secondary illumination (reflection)transmission (transparency)focusing effects (refraction)
No obvious way to add these effects to “local” shading model
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 5
Ray Casting for Analytic Geometry Sampling
Address Visibility, Shading separatelyResolve visibility per-pixel using ray-primitive intersectionEvaluate local lighting model once at each visible pixel
eye
����������������������������������������������������������������������������������������������������������������������������������
eye
p
n
p
n
ρ
ρ
light source
(no)
Use routine Shade() for lighting evaluation (Phong model):
// Shade obj surface at point ShadeP, normal ShadeN,
// as seen along direction Along
Radiance Shade ( Object obj, Ray Along,
Point ShadeP, Vector ShadeN ) {
... // sum Phong term for each light
}
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 6
Ray Casting with “Analytic” Visibility
Hit Cast ( Point R, Ray D ) {
find minimum t>0 such that R + t * D hits object
if ( object hit )
return ( object identifier, t, N )
else
return ( background object identifier, t )
} // Cast
eye
����������������������������������������������������������������������������������������������������������������������������������
% ivray raycast.iv -e raycast.env -s L
FrameBuffer Render ( frustum, viewport ) {
Framebuffer FB[w][h];
For each raster y
For each pixel x
E = direction from eye through pixel x, y
hit = Cast ( eye, E );
FB[x][y] = Shade ( hit.obj, E, eye + hit.t * E, hit.N );
return FB
} // Render by Ray Casting
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 7
Ray Casting for Visibility
Advantages?Smooth variation of silhouettes; depth, normal, shading
Generality: can render anything withwhich a ray can be intersected !
Compactness of representationDisadvantages?
Time complexity (N objects, R pixels)Wasted work at “background” pixels
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 8
Ray Casting and Shadow Tests
Idea (Appel, 1968):Cast ray from eye through each pixelDetermine closest object along ray (and visible point there)Shade by summing contributions from unoccluded lights
Non-recursive! (But improved quality, realism)(Primary) shadows handled w/ existing capability!
eye
����������������������������������������������������������������������������������������������������������������������������������
light
light
��������������������
% ivray raycast.iv -e raycast.env -s S
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 9
Recursive Ray Tracing
Extend to reflection, refractionShading must take entire scene into accountRay tracing is a “global illumination algorithm”
Idea: Light originates at light sources, so“trace” photon paths from the light source
Known as Forward Ray Tracing:At each interaction, surface properties dictate
absorption, reemission, transmission probability
eye
O
light
����������������������������������������������������������������������������������������������������������������������������������
Typically expressed as BRDF f (θi, φi, θe, φe) ∈ [0..1]Disadvantages of Forward Ray Tracing?
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 10
Forward Ray Tracing
Disadvantagesvery few of the photons end up at the eyevery hard to know in which directions
photons should be sentenormous number of cycles expended per photon
(can be ameliorated by packet tracing)result is usually objectionable noise
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 11
Backward Ray Tracing
Insight: we “see” only those rays that arrive at the eyeSo, trace “eye rays” E backward into scene
Find contributions to shading (only) at surface pointsEvaluate contributions along the viewing direction
eye
O
light
����������������������������������������������������������������������������������������������������������������������������������
N
R
S
T
E
% ivray raycast.iv -e raycast.env -s R -d 1
Likely directions in which to sample:Shadow rays S (to light sources)Reflection rays R (along specular direction)Refraction rays T (along refraction direction)
Note: Shading operation is recursive !
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 12
Recursive Ray Tracing: Examples
% ivray raycast.iv -e raycast.env -s R -d 0
% ivray raycast.iv -e raycast.env -s R -d 1
% ivray sphereplane.iv -e raycast.env -s R -d 2
Experiment with reference ivray to understand these
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 13
Physical Units for Ray Tracing
From radiometry, measurement of EM energy (distinctfrom photometry, visual sensation of EM energy)
Radiance L:[power] / ([src area] [rcvr steradian])
“Power per unit projected area perpendicularto the ray per unit solid anglein the direction of the ray”
dA dω
A dA
POWER
AREA= RADIOSITYTOTAL EXITANT POWER
POWER
AREA STERADIAN= RADIANCE
SOURCERECEIVER
AS SEEN FROM SOURCE
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 14
Radiance Propagation
Consider two virtual spheres of radius r1, r2centered at differential source element dA, and
the patches R1,R2 defined on them by dω
dA
dω
R2
R1
Power flowing through R1 is P1, through R2 is P2
L1 =P1
A1 · dω1L2 =
P2
A2 · dω2
How are L1 and L2 related?
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 15
Radiance Propagation
Clearly P1 = P2; A1 = A2 = dA; dω1 = dω2
dA
dω
R2
R1
L1 =P1
dA · dω1=
P2
dA · dω2= L2
Radiance is constant along a ray!(What does this assume about propagation medium?)
Analogous derivation for fixed-size receiver
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 16
Response of a Sensor due to Radiance
Consider a small exposure meter whose field of viewimpinges on a large, uniformly illuminated surfaceSensors: retinal cells; film grains; CCD elements...
(after Hanrahan, 1993)
Aperture Sensor
What is total power impinging on sensor?Proportional to total surface area visible to sensorProportional to solid angle subtended by sensor
as viewed from the source(this is just the fraction of source’s energy received by the sensor)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 17
Response of a Sensor due to Radiance
Once again, radial dependence cancels; conclude:Sensor response proportional to surface radiance!
(after Hanrahan, 1993)
Aperture Sensor
Thus, for two reasons:radiance constant along a raysensor response proportional to radiance
radiance is the quantity that shouldbe associated with a propagating ray!
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 18
Radiance and Reflection
Suppose a light source illuminates a surface patchConsider a viewing ray bouncing among perfect mirrors (ks = 1)
dA
dωL
E
Is there an equivalent situation with no mirrors?Now assign mirrors coefficients of reflection ks, kd < 1
What happens?
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 19
Reflection, Transmission Rays
Radiance is attenuated by reflection!
dA
dω
L
kS1
LkS1
kS2
LkS1 kS2
In these units, no attenuation due to distance from surface
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 20
Backward Ray Tracer Pseudo-Code
global int maxdepth = d; // trace only d bounces
RayTrace ( frustum, viewport ) {
For each raster y
For each pixel x
E = ray from eye through pixel x, y
FrameBuffer[x][y] = Trace ( eye, E, 1 )
} // RayTrace
Note: RayCast() returns hit structure containing:scene object hit->objectintersection parameter hit->tsurface point hit->P, normal hit->N
Radiance Trace ( Point R, Ray D,
int depth ) {
Hit *hit = RayCast ( R, D );
if ( hit )
return Shade ( hit->object, D, hit->P, hit->N, depth );
else
return Background ( R, D );
} // Trace
Note: Trace() returns a Radiance valueFor now, we’ll interpret this as an RGB valueLater in term, we’ll connect physical units to perceptual sensation
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 21
Backward Ray Tracer Pseudo-Code
// Shade obj surface at point ShadeP, normal ShadeN,
// as seen along direction Along
Radiance Shade ( Object obj, Ray Along,
Point ShadeP, Vector ShadeN, int depth ) {
Radiance r = (0,0,0); // used to aggregate lighting terms
// collect ambient contribution
r += environment’s ambient radiance;
// collect local illumination contributions
For ( each light ) {
Ray sRay = Ray from point shadeP to light source;
if ( sRay . ShadeN > 0 ) {
r += diffuse contribution * light visibility
r += specular contribution * light visibility
}
}
// terminate recursion
if ( depth == maxdepth ) return r;
// continued
...
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 22
Backward Ray Tracer Pseudo-Code
...
// Shade() continued
if ( object reflective ) {
Radiance rRefl;
Ray rRay = reflection ray direction;
rRefl = Trace ( ShadeP, rRay, depth + 1 )
r += rRefl * material specular coefficient
}
if ( object transparent ) {
Ray tRay = refraction ray direction;
if ( not total internal reflection ) {
Radiance rRefr;
rRefr = Trace ( ShadeP, tRay, depth + 1 )
r += rRefr * material transmission coefficient
}
else {
// ... TBD (Asst 6)
}
}
// return aggregate radiance
return r;
} // Shade
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 23
Revised Backward RT Pseudo-Code
Want to avoid spending many cycles for little radianceParameter maxdepth has no notion of radiance
Trace takes an additional parameter, weightand returns a Radiance value
We define a new global: float minweight
global int maxdepth = d; // trace only d bounces, or
global float minweight = w; // until attenuation exceeds w
RayTrace ( resolution, view frustum ) {
For each raster y
For each pixel x
E = ray from eye through pixel x, y
FrameBuffer[x][y] = Trace ( eye, E, 1, 1.0 )
} // RayTrace
We modify Trace() to take weight parameter:Radiance Trace ( Point R, Ray D,
int depth, float weight ) {
Hit *hit = RayCast ( (R,D) );
if ( hit )
return Shade ( hit->object, D, hit->P,
hit->N, depth, weight )
else
return Background ( R, D )
} // Trace
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 24
Revised Shade() Pseudo-Code
// Shade obj surface at point ShadeP, normal ShadeN,
// as seen along direction Along
Radiance Shade ( Object obj, Ray Along,
Point ShadeP, Vector ShadeN,
int depth, float weight ) {
... // same as previous pseudo-code
// conditionally spawn reflection ray
if ( obj->k_s * weight >= minweight ) {
Ray rRay = reflection ray
radiance += obj->k_s
* Trace ( ShadeP, rRay,
depth + 1, obj->k_s * weight )
}
// conditionally spawn transmission ray
if ( obj->k_t * weight >= minweight ) {
Ray tRay = refraction ray
if ( not total internal reflection )
radiance += obj->k_t
* Trace ( ShadeP, tRay,
depth + 1, obj->k_t * weight )
}
return radiance;
} // Shade
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 25
Example Call Stack of Trace, Shade
kS1
kS2
source
R
D
R’
N1D’
R’’
N2 D’’
Trace ( R, D, 1, 1.0 );
Shade ( object, D, R’, N1, 1, 1.0 ) // 1st surface
// radiance += k_s1 * Trace ( R’, D’, 2, k_s1 )
tmp = Trace ( R’, D’, 2, k_s1 )
Shade ( object, D’, R’’, N2, 2, k_s1 ) // 2nd surface
radiance += k_s2 * f ( D’, R’’, N2, src )
...
return radiance L; // k_s2 * ... src
radiance += k_s1 * L;
return radiance; // k_s2 * k_s1 * ... src
return radiance; // k_s2 * k_s1 * ... src
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 26
Ray Spawning / Termination
Termination conditions:maxdepth exceededminweight arises from multiple reflectionsRay leaves the scene (encounters background)
When might these criteria work poorly?Example problematic scenes?
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 27
Recap: Ray Tracer Components
Sample generatorOne eye-ray per pixel
(You will do super-sampling in Asst 6)Intersection finder
Workhorse function RayCast
Simple bounding-box test for accelerationShader, Secondary Ray generator
Radiance Aggregation (base case)Shadow (uses RayCast for shadow testing)ReflectionRefraction
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 28
Assignments 5 & 6 Infrastructure
Invoking ivray:% ivray [-d maxdepth] [-s shademode]
where shademode controls the shading function as:
[-s shademode (F,N,A,L,S,R)
Flat (use material base color)
Normal (use object normal as color)
Ambient (use ambient light only)
Local (use ambient, diffuse, & specular)
Shadows ("L" mode, with shadowing)
Recursive ("S" mode, with recursive rays)]
Other command-line arguments:Recursion termination conditionsSampling, anti-aliasing, etc.
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 29
Ray Tracing Extensions
Modify geometry (position or normal)Modify material characteristics (ray spawning)Simulate optical paths, camera geometry, wavelength distributionSample temporally to simulate motionAdaptive/hybrid sampling strategiesVisualizationAcceleration data structures (future lecture)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 30
Bump Mapping
Perturb normals according to texture or function
(Stanford Graphics Lab)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 31
Displacement Mapping
Perturb surface position; account for shadows, interreflection etc.
(Utah Graphics Lab)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 32
Glossy Materials
Displace origin of reflection, transmission rays
(Andy Whittock, Toonnation)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 33
Soft Shadows
Subdivide and sample area light sources
(Cornell Computer Graphics Lab)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 34
Optical Effects
Simulate camera optical path for various effects:Depth of field; barrel distortion; vignetting; etc.
Also, wavelength-dependent effects (e.g., chromatic aberration)(Kolb & Hanrahan, Siggraph ’95)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 35
Caustics
Identify extremal paths from source to surfaces
(Hanrahan & Mitchell, Siggraph ’92)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 36
Motion Blur
Simulate finite (non-zero) shutter speed; sample temporally
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 37
Adaptive Sampling (Gridded)
Idea: Show coarse picture quicklySample along coarse grid, interpolate, refine
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 38
Adaptive Sampling (Radiance-Based)
Idea: Hybrid of ray-tracing, screen-space interpolationSubdivide whenever radiance is discontinuous, or has high gradient
(Research of graphics lab alumna, Kavita Bala, 1990)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 39
Visualization
Show scene, camera, lights, ray intersections etc.Example: Ben Garlick’s SGI demo “flyray”:cd /mit/6.837/demos/flyray/data; ../flyray
(Parallel application)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 40
Next week:
Tuesday: Animation & SimulationThursday: Final Project Brainstorming
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 41
Secondary Rays: Reflection
p
LN
RL
L
L
−L
R
Compute reflection ray R as:
L‖ = N(L · N)
R = L‖ − L⊥= N(L · N) − (L − N(L · N))
= N(L · N) − L + N(L · N)
= 2N(L · N) − L
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 42
Secondary Rays: Refraction
All media have index of refraction ηratio of c (in vacuum) to light speed (in material)Of course, η ≥ 1 for all physical materials
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
N
−N
I
θi
θt
T
M
ηt
ηi
ηt > ηi
sparse
dense
Consider boundary admitting incident (i)and transmitted (t) rays
Snell’s law says that, at this boundary
sin θi
sin θt=
ηt
ηior
ηi sin θi = ηt sin θt
(actually, η depends on λ, causing dispersion)
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 43
Computing Refraction Vector
Plugging it all in:
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
N
−N
I
θi
θt
T
M
ηt
ηi
ηt > ηi
T
T
I
I
T = −ηi
ηtI + N
ηi
ηtcos θi −
√√√√√√√√1 − (ηi
ηt)2(1 − cos2 θi)
Eliminating cosines:
T = −ηi
ηtI + N
ηi
ηtN · I −
√√√√√√√√1 − (ηi
ηt)2(1 − (N · I)2)
What if expression under radical is negative?
MIT 6.837 Computer Graphics Thursday, 17 October 2002 (L12) Page 44