<p>I will not answer your questions directly, but will try to change your mindset a bit. I hope got your intentions reasonably well... </p>

<p>The usual way the path tracing is implemented is that the reflection integral is split into direct and indirect illumination and they are estimated separately.</p>

<p><strong>The direct illumination</strong> can be estimated using more sampling strategies which are combined together using the multi-sample multiple importance sampling method by Veach. Typically, there is just BSDF sampling and light sampling used, but you can also add things like light portals sampling and other more sophisticated stuff. I guess this is where you are headed.</p>

<p><strong>The indirect illumination</strong> is usually estimated by just one sampling strategy (typically BSDF sampling) because you want to avoid exponential growth of recursive paths count. That's the reason why path tracing has poor performance for indirect illumination reflected/refracted through glossy/specular materials.</p>

<p>A nice thing about the split integral is that you can share samples between the direct and indirect integral. If you have two integrals over the same domain and have a sampling strategy that can be used for both, then you can generate a sample to estimate the first integral and then use the same sample for the second integral as well. There is no problem with correlated samples here because we have two separate computations. In practice you generate a BSDF sample with some PDF, shoot a ray in that direction and use the intersection point to estimate both direct and indirect integral separately.</p>

<hr>

<p>PS: I guess that for indirect illumination estimator you could possibly use the one-sample multiple importance sampling method by Veach to incorporate the light portals and other sampling strategies, but I have some doubts about the efficiency of the resulting estimator, especially when reusing the samples for the direct illumination integral.</p>

CC BY-SA 3.0
2017-03-18T10:00:31.967Z
Thanks for your answer. You mentioned that brdf samples can be shared between direct and indirect. Could you explain this a bit more please.
ali
CC BY-SA 3.0
2017-03-18T14:44:41.553Z
You're welcome, @ali. I extended the answer. If not clear enough, please, let me know.
ivokabel
CC BY-SA 3.0
2017-03-18T16:17:19.310Z
Well, a bit struggling to get your idea, but I guess that's what I used to do in this situation: on doing the direct lighting, as the solid angle for visible part of the sky and the external obstruction are same, I could use one pdf to compute the contribution of the both: either from the sky(if no hit) or from the external obstruction. The problem arises on computing the radiance of the external hit as it needs recursive calls(a separate complete path) to get the correct estimate. This works though makes it quite slow and a complex code; it is also advised not to do indirect in direct part.
ali
CC BY-SA 3.0
2017-03-18T00:22:37.870Z
2017-03-18T14:42:15.503Z
2017-03-18T14:42:15.503Z
ivokabel
<p>Apologies for posting two questions in one post, but as they are relevant I kept them in one.</p>

<h3>Question 1</h3>

<p>In the definition of multi sample estimator that Veach has defined, the integrand is the same for all the n sampling strategies. If this is so, then is it not the case that, in direct lighting, those shadow rays that miss the light geometry are to be considered, as the integrand is not zero (and the PDF is also not zero) but has some value, not from the light of course, but due to the surfaces that have occluded the light? </p>

<p>Would missing those contributions not be the same as partitioning the integral in sampling the lights and BRDF, whereas MIS claims to give 
a solution without partitioning the integral?</p>

<h3>Question 2</h3>

<p>My main problem is to sample adequately part of the scene where light comes from the external obstructions (marked as P2 in the image). The only source of light is skylight coming in through the window opening. P1 is PDF for sampling window area (or solid angle) to get direct light; P2 is same PDF but to account for external surfaces contributions; and P3 is BRDF sampling for indirect light from indoor surfaces. I could rely just on BRDF sampling to account for external surfaces but as their contribution is large (illuminance from infinite source) I want to explicitly account for them.  </p>

<p>I don't intend to partition the integral into three regions as it ends up to have recursive calls to get the contribution of external hits; it also slows down and makes the code too complex. I therefore guess I need to use MIS to account for indirect contribution of externals surfaces but am not clear how it is to be done.</p>

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

<p>I tried to take one sample from BRDF P3 with $W3 = p_3/(p_3+p_2)$, and one from P2 PDF with $W2 = p_2/(p_2+p_3)$. I am not clear how to evaluate the integrand for samples taken from P2 distributions. This is the pseudocode:</p>

<pre><code>for each measurement point x {
    while(1){
        //P1
        //DirectLight routine uses P1 if x is indoor hit or 
        //sampling hemisphere if x is outdoor, to get direct light from sky 
        totalEstimate += DirectLight(x) * throughput

        //P2
        y = Trace one sample from P2
        if y is external surface {
           weight = p2(y) / (p2(y)+p3(y))
           totalestimate += DirectRadiance(y) * weight * brdf(x) * dot(x, Nx) / P2  
        }

        //P3
        z = Trace one sample form P3
        if z is a hit{
            weight = p3(z) / (p3(z)+p2(z))
            throughput *= weight * brdf(x) * dot(x, Nx) / P3  
        }
        else 
            break;

        //using russian roulette to terminate the path.. 
    }
}
</code></pre>

<p>I tried this but had increase in variance. The measurement points are few points in room floor area and a contour line is drawn based on a the values. The above gives higher variance than using only P1 and P3 with no MIS weights.</p>

<p><strong>Update</strong>:</p>

<p>This excersise in PBRT seems to be relevant to this question. So I post it here
in case it helps.</p>

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

CC BY-SA 3.0
2017-03-18T14:48:00.813Z
Are you trying to implement a general-use robust path tracer or is it intended to be used in a special (and fairly difficult) scenarios like the one you showed in your picture?
ivokabel
CC BY-SA 3.0
2017-03-18T16:29:40.347Z
No no aim for implementing a general-use path tracer. Yet this is sort of a typical scenario in doing daylight calculation and I try to improve the efficiency of path tracer here. I came across an exercise in pbrt book which suggests to flag, and then sampling certain objects which are important source of indirect, along with brdf sampling(I have updated the question with this exercise, please take a look); and thought this could be a solution to my case.
ali
CC BY-SA 3.0
2017-03-19T00:44:43.883Z
I've edited for appearance only - I didn't want to change the equations without checking with you first. I'm guessing that in both the description and the pseudocode it should say $W2 = p_2 / (p_2 + p_3)$ rather than $W2 = p_2 / p_2 + p_3$ (since that would evaluate the division before the addition).
trichoplax is on Codidact now
CC BY-SA 3.0
2017-03-19T06:45:59.497Z
Many thanks @trichoplax. It is correct the way you have written it. My apology as I am new to this group and couldn't find correct fonts/style for maths.
ali
CC BY-SA 3.0
2017-03-19T13:46:48.897Z
There is a guide to using MathJax for mathematical formatting [over on Worldbuilding Stack Exchange](https://worldbuilding.meta.stackexchange.com/questions/607/how-do-i-add-mathematical-notation-using-latex-mathjax), but there is no obligation to use MathJax - I just edited it in to make it more readable.
trichoplax is on Codidact now
CC BY-SA 3.0
2017-03-19T23:22:52.830Z
ali, just to be sure, do I get it right that P2 (the black part of the image) is the geometry which blocks light from the white background visible on your image? And, what do you mean "P2 is same PDF but to account for external surfaces contributions"? I have problems understanding this sentence. Is it the same as P1, or is it somehow changed P1?
ivokabel
CC BY-SA 3.0
2017-03-20T11:13:10.697Z
First thanks for your attention :). The black part of the image, marked as P2, is external buildings that blocks light from the sky for indoor surfaces. Yes P2 is same pdf as P1; P2 is 1/(window area) to sample points on the window to estimate the contribution of external buildings. P1 is same pdf, 1/(window area), again to sample points on window opening; but this time they are shadow rays to get an estimate from the visible sky(direct light);
ali
CC BY-SA 3.0
2017-03-20T11:13:13.713Z
Its essentially one estimator in both cases with same pdf, one to get the direct light, the other the indirect from the external buildings. The only different is the Visibility test in the two estimators. In P1 any shadow rays that hits the external objects are dismissed whereas in the case of P2 any ray that returns no intersect is ignored(as the domain is on external buildings). I hope this explains better.
ali
<raytracing><pathtracing><global-illumination><importance-sampling>
Efficiently sampling specific surfaces using MIS in path tracing
ali
# Efficiently sampling specific surfaces using MIS in path tracing

(Asked by: username_0 on 2017-03-16)

Apologies for posting two questions in one post, but as they are relevant I kept them in one.

### Question 1

In the definition of multi sample estimator that Veach has defined, the integrand is the same for all the n sampling strategies. If this is so, then is it not the case that, in direct lighting, those shadow rays that miss the light geometry are to be considered, as the integrand is not zero (and the PDF is also not zero) but has some value, not from the light of course, but due to the surfaces that have occluded the light?

Would missing those contributions not be the same as partitioning the integral in sampling the lights and BRDF, whereas MIS claims to give
a solution without partitioning the integral?

### Question 2

My main problem is to sample adequately part of the scene where light comes from the external obstructions (marked as P2 in the image). The only source of light is skylight coming in through the window opening. P1 is PDF for sampling window area (or solid angle) to get direct light; P2 is same PDF but to account for external surfaces contributions; and P3 is BRDF sampling for indirect light from indoor surfaces. I could rely just on BRDF sampling to account for external surfaces but as their contribution is large (illuminance from infinite source) I want to explicitly account for them.

I don't intend to partition the integral into three regions as it ends up to have recursive calls to get the contribution of external hits; it also slows down and makes the code too complex. I therefore guess I need to use MIS to account for indirect contribution of externals surfaces but am not clear how it is to be done.

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

I tried to take one sample from BRDF P3 with $W3 = p\_3/(p\_3+p\_2)$, and one from P2 PDF with $W2 = p\_2/(p\_2+p\_3)$. I am not clear how to evaluate the integrand for samples taken from P2 distributions. This is the pseudocode:

```
for each measurement point x {
    while(1){
        //P1
        //DirectLight routine uses P1 if x is indoor hit or 
        //sampling hemisphere if x is outdoor, to get direct light from sky 
        totalEstimate += DirectLight(x) * throughput

        //P2
        y = Trace one sample from P2
        if y is external surface {
           weight = p2(y) / (p2(y)+p3(y))
           totalestimate += DirectRadiance(y) * weight * brdf(x) * dot(x, Nx) / P2  
        }

        //P3
        z = Trace one sample form P3
        if z is a hit{
            weight = p3(z) / (p3(z)+p2(z))
            throughput *= weight * brdf(x) * dot(x, Nx) / P3  
        }
        else 
            break;

        //using russian roulette to terminate the path.. 
    }
}

```

I tried this but had increase in variance. The measurement points are few points in room floor area and a contour line is drawn based on a the values. The above gives higher variance than using only P1 and P3 with no MIS weights.

**Update**:

This excersise in PBRT seems to be relevant to this question. So I post it here
in case it helps.

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

**Tags:** raytracing, pathtracing, global-illumination, importance-sampling

> **Comments:**
> **username_1**: Are you trying to implement a general-use robust path tracer or is it intended to be used in a special (and fairly difficult) scenarios like the one you showed in your picture?  
> **username_0**: No no aim for implementing a general-use path tracer. Yet this is sort of a typical scenario in doing daylight calculation and I try to improve the efficiency of path tracer here. I came across an exercise in pbrt book which suggests to flag, and then sampling certain objects which are important source of indirect, along with brdf sampling(I have updated the question with this exercise, please take a look); and thought this could be a solution to my case.  
> **username_2**: I've edited for appearance only - I didn't want to change the equations without checking with you first. I'm guessing that in both the description and the pseudocode it should say $W2 = p_2 / (p_2 + p_3)$ rather than $W2 = p_2 / p_2 + p_3$ (since that would evaluate the division before the addition).  
> **username_0**: Many thanks @username_2. It is correct the way you have written it. My apology as I am new to this group and couldn't find correct fonts/style for maths.  
> **username_2**: There is a guide to using MathJax for mathematical formatting [over on Worldbuilding Stack Exchange](https://worldbuilding.meta.stackexchange.com/questions/607/how-do-i-add-mathematical-notation-using-latex-mathjax), but there is no obligation to use MathJax - I just edited it in to make it more readable.  
> **username_1**: ali, just to be sure, do I get it right that P2 (the black part of the image) is the geometry which blocks light from the white background visible on your image? And, what do you mean "P2 is same PDF but to account for external surfaces contributions"? I have problems understanding this sentence. Is it the same as P1, or is it somehow changed P1?  
> **username_0**: First thanks for your attention :). The black part of the image, marked as P2, is external buildings that blocks light from the sky for indoor surfaces. Yes P2 is same pdf as P1; P2 is 1/(window area) to sample points on the window to estimate the contribution of external buildings. P1 is same pdf, 1/(window area), again to sample points on window opening; but this time they are shadow rays to get an estimate from the visible sky(direct light);  
> **username_0**: Its essentially one estimator in both cases with same pdf, one to get the direct light, the other the indirect from the external buildings. The only different is the Visibility test in the two estimators. In P1 any shadow rays that hits the external objects are dismissed whereas in the case of P2 any ray that returns no intersect is ignored(as the domain is on external buildings). I hope this explains better.  

---

## 1 answers

### Answer by username_1 on 2017-03-18. Score: 3

I will not answer your questions directly, but will try to change your mindset a bit. I hope got your intentions reasonably well...

The usual way the path tracing is implemented is that the reflection integral is split into direct and indirect illumination and they are estimated separately.

**The direct illumination** can be estimated using more sampling strategies which are combined together using the multi-sample multiple importance sampling method by Veach. Typically, there is just BSDF sampling and light sampling used, but you can also add things like light portals sampling and other more sophisticated stuff. I guess this is where you are headed.

**The indirect illumination** is usually estimated by just one sampling strategy (typically BSDF sampling) because you want to avoid exponential growth of recursive paths count. That's the reason why path tracing has poor performance for indirect illumination reflected/refracted through glossy/specular materials.

A nice thing about the split integral is that you can share samples between the direct and indirect integral. If you have two integrals over the same domain and have a sampling strategy that can be used for both, then you can generate a sample to estimate the first integral and then use the same sample for the second integral as well. There is no problem with correlated samples here because we have two separate computations. In practice you generate a BSDF sample with some PDF, shoot a ray in that direction and use the intersection point to estimate both direct and indirect integral separately.

---

PS: I guess that for indirect illumination estimator you could possibly use the one-sample multiple importance sampling method by Veach to incorporate the light portals and other sampling strategies, but I have some doubts about the efficiency of the resulting estimator, especially when reusing the samples for the direct illumination integral.

> **Comments:**
> **username_0**: Thanks for your answer. You mentioned that brdf samples can be shared between direct and indirect. Could you explain this a bit more please.  
> **username_1**: You're welcome, @username_0. I extended the answer. If not clear enough, please, let me know.  
> **username_0**: Well, a bit struggling to get your idea, but I guess that's what I used to do in this situation: on doing the direct lighting, as the solid angle for visible part of the sky and the external obstruction are same, I could use one pdf to compute the contribution of the both: either from the sky(if no hit) or from the external obstruction. The problem arises on computing the radiance of the external hit as it needs recursive calls(a separate complete path) to get the correct estimate. This works though makes it quite slow and a complex code; it is also advised not to do indirect in direct part.  

---

