I started to develop raytracer using C++ for learning computer graphics.

You can find source code in here.

Main references for this raytracer are:

First, I wrote BMP image writer and math, vector utils. Then I wrote sphere, plane, world, light structures and basic intersection code. Most raytracer tutorials starts teaching using global illumination and there is a good reason for that. The power of raytracing is creating a photorealistic image using global illumination in relatively small code. But I started using direct illumination from my small OpenGL-rendering experiences to understand the core concept.

Diffuse Lighting

After writing the diffuse lighting code image is already getting started to look good and 3D-ish. Now, we need hard shadows for direct illumination. I used a very simple solution for hard shadows. Just throw shadow ray to light and check for intersection. If there is a intersection then threat that pixel as a shadow. Super simple stuff:

Hard Shadows

Then I added more lights to the scene and wrote very simple and not physically accurate multi light support. Just for seeing multiple shadows. And image looks good for such basic calculations. In the next blog post, I will try to implement little more realistic light calculations for this raytracer.

Render