390 likes | 499 Views
Computer Graphics SS 2014 Ray-Tracing. Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung. Basics. Ray is a straight path along which light photons travel Multiple photons can travel along the same ray at the same time
E N D
Computer Graphics SS 2014 Ray-Tracing Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung
Basics • Ray is a straight path along which light photons travel • Multiple photons can travel along the same ray at the same time • Photons originate at some light source and bounce around the geometry in the scene until they hit the eye • If photons collide with objects they might get absorbed or they change their direction due to the laws of reflection
Basics • Tracing photons forwards from each light source would lead to an excellent picture of the scene • But most photons will never hit the eye • Therefore, we trace photons backwards from the eye into the scene • Requires a sampling structure, i.e. a virtual pixel plane, to determine the rays to follow
Basics • The classicalraytracingmethod • Recursivecomputationofpathsthroughthescene Interaction withobjects, i.e. absorption, specular reflection, refraction, Point-wiseevaluationof localilluminationmodel andshadows
Basics • The classicalraytracingmethod • The dottedlinesrepresentshadowrays, whichareshottothelightsource • Ifthesurfacepointis in shade, nothinghappens, elsethelocalilluminationfromthelightsourceisevaluated
Basics • The basic ray tracing method
Basics • The basic ray tracing method Two bounces No bounce One bounce
Basics • Light transport • Classical (so calledWhitted) raytraceronlysimulates (a) andreflectionoflocalilluminationdue topoint light source
Basics • Recursiveraytraversalresults in a tree-likecomputation order • Primary, secondary, tertiary etc. rays • Oneor multiple shadowraystopointlight source • More work in branches but lesscontributiontothe final imagedue toabsorption I = Idirect+ ksIreflected+ ktIrefracted Idirect= Idiffuse+ Ispecular primaryray L1 R1 T1 L3 L2 T2 R1 R3 T3
distance toview plane upvector height viewing direction point of view width look vector position Basics up vector projection of up vector • The ray tracing camera
Basics • The numberofsamplestotake, i.e. thenumberofraystoshot, isdefinedbytheresolutionoftheviewport (thepixel raster)
Basics • Samplingtheimage plane • A continuousspheresampledatvaryingviewportresolution
point of view Basics • The ray tracing camera mimics an infinite view frustum • The portion of the scene that is visible • Attention: light paths have to consider objects/light sources outside the frustum
Basics • Sampling theimage plane withat least oneray per pixel for (eachpixel) { ray= getRay(viewpoint, pixelcenter) pixelcolor = traverse(ray) } traverse(ray) { compute_first_ray_object_intersection computenormal, reflectionandrefractionray color= evaluate_local_lighting_model(normal) return(color + kstraverse(reflect) + kttraverse(refract)) } Attention: recursiontermination
Basics • Trace a ray through each pixel into the scene • Reflect/refract at specular/transparent surfaces • Continue until • Pure diffuse surface is hit (Whittedraytracer only) or • Energy drops below threshold because of attenuation or • The ray leaves the scene • Local illumination: Idirect= Idiffuse+ Ispecular
Path notation • Classification of global illumination algorithms • What happens along a ray? E: the eyeD: diffuse reflectionS: specular reflectionL: the light source • Correct global illumination must simulate all combinations of interactions:L(D|S)*E
Path notation • Classical ray tracing simulates only LS*E and LDS*E paths • See reflected objects / look through transparent objects • Point light sources create sharp shadow boundaries
Path notation • Classical ray tracing approximates the rendering equation • BRDF reduced to • Perfectreflection/refraction • Diffuse (specular) reflection of direct light • Hemisphere integral reduced to sum of three rays
Path tracing (Kajiya 1986) • Observation • Many rays per pixel are spawned recursively, having ever decreasing contribution, in particular, if also diffuse reflection is considered • Work around • Trace each ray through the scene as a single path (i.e. do not create children at intersection points) • Trace many rays per pixel • Trace paths first along which most energy is received
Path tracing • Example
Path tracing • A pathiscreatedbyfollowingonerayateachintersectionpoint • A randomfactordeterminesthe type ofraytobefollowed and itsdirection • The probabilityofselecting a rayof a certain type depends on material properties • Definekd+ks+kt-1 = 0 • Chooserandomnumberx [0,1] • Ifx < kdshoot diffuse rayelseifx < kd+ksshootspecularrayelseshoottransmittedray
Path tracing • Extension bypickingrandomdirectionsvia importance sampling • The integrantissampled in areasthatcontributemosttothe integral • The probabilityofchoosingdirectionsdshouldbe proportional tothecosinebetweendandrforglossyreflectionsdandnfor diffuse reflections
Path tracing • Importance sampling Sampling directionscanbechosenwithhigherprobabilityinto „important“ directions
Path tracing • Example 4 rays per pixel
Path tracing • Example 225 rays per pixel
Path tracing • Example 400 rays per pixel