@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
26 lines (22 loc) • 711 B
JavaScript
/**
* Returns the PDF for a particular GGX sample after reflecting the view vector
* about a microfacet normal (includes the Jacobian for going from half vector to lighting vector)
*
* N = surface normal
* L = light direction
* V = view direction
* H = normalize( V + L )
*
* @param {number} NoH dot product of N and H
* @param {number} HoV dot product of H and V
* @param {number} roughness
* @returns {number}
*/
export function pdf_GGX(NoH, HoV, roughness) {
// convert to perceptual roughness
const m2 = roughness * roughness;
const X = NoH * NoH * (m2 - 1) + 1;
const d = m2 / (Math.PI * X * X);
const pM = d * NoH;
return pM / (4 * HoV);
}