# Pdf division in BRDF sampling

While following scratchapixel's tutorial on indirect diffuse implementation in path tracing, the samples gets divided by the pdf, which in case of a uniform pdf results in $$1/2\pi$$ so we have that the sum of N samples gets multiplied by this factor: $$k=\frac{1}{N * \frac{1}{2 \pi}} = \frac{2\pi}{N}$$

The problem with this is that unless the albedo color is very dark, the final color quickly increases:

(From "Step 7: Add the Contribution of the Indirect Diffuse..." in the link above)

$$hitColor = (directDiffuse + \frac{2\pi * indirectDiffuse}{N}) * \frac{albedo}{\pi};$$

Other implementations instead just average the samples and the $$2\pi$$ term above is completely absent, like in Shirley's "ray tracing in a weekend" p.20

Which one is correct?

There's a difference in Shirley's and scratchapixel implementation, in the fact that Shirley's is a progressive path tracer (evaluates one path at a time)

While scratchapixel's is a non-progressive or branched path tracer, evaluating multiple paths at once:

But I believe this does not allow us to remove the $$2\pi$$ term in the former, because we are doing the same thing (sampling the BRDF hemisphere) albeit differently.

When evaluating direct lighting with point lights, the solid angle term is also completely absent, which makes things even more strange:

Here the integral over the hemisphere is 0 except in the direction $$\omega i$$, but (for example considering only diffuse) we only use:

$$L(P) = albedo*L(\omega i, P)*cos\theta$$

where $$L(P)$$ is the radiance from the point $$P$$, and $$L(\omega i, P)$$ gets replaced with our light radiance, $$\theta$$ is the angle with from $$\omega i$$ to the surface normal. Where has the solid angle term ($$\omega i$$) gone?

• The problem with this is that unless the albedo color is very dark, the final color quickly increases - how is it a problem, and how does it "quickly increase"? Other implementations instead... - link those. Apr 16, 2020 at 19:46
• @lightxbulb I've updated the question with more details. Regarding the quickly increasing color, let's assume for simplicity you have a fully white material (1, 1, 1) and we take only one indirect sample ($N=1$) which happens to be fully red (1, 0, 0), we end up with: $hitcolor = \frac{2\pi*indirectDiffuse}{N}*\frac{albedo}{\pi} = \frac{2 * (1, 0, 0)}{1}*(1, 1, 1) = (2, 0, 0)$ which is double of the indirect diffuse sample we took. It looked strange to me. Apr 17, 2020 at 4:37
• 1) it's Shirley not Sherley. 2) The $2pi$ is missing in RT in a weekend, because it's using cosine weighted sampling and the constant $\pi$ factor is assumed to cancel with an implicit factor in the albedo. 3) The $2\pi$ factor will be absent in an estimator sampling point lights because those can be sampled only through next event estimation, in which case the pdf is not the one for bsdf sampling. 4) Point lights are represented though Dirac deltas which gets rid of the integrand and $d\omega_i$. Apr 17, 2020 at 8:02
• @lightxbulb The 2pi is missing in RT in a weekend, because it's using cosine weighted sampling and the constant π factor is assumed to cancel with an implicit factor in the albedo. - If the π term cancels out it should leave a $2$ factor, which isn't present? - Point lights are represented though Dirac deltas which gets rid of the integrand and dωi - Thanks for the explaination, this confirms what I was suspecting Apr 17, 2020 at 8:07
• ↑corrected RT weekend author's name Apr 17, 2020 at 8:14