Ray Tracer in Python (Part 4) - Show Notes of "Let there be light"

3 min read · Posted on: Mar 28, 2020

Probably a global lockdown is a good time to resume a series that demands a lot of your time. Not really if your kids are home too. But I’ve been getting enough reminders through comments and emails that I thought it’s time to tackle this challenging episode.

Yes, this is an episode with a lot of Physics and Mathematics. But you will observe it has a very gentle learning curve since there is enough background presented in the problem requirements and in previous episodes. The real challenge is in translating the math to code.

Computers are computing devices crunching numbers all the time. So you might think implementing math formulas should be straightforward. Unless you are a scientist or a mathematician, in which case, you would know the truth which is – it is not straightforward at all.

I remember before Doom came out, it was very hard to develop a 3D engine. Most of the available research involved understanding computer graphics text books with a lot of math theory. It’s a painful task to translate formulas into algorithms and later performant code. There are many ways you could get it wrong. But only one way to get it right. Even more frustrating is forgetting to account for edge conditions like a negative result or divide by zero and floating point errors.

I remember referring one of the most popular books at that time Numerical Recipes in C++ to understand how to implement some of the algorithms. But I had to abandon the project after a working prototype because making a game engine (alone) is a tonne of work!

In this part, I have used a lot of images and slides to make sure that I don’t skip any explanations (like how cosine and dot products are related). I know that these videos are being watched by all kinds people – students, experienced programmers and non-programmers. So I have not made any assumptions.

Hopefully you would enjoy this part without any challenges. Even if you do, it should be fun 😊

These are the topics we will cover in this episode:

  • Introduction
    • Adding lights
    • Phong reflection model
    • Ambient, Diffuse and Specular Shading
  • Sub-problem: Let there be light
  • Coding the solution
    • New classes
    • Command-line arguments with argparse
    • Progress Bar(?)

Here is the video:

Code for part four is tagged on the Puray Github project

Show Notes

Books and articles that can help understand this part:

  • Game Engine Architecture Great introduction to graphics concepts and techniques used in computer games. It might be different from raytracing since focus is on realtime rendering rather than realism.

  • Argparse Tutorial argparse is the new standard for Python argument parsing.

Note: References may contain affiliate links


Don't miss any future posts!

Share on: Twitter, Hacker News, Reddit, Facebook, Google+

Next: ▶   Ray Tracer in Python - Show Notes of "Ray Tracing a Coronavirus"

Prev: ◀   A Guide to ASGI in Django 3.0 and its Performance

Up: ▲   Blog

Hi! Welcome to ArunRocks, an odd collection of writeups on programming, travel, gadgets and practically anything under the sun. This state of affairs could be blamed on the ecelectic interests of your host, Arun Ravindran. He loves programming in several languages especially Python.

Frequent Tags

python (36) django (19) movies (11) productivity (11) tutorial (10) gaming (8) humour (8) creativity (7) featured (7) screencast (7) puray (6) python3 (6) ray-tracer (6) review (6) programming (5) wordpress (5)


comments powered by Disqus