CS 6620 - Fall 2017 - Ray Tracing for Graphics

Project 2 - Shading

Kevin Parker


Images

RGB image

Z-buffer


Challenges

I had two main challenges and a couple of much smaller missteps with this assignment.

Bad Cast

This is actually a bug that rolled over from project 1, but didn't have any relevant code at the time to expose the bug. I was accidentally trying to cast an "Object" type to a "Node", which caused all kinds of strange issues when I wasn't able to access the data I needed. I was wondering if I was being messy with memory allocation and freeing in any random place in the program. However, I realized they weren't even in the same inheritance hierarchy and fixed the issue. If any interesting output were produced, I would give a screenshot here, but this mostly just produced a black screen. Those are pretty easy to imagine, without a sample image.

Stale Memory

The second cause was related to stale data being stored on the stack and never being reset. Specifically, I was never zeroing out the value of each color before using it again, so it caused both undefined behavior and incredibly bright colors (in the thousands) getting brighter in the last pixels rendered for the section. Specifically in the image below, note how the top-left pixel of each "chunk" (of 64x64 pixels) is sometimes (due to luck alone) the correct color, then everything past there (apparently in column-major order, since I wasn't careful with my loop order) was way brighter than expected.

The final issue I hit was very trivial to fix. I forgot to poll the children for their materials and accidentally was grabbing the parent's material. Note how the sphere at the top-right is blue instead of red.

Forgot Children Materials


Timing

19ms render time on 8 threads, rendering to the image row-major. (A couple more milliseconds for column-major as I discovered by the "Stale Memory" bug above).


Machine Specs

MacBook Pro (15-inch, 2016)

2.7 GHz quad-core Intel Core i7 Skylake (6820HQ)

16 GB 2133 MHz LPDDR3 RAM