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 Ray Tracing Ray Tracing is a way of producing occasionally stunning 3-D pictures. It's also a nice way to explore O-O programming (not again!). It's unfortunately full of math. I'll help as I can and we'll try to keep the math from overwhelming us. Let's peek at the wikipedia: http://en.wikipedia.org/wiki/Ray_tracing

3 CIS 310: Visual Programming, Spring 2006 Western State College Light Rays A ray tracer makes light move "backwards" – that is, go from effect to cause in the lighting world. Instead of light entering your eye, we instead shoot out a "reversed" light beam to see how light can enter the eye at that angle.

4 CIS 310: Visual Programming, Spring 2006 Western State College Help from the Internet Since we don't have a text, we'll use a bunch of websites to help us figure out ray tracing. Note that there's a LOT of code out there. I don't recommend that you try to graft this code into your project – that's probably harder than writing it from scratch anyway. I'll make a lot of links in the wiki to help us through this project.

5 CIS 310: Visual Programming, Spring 2006 Western State College A P3 Class Like last project, we need a class to represent basic math objects. We'll need all of the 2-D operations, but this time in 3-D. I'll leave the 3-D generalizations to you – ask if you have questions. We're going to conflate points and vectors – this can be confusing but that's life.

6 CIS 310: Visual Programming, Spring 2006 Western State College Efficiency Our goal will NOT be efficiency! As usual, it's better to make the code simple initially and then improve it slowly than to try and write optimized code from the start. Unlike some ray tracers, we'll use completely functional (non mutating) P3 objects. This is slower but prevents some seriously confusing hassles.

7 CIS 310: Visual Programming, Spring 2006 Western State College Light Rays A light ray is a pair containing a originating point (P3) and direction - normalized P3, a P3 on the unit sphere (magnitude 1) This is obviously a good candidate for a class. The key to this whole representation is to think of a light ray as a trajectory; light moves at a speed of "1" in our world. This is nice – it means that distance = travel time.

8 CIS 310: Visual Programming, Spring 2006 Western State College Rays as Trajectories Ray = (origin, direction) P(t) = origin + t * direction How does the "t*" work? How does the "+" work?

9 CIS 310: Visual Programming, Spring 2006 Western State College The Viewing Plane How to we turn a 3-D scene into a 2-D image? We mimic the eye and consider a single point (like the iris of your eye) to focus our light rays through. In a real eye, the viewing plane is behind the focus point – that actually inverts the image at the back of your eye! Here we'll place the "viewing plane" in front of the focus point. So what we want to do is compute a light ray for each pixel in the viewing plane.

10 CIS 310: Visual Programming, Spring 2006 Western State College Where Is the Viewing Plane? Let's keep things as computationally simple as possible! The viewing plane will be at x = 0 and the place we'll view from is at (-d,0,0). If we change the view point this will be the like choosing a different lens on a camera. We'll stay at (d,0,0) just to keep things simple. That is, we'll be distance d from the viewing plane and all of our object should be somewhere that the x coordinate is positive. We'll cram our eye into a 2x2 square, with y and z going from -1 to 1. This keeps things nicely centered!

11 CIS 310: Visual Programming, Spring 2006 Western State College Pixels to Viewing Plane Coordinates If we have a view port that’s "h" high and "w" wide, where should the pixel at (x,y) be on the viewing plane? Note: keep the image square! Let's work this out in class.


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

Similar presentations


Ads by Google