Context: I am attempting to implement Trowbridge–Reitz (GGX) based on Microfacet Models for Refraction through Rough Surfaces in a pathtracer. I use numerical integration to check if the pdfs integrate to 1 (I convert solid angle to spherical coordinates using the jacobian and integrate that):
It is stated that the probability of generating a given microfacet normal for GGX is
Where m is the microfacet normal and n is the macrofacet normal (which I set to (0, 0, 1) for the sake of testing). Note that || on the dot product isn't needed since D(m) < 0 if the dot product is below zero due to the positive characteristic function (X+) on all the given microfacet distributions including GGX (see below).
As expected when I integrate p_m(m) it indeed does integrate to 1 as you would expect.
The problems arise when I try to integrate the pdf of the sampled direction (o). Which I should be able to do by using the jacobian.
The paper states that for ideal reflection the jacobian is 1/(4|o dot h|)
So I reasoned that this would be true:
The reason why I'm assuming the first equality is true is due to:
"Let us assume that for any given incident and outgoing directions, there is at most one microsurface normal that scatters energy from i to o, and that we can compute that normal as h(i, o), which we call the half-direction". As well as the equation above (38).
I would like to point out that I am only doing ideal reflection, so no refraction.
The problem is when I attempt to integrate the expression in the image above. It does not integrate to 1 or a consistent value.
To make the distribution integrate to 1 I have to get rid of the positive characteristic function in D(m). Which results in p_m(m) integrating to 0 but p_o(o) integrating to 1.
Why does removing the positive characteristic function have this result and why doesn't p_o(o) integrate to 1 when it remains?
Also as a side note, I find that using
to calculate o given h and i leads to sampled distribution not matching up with the pdf (I use a chi-squared test of the binned values to verify this) compared to not using the absolute value (which matches up to most formulas online). Note that for my testing I generate i in the top hemisphere and pointing away from the surface.