-
-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Currently, the material system is not quite physically correct. Take for instance the diffuse material:
bool lambertianBSDF(struct hitRecord *isect, struct color *attenuation, struct lightRay *scattered, sampler *sampler) {
struct vector scatterDir = vecNormalize(vecAdd(isect->surfaceNormal, randomOnUnitSphere(sampler))); //Randomized scatter direction
*scattered = ((struct lightRay){isect->hitPoint, scatterDir, rayTypeScattered});
*attenuation = diffuseColor(isect);
return true;
}The rendering equation is:
The Lambertian BSDF is:
Thus, if you want your MC estimator to be correct, you need to sample a direction according to some pdf
and use it to evaluate the BSDF, then multiply that by the cosine and incoming light, and divide by that pdf. You then get the correct MC estimator:
In the case of the Lambertian BSDF, that would give:
Note that the incoming light is computed by
pathTrace so that's already taken care of. In the current version of the code, the division by , the multiplication by the cosine, and the division by the sampling pdf are completely missing, though, and that's the case for every material in the framework. There are cases where you can avoid multiplying by the cosine, namely:
- if the BSDF already contains a division by the cosine (which is the case for perfect mirrors, or perfect glass),
- if the pdf used to sample contains the cosine, in which case the division by the pdf cancels the multiplication by the cosine.
As far as I can see, the diffuse BSDF that you have doesn't fall into that category (it is not using cosine-weighted hemisphere sampling). Thus, I think it is not physically correct.
If you want references on the topic, I can recommend PBRT. It's not perfect, but it gets the points across. For a reference on the formulas, there's the very good GI compendium. If you want to discuss this further, I am on Discord and can get in touch if you're interested. Alternatively, if you think it's fine to leave this not physically correct, that's an option too, although I would not suggest to do that as solving visual bugs such as fireflies and the like will get harder.