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

Raytrace Theory Help

Started by adoado Oct 3, 2010 at 6:32 PM 3 replies 1.2k views
Original Post
adoado
adoado
Hi all,

I am currently trying to build my own implementation of a ray tracer; so far, I have implemented a very simple lighting model, but I am stuck on the idea of how reflection will work. Here is why:

Every intersection, I perform another trace to see what is 'reflecting' on this object; my problem is, will the secondary intersection be lit? How can it be - I am still performing the lighting?

Essentially, I have no idea of the lighting at the location of the reflection intersection. How do I get this, as the location itself has not even done initial tests yet? Do you render once for diffuse lighting, then the whole scene again for reflections, etc. and simply add them?

Cheers for reading,
Adrian G.
Darg
Darg
Hrm, well think about how you would do it if the initial object wasn't reflective.

You would shoot the way, it would hit the object, you would then shoot shadow rays towards any lights within range in order to test whether it is in shadow or not, you add the light up for those lights that aren't shadowed.

You do the exact same thing with reflection/refraction apart from the fact that you allow the ray to bounce a certain amount of times around the scene. Say you have a reflection limit of 8, it would bounce off reflective objects 8 times or until it came to a non-reflective object. Then, starting with that last object hit you would calculate the colour for it using the standard method of sampling texture, gathering light etc. Once you have its final colour you save that and move back one bounce to the previous intersection. You gather the same information for that but you also factor in the colour of the object you just calculated for the reflective value.

You keep moving back up the list of reflections, using the previous colour value as the reflective colour of the next one up the list until you reach the first object you intersected which is where the actual pixel will be drawn to the screen. You do the same calculations for that and then draw it.

The only difference then between reflections and refractions is the angle of the new ray being shot out from the initial intersection.
Portfolio & Blog:http://scgamedev.tumblr.com/
Liam M
Liam M
You may find the articles on the long defunct Flipcode of some interest:

http://www.flipcode.com/archives/articles.shtml

"Raytracing Topics & Techniques by Jacco Bikker" is a good introduction to some raytracing concepts. I'm hesitant to describe too much, because your question can be answered in a few ways.

[Edited by - Liam M on October 3, 2010 10:17:33 PM]
cignox1
cignox1
Suppose you have your main rendering function:

TraceRay()

wich computes the intersection and performs the diffuse lighting. What you need to do is simply call that method again on the reflection ray and add the resulting value to the final pixel color. For this you usually use recursion.

Anyway, the tutorial reported is really a nice introduction to RT.
adoado
adoado
Hey everyone, thanks a lot for the feedback! It has definitely helped clear that up.

Cheers!
Adrian G.

Topic Locked

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

Sign in to reply to this topic.