
Interactive Computer Graphics Lecture 11: Ray tracing Some slides adopted from H. Pfister, Harvard Graphics Lecture 11: Slide 1 Graphics Lecture 10: Slide 2 Direct and Global Illumination • Direct illumination: A surface point receives light directly from all light sources in the scene. – Computed by the direct illumination model. • Global illumination: A surface point receives light after the light rays interact with other objects in the scene. – Points may be in shadow. – Rays may refract through transparent material. – Computed by reflection and transmission rays. Graphics Lecture 10: Slide 3 1 Albrecht Dürer’s Ray Casting Machine Arthur Appel, 1968 • Albrecht Dürer, 16th century • On calculating the illusion of reality, 1968 • Cast one ray per pixel (ray casting). – For each intersection, trace one ray to the light to check for shadows – Only a local illumination model • Developed for pen-plotters Graphics Lecture 10: Slide 5 Ray casting Ray Casting cast ray Intersect all objects color = ambient term For every light cast shadow ray col += local shading term 2 Turner Whitted, 1980 Turner Whitted, 1980 • An Improved Illumination Model for Shaded Display, 1980 • First global illumination model: – An object’s color is influenced by lights and other objects in the scene – Simulates specular reflection and refractive transmission Recursive ray casting Does it ever end? trace ray • Stopping criteria: Intersect all objects – Recursion depth: Stop after a number of bounces color = ambient term For every light – Ray contribution: Stop if reflected / transmitted contribution cast shadow ray becomes too small col += local shading term If mirror col += k_refl * trace reflected ray If transparent col += k_trans * trace transmitted ray 3 Ray tracing: Primary rays Ray tracing: Secondary rays • For each ray we need to test which objects are intersecting • Secondary rays are rays originating at the intersection the ray: points – If the object has an intersection with the ray we calculate the • Secondary rays are caused by distance between viewpoint and intersection – rays reflected off the intersection point in the direction of – If the ray has more than one intersection, the smallest distance reflection identifies the visible surface. – rays transmitted through transparent materials in the direction of • Primary rays are rays from the view point to the nearest refraction intersection point – shadow rays • Local illumination is computed as before: q L = ka + (kd (n⋅ l) + ks(v⋅ r) )Is € Recursive ray tracing: Putting it all together Recursive Ray Tracing: Ray Tree • Illumination can be expressed as primary ray q L = ka + (kd (n⋅ l) + ks(v⋅ r) )Is + kreflected Lreflected + krefracted Lrefracted € primary ray secondary rays Graphics Lecture 10: Slide 16 4 Precision Problems Precision Problems • In ray tracing, the origin of (secondary) rays is often on the surface of objects – Theoretically, the intersection point should be on the surface – Practically, calculation imprecision creeps in, and the origin of the new ray is slightly beneath the surface • Result: the surface area is shadowing itself ε to the rescue ... Mirror reflection • Check if t is within some epsilon tolerance: • Compute mirror contribution – if abs(µ) < ε • Cast ray in direction symmetric wrt. normal • point is on the surface • Multiply by reflection coefficient (color) – else • point is inside/outside – Choose the ε tolerance empirically • Move the intersection point by epsilon along the surface normal so it is outside of the object • Check if point is inside/outside surface by checking the sign of the implicit (sphere etc.) equation 5 Mirror reflection Mirror reflection • Don’t for get to add epsilon to the ray primary ray n secondary ray v v’ φin φout Mirror reflection Mirror reflection • To calculate illumination as a result of reflections The v, v’ and n are unit vectors and coplanar so: – calculate the direction of the secondary ray at the intersection of the primary ray with the object. v’ = α v + β n • given that Taking the dot product with n yields the eq.: – n is the unit surface normal – v is the direction of the primary ray n⋅v’ = α v⋅n + β = v⋅n – v’ is the direction of the secondary ray as a result of reflections Requiring v’ to be a unit vector yields the second eq.: 1 = v’⋅v’ = α2 + 2 α β v⋅n + β2 • Solving both equations yields: v'= v − (2v ⋅ n)n v'= v − (2v ⋅ n)n 6 Transparency Refraction n • The angle of the refracted ray can be • Compute transmitted contribution determined by Snell’s law: • Cast ray in refracted direction v Medium 1 η1 sin(φ1) = η2 sin(φ2) • Multiply by transparency coefficient φ1 (eg air) • η1 is a constant for medium 1 • η2 is a constant for medium 2 • φ1 is the angle between the incident ray and the € surface normal Medium 2 • φ2 is the angle between the refracted ray and the surface normal (eg glass) φ2 v’ Refraction Refraction • In vector notation Snell’s law can be written: • This equation only has a solution if 2 η (n v)2 1 2 k1(v×n) = k2 (v'×n) ⋅ > − η1 • The direction of the refracted ray is • This illustrates the physical phenomenon of the limiting angle: – if light passes from one medium to another medium whose index of refraction 2 is low, the angle of the refracted ray is greater than the angle of the incident η1 2 η2 v′ = (n⋅ v) + −1 − n⋅ v ⋅ n + v ray € η η 2 1 – if the angle of the incident ray is large, the angle of the refracted ray is larger than 90o ➨ the ray is reflected rather than refracted € 7 Refraction Amount of reflection and refraction • Make sure you know whether you are entering or leaving • Traditional (hacky) ray tracing the transmissive material – Constant coefficient reflectionColor – Component per component multiplication • Better: Mix reflected and refracted light according to the Fresnel factor. L = k fresnel Lreflected + (1− k fresnel )Lrefracted € Fresnel factor Fresnel factor • More reflection at grazing angle 8 Schlick’s Approximation Example • Schlick’s approximation 5 k fresnel (θ) = k fresnel (0) + (1− k fresnel (0))(1− (n⋅ l)) • kfresnel(0) = Fresnel factor at zero degrees • Choose kfresnel(0) = 0.8, this will look like stainless steel € How do we add shadows? How do we add shadows? q L = ka + s(kd (n⋅ l) + ks(v⋅ r) )Is + kreflected Lreflected + krefracted Lrefracted 0 if light source is obscured s = 1 if light source is not obscured € € 9 Shadows: Problems? Example • Make sure to avoid self-shadowing Shadows Soft shadows • One shadow ray per intersection • Multiple shadow rays to sample per point light source area light source 10 Reflection: Conventional ray tracing Reflection: Conventional ray tracing • One reflection per intersection • How can we create effects like this? Reflection: Monte Carlo ray tracing Glossy surfaces • Random reflection rays around mirror direction 11 Ray tracing Monte-Carlo Ray Tracing • Cast a ray from the eye through each pixel • Cast a ray from the eye through each pixel • Trace secondary rays (light, reflection, refraction) • Cast random rays from the visible point – Accumulate radiance contribution Monte-Carlo Ray Tracing Monte-Carlo Ray Tracing • Cast a ray from the eye through each pixel • Cast a ray from the eye through each pixel • Cast random rays from the visible point • Cast random rays from the visible point • Recurse • Recurse 12 Monte Carlo Path Tracing Monte Carlo Ray Tracing • Trace only one secondary ray per recursion • Send rays to light • But send many primary rays per pixel Example Example • 1 sample per pixel • 256 samples per pixel 13 Some cool pictures Some cool pictures Graphics Lecture 10: Slide 54 Some cool pictures Some cool pictures 14 Some cool pictures took 4.5 days to render! 15 .
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages15 Page
-
File Size-