I was/am struggling to understand the math, and I just read this PI or not to PI in game lighting equation | Sébastien Lagarde to get some idea of whether or not there should be a PI in the calculation.
Now, from what I understand, generally the lightColor’s unit in a game is defined in the way so that outColor = PI * BRDF * materialDiffuse * lightColor * NdotL, which in turn makes the Lambertian diffuse as simple as outColor = materialDiffuse * NdotL * lightColor. Or if the lightColor represents the actual intensity, the equation would be materialDiffuse * NdotL * lightColor / PI.
But while reading Urho3D’s shader, I found that its Lambertian term seemingly strangely is divided by PI twice!
See in PBRLitSolid.hlsl: void PS(…)
finalColor.rgb = BRDF * lightColor * (atten * shadow) / M_PI;
and in BRDF.hlsl: LambertianDiffuse(…)
return diffuseColor * (1.0 / M_PI) ;
also in BRDF.hlsl: CustomLambertianDiffuse(…)
return diffuseColor * (1.0 / M_PI) * pow(NdotV, 0.5 + 0.3 * roughness)
How come “/ M_PI” is done twice?
Let’s forget the Lambertian term, why is the finalColor BRDF * lightColor / M_PI in the first place?
Should it be “* M_PI” instead?
Excuse me for being a total amateur in CG, but please somebody tell me where did I miss. Or if Urho3D is using some other rendering scheme, could you explain, or is it documented somewhere?
Thanks in advance!