Wednesday, 24 February 2021

Ray Tracing in One Weekend Review

I've now finished this web book; admittedly it took me a little longer than 1 weekend due to chores and other things getting in the way but it's definitely doable in one weekend.

It basically teaches you how to brute force your way to creating a ray tracer using C++ and a lot of scary looking maths equations. With that said, it's basically an exercise in copying code correctly as there isn't much interaction with the concepts taught. That is left up to you at the end of the book.

Instead you will go through creating materials, cameras and various methods like calculating reflections that can be used in whatever your mind cooks up. You will have this scene by the end of it though:

Ray Tracing in One Weekend Review

That is the final image size for me; it's 400x225 with a paltry 100 samples per pixels and it took a whopping 27 minutes to render. This is where you can do some self-learning and improve the code. I've already tasked myself with parallelising the pixel calculations as currently the program only uses 1 core and 1 thread to do all the work.  I have an i7-4790k which has 4 cores (and therefore 8 threads). I could use the standard C++ library to spin up as many threads as possible across all cores and get the render done much faster.

I have very little experience with multi-threading so this seems like a nice way to ease myself into the subject. After that, I'd like to create some more material types and perhaps even make the render interactive by being able to move the camera? I would have to turn the the samples per pixel down to about 15 but I think it would be doable. I think this would be similar to how Blender displays objects when you switch to the cycles renderer.

I think if you are an absolute beginner into graphics or general programming this will go over your head. The author doesn't even mention how you create the image and assumes that you know to call a certain command in command line. For reference you navigate to the folder the exe is stored in and type: RayTracing.exe > image.ppm

This will redirect cout to the supplied format instead. I found the PPM to be a bit bulky as it's all text but allows you to spot bad pixels easily (useful when attempting to multi-thread). PhotoShop opens it fine but I had difficulty finding another program to open that format as the IrfanViewer website was blocked by my anti-virus.

All in all; worth a weekend or two of your time if you're interested in rendering, graphics and ray tracing. There are two other books to complete after this as well that go into more depth on the topic.

No comments:

Post a Comment