Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ray Tracing Tutorial. Ray Casting One type of visibility algorithm.

Similar presentations


Presentation on theme: "Ray Tracing Tutorial. Ray Casting One type of visibility algorithm."— Presentation transcript:

1 Ray Tracing Tutorial

2 Ray Casting One type of visibility algorithm

3 Basic Idea RayCast(Camera, Scene, img_w, img_h) { for (row=0; row < img_h; row++) { for (col=0; col< img_h; col++) { ray = constructRay(camera, row, col); (hit,color)=getIntersection(ray, scene); image[row][col] = color; } return image }

4 Constructing Primary Rays CoP u n v X min, Y min

5 Constructing Primary Rays CoP

6 Constructing Primary Rays CoP

7 Constructing Primary Rays CoP

8 Gathering all the info from.dat file Camera specification Viewport Resolution Camera {perspective, orthographic} CoP point lookat point up vector

9 Visualizing the components CoP Look at point up vector Width (in pixels) Height (in pixels) x_res y_res focal length

10 Constructing the Orthogonal Basis CoP Look at point up vector u n v n = normalize lookat vector u = n x up v = u x n

11 Computing Starting Point CoP u n v X, Y Beware of units. Pixels versus world units focal length

12 Constructing a Primary Ray CoP

13 Cast Ray Current Pixel Color (0.2,0.8,0.2) due to ambient term

14 CoP Check for Intersections Current Pixel Color (0.2,0.8,0.2) due to ambient term Beware of near and far clipping planes as well

15 Some Tips Try the simplest test case you can think of (eg one sphere, and simple camera location) Break Down into steps –Ray Cast in BW with spheres (ensure generation of primary rays is correct) –Shade with Primary Ray contribution. –Try more complex surfaces Normalize, Normalize, Normalize Clamp color [0,1]

16 CoP Pick Nearest Current Pixel Color (0.2,0.8,0.2) due to ambient term

17 Computing the Surface Lighting Effect

18 CoP Connect Light Ray Current Pixel Color (0.2,0.8,0.2) due to ambient term

19 I R = I R,ambdiff + I R,diffused + I R,specular I G = I G,ambdiff + I G,diffused + I G,specular I B = I B,ambdiff + I B,diffused + I B,specular

20 I = I ambdiff + I diffused + I specular For example (0.2, 0.8, 0.2) for this material. A constant. Independent of lighting And viewing direction

21 I = I ambdiff + I diffused + I specular N L I diffused = k d I l (N.L) Compute for all 3 channels. For example (0.1, 0.1, 0.1). Independent of Viewpoint

22 I = I ambdiff + I diffused + I specular N L I specular = k s I l (V.R) ns Compute for all 3 channels. For example (0.2, 0.2, 0.2). V R

23 I = I ambdiff + I diffused + I specular = ( 0.2, 0.8, 0.2) + (0.1, 0.1, 0.1) + (0.2, 0.2, 0.2) = (0.5, 1.0, 0.5) Clamp to [0,1]

24 CoP Current Pixel Color (0.5,1.0,0.5) Connect Light Ray

25 What about areas in shadow?

26 CoP Current Pixel Color (0.2,0.8,0.2) due to Ambient term Connect Light Ray

27 Ray Tracing Physical World : –Photons shoot out from light sources, reflect off surfaces and into the eye. –Problem : Only small fraction reaches the eye (or image plane). Difficult to simulate. Alternative way to simulate : –Reverse the process! –Trace the path backwards i.e from the eye (or pixels) back to the light sources. –Ray Tracing!

28 We modify the Ray-Casting algorithm to trace rays bouncing off the surfaces.

29 Outer Loop Select center of projection and window on view plane; For (each scan line in image) { For (each pixel in scan line) { 1) Construct ray from center of projection through pixel 2) pixel = trace(ray,1); }

30 color trace(RT_ray ray, int depth) { Determine closest intersection of ray with an object if there is an intersection { 1) compute normal at intersection 2) return shade ( closest object hit, ray, intersection, normal, depth ) } Shade will return the cumulative color by recursively calling trace with depth counter decremented at each invocation.

31 CoP Contribution From Primary Ray (0.5,1.0,0.5)

32 CoP Contribution From Secondary Ray (0.5,1.0,0.5) V2V2 V1V1 L (0.8,0.8,0.0)

33 CoP Final Pixel Color (0.5,1.0,0.5) V2V2 V1V1 L (0.8,0.8,0.0) + = ksks

34 The End


Download ppt "Ray Tracing Tutorial. Ray Casting One type of visibility algorithm."

Similar presentations


Ads by Google