@openhps/core
Version:
Open Hybrid Positioning System - Core component
28 lines (27 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDistanceAttenuation = void 0;
var _TSLBase = require("../tsl/TSLBase.js");
/**
* Represents a `discard` shader operation in TSL.
*
* @method
* @param {Object} inputs - The input parameter object.
* @param {Node<float>} inputs.lightDistance - The distance of the light's position to the current fragment position.
* @param {Node<float>} inputs.cutoffDistance - The light's cutoff distance.
* @param {Node<float>} inputs.decayExponent - The light's decay exponent.
* @return {Node<float>} The distance falloff.
*/
const getDistanceAttenuation = exports.getDistanceAttenuation = /*@__PURE__*/(0, _TSLBase.Fn)(({
lightDistance,
cutoffDistance,
decayExponent
}) => {
// based upon Frostbite 3 Moving to Physically-based Rendering
// page 32, equation 26: E[window1]
// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
const distanceFalloff = lightDistance.pow(decayExponent).max(0.01).reciprocal();
return cutoffDistance.greaterThan(0).select(distanceFalloff.mul(lightDistance.div(cutoffDistance).pow4().oneMinus().clamp().pow2()), distanceFalloff);
}); // validated