I'm following this book, Computer Graphics from scratch: A programmer's introduction to 3D rendering, to build a simple raytracer and rendering the scene to a bitmap image. I've run into a problem when doing the recursive reflections. When the program performs the recursion, the image ends up having corrupted pixel/color data (not sure how else to explain it). I've run into a similar problem earlier when I added specular reflections because I forgot to saturate the color values. However, now I'm not sure where the problem is.
The first image is what it currently renders. The second is what it should look like (aside from the image size).
This is the output without any recursive reflections for reference:
Here is my code (c++):
Defines.h (where I define the bitmap header data as well as other things)
I'm not familiar with bitmap formatting. I used this as a reference.
main.cpp (where all the functions related to the raytracing algorithm are defined and used and where I write the data to the .bmp file)
You can assume the math functions work. If needed I can provide the math library in an edit.
I noticed if I removed lighting or just scaled the color by a constant value but still do the recursion I get this result:
I don't know if the problem lies with my implementation of the algorithm or how I'm handling writing the data to a bitmap file. I've looked over the algorithm in the book and compared it to my implementation and I don't see anything different, but maybe another set of eyes can help.
Thanks.