That is exactly what a ray tracer does, except in reverse. It would be horribly wasteful to calculate all the rays that eminate from a light source, in hopes that a few will eventually make it to the image. Instead, a ray tracer starts with the simplifying assumption that the only light rays we care to map are the ones that actually make it to the camera, and so that is how the processing is done. Conceptually, we just shoot light rays backwards through the scene and bounce them off objects in a scene and if the ray eventualy hits a light source, then we know that we can color the corresponding pixel of the image according to the objects that the ray bounced off from. In all, its a lot of trigonometry.
And, in answer to your question Dad, it is exactly the same as a mathematical ray. I have been visiting Wikipedia, a lot, to refresh my brain on the quadratic equation, vectors, dot products, and general trigonometry. As a sampling, I took the equation for a 3D sphere and the equation for a ray/line and solved to find the distance along the ray where the ray intersects the sphere, this is the result:

I then solve that equation and, voila!, I know if a ray hit the sphere! Got it? ;)
Here are some images of the latest work on the ray tracer. I added light sources and some diffuse shading of the sphere. The sphere now actually looks something like a sphere, and less like a plain circle.
This the first image I rendered where it actually looks like a sphere. The light source is off image to the upper left. My heart skipped a beat out of sheer surprise when it came out looking so clean and clear (and correct). :)

This image is after a few hours of bug fixing, and adding in a ambient light factor. This is an image of a blue sphere with two light sources, way off in the distance, they are visible in the image as two white dots to the upper left and right of the sphere. Notice how the shading of the sphere is different based on the position of the light sources. The upper left light is further away, and so its shading is different.

Now, I just need to blog about something that is not ray tracing related, lest this become a ray tracing blog. *hrmm...* Forget it, I'm pretty focussed on this thing for now, I fully intend that this ray tracer becomes part of a software portfolio that I can share with future prospective employers. Till next time...
No comments:
Post a Comment