8
EECS 487: Interactive Computer Graphics Lecture 29: Distributed Ray Tracing Ray Tracing Introduction and context ray casting Recursive ray tracing shadows reflection refraction Ray tracing implementation Distributed Ray Tracing anti-aliasing motion blur depth-of-field glossy surface translucency soft-shadows Why Does Ray Tracing Look Obviously Computer Generated? Crisp images . . . too “perfect”: surfaces are perfectly shiny glass is perfectly clear everything in perfect focus every object is completely still even the shadows have perfect silhouettes but . . . up close, edges are jagged Replace each single ray with a distribution of multiple rays a.k.a. distribution ray tracing average results together Multiple rays everywhere: multiple primary rays through a pixel: supersampling: distribute rays spatially motion blur: distribute rays temporally depth of field: distribute rays through a lens multiple shadow rays to sample an area light soft shadows multiple reflection rays glossy surfaces (blurry reflection, rough specular) multiple refraction rays translucency “Distributed” Ray Tracing multiple secondary rays r n d l 1 t l 2 shadow rays (primary ray)

Computer Graphics - Electrical Engineering and Computer ...web.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · Computer Graphics Lecture 29: • Distributed Ray Tracing Ray

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Computer Graphics - Electrical Engineering and Computer ...web.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · Computer Graphics Lecture 29: • Distributed Ray Tracing Ray

EECS487:InteractiveComputerGraphicsLecture29:•  DistributedRayTracing

RayTracing

Introductionandcontext•  raycasting

Recursiveraytracing•  shadows•  reflection•  refraction

Raytracingimplementation

DistributedRayTracing•  anti-aliasing• motionblur• depth-of-field• glossysurface•  translucency•  soft-shadows

WhyDoesRayTracingLookObviouslyComputerGenerated?Crispimages...too“perfect”:•  surfacesareperfectlyshiny

•  glassisperfectlyclear

•  everythinginperfectfocus

•  everyobjectiscompletelystill

•  eventheshadowshaveperfectsilhouettes

•  but...upclose,edgesarejagged

Replaceeachsingleraywithadistributionofmultiplerays�a.k.a.distributionraytracing•  averageresultstogether

Multiplerayseverywhere:• multipleprimaryraysthroughapixel:•  supersampling:distributeraysspatially•  motionblur:distributeraystemporally•  depthoffield:distributeraysthroughalens

• multipleshadowraystosampleanarealight•  softshadows

• multiplereflectionrays•  glossysurfaces(blurryreflection,roughspecular)

• multiplerefractionrays•  translucency

“Distributed”RayTracing

multiplesecondaryrays

r n

−dl1

t

l2shadow rays

(primary ray)

Page 2: Computer Graphics - Electrical Engineering and Computer ...web.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · Computer Graphics Lecture 29: • Distributed Ray Tracing Ray

Supersampling

Insteadofpointsamplingthecolorofapixelwitharay,wecastmultipleraysfromeye(primaryrays)throughdifferentpartsofonepixelandaveragedowntheresults•  forexample,castn×nsub-pixelrays,andaveragetheresultstogether:

c pixel =1n2

csubpixel (i, j )j=0

n−1

∑i=0

n−1

Curless08

Non-fixedSamplingPatterns

Super-samplingdoesn’teliminatealiasing,itsimplypushesittohigherfrequencies

•  supersamplingcapturesmorehighfrequencies,butfrequenciesabovethesupersamplingratearestillaliased

•  fundamentally,problemisthatthesignalisnotbandlimited�aliasinghappens

Otherthanregular,fixedsamplingpattern,samplingcanalsobestochastic(a.k.a.,random,probabilistic,orMonteCarlo)

Durand08

StochasticSupersamplingSamplestakenatnon-uniformlyspacedrandomoffsets

Replaceslow-frequencyaliasingpatternbynoise,whichislessobjectionabletohumans

However,withrandomsampling,wecouldgetunlucky,e.g.,allsamplesinonecorner• over80%ofthesamplesareblackwhilethepixelshouldbelightgrey

onepixel Durand08

uniform

stochastic

StratifiedSamplingTopreventclusteringoftherandomsamples,dividedomain(pixel)intonon-overlappingregions(sub-pixels)calledstrata

Takeonerandomsampleperstratum

Jitteredsamplingisstratifiedsamplingwithper-stratumsampletakenatanoffsetfromthecenterofeachstratum:•  onesampleperstratum•  randomlyperturbthesamplelocation•  sizeofperturbationvectorlimitedbythesubpixeldistance

•  patentedbyPixar!

onepixel

Durand

Page 3: Computer Graphics - Electrical Engineering and Computer ...web.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · Computer Graphics Lecture 29: • Distributed Ray Tracing Ray

Aliasinghappensintimeaswellasinspace•  thesamplingrateistheframerate:

30Hz(NTSC),25Hz(PAL),24Hz(film)•  ifwepoint-sampletime,objectshaveajerky,strobbedlook,e.g.,samplingat¼rotation

•  ormovebackward,e.g.,sampledat¾rotation

•  seehttp://www.michaelbach.de/ot/mot_wagonWheel/index.html•  fastmovingobjectsmovelargedistancesbetweenframes•  becarefulwhendoingcollisiondetection!

TemporalAliasing:MotionBlur

Curless,Hanrahan

Filmautomaticallydoestemporalanti-aliasing•  photographicfilmintegratesovertheexposuretime•  thisshowsupasmotionblurinthephotographs

TemporalAliasing:MotionBlur

Hodgins06,Londonetal.

Toavoidtemporalaliasingweneedtoaverageovertimealso

Sampleobjectstemporally•  castmultipleraysfromeyethroughthesamepointineachpixel•  eachoftheseraysintersectsthesceneatadifferenttime:r(e, d, t)•  averageoutresults

Theresultisstill-framemotionblurandsmoothanimation

TemporalAliasing:MotionBlur

Hodgins06,Durand08,Merrell08

t0 t1 t2

DepthofFieldandAperture

Objectisconsideredinfocusifonan8×10printviewedatadistanceof10”,diameterofC ≤ 0.01”(1930’sstandard!)

LaterhumanstudyshowsthatCshouldbe≤ 0.003”

normankoren.com/Tutorials/MTF6.html

Thinlensequation1/s + 1/d = 1/fwherefislensfocallengtha =apertureC = circleofconfusion

object imageplane

f: front;r:rear

depthoffield:distancesforwhich

C ≤ 0.01”

Page 4: Computer Graphics - Electrical Engineering and Computer ...web.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · Computer Graphics Lecture 29: • Distributed Ray Tracing Ray

DepthofFieldRealcamerashavelenseswithfocallengths•  onlyoneplaneistrulyinfocus•  pointsawayfromthefocusprojectas“circleofconfusion”•  thefurtherawayfromthefocusthelargerthecircle

Therangeofdistancesthatappearinfocusisthedepthoffield•  smallerapertures(largerf-numbers)resultingreaterdepthoffield

Depthoffieldcanbesimulatedbydistributingprimaryraysthroughdifferentpartsofalensassembly

Hart08

Standardraytracing:• allraysemanatefromB• pixelDusesrayBD• pixelE,forobjectbehind(orinfrontof)thefocalplane,usesrayBE

Distributedraytracing:•  raysemanatefromlensplane• pixelDusesraysAD, BD, CD• pixelEaveragesraysAE, BE, CE•  tosimulatemoreaccurately,firstrefractprimaryraysthroughlens

B

C

D

E

Putimageplaneatfocalplane

Startraysatlensplane

A

DoF:Implementation

Hart08

Orsimplyselecteyepositionsrandomlyfromasquareregion

DoF:Implementation

/Shirley02

GlossySurfacesRaytracingsimulatesperfectspecularreflection,trueonlyforperfectmirrorsandchromesurfacesMostsurfacesareimperfectspecularreflectors:•  surfacemicrofacetsperturbdirectionofreflectedrays•  reflectraysinaconearoundperfectreflectiondirection• Phongspecularlightingtriestofakethiswiththemshiexponent

RTR,TP3

Page 5: Computer Graphics - Electrical Engineering and Computer ...web.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · Computer Graphics Lecture 29: • Distributed Ray Tracing Ray

GlossyReflections:ImplementationForeachray-objectintersection•  insteadofshootingonerayintheperfectspecularreflection(mirror)direction,•  stochasticallysamplemultiplerayswithintheconeaboutthespecularangle•  strengthofreflectiondropsoffrapidlyawayfromthespecularangle,•  probabilityofsamplingthatdirectionshouldfalloffsimilarly

perfectmirror θθ

polishedsurface θθ

Hart08,Yu08,Durand08

GlossyReflections

near farobject object

RTR,Curless09,Hart08

Insteadofmirrorimages:•  highlightscanbesoft•  blurredreflectionsofobjects

Nearbyobjectsreflectmoreclearlybecausedistributionstillnarrow

Fartherobjectsreflectmoreblurrybecausedistributionhasspread

TranslucencySimilar,butforrefraction•  insteadofdistributingraysaroundthereflectionray,distributethemaroundtherefractedray

Transparent Translucent

Merrell08,Curless08 Akenine-Möller02

receiver

occluder/caster

self-shadowing:bothoccluderandreceiver

ShadowsDarknesscausedwhenpartoralloftheilluminationfromalightsourceisblockedbyanoccluder(shadowcaster)

shadowshadow

Page 6: Computer Graphics - Electrical Engineering and Computer ...web.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · Computer Graphics Lecture 29: • Distributed Ray Tracing Ray

HardandSoftShadowsPointlightsourcesgiveunrealistichardshadows

Lightsourcesthatextendoveranarea(arealightsources)castsoft-edgedshadows•  somepointsseeallthelight:fullyilluminated•  somepointsseenoneofthelightsource:theumbra•  somepointsseepartofthelightsource:thepenumbra

Durand,Chenney

umbra penumbrapenumbra

arealightsource

occluder

pointlightsource

RayTracingAreaLightSourcetoCreateSoftShadowsCastmultipleshadowraysfromsurface,distributedacrossthesurfaceofthelight:eachraytoadifferentpointonthelightsource• insidetheumbra,noshadowraysgetthroughtolight

• insidethepenumbra,someshadowraysgetthroughandsomepartsofthearelightisvisible

• outsidethepenumbra,allshadowraysgetthrough

Chenney

outsidethepenumbra

insideumbra

inthepenumbra

shadowrays

RayTracingAreaLightSourcetoCreateSoftShadowsAteachpoint,sumthecontributionsofshadowraysfromthatpointtofindthestrengthofshadow:hits/rays=%illuminated

Durand20%illuminated

SamplingAreaLightAnti-aliasing:•  breakapixelintoagridofsub-pixelsanddistributeraysoverthesub-pixels

Soft-shadows:•  breakanarealightintoagridofN = n×npointlights,eachwith1/N-ththeintensityofthebaselight•  samplethelight,notthepixel•  eachprimaryraygeneratesmultipleshadowraysperlight

Shirley02

Page 7: Computer Graphics - Electrical Engineering and Computer ...web.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · Computer Graphics Lecture 29: • Distributed Ray Tracing Ray

ClassicRecursiveRayTracing

trace(ray) { (point, normal) = ray.intersect(scene); return shade(point, normal) }

shade(pt, normal) { color = 0 for each light source { if(!intersect(shadow_ray, scene)) color += direct_illumination } if(specular) color += F * trace(reflected_ray) // also add transmitted color… return color }

render() { for each pixel { generate primary/viewing ray pixel_color = trace(primary_ray) } }

DistributedArea-LightSampling trace(ray) {

(point, normal) = ray.intersect(scene); return shade(point, normal) }

shade(pt, normal) { color = 0 for each light source {

generate N random shadow rays foreach (shadow ray) {

if(!intersect(shadow_ray, scene)) color += direct_illumination*1/N

} } if(specular) color += F * trace(reflected_ray) // also add transmitted color… return color }

render() { for each pixel { generate primary/viewing ray pixel_color = trace(primary_ray) } }

supersampledraytracing:oneshadowraypereyeraycentered

distributedraytracing:16shadowrayspereyerayuniform

Pharr

SampleDistribution?Uniformdistributiongivesrisetosharptransitions/patternsinsidepenumbra4eyeraysperpixelinbothcases:

StochasticSamplingofAreaLight

Arealightrepresentedasarectanglein3D,eachray-objectintersectionsamplesthearea-lightatrandom:r = c + ξ1a + ξ2 b,where ξ1andξ2arerandomvariablesStratifiedsamplingofthearealightwithsamplesspaceduniformlyplusasmallperturbation{ r(i, j), 0 ≤ i, j ≤ n−1 }

Shirley

a

bc

r(0, 0)

r(3, 3)

arealight

Page 8: Computer Graphics - Electrical Engineering and Computer ...web.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · Computer Graphics Lecture 29: • Distributed Ray Tracing Ray

stochasticraytracing:4eyeraysperpixeloneshadowraypereyerayrandom

distributedraytracing:4 eye rays per pixel�16shadowrayspereyerayjitteredPharr

SamplingRate

Aswithstochasticsuper-samplingforanti-aliasing,lightsamplingratemustbehigh,otherwisehigh-frequencynoisebecomesvisible