(L) [2016/11/01] [ost
by yiningkarlli] [Question about microfacet reverse pdf and SmallVCM] Wayback!Recently I decided to implement a simple dielectric microfacet Bsdf in SmallVCM in order to be able to validate something in my own renderer. The microfacet Bsdf I'm implementing is very simple; just a Phong normal distribution for now to keep things simple and the rest based off of Walter's "Microfacet Models for Refraction through Rough Surfaces" paper, without the 2014 Eugene d'Eon visible normal important sampling extension.
I'm having some trouble with the reverse pdf for refraction. I thought I understood the reverse pdf, but apparently not since my VCM and pathtraced images using microfacet refraction aren't converging to the same thing. My understanding was that the reverse pdf is literally what the name says; it's effectively what you'd get if you ran the bsdf backwards with the input and output directions switched. I implemented the forward pdf as:
float mPdf = microfacet.calculateD(halfVectorLocal) * halfVectorLocal.z;
float eta = inputDotNormal > 0.0f ? m_eta : 1.0f / m_eta;
float bottom = (eta * inputDotHalf) + outputDotHalf;
float bottom2 = bottom * bottom;
float directPdfW = mPdf * (1.0f - fresnelTerm) * (eta * eta) * glm::abs(outputDotHalf) / (bottom2);
...as such, I thought that the reverse pdf should just be:
(ignoring the Walter trick for adjusting the roughness for importance sampling...)
float rEta = outputDotNormal > 0.0f ? m_eta : 1.0f / m_eta;
float rBottom = (rEta * outputDotHalf) + inputDotHalf;
float rBottom2 = rBottom * rBottom;
float reversePdfW = mPdf * (1.0f - fresnelTerm) * (rEta * rEta) * glm::abs(inputDotHalf) / (rBottom2);
This doesn't seem to work. Does anyone have any thoughts or hints?
Also, in SmallVCM's bsdf sampling function, the bsdf result seems to be implicitly multiplied by the PDF and divided by outCosTheta before being returned. How should this work for a microfacet brdf that doesn't have symmetrical sampling? If fromLight is true, should the sample result be multiplied by the reverse pdf instead of the forward pdf?
Any help in clearing up these questions would be greatly appreciated. Thanks!
(L) [2016/11/02] [ost
by koiava] [Question about microfacet reverse pdf and SmallVCM] Wayback!As I understand the way you calculate microfacet pdf stays the same, you just call pdf function for light subpath where wi and wo are swapped.
Inverse pdf calculation should be same as you do in bdpt so you can take pbrt as reference.[LINK https://github.com/mmp/pbrt-v3/blob/master/src/integrators/bdpt.cpp#L198]
(L) [2016/11/02] [ost
by yiningkarlli] [Question about microfacet reverse pdf and SmallVCM] Wayback!>> koiava wrote:As I understand the way you calculate microfacet pdf stays the same, you just call pdf function for light subpath where wi and wo are swapped.
Inverse pdf calculation should be same as you do in bdpt so you can take pbrt as reference.[LINK https://github.com/mmp/pbrt-v3/blob/master/src/integrators/bdpt.cpp#L198]
Okay, that's what I originally thought. I found my mistake; turns out, I forgot to treat the microfacet bsdf as a glossy event and was treating it as a pure specular event, which screws up all kinds of things.  [SMILEY :roll:] Stupid mistake that I completely overlooked, and subsequently drove me mad for a few days to find.
Thanks for confirming that I'm not crazy!