0
$\begingroup$

Problem

I am following the book Ray tracing in one weekend , and I got stuck after the implementation of the material Metal. I checked my code many times, and it looks exactly like the code implemented by Peter Shirley. The problem is that, at this point, my code would need to generate this image:

enter image description here

Instead, my implementation results in this:

enter image description here

There is no reflection on the left and right sphere, even if the code looks fine. I am not posting the code here since many classes are involved, and I implemented it following strictly the book. Did someone have a similar problem? I can post relevant parts of code that can help.

Possible solution

The function of the reflection is not the problem, since it is very simple and it is exactly like the one proposed in the book. Also, when I set the sphere below (the floor) as Metal instead of Lambertian, it shows the reflections correctly:

enter image description here

This suggests that the problem is not the reflection function, nor the material.

$\endgroup$
  • 2
    $\begingroup$ Try posting the relevant section where you calculate reflection. Are you using Monte-Carlo methods to simulate GI as well? The grey sphere is getting a greenish tint from the floor. Seems like color bleeding effect due to GI but simple raytracers don't do that. It could be that the reflection function is working partially. $\endgroup$ – gallickgunner Feb 16 at 13:40
  • $\begingroup$ You'll have to post the relevant parts of your code. Shirley's code is available on github, and it works correctly if you compile it, thus even if you say that the code is the same, it most certainly is not. $\endgroup$ – lightxbulb Feb 16 at 15:09
  • 2
    $\begingroup$ Note that it's not just the metal reflection that's wrong in your image, it's obvious that the middle (lambertian) sphere is also wrong. $\endgroup$ – lightxbulb Feb 16 at 17:34
  • $\begingroup$ It seems like the normals on your spheres are wrong. $\endgroup$ – Sebastián Mestre Feb 17 at 1:31
0
$\begingroup$

The problem was in the way I was calculating the function bool Sphere::hit(). The author eliminates some redundant 2's that cancel each other without explicitly showing it, and if you don't pay attention to this detail the code the hit function will not work as it is supposed to. In case someone else is stuck, that might be the problem.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.