Presentation is loading. Please wait.

Presentation is loading. Please wait.

1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

Similar presentations


Presentation on theme: "1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing."— Presentation transcript:

1 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing

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

3 3GR2-00 Ray Tracing Example

4 4GR2-00 Firing Rays pixel positions on view plane camera 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. light

5 5GR2-00 Finding Intersections pixel positions on view plane camera 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 light

6 6GR2-00 Intensity Calculation pixel positions on view plane camera 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 light

7 7GR2-00 Phong Reflection Model light source N L R V eye surface I( ) = K a ( )I a ( ) + ( K d ( )( L. N ) + K s ( R. V ) n ) I*( ) / dist Note: R.V calculation replaced by H.N for speed - H = (L+V)/2 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.

8 8GR2-00 Intensity Calculation pixel positions on view plane camera 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 light

9 9GR2-00 Shadows pixel positions on view plane camera 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. light shadow ray

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

11 11GR2-00 Reflected Ray- Intersection and Recursion 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. pixel positions on view plane camera light

12 12GR2-00 Reflected Ray - Intensity Calculation pixel positions on view plane camera 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 13GR2-00 Ray Termination pixel positions on view plane camera Rays terminate: - on hitting diffuse surface - on going to infinity - after several reflections - why?

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

15 15GR2-00 Refraction N V T i r r i Change in direction is determined by the refractive indices of the materials, i and r Snells Law: sin r = ( i / r ) * sin i T = ( i / r ) V - ( cos r - ( i / r ) cos i ) N

16 16GR2-00 Refraction Contribution n The contribution due to transmitted light is taken as: k t * I t ( ) – where k t is the transmission coefficient I t ( ) is the intensity of transmitted light, again calculated separately for red, green, blue

17 17GR2-00 Intensity Calculation pixel positions on view plane camera 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 18GR2-00 Binary Ray Tracing Tree S1 S2S3 S4 pixel positions on view plane camera S1 S2 S3 S4 R1R1 T1T1 T1T1 R1R1 The intensity is calculated by traversing the tree and accumulating intensities light

19 19GR2-00 Calculating Ray Intersections n A major part of ray tracing calculation is the intersection of ray with objects n Two important cases are: – sphere – polygon

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

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

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

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

24 24GR2-00 Ray Tracing Example

25 25GR2-00 Depth 0

26 26GR2-00 Depth 1

27 27GR2-00 Depth 2

28 28GR2-00 Depth 3

29 29GR2-00 Depth 4

30 30GR2-00 Depth 7

31 31GR2-00 Acknowledgements n As ever, thanks to Alan Watt for the excellent images


Download ppt "1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing."

Similar presentations


Ads by Google