@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
39 lines (28 loc) • 840 B
JavaScript
// const k = Math.sqrt( (2*0.1*0.1)/Math.PI);
const k = 0.07978845608028655;
/**
* Using Smith inverse-square bounded approximation
* @see "An Inexpensive BRDF Model for Physically-based Rendering" by Christophe Schlick
* @param {number} distance
* @param {number} min
* @param {number} max
* @return {number}
*/
export function interpolate_irradiance_smith(distance, min, max) {
if (distance <= min) {
return 1;
} else if (distance > max) {
return 0;
}
/*
Original formula:
G(v) = v / (v - k*v + k)
k = sqrt(2*(m^2)) / pi)
we assume M to be 0.1 for our purposes
where G is the fall-off
*/
const range = max - min;
const v = (distance - min) / range;
const fall_off = v / (v - k * v + k);
return 1 - fall_off;
}