# Efficiently sampling specific surfaces using MIS in path tracing

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.

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.

• 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 Mar 18 '17 at 14:48
• 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 Mar 18 '17 at 16:29
• 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 Mar 19 '17 at 0:44
• 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 Mar 19 '17 at 6:45
• There is a guide to using MathJax for mathematical formatting over on Worldbuilding Stack Exchange, but there is no obligation to use MathJax - I just edited it in to make it more readable. – trichoplax Mar 19 '17 at 13:46

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.

• 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 Mar 18 '17 at 10:00
• You're welcome, @ali. I extended the answer. If not clear enough, please, let me know. – ivokabel Mar 18 '17 at 14:44
• 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 Mar 18 '17 at 16:17