# Calculate BRDF and PDF when doing direct light sampling

I learned in PBRT that to sample direct lighting for a surface a integrator usually calculates the sample as $$Sample = \frac{L_d(p,\omega_r) f(p,\omega_o,\omega_r)|cos\theta_i|}{p(\omega_r)}$$ where BRDF $$f(p,\omega_o,\omega_r)$$ is the sum of brdf from all the components (for instance microfacet specular & lambertian diffuse), and PDF $$p(\omega_r)$$ is the average of all the components. My question is why for $$f$$ we calculate sum while for $$p$$ it's average. I have the intuition that for $$f$$ we should also calculate average. In addition, why can we use the distribution of importance sampling to evaluate $$p(\omega_r)$$ for the given $$\omega_r$$?

1) When we have multiple BRDFs, adding thier components together can break energy conservation, as I think you suspect. However most renderers will handle this problem when constructing the layered BRDFs. For example you would might weight each layer or use a fresnel term to decide the weight for each layer.

Here is the spec for arnolds standard shader:

https://autodesk.github.io/standard-surface/

Each layer is multiplied by 1 - previous layer weight, which the artist is setting. This is done inside the fr function, which means that energy conservation is solved here.

2) The pdf is an average, I think, if each bxdf has an equal chance of being sampled. You therefore average the pdf even though each layer may contribute different amounts.

Note: Becareful which value you use for p(wr), this will be the pdf you used to sample your direction, so either the bxdf pdf or the light pdf. (You still need to calculate both pdfs at some point for MIS though.)

• Hi Peter thanks for your answer. May I ask, for 1), do you mean arnold is actually calculating weighted average (weighted sum here is actually more like an weighted average because it's lerp and lerp and lerp)? Thank you! May 13 '20 at 16:18
• If your interseted can read the OSL implementation here github.com/Autodesk/standard-surface/blob/master/reference/… May 13 '20 at 16:42
• The best way to think about it is that each layer is revealing the one below it as you reduce it's strength. For example if you have 3 layers of Specular -> Metal -> Diffuse, then you would multiply the diffuse albedo by (1 - specular) * (1 - metal) to get your fr term. This is a simplification but the post I linked shows exactly how each is calculated. May 13 '20 at 16:45
• Yes I got that. But still not confident about why PBRT is doing a sum for brdf... May 14 '20 at 2:04
• Basically the material or ui, which is the collection of bxdfs, will make sure they are energy conserving when you sum them together. If you just averaged all your bxdfs, they would get equal weight which would make things difficult if, for example, you wanted to have a strong diffuse component and only a subtle amount of specular. May 14 '20 at 10:18