Skip to main content
GameDev.net gamedev.net
🔒 Locked

Ray Tracing Shadows and Refraction

Started by Geometrian Jun 7, 2008 at 4:06 PM 7 replies 3.5k views
Original Post
Geometrian
Geometrian
Hello, I'm making a ray-tracer. It will have reflection, refraction, and shadows. I started with spheres, because they are simple. Before I move to polygons I want these effects. There weren't really any good resources for making a ray-tracer in Python, (which is what I mostly use), so I just figured it out. As a consequence, I know precisely how every bit of it works, and am not just stitching together other peoples' code. Here's some screenshots of what I've got so far: http://geometrian.com/Gallery.php. It is pretty fast, even though it is in Python and not optimized. As you can see, I have succeeded at making a ray-tracer which renders shadows and reflections quite well. I am, however, noticing a problem implementing refraction. Refracting objects bend light. It has occurred to me that refracting objects should bend shadow rays too. As the picture demonstrates, a direct-line shadow ray (black) would hit a refracting object and be bent (bending black), not reaching the light. The point would be interpreted as being in shadow. An alternate indirect shadow ray (red) would actually illuminate it, so the conclusion that the point is in shadow is wrong. Ray Tracing Refracting Objects with Shadow Rays Because I want my ray-tracer to be as accurate as possible, it must support shadows and refraction at the same time. How can this be done? Thanks, Geometrian
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
nullsquared
nullsquared
Ray tracing is done backwards - instead of light rays hitting the eye, the eye "rays" hit the light. Meaning, refractions and what-not cannot redirect the light, since you're not tracing the light. This is where solutions such as photon mapping come into play.
Neutrinohunter
Neutrinohunter
Ray Tracing can be done either way, there are forward and backward versions which are possible. Though you have found a limitation in the technique that you are using. Look into path tracing, monte carlo ray tracing and photon tracing. Any of those techniques will improve what you have.
Geometrian
Geometrian
OK, thanks everyone.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
Lord Crc
Lord Crc
In addition you can do it both ways at "the same time", called Bidirectional path tracing. It can however be a bit tricky to implement. One paper describing it can be found here. Also, Veach's thesis is considered a very good source.

If you're "just" after something which looks good, I'd recommend you try out photon mapping first. It's relatively easy to implement, and produces nice results.
cignox1
cignox1
IMHO you should leave this issue apart for now. There are many other things in a RT you should consider (what about meshes, acceleration structures, textures?). For example, one you have your reflection/refraction code working in a basic way, you could implement Fresnel to compute reflection/refraction coefficents given the light incidence angle. Then simple textures and normal mapping (wich is not all that complex).

Once you have this basic raytracer ready, you can move to global illumination with one of the aforementioned algorithms (path tracing, bidirectional path tracing, photon mapping,...). This will take into account indirect light effects (to correctly compute the 'ambient' term) and also the caustics for reflective/refractive surfaces focusing the light.

Of course, nothing prevents you from implementing a simple photon mapping just for caustics...
Geometrian
Geometrian
I just got a polygonal ray-tracer working--here's a wheel: http://www.geometrian.com/RayTracingGallery/Image12.png
so meshes, check! The optimization is still pretty bad though. Currently, it is based on bounding spheres. I imagine cubic space division or something would be faster.

I think I'll try photon mapping then.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.