Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Today’s Topics Questions? Go over the pseudocode for ray tracing Adding surface detail –Texture mapping

3 RayTracing Let's take a look at the handout which shows pseudocode for a recursive ray tracing algorithm and see what it entails. We'll have all our objects defined in the world (assume only spheres and polygons) with world coordinates. First part shows that we decide on a CoP and a view plane then go through the image to be created one pixel at a time from left to right on a scan line and top to bottom in scan lines. For each pixel we –Determine the ray through the center of the pixel starting at the CoP (how to we determine this?)‏ –Then call RT_trace and pass in that ray and the number 1 (for the current depth in the ray tree)‏ –RT_trace will return the color that the pixel should be RT_trace first determines which is the closest object of intersection (how would we do this?)‏ –If the ray doesn't intersect any object, then return the background color (whatever you decide it to be) otherwise...

4 RayTracing RT_trace first determines which is the closest object of intersection (how would we do this?)‏ –If the ray doesn't intersect any object, then return the background color (whatever you decide it to be) otherwise –call RT_shade with the closest object intersected, the ray, the point of intersection, the normal at that intersection (calculate this) and the depth (which is 1 the first time). How do we compute the point of intersection with the object? How do we compute the normal there? In RT_shade we set the color initially to be some ambient term (based on an ambient coefficient for the object, the object's color and our ambient light defined in our world.)‏ Go through all the lights in our world and determine the shadow rays one at a time. It then says “if the dot product of normal and direction to light is positive”. Can anyone describe what that tells us? –If a shadow ray is blocked by an opaque surface then ignore it. –If a shadow ray goes through a transparent surface reduce the amount of light transmitted by some factor (k t ) which is associated with the object (see Basic Transparency Model discussion on pages 578-579 in text). –If a shadow ray doesn't intersect anything, then just attenuate the light based on the distance. Use this attenuated light and the surface's diffuse property to compute the diffuse term.

5 RayTracing Then add each of the shadow ray/diffuse contributions to the color RT_shade then continues as long as depth < MaxDepth. Depth is initially 1 and MaxDepth can be set to something like 4. –Recursively call RT_trace for the reflection ray (and depth+1) if the surface is specularly reflective Scale the color returned by the specular coefficient of the surface Add this to the color of the pixel we're calculating –Recursively call RT_trace for the refraction ray (and depth+1) if the surface is transparent Scale the color returned by the transmission coefficient of the surface Add this to the color of the pixel we're calculating Return color

6 RayTracing Comments about ray tracing –To store which object is closest for a given ray through a pixel, we could use an altered form of the z-buffer method. –How did z-buffer method (aka depth buffer) work again?

7 RayTracing A few comments about ray tracing –To store which object is closest for a given ray through a pixel, we could use an altered form of the z-buffer method. –How did z-buffer method (aka depth buffer) work again? It stored the color of the nearest surface for each pixel into the frame buffer and the distance into a z-buffer Instead of storing the distance into the z-buffer, store which object is closest into an item-buffer.

8 RayTracing A few comments about ray tracing –Instead of creating the same depth tree for each ray (that is, the number of levels of recursion) at a particular level, determine if the expected maximum contribution (to the color of the pixel) of the ray to be cast will not be above some threshold. If it is deemed to be insignificant, don't cast it. If it has the potential to be significant, cast it. For example, a primary ray hits an object which could cast a reflection ray and that reflection ray also hits an object and casts a reflection ray and that one also hits an object and can cast a reflection ray. The surface that the second reflection ray hits might have a very small specular coefficient thereby influencing the color of the pixel insignificantly, so, then don't cast that ray (and you can save the computation for that ray as well as the ray it would have spawned, and so on.)‏ Ideally in this situation, only the ones that count will be recursed to further depths.


Download ppt "CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann."

Similar presentations


Ads by Google