Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing.

Similar presentations


Presentation on theme: "CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing."— Presentation transcript:

1 CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing

2 CIS 310: Visual Programming, Spring 2006 Western State College Objects in Our World OK – next idea: The ray tracer needs to have something for the light rays to hit! So we need to place some objects in our world. We don't want to get TOO mathematical so let's stick with just three sorts of objects: * Spheres * Planar objects * Point light sources

3 CIS 310: Visual Programming, Spring 2006 Western State College Equation of a Sphere What's a sphere in 3-D? Simple: (x-xc) 2 + (y-yc) 2 + (z-zc) 2 = r 2 That is, a sphere is a center (P3) and a radius.

4 CIS 310: Visual Programming, Spring 2006 Western State College A Planar Object We'll define a planar object in a nice, simple way. We'll map the 3-D point onto a 2-D plane. Or look at this from the other direction: we're going to move a 2-D object into a 3-D world. How do we do this? * Translate the origin to some new point (a P3) * Point the plane in some direction (a normalized P3) * Scale the plane by some constant factor * Spin the object (an angle)

5 CIS 310: Visual Programming, Spring 2006 Western State College Working With Objects So what do we need to do with these objects? There's really only one thing that we have to do: find out where a ray intersects the object (a point). We also would like to know the angle of the object at that point so we can shade the color, bounce the ray, or whatever we want. We'll address the math later …

6 CIS 310: Visual Programming, Spring 2006 Western State College The Ray Tracer for each pixel in viewing plane: compute a ray based on the eye position launch the ray into the scene to get back a color save the color in a bitmap That sounds easy! What's the hard part?

7 CIS 310: Visual Programming, Spring 2006 Western State College Following Rays The nasty bit is following each ray to see what it hits. That's where we have to do intersections between rays and objects. Ignoring the efficiency of visiting every object for every ray, we have the following: trace(ray) = best = infinity for each object o in world best = min(o.intersect(ray), best) Here, intersect returns the distance along the ray. I didn't bother to keep track of which object is being intersected but that's easy.

8 CIS 310: Visual Programming, Spring 2006 Western State College Hitting an object Now we know which object (and where on that object) the ray hits. What's next? There are three basic ways an object acquires a color at a point: a) A light source reveals the coloring (texture) of the object at that point b) The object reflects rays from other places in the scene c) The object refracts a ray (the ray passes through the object in some way) In theory, all of these can happen at once. This requires a color blend

9 CIS 310: Visual Programming, Spring 2006 Western State College Recursion Ray tracing is a classic example of control recursion. When a ray hits an object you respond by sending new rays (maybe lots of them) off in new directions. Note that rays lose intensity as they go. One optimization is to delete rays when they lose too much intensity (this is hard in that you don't know the intensity until after you get to a light source! But you can keep track of a multiplier and the brightest source)

10 CIS 310: Visual Programming, Spring 2006 Western State College Hitting a non-reflective source Let's start with the simplest case: a ray hits an opaque object – the ray doesn't bounce or refract so all you see is the underlying color of the object. But how much illumination do you give the color of the object? That's the tricky part! The way you compute illumination is to cast rays to each light source from the object's surface.

11 CIS 310: Visual Programming, Spring 2006 Western State College Shading If a light source illuminates a point, how much light is reflected by the surface? This depends on the normal vector of the surface and direction of the light source. I'll skip the math right now and simply point out that you need to shoot rays to every light source. When the ray is obstructed, ignore the source. When the ray is unobstructed, allow it to contribute to the color.

12 CIS 310: Visual Programming, Spring 2006 Western State College Texture Mapping Any function that converts a 3-D coordinate on an object into a 2-D coordinate can be used as a texture map. The texture map "wraps" a surface in a 2-D image.

13 CIS 310: Visual Programming, Spring 2006 Western State College The Next Step We need to write a good math library. * Intersect a ray and a sphere * Intersect a ray and a plane * Mappings for a sphere and a plane * Shading functions * Reflection / refraction ray transformations

14 CIS 310: Visual Programming, Spring 2006 Western State College Things You Need to Do * Set up the raster to ray part of the system * Object representations (we can do an object design now …) * Search for the closest object along a ray * Various ray scattering algorithms * Color operations (how do you do these?) * Make a cool picture for me


Download ppt "CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing."

Similar presentations


Ads by Google