33
1 Computer Graphics 15-462 Announcements Written Assignment 2 out (due March 8)

Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

1Computer Graphics 15-462

AnnouncementsWritten Assignment 2 out (due March 8)

Page 2: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

Advanced Ray Tracing

(Recursive) Ray TracingAntialiasingMotion BlurDistribution Ray TracingRay Tracing and Radiosity

(Recursive) Ray TracingAntialiasingMotion BlurDistribution Ray TracingRay Tracing and Radiosity

Page 3: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

3Computer Graphics 15-462

Assumptions• Simple shading (OpenGL, z-buffering, and Phong

illumination model) assumes:– direct illumination (light leaves source, bounces at most once, enters eye)– no shadows– opaque surfaces– point light sources– sometimes fog

• (Recursive) ray tracing relaxes those assumptions, simulating:

– specular reflection– shadows– transparent surfaces (transmission with refraction)– sometimes indirect illumination (a.k.a. global illumination)– sometimes area light sources– sometimes fog

Page 4: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

4Computer Graphics 15-462

Ray Types for Ray Tracing

Four ray types:– Eye rays: originate at the eye– Shadow rays: from surface point toward light source– Reflection rays: from surface point in mirror direction– Transmission rays: from surface point in refracted direction

Page 5: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

5Computer Graphics 15-462

Ray Tracing Algorithm

send ray from eye through each pixelcompute point of closest intersection with a scene surfaceshade that point by computing shadow raysspawn reflected and refracted rays, repeat

Page 6: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

6Computer Graphics 15-462

Ray GenealogyEYE

L1 L2

Obj1

Obj2

Obj3Eye

Obj1

RAY TREERAY PATHS (BACKWARD)

Page 7: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

7Computer Graphics 15-462

Ray GenealogyEYE

L1 L2

Obj1

Obj2

Obj3Eye

Obj1

RAY TREERAY PATHS (BACKWARD)

L1

L2

T RObj2

Obj3

Page 8: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

8Computer Graphics 15-462

Ray Genealogy

Eye

Obj1

RAY TREERAY PATHS (BACKWARD)

L1

L2

T RObj2

Obj3

EYE

L1 L2

Obj1

Obj2

Obj3

L1

L2

L1

L2R

T R

X XX

Page 9: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

9Computer Graphics 15-462

When to stop?

When a ray leaves the scene

When its contribution becomes small—at each step the contribution is attenuated by the K’s in the illumination model.

[ ]shinynsdlightattaa kkIfIkI )(coscos φθ ++=

EYE

L1 L2

Obj1

Obj2

Obj3

Page 10: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

10Computer Graphics 15-462

Ray Casting vs. Ray Tracing

Ray Casting -- 1 bounce

Ray Tracing -- 2 bounces Ray Tracing -- 3 bounces

Page 11: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

11Computer Graphics 15-462

Ray Tracing—Demo program

http://www.siggraph.org/education/materials/HyperGraph/raytrace/rt_java/raytrace.html

Page 12: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

12Computer Graphics 15-462

Writing a Simple Ray Tracer

Raytrace() // top level functionfor each pixel x,y

color(pixel) = Trace(ray_through_pixel(x,y))

Trace(ray) // fire a ray, return RGB radianceobject_point = closest_intersection(ray)if object_point return Shade(object_point, ray)else return Background_Color

Page 13: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

13Computer Graphics 15-462

Writing a Simple Ray Tracer (Cont.)

Shade(point, ray) /* return radiance along ray */radiance = black; /* initialize color vector */for each light source

shadow_ray = calc_shadow_ray(point,light)if !in_shadow(shadow_ray,light)

radiance += phong_illumination(point,ray,light)if material is specularly reflective

radiance += spec_reflectance * Trace(reflected_ray(point,ray)))

if material is specularly transmissiveradiance += spec_transmittance * Trace(refracted_ray(point,ray)))

return radiance

Closest_intersection(ray)for each surface in scene

calc_intersection(ray,surface)return the closest point of intersection to viewer (also return other info about that point, e.g., surface normal, material properties, etc.)

Page 14: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

14Computer Graphics 15-462

Raytracing Example

http://www.med.osaka-u.ac.jp/pub/cl-comp/saito/raytr/saturn-img.html

Page 15: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

15Computer Graphics 15-462

Raytracing Example

http://www.povray.org/

Page 16: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

16Computer Graphics 15-462

What problems do you see?Images are VERY cleanAlignment of objects and sampling can lead to

unintended patterns

Solution:more raysmore randomness

Page 17: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

17Computer Graphics 15-462

Problem with Simple Ray Tracing: Aliasing

Page 18: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

18Computer Graphics 15-462

Aliasing

Ray tracing gives a color for every possible point in the image

But a square pixel contains an infinite number of pointsThese points may not all have the same colorSampling: choose the color of one point (center of pixel)Regular sampling leads to aliasing

jaggiesmoire patterns

aliasing means one frequency (high) masquerading as another (low)e.g. wagon wheel effect

Page 19: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

19Computer Graphics 15-462

Anti-aliasingSupersampling

Fire more than one ray for each pixel (e.g., a 4x4 grid of rays)Average the results (perhaps using a filter)

blackboard

Page 20: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

20Computer Graphics 15-462

Anti-aliasing: Supersampling

Can be done adaptively–divide pixel into 2x2 grid, trace 5 rays (4 at corners, 1

at center)–if the colors are similar then just use their average–otherwise recursively subdivide each cell of grid–keep going until each 2x2 grid is close to uniform or

limit is reached–filter the result

Page 21: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

21Computer Graphics 15-462

Adaptive Supersampling

• Is adaptive supersampling the answer?– Areas with fairly constant appearance are sparsely sampled (good)– Areas with lots of variability are heavily sampled (good)

• But...– even with massive supersampling visible aliasing is possible when the

sampling grid interacts with regular structures– problem is, objects tend to be almost aligned with sampling grid– noticeable beating, moire patterns are possible

• So use stochastic sampling– instead of a regular grid, subsample randomly– then adaptively subsample

blackboard

Page 22: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

22Computer Graphics 15-462

Supersampling

Page 23: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

23Computer Graphics 15-462

Temporal Aliasing: Motion Blur

Aliasing happens in time as well as space– the sampling rate is the frame rate, 30Hz for NTSC video, 24Hz for film– fast moving objects move large distances between frames– if we point-sample time, objects have a jerky, strobed look

Real media (film and video) automatically do temporal anti-aliasing

– photographic film integrates over the exposure time– video cameras have persistence (memory)– this shows up as motion blur in the photographs

To avoid temporal aliasing we need to filter in time too– so compute frames at 120Hz and average them together (with

appropriate weights)?– a bit expensive

Page 24: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

24Computer Graphics 15-462

Motion Blur

Apply stochastic sampling to time as well as spaceAssign a time as well as an image position to each rayThe result is still-frame motion blur and smooth animation

Jitter time: T = T0 + δ(T1 – T0) for each ray

Page 25: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

25Computer Graphics 15-462

Example of Motion Blur

From Foley et al. Plate III.16

Rendered using distribution ray tracing at 4096x3550 pixels, 16 samples per pixel.

Note motion-blurred reflections and shadows with penumbrae cast by extended light sources.

Page 26: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

26Computer Graphics 15-462

Glossy ReflectionSimple ray tracing spawns only one reflected ray—perfect reflectionBut Phong illumination models a cone of rays

Produces fuzzy highlightsChange fuzziness (cone width) by varying the shininess parameter

Can we generate fuzzy highlights?YesBut there’s a catch

we can’t do light reflected from the fuzzy highlight onto other objects

A more accurate model is possible using stochastic samplingStochastically sample rays within the cone Sampling probability drops off sharply away from the specular angleHighlights can be soft, blurred reflections of other objects

Page 27: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

27Computer Graphics 15-462

Soft ShadowsPoint light sources produce sharp shadow edges

– the point is either shadowed or not– only one ray is required

With an extended light source the surface point may be partially visible to it

– only part of the light from the sources reaches the point– the shadow edges are softer– the transition region is the penumbra

Accomplish this by– firing shadow rays to random points on

the light source– weighting them by the brightness– the resulting shading depends on

the fraction of the obstructedshadow rays

source

surface

opaque object

shadowrays

Page 28: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

28Computer Graphics 15-462

Soft Shadows

blackboard

firing shadow rays to random points on the light sourceweighting them by the brightnessthe resulting shading depends onthe fraction of the obstructed shadow

rays

Page 29: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

29Computer Graphics 15-462

Soft Shadows

fewer rays,more noise

more rays,less noise

Page 30: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

30Computer Graphics 15-462

Depth of FieldThe camera model only approximates real optics

– real cameras have lenses with focal lengths– only one plane is truly in focus– points away from the focus project as disks– the further away from the focus the larger the disk

The range of distances that appear in focus is the depth of field

Simulate this using stochastic sampling through different parts of the lens

Page 31: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

31Computer Graphics 15-462

Distribution Ray Tracingdistribute rays throughout a pixel to get spatial antialiasingdistribute rays in time to get temporal antialiasing (motion blur)distribute rays in reflected ray direction to simulate glossdistribute rays across area light source to simulate penumbras

(soft shadows)distribute rays across eye to simulate depth of fielddistribute rays across hemisphere to simulate diffuse

interreflection

also called: “distributed ray tracing” or stochastic ray tracing

aliasing is replaced by less visually annoying noise.powerful idea! (but requires significantly more computation)

Page 32: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

32Computer Graphics 15-462

Examples

http://www.graphics.cornell.edu/online/tutorial/raytrace/

Including texture map and bump map

Page 33: Announcementsjkh/462_s07/14_raytracing.pdf · Microsoft PowerPoint - 22_raytracing.ppt Author jkh Created Date 2/28/2007 3:32:20 PM

33Computer Graphics 15-462

Examples

http://www.graphics.cornell.edu/online/tutorial/raytrace/

Semi-transparent glass with etched image.