Ray Tracing, Lighting, and Materials


I’m currently attempting to write a Ray Tracer using OpenGL. I have been reading the Red Book, as well as other sources to help me figure this all out. I’m a little confused though. I’ve defined a spotlight to use, and I’m using Specular lighting to simulate a shiney material. What I’m confused about is whether or not I should be using Diffuse or Ambient light as well. I’ve been trying out various combinations, but I can’t seem to come up with anything that gives me the really shiney results I’m looking for. Also, does OpenGL do the calculation of the reflections for you? Or do you have to specify the ray and determine the color yourself? Any help is appreciated!

OpenGL won´t do any raytracing for you, it uses rasterization.


So are you saying it’s impossible to do ray tracing with OpenGL (highly doubtful)? Or are you just saying that OpenGL will not handle the calculations for me and I have to write functions to do all that work?

I didn’t think OpenGL would do that, I was just looking for some clarification.


You need some more info about 3d computer graphics.

Raytracing is :

  • a way to simulate real light by using reverse path of the light (from observer to lights, bouncing on surfaces and going through deep semi opaque materials such as fog)
  • each pixel of the scene become a single ‘reverse photon’, tests for every surface it can bounce on, then is reflected, then loop until going to the void or hitting some iteration limit.
  • scene complexity is more linked to number of pixels and number of reflections than number of graphic primitives
  • the type of computations involved is not well suited to hardware acceleration (only hardware example I am aware of : Art Render Pure )

OpengGL is NOT raytracing. It is scanline rendering. Much more suited to hardware pipeline parallelism.

  • each triangle is drawn on screen. No reverse ligthpath, it is more like painting.

A more in-depth comparison of rendering techniques .

Of course, you can do some part in OpenGL and some in software ( example ), or even do some super-simple raytracing thanks to GL Shading Language.
Most of the time the best way is still to fake raytrcing, thanks to shadow mapping/stencil shadows and using cubemapped reflections : example here, news dated 31.12.04, have a look at the video :

I hope I made all that clearer.

CLICK! Thanks guys, you’ve clarified things for me.