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

enter image description here

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[?] $$


1 Answer 1


You can sample using absolutely any distribution you want, as long as you weight the results by dividing by the pdf of the sampled distribution. It will converge to the right answer (as long as the distribution is nonzero everywhere that you want to integrate). Different distributions will give different amounts of variance though. The trick with importance sampling is to find a distribution that minimizes variance while still being cheap to compute. A distribution similar to the shape of the function you're integrating, or equal to some factor of that function (so that it cancels when you divide), works best. In other words you try to guide the sampling toward areas that are more important to the result, hence, "importance" sampling.

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.)

  • $\begingroup$ What is pdf for the cosine distribution? ; I managed to get that black spots by using ggxProb mentioned in here - cwyman.org/code/dxrTutors/tutors/Tutor14/tutorial14.md.html ; Image on the right is explained in details in blog post and I managed to get it working and I understand most of theory. I would say that I only don't understand why we have to Jacobians and how do we find them. $\endgroup$ Oct 2, 2020 at 8:45
  • 1
    $\begingroup$ The pdf for the cosine distribution is $\cos(\theta)/\pi$. $\endgroup$ Oct 2, 2020 at 17:10
  • $\begingroup$ 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. $\endgroup$ Oct 5, 2020 at 8:38
  • 2
    $\begingroup$ @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. $\endgroup$ Oct 5, 2020 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.