In Part 7, we smoothed out the edges of our spheres using antialiasing. In this chapter, we start making these spheres look a little more realistic.
Speed Bump
After adding initial diffuse properties to the spheres I noticed a severe slowdown in execution time. I mean we’re talking over 5 minutes to complete the render process! I cracked open my performance monitoring tool of choice (XCode Instruments since I’m on a Mac) and started identifying long-running functions. It turned out all the random ray generation necessary to create a diffuse appearance was the culprit.
In the end, two changes dramatically increased speed:
- Increased the optimization level of the Rust dev profile:
[profile.dev]
opt-level = 1 - Fixing the shadow acne problem where too much speckling occurs by changing the second parameter passed into the world.hit() function from 0.0 to 0.001.
if world.hit(r, 0.001, INFINITY, &mut rec) {
This means we ignore more hits and don’t generate as many rays which makes things so much faster!
Three Diffusion Options
We now have three different options for creating diffuse lighting for our spheres:



Notice the subtle differences in shadow, shading, and color. Not sure if any one of these is better than the others, just different. All three of these options could be useful down the road as we render more complex scenes.
Metal
Next time, we start making these spheres look metallic! In the meantime, feel free to follow my code and the online book I’m following.
Tags: coding rust software