(possible duplicate)
I'm trying to implement multiple importance sampling, as described in the PBRT book (no bouncing yet, I want to make MIS work first).
What my problem is, that while the BRDF sampling looks okay, the light sampling is much dimmer (yet according to the pictures in the book they should look the same in intensity).
I uploaded the (updated) compilable code (VS 2015). The relevant parts can be found in multipleimportance.frag (SampleLightsExplicit) and pbr_common.head (ConeSampleSphere).
(note that I don't apply the MIS weights yet)
for (int k = 0; k < numLights; ++k) {
SceneObject light = objects.data[k];
center = vec3(light.toworld[3].xyz);
radius = light.toworld[0][0];
// importance sample light (xyz = direction, w = PDF)
sample1 = ConeSampleSphere(p, center, radius, pixel, seed + float(k));
// cast shadow ray
vis = Visibility(p, sample1.xyz, k);
ndotl = vis * max(0.0, dot(sample1.xyz, n));
// evaluate BRDF
fd = vec3(0.0); //obj.color.rgb * ONE_OVER_PI;
fs = CookTorrance_General(sample1.xyz, v, n, vec3(0.04), roughness);
sum += (light.color.rgb * (fd + fs) * ndotl) / sample1.w;
}
My question is why light sampling looks so dim? Did I misunderstand something?
UPDATE
Looking through the code I noticed some inconsistencies which probably originated from a typo in one of the older SIGGRAPH course notes (can't tell which one tho).
The PDF of the GGX distribution is:
PDF = D(h) * dot(n, h)
While some implementations (including UE4) incorrectly write it as
PDF = (D(h) * dot(n, h)) / (4 * dot(v, h))
which essentially means that they include the Cook-Torrance denominator into this variable (ndotl cancels out). Dividing with the correct PDF cancels out D in the Cook-Torrance model, which I forgot to account for, while the 1 / (4 * dot(v, h)) term goes into the Vis_Schlick function.
So regarding intensity the second picture is the "correct" one. The dimness is still a problem tho. Changing the Fresnel F0 to 0.11 (as it supposedly is in the book) and applying the MIS weights, the picture looks a lot more promising, except for the topmost plate which should almost explicitly reflect the light sources:
So this is almost okay now. I'm gonna look deeper into the MIS part to see why it makes those highlights disappear.
bsdf_pdf
and missing thendotl
factor while computing your bsdf sample. Also post the code for both the calculations here. Not everyone's gonna download the whole project. $\endgroup$