<p>The problem was in the way I was calculating the function <code>bool Sphere::hit()</code>. 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 <code>hit</code> function will not work as it is supposed to. In case someone else is stuck, that might be the problem.</p>

CC BY-SA 4.0
2019-02-17T13:47:40.817Z
2019-02-17T13:47:40.817Z
maurock
<p><b> Problem </b></p>

<p>I am following the book <b>Ray tracing in one weekend </b>, 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:</p>

<p><a href="https://i.sstatic.net/EIo3S.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EIo3S.png" alt="enter image description here"></a></p>

<p>Instead, my implementation results in this:</p>

<p><a href="https://i.sstatic.net/M0qkU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/M0qkU.png" alt="enter image description here"></a></p>

<p>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. </p>

<p><b> Possible solution </b></p>

<p>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:</p>

<p><a href="https://i.sstatic.net/vnLjf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vnLjf.png" alt="enter image description here"></a></p>

<p>This suggests that the problem is not the reflection function, nor the material. </p>

CC BY-SA 4.0
2019-02-16T13:40:43.293Z
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.
gallickgunner
CC BY-SA 4.0
2019-02-16T15:09:23.743Z
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.
lightxbulb
CC BY-SA 4.0
2019-02-16T17:34:14.277Z
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.
lightxbulb
CC BY-SA 4.0
2019-02-17T01:31:50.447Z
It seems like the normals on your spheres are wrong.
Sebastián Mestre
<raytracing><reflection>
Ray tracing in One weeked: issue with metal reflection
maurock
# Ray tracing in One weeked: issue with metal reflection

(Asked by: username_0 on 2019-02-16)

**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](https://i.sstatic.net/EIo3S.png)](https://i.sstatic.net/EIo3S.png)

Instead, my implementation results in this:

[![enter image description here](https://i.sstatic.net/M0qkU.png)](https://i.sstatic.net/M0qkU.png)

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](https://i.sstatic.net/vnLjf.png)](https://i.sstatic.net/vnLjf.png)

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

**Tags:** raytracing, reflection

> **Comments:**
> **username_1**: 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.  
> **username_2**: 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.  
> **username_2**: 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.  
> **username_3**: It seems like the normals on your spheres are wrong.  

---

## 1 answers

### Answer by username_0 on 2019-02-17. Score: 0 | Accepted answer

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.


---

