CS 148 Fall 2020-2021 Due Date: Monday, 5 October 2020 by 7 pm PT

Follow the instructions carefully. If you encounter any problems in the setup, please do not hesitate to reach out to CAs on Piazza or attend office hours on Nooks.

Be aware of the Checkpoints below. Make sure you complete each one since we will do the grading based on them.

This week, we will write a Python ray tracer in Blender. The scene is created in Blender, and we will use scripts to get information from the scene through Blender's Python API, and create our own routine for bouncing lights in the scene to get rendered images. The image above shows the four main steps to our final image. The power of ray tracing mostly lies in step 3 and 4, where we add reflection and transmission to the objects. In contrast, scanline renderers cannot handle them with physical correctness.

This week, we will create a ray tracer using Python in Blender. The scene is created in Blender, and we will use scripts to get information from the scene through Blender's Python API, and create our own routine for bouncing lights in the scene to get rendered images. The image above shows the four main steps to our final image. The power of ray tracing mostly lies in step 3 and 4, where we add reflection and transmission to the objects. In contrast, scanline renderers cannot handle them with physical correctness.

For shading, we will adopt a popular shading model called Blinn-Phong. It is a simple but sufficient (at least for this simple ray tracer) approximation of how light interacts with objects, and is adopted by OpenGL and Direct3D as the default shading model. Read more here.

<aside> ⚠️ Start early! This assignment is more coding intensive than the others. Checkpoint 1-3 only require Tuesday's lecture, checkpoint 4-6 will need Thursday's lecture.

</aside>

<aside> ⚠️ Please read through this handout before you start coding. We provide many helpful tips here.

</aside>

<aside> ⚠️ There will be a lot of math and logic that you need to comprehend before writing your own ray tracer. If you get overwhelmed at any point, we suggest you review the lecture slides and make sure you understand the high-level idea.

</aside>

First, download the .blend file for this homework.

http://web.stanford.edu/class/cs148/assignments/hw3_ray_tracing.blend

There's nothing more to it other than two text files, an already set-up scene, and a better workspace layout for doing scripting work. You can copy the scripts to a blank Blender file, add/delete objects and lights, and everything should work as well. However, please do not change anything in the scene for submission.

I. Scripting in Blender

In this homework, we will use Blender's scripting functionality to write a ray tracer.

I.1. Start Blender from command line

<aside> 📖 For Python development in Blender, it is easier to use the console/terminal since the Blender output will be there, making it easier for us to print debug information, such as print(). To use the console, we need to launch Blender from the command line. See the Blender manual for more information.

</aside>

First, start Blender from the command line. The command line will be the place we see debug information.