This was one of my favorite class projects… the goal was to write a Ray Tracer using OpenGL. This is a video of the result, which has a magnifying glass, reflections, texture-mapping, shadows and anti-aliasing.
it’s hard to come by more satisfying coding, where the output isn’t just a string or graph, but pictures that sometimes look somewhat real.
The idea behind the ray tracer is pretty simple: image drawing lines from your eyeball through a screen to objects on the other side. Each pixel is a square in that screen. The tricky part, which doesn’t sound hard at all, was figuring out where the intersection of a random line from your eye and a point on a triangle or sphere was.
But that’s pretty much all there is to it: For each pixel, draw a line from your eye to that pixel and see where it hits imaginary objects floating on the other side.
-For shadows, draw lines from the light source to the objects.
-For reflections, just bounce the lines off each surface, adding in some color to the current line’s pixel based on how reflective the object is.
-Anti-aliasing: just make the grid finer and then average, say, 9 lines for each final pixel output.
(complete instructions)