Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site gcc-bill.ARPA
Path: utzoo!linus!philabs!cmcl2!harvard!gcc-bill!brad
From: brad@gcc-bill.ARPA (Brad Parker)
Newsgroups: net.graphics
Subject: Re: ray casting (far too long...)
Message-ID: <318@gcc-bill.ARPA>
Date: Mon, 16-Sep-85 23:14:44 EDT
Article-I.D.: gcc-bill.318
Posted: Mon Sep 16 23:14:44 1985
Date-Received: Fri, 20-Sep-85 01:06:21 EDT
References: <1858@bmcg.UUCP>
Reply-To: brad@gcc-bill.UUCP (Brad Parker)
Organization: General Computer Company, Cambridge Ma (Home of the HyperDrive)
Lines: 65
Summary:
In article <1858@bmcg.UUCP> fredc@bmcg.UUCP (Fred Cordes) writes:
>
> I first saw ray casting/ray tracing at SIGGRAPH 83. I listened to James
> Kajiya's paper...
(He's only one crazy enough to ray trace fractals!)
> The problem is I can't get a handle on how objects are described when they're
> ray traced.
> Thanks much, Fred Cordes
This will probably be one of 10,000 replies, and I probably am the last
who should try and explain this, but after listening to Turner Witted
last year, I went out and wrote code to do this...
The idea I use to explain this is a so called "pin hole camera". Imagine a
camera which is made from a shoe box. The "film" is taped to one end of
the inside of the box, and a small "pin hole" is made in the other end.
All light stiking the film passes through the small hole.
Your code creates an "image plane" which corresponds to the
film. An easy way to do this is to create an array in which each element
corresponds to one pixel. Your code sends a "ray" from each element in
the array (or pixel) through the "pin hole" into the object space. When
the ray hits and object in the object space, you calculate the intensity
of the light at the intersection point and color the pixel in the array.
Rays are described as a starting point and a direction. The starting
point is easy (x in array, y in array, z = -(distance from image plane to
pin hole)). The direction is a vector from the image plane point towards
the pin hole. To find intersections in the image plane, you must
describe each object in such as way that you can find the intersection
of the object and a line described as a point and direction vector.
Start with a sphere (ever wonder why so many ray traced pictures have
spheres in them?). x**2 + y**2 + z**2 = r**2. Describe your ray as
x = x0+x1*t, y = y0+y1*t, z = z0+z1*t. (x0, y0, z0) is the starting point and
(x1,y1,z1) is th direction vector. Substitute the ray as a function
of t into the equation of a sphere. Solve for t. Once you have the
algebraeic eqation for the intersectoin in t, you are set. For each ray,
solve for t. If t is real (not imaginary), you have an intersetion.
Substitute t back into the ray equation and find the 3d point of the
intersection. At this point, it is wise to calculate the normal vector
at the point of intersection, as this is critical to calculating the
illumination value (this is done by taking partial derivatives of the
sphere equation in x,y, and z). See any good graphics text on this.
You should also send a ray toward the light source to determine if the
intersection point is in a shadow or is directly illuminated.
There you have it, simple ray tracing (sorry to those who already know this).
Other objects are similar, you need only determine a method of
solving for for the intersection "t" alongs the ray and determine the
normal vector at the point of intersection. Turner Whitted supposedly
published some "cook book" code for this whole process at this year's SIGRAPH.
You can produce code which treats the "image plane" as a normalized
coordinate space (-1 < x < 1 and -1 < y < 1) and map the resultant pixel
locations into your bitmap. Doing things in a normalized way has many
advantages.
Good Luck. Ps: Your pictures will probably come out upside down the first
time. I assume this is homage paid to some graphics diety who no
doubt resides somewhere in Utah ;-)
(wow - did I really type all this?)
--
J Bradford Parker
uucp: seismo!harvard!gcc-bill!brad
"She said you know how to spell AUDACIOUSLY? I could tell I was in love...
You want to go to heaven? or would you rather not be saved?" - Lloyd Coal