The Ray Tracer Challenge: reflection tests 4 and 5 failing

@jamis

I’m getting odd values for my color calculations in tests 4 and 5 in the reflection section-

github.com/zdybak/ray

The tests are line in world.rs starting on lines 349 and 367

I’ve put in some debug statements in shade_hit to see what’s going on-

Blockquote

---- world::tests::reflected_color_of_reflective_material stdout ----
Hit detected shadow:true with surface: Color { red: 0.08000000000000002, green: 0.1, blue: 0.06 }
and reflected: Color { red: 0.0, green: 0.0, blue: 0.0 }
results in : Color { red: 0.08000000000000002, green: 0.1, blue: 0.06 }
Hit detected shadow:true with surface: Color { red: 0.1, green: 0.1, blue: 0.1 }
and reflected: Color { red: 0.04000000000000001, green: 0.05, blue: 0.03 }
results in : Color { red: 0.14, green: 0.15000000000000002, blue: 0.13 }
thread ‘world::tests::reflected_color_of_reflective_material’ panicked at ‘assertion failed: (left == right)
left: Color { red: 0.07, green: 0.07500000000000001, blue: 0.065 },
right: Color { red: 0.19032, green: 0.2379, blue: 0.14274 }’, src\world.rs:345:9
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

---- world::tests::shade_hit_with_reflective_material stdout ----
Hit detected shadow:true with surface: Color { red: 0.08000000000000002, green: 0.1, blue: 0.06 }
and reflected: Color { red: 0.0, green: 0.0, blue: 0.0 }
results in : Color { red: 0.08000000000000002, green: 0.1, blue: 0.06 }
Hit detected shadow:true with surface: Color { red: 0.1, green: 0.1, blue: 0.1 }
and reflected: Color { red: 0.04000000000000001, green: 0.05, blue: 0.03 }
results in : Color { red: 0.14, green: 0.15000000000000002, blue: 0.13 }
Hit detected shadow:true with surface: Color { red: 0.1, green: 0.1, blue: 0.1 }
and reflected: Color { red: 0.07, green: 0.07500000000000001, blue: 0.065 }
results in : Color { red: 0.17, green: 0.17500000000000002, blue: 0.165 }
thread ‘world::tests::shade_hit_with_reflective_material’ panicked at ‘assertion failed: (left == right)
left: Color { red: 0.17, green: 0.17500000000000002, blue: 0.165 },
right: Color { red: 0.87677, green: 0.92436, blue: 0.82918 }’, src\world.rs:363:9

Blockquote

It looks to me like the green of the default world sphere is instantly only getting ambient because it’s coming up as in shadow, but if the ray is cast down and bouncing up to the bottom of the sphere then I think that’s correct anyway?

Neither of my calculated colors (left side) are even close though.

The issue turned out to be my implementation of planes was not applying local translations to the ray, and basically the plane transform was being ignored. (It became quite clear after rendering the image and seeing the plane bisect the sphere).

More details are listed in the old book forum - Chapter 11 Test #4 and #5 | The Ray Tracer Challenge

1 Like