# Ray Tracing Help

Hi guys, I’m trying to implement a backwards ray trace and I’m a little lost. I know that I have to send a ray through every pixel and see if it collides with something. I have written a class for a ray that contains an origin and a direction, but I’m not sure how to apply it to go through every pixel, see if it collides with anything, get its color, store it and then display it. if anyone has any input, please let me know.

Start from the point of view. Then trace rays from this point of view which go threw any pixel of your screen then continue these rays to see which object it interacts.
Then regarding the nature of these objects, you’ll need to refract, reflect the ray to know the color behind (in case of transparency), and/or if the object is lit or in shadow.

In fact Ray Tracing has nothing to do with OpenGL. One might use OpenGL to show the result generated by a Ray Tracer in Real Time or something like this.

Ray Tracing is commonly used as a offscreen rendering due to the quality of final image and time spend to generate a single frame.

When I started in Ray Tracing world (and this was last year) I use OpenGL to actually view the rays across the scene. Ofcourse I was dealing with a small amount of rays just for learning process.

I think the most important concept regarding ray tracing is to understand its basic concepts like, physics of light, what is a ray and what kind of rays a ray tracer must deal with (primary, shadow, reflective, refractive) and the last, but most important, how do compute collisions between rays and objects.

Collision detection is a key concept behind ray tracing. One need to implement collion between ray and objects as fast as possible. Many data structures are used together with ray tracing in order to minimize such time (i.e. BVH, KD-Trees, OcTrees), but this is an advanced topic and you should start with the basic ones.

As basics, don’t forget to learn about 3D vectors, matrix multiplications, homogenous coordinates, and projections.

Thanks for the help guys. I understand the process of shooting a ray through each pixel on the screen and then seeing if it collides with anything, but what I am confused is the actual syntax and code for doing this. I know that to shoot a ray through a pixel, you need to take into account the aspect ratio and the field of view, but I don’t how to apply those to run through every point and then check if it collides with anything.

Did you learn about the concepts I mentioned above ?

``````
for (y=0;y<height;h++) {
for (x=0;x<width;x++) {
color[x,y]=shoot(unprojectPixelToWorldVector(x,y));
}
}

``````

Hi ZbuffeR,

Yes, I am familiar with vectors, matrices, and coordinates, but I am less familiar with projections.

I think I figured out how to send a ray through each pixel, but, I am still a little confused on how to do the intersect calculation. I know that I have to check if the ray is contained in a triangle, vertex, or sphere, but I don’t know how.

This is an OpenGL forum, not a ray tracing forum. And OpenGL is a rasterizer, not a ray tracer. Google is probably more likely to find you answers. Just search for things like “ray triangle intersection.”