CS 148 Fall 2021-2022 Due Date: Monday, October 25th 2021 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.

Rendered with the code from this homework. Timed on i9-9900X CPU @ 3.50GHz (single-threaded).

Rendered with the code from this homework. Timed on i9-9900X CPU @ 3.50GHz (single-threaded).

This week we will continue building our SimpleRT ray tracer. Last week we explored area lights and BSDF materials in Cycles. Starting from point lights and direct illumination only, we will then implement area lights, sampling, and global illumination in this homework.

<aside> ⚠️ Start early! Like HW3, this assignment is more coding intensive than the others.

</aside>

<aside> ⚠️ Rendering can take a long time! The final image will take an hour to render.

</aside>

To better demonstrate the effect of global illumination, we will use the classic Cornell box. Download the blender scene with an updated UI script simpleRT_UIpanels:

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

Then add your HW3 code to the current Blender file by selecting File ‣ Append, browse to your HW3 .blend file ‣ Text ‣ simpleRT_plugin. (Of course, you can also create a new text and copy-paste your code). The code will not work directly with HW5 scene, see below for the fix.

Make the following changes to your code from HW3:

  1. Update the code to use the same lighting system as Blender Cycles.

    Change the line for light_color from:

    light_color = np.array(light.data.simpleRT_light.color * light.data.simpleRT_light.energy)
    

    to:

    light_color = np.array(light.data.color * light.data.energy / (4 * np.pi))
    

    Your code should run at this point after you run simpleRT_UIpanels. The image may look incorrect — we'll fix that in the next step.

  2. Update the condition that determines if a location is in shadow or not. In the HW3 code, we did not account for the situation where shadow rays hit objects behind the light. This means that the current location will be shadowed when there are objects behind the light, which should not happen. We need to fix it by having a stricter condition to determine shading.

    Introduce light_hit_loc to receive the hit location of the shadow ray:

    # cast the shadow ray from hit location to the light
    has_light_hit, **light_hit_loc**, _, _, _, _ = ray_cast(scene, new_orig, light_dir)
    

    Then add another condition to the if-statement that checks has_light_hit to tell if the object is in shadow. (Hint: the distance that the shadow ray travels from the hit location should be less than the distance to the light.)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1d0e0ee8-cba5-455d-a3b3-f960fa9231ef/step1.1.jpg

<aside> ⚠️ Your submission images should be rendered at 100%, e.g. 480 px × 480 px, and depth set to 3. You can turn down the resolution during debugging.

</aside>