1 / 31

Introduction to Ray Tracing: Advanced Computer Graphics Lecture

This lecture introduces the concept and process of ray tracing in computer graphics, including the calculation of ray intersections, intensity calculations, reflections, refractions, shadows, and the use of binary ray tracing trees.

Download Presentation

Introduction to Ray Tracing: Advanced Computer Graphics Lecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GR2Advanced Computer GraphicsAGR Lecture 13 An Introduction to Ray Tracing

  2. Ray Tracing • Ray tracing is an alternative rendering approach to the polygon projection, shading and z-buffer way of working • It is capable of high quality images through taking account of global illumination

  3. Ray Tracing Example

  4. pixel positions on view plane camera Firing Rays light The view plane is marked with a grid corresponding to pixel positions on screen. A ray is traced from the camera through each pixel in turn.

  5. pixel positions on view plane camera Finding Intersections light We calculate the intersection of the ray with all objects in the scene. The nearest inter- section will be the visible surface for that ray

  6. light pixel positions on view plane camera Intensity Calculation The intensity at this nearest intersection is found from the usual Phong reflection model. Stopping at this point gives us a very simple rendering method. Often called: ray casting

  7. I() = Ka()Ia() + ( Kd()( L . N ) + Ks( R . V )n ) I*() / dist Phong Reflection Model light source N R eye L  V  surface dist = distance attenuation factor Here V is direction of incoming ray, N is normal, L is direction to light source, and R is direction of perfect spec. reflection. Note: R.V calculation replaced by H.N for speed - H = (L+V)/2

  8. light pixel positions on view plane camera Intensity Calculation Thus Phong reflection model gives us intensity at point based on a local model: I = I local where I local = I ambient + I diffuse + I specular Intensity calculated separately for red, green, blue

  9. light pixel positions on view plane camera Shadows To determine if the point is in shadow, we can fire a ray at the light source(s) - in direction L. If the ray intersects another object, then point is in shadow from that light. In this case, we just use ambient component: I local = I ambient Otherwise the point is fully lit. shadow ray

  10. light R1 R1 = V - 2 (V.N) N pixel positions on view plane camera Reflected Ray Ray tracing models reflections by looking for light coming in along a secondary ray, making a perfect specular reflection.

  11. pixel positions on view plane camera Reflected Ray- Intersection and Recursion light We calculate the intersection of this reflected ray, with all objects in the scene. The intensity at the nearest intersection point is calculated, and added as a contribution attenuated by distance. This is done recursively.

  12. pixel positions on view plane camera Reflected Ray - Intensity Calculation light The intensity calculation is now: I = I local + k r * I reflected Here I reflected is calculated recursively k r is a reflection coefficient (similar to k s )

  13. pixel positions on view plane camera Ray Termination Rays terminate: - on hitting diffuse surface - on going to infinity - after several reflections - why?

  14. T1 pixel positions on view plane camera Transmitted Ray If the object is semi- transparent, we also need to take into account refraction light Thus we follow also transmitted rays, eg T1.

  15. Refraction r i Change in direction is determined by the refractive indices of the materials, i and r T r N i Snell’s Law: sin  r = ( i /  r ) * sin  i V T = ( i /  r ) V - ( cos  r - ( i /  r ) cos  i ) N

  16. Refraction Contribution • The contribution due to transmitted light is taken as: kt * It(  ) • where kt is the transmission coefficient It(  ) is the intensity of transmitted light, again calculated separately for red, green, blue

  17. pixel positions on view plane camera Intensity Calculation The intensity calculation is now: I = I local + k r * I reflected + k t * I transmitted I reflected and I transmitted are calculated recursively

  18. pixel positions on view plane camera Binary Ray Tracing Tree S4 light S1 T1 R1 S2 S3 R1 S2 S3 T1 S1 S4 The intensity is calculated by traversing the tree and accumulating intensities

  19. Calculating Ray Intersections • A major part of ray tracing calculation is the intersection of ray with objects • Two important cases are: • sphere • polygon

  20. Ray - Sphere Intersection Let camera position be (x1, y1, z1) Let pixel position be (x2, y2, z2) Any point on ray is: x(t) = x1 + t * (x2 - x1) = x1 + t * i y(t) = y1 + t * (y2 - y1) = y1 + t * j z(t) = z1 + t * (z2 - z1) = z1 + t * k As t increases from zero, x(t), y(t), z(t) traces out the line from (x1, y1, z1) through (x2, y2, z2). Equation of sphere, centre (l, m, n) and radius r: (x - l)2 + (y - m)2 + (z - n)2 = r2

  21. Ray - Sphere Intersection Putting the parametric equations for x(t), y(t), z(t) in the sphere equation gives a quadratic in t: at2 + bt + c = 0 Exercise: write down a, b, c in terms of i, j, k, l, m, n, x1, y1, z1 Solving for t gives the intersection points: b2 - 4ac < 0 no intersections b2 - 4ac = 0 ray is tangent b2 - 4ac > 0 two intersections, we want smallest positive

  22. Ray - Polygon Intersection Equation of ray: x(t) = x1 + t * i y(t) = y1 + t * j z(t) = z1 + t * k Equation of plane: ax + by + cz + d = 0 Intersection: t = - (ax1 + by1 + cz1 + d) / (ai + bj + ck) Need to check intersection within the extent of the polygon.

  23. Ray Tracing - Limitations • Ray tracing in its basic form is computationally intensive • Much research has gone into increasing the efficiency and this will be discussed in next lecture.

  24. Ray Tracing Example

  25. Depth 0

  26. Depth 1

  27. Depth 2

  28. Depth 3

  29. Depth 4

  30. Depth 7

  31. Acknowledgements • As ever, thanks to Alan Watt for the excellent images

More Related