Lecture 17: Recursive Ray Tracing. Where is the way where light dwelleth? Job 38:19

Similar documents
Recursive Ray Tracing. Ron Goldman Department of Computer Science Rice University

So far, we have considered only local models of illumination; they only account for incident light coming directly from the light sources.

Lecture 10: Ray tracing

Lecture 19: All Together with Refraction

Raytracing. COSC 4328/5327 Scott A. King

Chapter 26 Geometrical Optics

Lecture 7 Notes: 07 / 11. Reflection and refraction

Introduction Ray tracing basics Advanced topics (shading) Advanced topics (geometry) Graphics 2010/2011, 4th quarter. Lecture 11: Ray tracing

Computer Graphics. Lecture 9 Environment mapping, Mirroring

Ray-Tracing. Misha Kazhdan

Reflection and Refraction

Reflection and Refraction

specular diffuse reflection.

GEOMETRIC OPTICS. LENSES refract light, so we need to know how light bends when entering and exiting a lens and how that interaction forms an image.

CS 325 Computer Graphics

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

26 Geometric Optics, Reflection

The Ray model of Light. Reflection. Class 18

Photorealism: Ray Tracing

Supplement to Lecture 16

Computer Graphics. Lecture 13. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura

Problem Set 4 Part 1 CMSC 427 Distributed: Thursday, November 1, 2007 Due: Tuesday, November 20, 2007

1. What is the law of reflection?

COMP30019 Graphics and Interaction Ray Tracing

(Equation 24.1: Index of refraction) We can make sense of what happens in Figure 24.1

Lighting and Shading

Light and the Properties of Reflection & Refraction

LIGHT. Speed of light Law of Reflection Refraction Snell s Law Mirrors Lenses

Index of Refraction and Total Internal Reflection

Lecture 14: Refraction

SESSION 5: INVESTIGATING LIGHT. Key Concepts. X-planation. Physical Sciences Grade In this session we:

Ray Tracing. Kjetil Babington

Ø Sampling Theory" Ø Fourier Analysis Ø Anti-aliasing Ø Supersampling Strategies" Ø The Hall illumination model. Ø Original ray tracing paper

Ray Optics. Physics 11. Sources of Light Rays: Self-Luminous Objects. The Ray Model of Light

Algebra Based Physics

L. R. & S. M. VISSANJI ACADEMY SECONDARY SECTION PHYSICS - GRADE: VIII REFRACTION OF LIGHT

PHYS 219 General Physics: Electricity, Light and Modern Physics

Physics 102: Lecture 17 Reflection and Refraction of Light

Chapter 26 Geometrical Optics

I have a meeting with Peter Lee and Bob Cosgrove on Wednesday to discuss the future of the cluster. Computer Graphics

Recall: Basic Ray Tracer

Intro to Ray-Tracing & Ray-Surface Acceleration

speed of light in vacuum = speed of light in the material

All forms of EM waves travel at the speed of light in a vacuum = 3.00 x 10 8 m/s This speed is constant in air as well

Lecture 11: Ray tracing (cont.)

Light: Geometric Optics

COMP371 COMPUTER GRAPHICS

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Computer Graphics. Lecture 10. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura 12/03/15

Phys 102 Lecture 17 Introduction to ray optics

Reflection & refraction

Reflection and Refraction

CS580: Ray Tracing. Sung-Eui Yoon ( 윤성의 ) Course URL:

At the interface between two materials, where light can be reflected or refracted. Within a material, where the light can be scattered or absorbed.

Outline The Refraction of Light Forming Images with a Plane Mirror 26-3 Spherical Mirror 26-4 Ray Tracing and the Mirror Equation

Physics 102: Lecture 17 Reflection and Refraction of Light

Reflection and Refraction

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

Rendering: Reality. Eye acts as pinhole camera. Photons from light hit objects

Optics: Laser Light Show Student Advanced Version

REFLECTION & REFRACTION

PHY 112: Light, Color and Vision. Lecture 11. Prof. Clark McGrew Physics D 134. Review for Exam. Lecture 11 PHY 112 Lecture 1

Assignment 6: Ray Tracing

Reflection & Mirrors

CS354 Computer Graphics Ray Tracing. Qixing Huang Januray 24th 2017

Ray Tracing. CSCI 420 Computer Graphics Lecture 15. Ray Casting Shadow Rays Reflection and Transmission [Ch ]

Computer Graphics. Ray Tracing. Based on slides by Dianna Xu, Bryn Mawr College

COMP 175 COMPUTER GRAPHICS. Lecture 11: Recursive Ray Tracer. COMP 175: Computer Graphics April 9, Erik Anderson 11 Recursive Ray Tracer

Light: Geometric Optics (Chapter 23)

Physics for Scientists & Engineers 2

General Physics II. Mirrors & Lenses

Physics 1C. Lecture 22A. "There are two ways of spreading light: to be the candle or the mirror that reflects it." --Edith Wharton

Today s Topic: Refraction / Snell s Law

Lecture 18: Primer on Ray Tracing Techniques

LECTURE 15 REFLECTION & REFRACTION. Instructor: Kazumi Tolich

Movie: For The Birds. Announcements. Ray Tracing 1. Programming 2 Recap. Programming 3 Info Test data for part 1 (Lines) is available

Unit 9 Light & Optics

Home Lab 7 Refraction, Ray Tracing, and Snell s Law

Ray Tracer Due date: April 27, 2011

Purpose: To determine the index of refraction of glass, plastic and water.

Light. Form of Electromagnetic Energy Only part of Electromagnetic Spectrum that we can really see

Science 8 Chapter 5 Section 1

Implementation Issues

Conceptual Physics 11 th Edition

Visible Surface Ray-Tracing of Stereoscopic Images

Reflection and Refraction of Light

Light and Lenses Notes

COMP environment mapping Mar. 12, r = 2n(n v) v

Ray tracing. EECS 487 March 19,

Geometrical Optics INTRODUCTION. Wave Fronts and Rays

LIGHT. Descartes particle theory, however, could not be used to explain diffraction of light.

Reading. Ray Tracing. Eye vs. light ray tracing. Geometric optics. Required:

Reflection and Mirrors Additional Review

3/10/2019. Models of Light. Waves and wave fronts. Wave fronts and rays

Lab 9. Reflection and Refraction

Reflections. I feel pretty, oh so pretty

Introduction. Experiment A: Snell s Law. Physics 1CL REFLECTION AND REFRACTION OF LIGHT Summer Session II 2010

Comp 410/510 Computer Graphics. Spring Shading

Lecture 21: Shading. put your trust in my shadow. Judges 9:15

Lighting and Reflectance COS 426

Transcription:

Lecture 17: Recursive Ray Tracing Where is the way where light dwelleth? Job 38:19 1. Raster Graphics Typical graphics terminals today are raster displays. A raster display renders a picture scan line by scan line. A scan line is a horizontal line consisting of many small, tightly packed dots called pixels. To display a scene using a raster display, we need to compute the color and intensity of the light at each pixel. The purpose of this lecture is to explain how to compute the color and intensity of light for each pixel given a 3-dimensional model of the objects in the scene and the location, color, and intensity of the light sources.. Recursive Ray Tracing For realistic rendering, we need the following setup: an eye point E, a viewing screen S, and one or more point light sources with known location, color, and intensity (see Figure 1). We also need to specify the locations and the shapes of all the objects in the scene, together with their reflectivity, transparency, and indices of refraction. Our goal is to display the -dimensional projection onto the screen of the 3-dimensional scene as viewed from the eye point, much like an artist painting the scene or a still photographer capturing a vista. We shall accomplish this task by tracing light rays from the scene back to the eye. Below is the basic ray tracing algorithm. Ray Tracing Algorithm For each pixel: i. Find all the intersections of the ray from the eye to the pixel with every object in the scene. ii. Keep the intersection closest to the eye. iii. Compute the color and intensity of the light at this intersection point. Render the scene by displaying the color and intensity at each pixel. Step i of the ray tracing algorithm requires us to compute the intersections of a straight line with lots of different surfaces. The difficulty of this intersection problem depends on the complexity of the surfaces in the scene. For planar surfaces these intersections are easy to compute: we simply solve one linear equation in one unknown. But for more complicated surfaces, we shall need more sophisticated tools. We will study line-surface intersection algorithms for a variety of different surfaces in Chapters 18 and 19. Step ii of the intersection algorithm is straightforward; in this chapter we shall concentrate on Step iii of the algorithm.

light refraction shadow light reflection pixel screen eye Figure 1: To determine the color and intensity at a pixel, a ray is cast from the eye point through the pixel. The color and intensity of the point where the ray first strikes a surface is computed by summing the contributions from the direct illumination of the unobstructed light sources and the contributions of reflected and refracted rays. To find the color and intensity of the light at a surface point, we need to consider not only the light shining directly on the surface from the light sources, but also the light reflected and refracted from these sources off of other surfaces. Thus the total intensity I at a surface point is given by I = I direct + k s I reflected + k t I refracted, (.1) where, as we observed in Chapter 16, I direct = I ambiant + I diffuse + I specular (.) and 0 k s,k t 1 are the reflection and refraction (transparency) coefficients. These coefficients depend on the physical characteristics of the surface, which can be determined experimentally or simply set by the programmer. Again the light reflected and refracted from other surfaces depends on the light shining directly on these surfaces as well as on the light reflected and refracted onto these surfaces from other surfaces. These observations lead to the binary light tree depicted in Figure.

I direct k s k t I reflected I refracted k s k t k s k t I reflected I refracted M I reflected I refracted Figure : Binary light tree. The intensity of light at a surface point (apex) is the sum (depicted here by arrows) of the intensities of the light from the point light sources shining directly on the surface and the intensity of the light reflected and refracted off of other surfaces. The intensity of the light reflected and refracted from other surfaces also depends on the light shining directly on these surfaces and the light reflected and refracted to these surfaces from other surfaces. This recursive computation is summarized graphically in the binary light tree depicted above. This tree must be truncated at a prespecified depth in order to avoid infinite recursion. Notice that for each object in the scene, we must decide whether it is reflecting, transparent, semi-transparent, or opaque -- that is, we need to assign values for reflectivity ( k s ) and transparency ( k t ). Moreover for transparent or semi-transparent objects, we need to assign an index of refraction (c i ). For opaque objects, c i = 0; for air, c i =1. Note too that for transparent, objects I direct = 0. 3. Shadows Just as we may not see every object in a scene because some objects are hidden from view by other objects closer to the eye, so too not every object in the scene is necessarily illuminated by every light source in the scene because some objects may lie in the shadow of other objects. That is, if an opaque object lies between a light source and a surface, then the surface will not be illuminated by the light source. To determined whether or not a surface point is illuminated by a point light source, we treat the surface point as a virtual eye and we cast a virtual ray from the surface point to the point light source. As in the ray casting algorithm, we compute all the intersections of this virtual ray with every object in the scene. If the virtual ray intersects an opaque object before the virtual ray hits the 3

light source, then the surface point lies in shadow; otherwise the surface point is illuminated by the light source. Below we summarize this basic shadow casting algorithm. Shadow Casting Algorithm For each surface point visible to the eye, cast a virtual ray to each light source. i. If the virtual ray hits an opaque object before the virtual ray hits a light source, then omit the contribution of this light source. That is, for this light source, I diffuse = I specular = 0. ii. If the virtual ray hits a transparent or semi-transparent object before the virtual ray hits the light source, then scale the contribution of this light source and continue to look for further intersections. Note that in step i, an object may be self shadowed -- that is, a point on an object (e.g. a sphere) may lie in the object s own shadow -- so we must compute intersections of the virtual ray even with the object containing the point of interest. Since we need to compute the intersections of the virtual ray with every object in the scene, shadow computations can be quite time consuming. To speed up shadow computations, we can take advantage of shadow coherence. The idea behind shadow coherence is that if a point P lies in the shadow of an object O, then a nearby point Q is also likely to lie in the shadow of the same object O. Therefore to speed up the shadow calculations, we store the current shadowing object and we test first for intersections with this object when we cast the virtual ray from the next point in the scene. Shadow rays not refracted; if shadow rays were refracted, these rays would not hit the light source! We could solve this problem by casting rays starting from the light sources instead of from the surface points taking refraction into account, but this approach is very expensive and not generally done. Typically this problem is ignored, since the resulting scenes still appear realistic. 4. Reflection To find the color and intensity of the light at a surface point, we need to calculate the light reflected off this point from other surfaces in the scene. To compute the color and intensity of this reflected light, we consider the surface point as a virtual eye and we cast a secondary ray from the surface point treating the surface as a mirror (see Figure 3). As in the standard ray casting algorithm, we find all the intersections of this secondary ray with every object in the scene, keep the closest intersection point, and calculate the color and intensity of the light at this intersection point recursively. We then add a scaled value of this color and intensity to the color and intensity at the original point. Below we summarize this reflection algorithm. 4

Reflection Algorithm For each visible point on a reflecting surface: i. Use the law of mirrors -- angle of incidence = angle of reflection -- to calculate a reflected secondary ray (see Figure 3). ii. Find all the intersections of this reflected secondary ray with every object in the scene. iii. Keep the intersection closest to the surface point. iv. Compute the color and intensity of the light at this intersection point recursively and add a scaled value of this contribution, k s I reflected, to the color and intensity at the original point. To find the reflected secondary ray R(t), let V = E P E P denote the unit vector from the point P to the eye point E, and let V and V denote the components of V parallel and perpendicular to the surface normal N at the point P (see Figure 3). Then V = V +V, so the reflected vector W is given by W =V V. But V = (V N)N V = V V =V (V N)N. Hence W = (V N)N V and R(t) = P + tw. Note that the calculation here of the reflected vector W is the same as the calculation of the reflected vector R for specular reflection (see Chapter 16, Section 5). N Eye V V V θ V θ W P Surface Figure 3: Law of the mirror: angle of incidence = angle of reflection. Thus if V is the unit vector from the point P to the Eye, then the reflected vector W is given by W =V V. 5

5. Refraction To find the color and intensity of the light at a surface point, we need to calculate not only the light reflected off this point from other surfaces in the scene, but also for transparent or semitransparent surfaces the light refracted through the surface at this point. Refraction is caused by light traveling at different speeds in different mediums: the denser the medium, the slower the speed of light. This change in speed gives the illusion of light bending when light passes between different mediums. To compute the color and intensity of refracted light, we again consider the surface point as a virtual eye and we cast a secondary ray from the surface point treating the surface as a refracting surface (see Figure 4). As in the standard ray casting algorithm, we again find all the intersections of this secondary refracted ray with every object in the scene, keep the closest intersection point, and calculate the color and intensity of the light at this intersection point recursively. We then add a scaled value of this color and intensity to the color and intensity at the original point. Below we summarize this refraction algorithm. Refraction Algorithm For each visible point on a transparent object: i. Use Snell s Law to calculate the refracted secondary ray (see Figure 4). ii. Find all intersections of the refracted ray with every object in the scene. iii. Keep the intersection closest to the surface point. iv. Compute the color and intensity of the light at this intersection point recursively and add a scaled value of this contribution, k t I refracted, to the color and intensity at the original point. To find the refracted secondary ray R(t), again let V = E P E P denote the unit vector from the point P to the eye point E, and let W denote the direction of the refracted ray (see Figure 4). To compute the refracted ray R(t), we need to calculate the refracted vector W in terms of the known vectors N and V. To perform this computation, we shall apply the following rule from optics: Snell s Law Let θ 1 be the angle between the unit vector V and the surface normal N at the point P, and let θ be the angle between the refracted vector W and the unit normal N at the point P pointing away from the eye. If the indices of refraction on either side of the surface are c 1 and c, then c = sin(θ ) c 1 sin(θ 1 ). (5.1) 6

N Eye V θ 1 P Surface θ θ 1 θ N Figure 4: The unit vector V from the point P to the eye, the surface normal N at the point P, and the refracted vector W. Here θ 1 is the angle between the surface normal N and the vector V, and θ is the angle between the refracted vector W and the vector N. By Snell s Law if the indices of refraction on either side of the surface are c 1 and c, then c = sin(θ ) c 1 sin(θ 1 ). W V Here is how we can use Snell s Law to find the refracted vector W in terms of the known vectors N and V. Since W lies in the plane of N and V, the refracted vector W is a linear combination of the vectors N and V. However, since W lies between N and V, initially it is easier to express W in terms of N and V. Thus there are constants α,β such that W =α( N) + β( V). (5.) Snell s Law contains the sine function, so to solve for the constants α,β, we shall invoke the cross product; in particular, we shall cross both sides of Equation (5.) with N and V. Crossing both sides of Equation (5.) with N, we find that ( N) W = β N V. Taking the length of both sides yields N W sin(θ ) = β N V sin(θ 1 ). But N,V,W are unit vectors. Therefore solving for β and invoking Snell s Law, we obtain β = sin(θ ) sin(θ 1 ) = sin(θ ) sin(θ 1 ) = c. (5.3) c 1 Similarly, crossing both sides of Equation (5.) with V, we find that W ( V ) =α N V. 7

Taking the length of both sides yields W V sin(θ 1 θ ) =α N V sin(θ 1 ) Again N,V,W are unit vectors. Therefore solving for α and invoking Snell s Law, we obtain α = sin(θ 1 θ ) = sin(θ 1 )cos(θ ) sin(θ )cos(θ 1 ) = cos(θ sin(θ 1 ) sin(θ 1 ) ) c cos(θ c 1 ). (5.4) 1 Since N and V are unit vectors, cos(θ 1 ) = N V. (5.5) Moreover cos(θ ) = 1 sin θ = 1 c c sin θ 1 = 1 c 1 c (1 cos θ 1 ) = 1 c 1 (N V) 1 c 1 (5.6) ( ). Putting together Equations (5.)-(5.6), we conclude that W = c (N V ) cos(θ c ) N c V, (5.7) 1 c 1 where cos(θ ) = 1 c c 1 ( 1 (N V) ). (5.8) The equation of the refracted ray is simply R(t) = P + tw. By the way the calculation here of the refracted vector W is the same as the calculation of slerp( N, V,t), for t = θ /θ 1 (see Exercise 3). Notice that for each color, we use the same index of refraction and therefore the same refracted ray. Technically this procedure is incorrect, but this tactic saves tremendously on computation time and the results still look realistic, so most ray tracing programs adopt this approach. There are some angles θ 1 between the vector V to the eye and the normal vector N to the surface at which refraction cannot occur. This phenomenon is called total reflection. Total reflection may occur when c / c 1 >1. In this case for some angles θ 1, c c 1 sin(θ 1 ) >1, so by Snell s Law sin(θ ) >1 which is impossible. To check for total reflection, test c 1 (N V) c 1 ( ) >1 1 (N V) > c 1 1 > (N V) + c 1. c c 8

In this case, cos(θ ) in Equation (5.7) is imaginary and the refracted vector W does not exist. Be careful to test for total reflection, otherwise your ray tracing program may crash. 6. Summary Recursive ray tracing is one of the most powerful tools in Computer Graphics for generating realistic images of virtual scenes. Shadows, reflections, and refractions are all modeled effectively by recursively tracing the paths of light rays through the scene. In recursive ray tracing, the total intensity at each surface point is given by the following recursive computation: Total Intensity I = I direct + k s I reflected + k t I refracted 0 k s,k t 1 I direct = I ambiant + I diffuse + I specular To find the reflected and refracted rays at each surface point, let N represents the unit normal vector at the surface point and let V represents the unit vector from the surface point to the eye. In addition, let c 1 and c represent the indices of refraction on opposite sides of the surface. Then we have the following formulas: Reflected Vector W = (V N)N V Refracted Vector W = c (N V ) cos(θ c ) N c V 1 c 1 cos(θ ) = 1 c 1 (N V) c 1 ( ) Total Reflection (N V) + c 1 <1 c To implement recursive ray tracing, we need to be able to calculate two things: surface normals and line-surface intersections. We shall take up the calculation of these items for a variety of different surfaces in the next two chapters. 9

Exercises: 1. Show that the reflection vector W in Figure 3 can be computed in each of the following ways: a. By finding the mirror image of the vector V in the plane perpendicular to V. b. By rotating the vector V by 180 o around the normal vector N. c. By finding the mirror image of the vector V in the plane perpendicular to the normal vector N and then negating the result.. Using the result of Exercise 1, part c, show that light following the law of the mirror -- angle of incidence = angle of reflection -- takes the shortest path from the light source through the mirror to the eye. 3. Consider the refraction vector W in Figure 4. a. Show that W = slerp( N, V,t), for t = θ /θ 1 (see Chapter 11, Section 6). b. Use the result of part a together with Snell s Law to derive Equation (5.7) for the refraction vector W. 4. Consider the refraction vector W in Figure 4. a. Show that W is the result of rotating the vector N thorough the angle θ about the axis vector N V N V. b. Using part a, show that W = sin(θ θ 1 )N sin(θ )V sin(θ 1 ). c. Use the result of part b together with Snell s Law to derive Equation (5.7) for the refraction vector W. 10