# Importance sampling a cosine distribution

Let's take a look at this blog article - https://schuttejoe.github.io/post/ggximportancesamplingpart1/ and image presented as a result of implementing it:

Inside above link, you can see description for this image saying

In order to have something to compare to on the left I generated an image by importance sampling a cosine distribution and on the right I generated an image using the technique described above. [...]

Based on the fact that image on the right was derived based on GGX pdf, how was image on the left generated? I assume we have our standard equation but what does it mean that it's generated with importance sampling a cosine distribution? $$f(w_i,w_o) = \frac{F(w_i, w_m) ~ G_2(w_i,wo_,w_m) D(w_m)}{4 ~ |w_i \cdot w_g| ~ |w_o \cdot w_g|} * PDF[?]$$

So what the author is saying is the image on the left was sampled with $$\omega_o$$ (or maybe $$\omega_m$$, I'm not sure) drawn from a cosine hemisphere distribution, just as an example of a distribution that does not match the BRDF very well. Then they calculate the samples as $$f(\omega_i, \omega_o) / p_{\cos}(\omega_o)$$ where $$p_{\cos}$$ is the pdf for the cosine distribution. This is just to show you that it gives the "correct" result, but with a ton of variance. (Although it looks like there are some black areas on the left image that suggest it's not really converging to the correct answer...but let's assume that's a bug.)
Then the image on the right is sampled with (presumably) $$\omega_m$$ drawn from a distribution matching the $$D(\omega_m)$$ term from the BRDF. Then when you calculate the BRDF you can leave out the $$D$$ factor since it's canceled by the $$D$$ factor in the pdf. (The pdf probably still has some normalization and some conversion of probability from $$\omega_m$$ to $$\omega_o$$, so you still have to divide by those factors.)
• The pdf for the cosine distribution is $\cos(\theta)/\pi$. Oct 2 '20 at 17:10
• So throughput for cosine distribution will be: $$\frac{NoL * ggx}{pdf} = NoL * ggx ~\frac{\pi}{cos(\theta)} = NoL * ggx ~\frac{\pi}{NoL} = ggx ~ * ~ \pi$$ ? I'm not planning to use it due to more efficient methods, but I'm interested if my understanding is correct. Oct 5 '20 at 8:38
• @DirectX_Programmer Yep that looks right. The fact that it cancels out the $N \cdot L$ is exactly why the cosine distribution is used for diffuse light. Oct 5 '20 at 23:56