<p><code>p</code> is gonna be zero for light sources. Light sources are defined by emission variable and color is zero for them. Hence the reflectance parameter calculated previous to this line <code>p</code> would be zero giving us <code>obj.e</code></p>

CC BY-SA 4.0
2019-04-01T06:04:50.273Z
2019-04-01T06:04:50.273Z
gallickgunner
<p>For those familiar with smallpt, the ray tracer in 99 lines: I am checking the code, and there is something that is not clear to me in the DIFFUSE ray scattering.
After the rays are shot, they keep bouncing until the if-statement with the Russian Roulette stops them. <br></p>

<pre><code>if (++depth&gt;5) if (erand48(Xi)&lt;p) f=f*(1/p); else return obj.e;
</code></pre>

<p>This means that, when rays are scattered and hit the light source, they don't actually stop there (which is what I thought at first: rays bounce until they hit the light source, or until they reach a specific amount of bounces). Am I missing something?</p>

CC BY-SA 4.0
2019-03-29T15:41:04.517Z
`p` is gonna be zero for light sources. Light sources are  defined by emission variable and color is zero for them. Hence the reflectance parameter calculated previous to this line (`p`) would be zero giving us `obj.e`
gallickgunner
CC BY-SA 4.0
2019-03-29T19:27:35.140Z
Getting a bounce off a lightsource is normal - imagine that your light source actually reflects light (like in the real world). However as @gallickgunner mentioned in the specific scene that you have the light source does not reflect any light (this doesn't need to be the case however).
lightxbulb
CC BY-SA 4.0
2019-03-30T23:20:49.147Z
@lightxbulb - wouldn't the contribution by the reflected light in that case be negligible unless the light's emission is very dim. I've always wondered that we could model real world light sources by an outer non-emissive shell and an inner emissive part. That way we can safely say that we stop when ever we hit a light souce or more specifically the core emissive part.
gallickgunner
CC BY-SA 4.0
2019-03-31T06:32:40.600Z
@gallickgunner What does the lightsource being dim have to do with its reflectivity? On what basis do you say it's "negligible"? And why do you believe you can throw away "negligible" contributions? You can always model a light the way you said, but that's only if that model is accurate to your use case. Note that the proposed model also ruins NEE.
lightxbulb
CC BY-SA 4.0
2019-03-31T07:12:38.827Z
I mean if the light source isn't dim, you aren't going to see the outer shell anyway. The emission part will be much stronger than an indirect reflection off the surface of the light source. It's gonna be "negligible" in the sense that it's not gonna add much to what's already there due to the emission part.
gallickgunner
CC BY-SA 4.0
2019-03-31T10:32:14.543Z
@gallickgunner That's wrong. Assume the light is however strong you want (not infinitely though), now assume it perfectly reflects light from one direction only, stick a light 100x stronger than your light there, you would have reflected radiance 100x stronger than your non dim light's radiance. In general such arguments like "negligible" do not work unless you can define robustly what "negligible" is and formally prove that it is indeed "negligible". My example clearly illustrates a case where the error can be arbitrarily large, thus not negligible by any informal meaning of the word.
lightxbulb
CC BY-SA 4.0
2019-03-31T11:05:43.810Z
Ok but there's another problem, if the scene consists of 10 lights. Upon striking a light source we'd have to loop over all the remaining ones and gather all the contributions then. That'd be endless. I'll ask a separate question about it though
gallickgunner
CC BY-SA 4.0
2019-03-31T15:24:40.753Z
@gallickgunner It will not be endless in general, it will be endless only if your operator is not a contraction and there is no way for enough energy to escape at the same time - then yes, in that case you won't have a steady state.
lightxbulb
CC BY-SA 4.0
2019-03-31T18:51:24.753Z
@gallickgunner Thank you for your answer, it's what I was looking for. If you write it in the answer, I can give you the best answer. Also, I have a question on how MC importance sampling works in smallpt, I'm going to ask it in a different question.
maurock
<raytracing><pathtracing><c++>
smallpt: when to stop diffuse ray scattering
maurock
# smallpt: when to stop diffuse ray scattering

(Asked by: username_0 on 2019-03-29)

For those familiar with smallpt, the ray tracer in 99 lines: I am checking the code, and there is something that is not clear to me in the DIFFUSE ray scattering.
After the rays are shot, they keep bouncing until the if-statement with the Russian Roulette stops them.

```
if (++depth>5) if (erand48(Xi)<p) f=f*(1/p); else return obj.e;

```

This means that, when rays are scattered and hit the light source, they don't actually stop there (which is what I thought at first: rays bounce until they hit the light source, or until they reach a specific amount of bounces). Am I missing something?

**Tags:** raytracing, pathtracing, c++

> **Comments:**
> **username_1**: `p` is gonna be zero for light sources. Light sources are  defined by emission variable and color is zero for them. Hence the reflectance parameter calculated previous to this line (`p`) would be zero giving us `obj.e`  
> **username_2**: Getting a bounce off a lightsource is normal - imagine that your light source actually reflects light (like in the real world). However as @username_1 mentioned in the specific scene that you have the light source does not reflect any light (this doesn't need to be the case however).  
> **username_1**: @username_2 - wouldn't the contribution by the reflected light in that case be negligible unless the light's emission is very dim. I've always wondered that we could model real world light sources by an outer non-emissive shell and an inner emissive part. That way we can safely say that we stop when ever we hit a light souce or more specifically the core emissive part.  
> **username_2**: @username_1 What does the lightsource being dim have to do with its reflectivity? On what basis do you say it's "negligible"? And why do you believe you can throw away "negligible" contributions? You can always model a light the way you said, but that's only if that model is accurate to your use case. Note that the proposed model also ruins NEE.  
> **username_1**: I mean if the light source isn't dim, you aren't going to see the outer shell anyway. The emission part will be much stronger than an indirect reflection off the surface of the light source. It's gonna be "negligible" in the sense that it's not gonna add much to what's already there due to the emission part.  
> **username_2**: @username_1 That's wrong. Assume the light is however strong you want (not infinitely though), now assume it perfectly reflects light from one direction only, stick a light 100x stronger than your light there, you would have reflected radiance 100x stronger than your non dim light's radiance. In general such arguments like "negligible" do not work unless you can define robustly what "negligible" is and formally prove that it is indeed "negligible". My example clearly illustrates a case where the error can be arbitrarily large, thus not negligible by any informal meaning of the word.  
> **username_1**: Ok but there's another problem, if the scene consists of 10 lights. Upon striking a light source we'd have to loop over all the remaining ones and gather all the contributions then. That'd be endless. I'll ask a separate question about it though  
> **username_2**: @username_1 It will not be endless in general, it will be endless only if your operator is not a contraction and there is no way for enough energy to escape at the same time - then yes, in that case you won't have a steady state.  
> **username_0**: @username_1 Thank you for your answer, it's what I was looking for. If you write it in the answer, I can give you the best answer. Also, I have a question on how MC importance sampling works in smallpt, I'm going to ask it in a different question.  

---

## 1 answers

### Answer by username_1 on 2019-04-01. Score: 0 | Accepted answer

`p` is gonna be zero for light sources. Light sources are defined by emission variable and color is zero for them. Hence the reflectance parameter calculated previous to this line `p` would be zero giving us `obj.e`


---

