Post on 09-Mar-2021
transcript
EECS487:InteractiveComputerGraphicsLecture27:• IntroductiontoGlobalIlluminationandRayTracing
RayTracing
Introductionandcontext• raycasting
Recursiveraytracing• shadows• reflection• refraction
Raytracingimplementation
DistributedRayTracing• anti-aliasing• soft-shadows• motionblur• depth-of-field• glossysurface• translucency
GlobalIlluminationComputesthecoloratapointintermsoflightdirectlyemittedbylightsourcesandoflightindirectlyreflectedbyandtransmittedthroughotherobjects,allowingforcomputationofshadows,reflection,refraction,caustics,andcolorbleedLightpathsarecomplex,notlight�triangle�pixelNaturefindsequilibriumefficientlyComputersstruggleL
Akeley
PipelinedRasterization
PerformprojectionofverticesRasterizetriangle:findwhichpixelsshouldbelitComputeper-pixelcolorTestvisibility,updateframebuffer
Durand
RayTracing
Hanrahan,Yu,Curless,Akeley
Canweproducemorerealisticresultsifwerenderascenebysimulatingphysicallighttransport?TheGreeksquestionedthenatureoflight:dolightraysproceedfromtheeyetothelightorfromthelighttotheeye?Moderntheoriesoflighttreatitasbothawaveandaparticle
image(pixels)
lights(photons)
objects(triangles)
viewer
GeometricOpticsWewilltakeacombinedandsomewhatsimplerviewoflight–theviewofgeometricoptics
Lightsourcessendoffphotonsinalldirections• modeltheseasparticlesthatbounceoffobjectsinthescene• eachphotonhasawavelengthandenergy(colorandintensity)• whenphotonsbounce,someenergyisabsorbed,somereflected,sometransmitted
• photonsbounceuntil:• allofitsenergyisabsorbed(aftertoomanybounces)• itdepartstheknownuniverse(notjusttheviewvolume!)• itstrikestheimageplaneanditscontributionisaddedtoappropriatepixel
Wecallthepathofthesephotons“lightrays”
Ifwecanmodellightrayswecangenerateimages
Curless,Hodgins
GeometricOpticsLightraysfollowtheserules:• travelinstraightlinesinfreespace
• donotinterferewitheachotheriftheycross(lightisinvisible!)
• travelfromthelightsourcestotheeye,butthephysicsisinvariantunderpathreversal(reciprocity)
• obeythelawsofreflectionandrefraction
Curless,Hanrahan
WhyTraceRays?Moreelegantthanpipelinedrasterization,especiallyforsophisticatedphysics:• modelinglightreflectance,e.g.,fromskin
• modelinglighttransport,e.g.,inter-reflection,caustics
• rendering,e.g.,softshadows
Easiestphotorealisticglobalilluminationrenderertoimplement
Jensen,Hart08
Raysemanatefromlightsourcesandbouncearound
Raysthatpassthroughtheimageplaneandentertheeyecontributetothefinalimage
Veryinefficientsinceitcomputesmanyraysthatareneverseen,mostrayswillneverevengetclosetotheeye!
Light-RayTracing
imageplane Merrell08
RayCastingForeachpixelshootaray(a3Dline)fromtheeyeintotheviewvolumethroughapointonthescreen• findthenearestpolygonthatintersectswiththeray• shadethatintersectionaccordingtolight,e.g.,byusingthePhongilluminationmodel,orotherphysically-basedBRDFs,tocomputepixelcolor
Computesonlyvisiblerays(sincewestartattheeye):moreefficientthanlighttracing
IntroducedbyAppelin1968forlocalillumination(onpenplotter)
Merrell,Curless
Image plane
l
n
RayCastingIlluminationModelSofarit’sstilllight→triangle→pixel
Withraycasting,weadditionallyshootarayfromeachpointtowardeachlightinthesceneandask:• isthelightvisiblefromtheintersectionpoint?
• doestherayintersectanyobjectsonthewaytothelight?
• iflightisnotvisible,itdoesn’tlitthepoint(pointinshadow)
RayCastingImage
Castrays
Findfirst
intersection
Shading
PipelinedRasterizationCommand
Geometry
Rasterization
Texture
Display
RayCastingvs.PipelinedRasterization
Zwicker06
SceneGraph
OutputImage
ImageOrder
ObjectOrder
RayTracingWhittedintroducedraytracingtothegraphicscommunityin1980:• recursiveraycasting• firstglobalilluminationmodel:• anobject’scolorisinfluencedbylightsandotherobjectsinthescene�shadows• simulatesspecularreflectionandrefractivetransmission
imageplaneMerrell08
Whitted80
RayTracingvs.PipelinedRasterization
RayTracing+ nocomputationforhiddenparts
- usuallyimplementedinsoftware
- slow,batchrendering- nodominantstandardforscenedescription(RenderManformat,POVray,PBRT,…)
+ photo-realisticimages:morecomplexshadingandlightingeffectspossible
PipelinedRasterization+ implementedinGPU+ standardizedAPIs+ interactiverendering,games- limitedphoto-realism:hardertogetglobalillumination(butgettingcloser)
Zwicker06
RecursiveRayTracingBasicidea:• Eachpixelgetslightfromjustonedirection�thelinethroughthescreenandtheeye
• Anyphotoncontributingtothatpixel’scolorhastocomefromthisdirection
• Soheadinthatdirectionandseewhatissendinglight• ifwefindnothing—done
• ifwehitalightsource—done
• ifwehitasurface—seewherethatsurfaceislitfrom,recurse
imageplaneHodgins,Merrell
Ray:aHalfLine
Anchorpoint:e = (xe, ye, ze, 1)
Ray:r = (e, d)Translatingrays:pointstranslate,directionsdon’tTr = (Te, Td) = (Te, d)
p = r(t) = e + t d,t > 0
Direction: d = s − e = (xd, yd, zd, 0)||d|| = 1preferred,butisnotalwaysso
s:screenintersection
Hart08
RecursiveRayTracingAlgorithm1. Foreachpixel(s),traceaprimaryrayfromtheeye(e),inthe
directiond = (s – e)tothefirstvisiblesurface
2. Foreachintersection,tracesecondaryrays,tocollectlight:• shadowraysindirectionslitolightsourcei• reflectivesurface:reflectedrayindirectionr,recurse• transparentsurface:refracted/transmitted/transparencyrayindirectiont,recurse
r n
−dl1
t
l2
shadow rays
ShadowRayAteveryray-objectintersection,weshootashadowraytowardseachlightsource
Iftherayhitsthelightsource(l1),thelightisusedinlightingcalculation,withtheshadowrayasthelightdirection
Iftherayhitsanobject(l2),theintersectionisinshadowandthelightisnotusedinlightingcalculation
Shadowraysdonotspawnadditionalrays(notransparencythroughtransparentobject!)
r n
−dl1
t
l2
shadow rays
RecursiveRayTracingd = primaryrayl = shadowraysr = reflectedrayst = transmittedrays
opaque,reflectiveobject transparent,
reflectiveobject
r1
r2
r3
t1
t2
l3
l1
l2
d
Merrell08
Howdeepdowerecurse?
RayTreeEachintersectionmayspawnsecondaryrays:• reflectedandtransmittedraysformaraytree• nodesaretheintersectionpoints
• edgesarethereflectedandrefractedrays
• shadowraysaresentfromeveryintersectionpoint(todetermineifpointisinshadow),buttheydonotspawnadditionalrays
Raysarerecursivelyspawneduntil:• raydoesnotintersectanyobject• treereachesamaximumdepth• lightreachessomeminimumvalue(reflected/refractedcontributiontocolorbecomestoosmall)
Merrell08
RayTreeExample
Raytreeisevaluatedbottomup:• depth-firsttraversal(byrecursion)• thenodecoloriscomputedbasedonitschildren’scolors(BG:background,ambientcolor)• don’tforgettonegatethenormalwheninsideanobject!
eyed
O1
r2
BG
r3 t2
O1 BG
r1 t1
O1 O2 opaque,reflectiveobject transparent,
reflectiveobject
r3
t2
l3
r1
t1 l1
r2
l2
d
O1
O2
Merrell08
raytrace() raytrace(ray r)
find first intersection color = ambient term for every light
cast shadow ray if (not in shadow)
color += local diffuse+specular terms // Phong illumination model
if reflective surface color += reflectedContrib // constant * raytrace(reflected ray)*local specular term
if transparent object color += refractedContrib // constant * raytrace(refracted ray)*local diffuse term
Durand
edray r
ShadowsIncreaserealismbyaddingspatialrelations• providecontactpoints,stop“floating”objects• providedepthcue• emphasizeilluminationdirection
Provide“atmosphere”
Palmer
Someofitisabsorbed(heat,vibration)Someofitisreflected(bouncesback)Someofitisrefracted(goesinsidethematerial)Theproportionofabsorbed,reflected,andrefractedlightdependonthemedium,thefrequencyoflight,andontheanglebetweenthedirectionofincidentlightandthesurfacenormalLightmayalsobescatteredbythemediumittraverses
Rossignac
LightHittingaSurface
Reflection:arrivingenergyfromonedirectiongoesoutinonlyonereflectiondirection
PerfectSpecularReflection
nd r
θi θr
θi = θr
r = d – 2(d � n)n
RefractionLighttransmitsthroughtransparentobjectsLightenteringanewmediumisrefracted• itstrajectorybendsinwardswhenenteringadensermedium• thinkofthewheelononesideofacartslowingdownfirst
• similarly,soundbendstowardscoolerair
Whydoeshotroadappearwet?• lightisbent:lighttravelsfasterthroughthehotairneartheground
Rossignac
RefractionAssumethatkicisthespeedoflightinmediumMiandktcisthespeedoflightinmediumMt:• indexofrefractionofamaterialMis:η = 1/k• lightbendswhenmovingfromonemediumtoanotheraccordingtoSnell’slaw(1621):ηi sin θi = ηt sin θt
glass
ηiair
ηt
nd
t
θi
θt
Let µ =ηiηt, v = −d
t = µv − µ(n • v) + 1− µ2 (1− (n • v)2 )( )n
Unrefracted (geometrical)line of sight Refracted (optical)
line of sight
Transparentobject
Line of sight
AB
qi
qt
Merrell,Rossignac,FvD
θi
θt
FresnelCoefficientCaptureshowmuchlightreflectsfromasmoothinterfacebetweentwomaterials(F,fractionoflightreflected):
c = F*creflection + (1−F) crefraction
• reflectancedependsonangleofincidence• notsomuchformetal(conductormaterial)• butdramaticallyforwater/glass(dielectric/insulatormaterial):
4%atnormal,100%atgrazingangle
Schlick’sapproximationofFresnelcoefficient:F(θ) = F (0) + (1−F (0))(1−(n•v))5
whereistheFresnelcoefficientatnormal(0º)
F(0) = ηt −ηi
ηt +ηi
⎛⎝⎜
⎞⎠⎟
2
Zwicker06,Gillies09
Gold:F(0) = 0.82Silver:F(0) = 0.95Glass:F(0) = 0.04Diamond:F(0) = 0.15
t = µv − µ(n • v)+ 1− µ2 (1− (n • v)2 )( )n
TotalInternalReflectionWhengoingfromadensetoalessdensemedium,theangleofrefractionbecomeslargerthantheangleofincidence(θt > θi)
Iftheangleofincidenceistoolarge(≥ θc),lightcangettrappedinsidethedensematerial• diamond→air:θc = 24.6º• water→air:θc = 48.6º• principlebehindopticalfiber
Canbenegativeforgrazingangleswhenη >1,e.g.,whengoingfromglasstoair,resultingintotalinternalreflection(norefraction)
Hart