LightUtils.js 649 B

1234567891011121314151617
  1. import { tslFn } from '../shadernode/ShaderNode.js';
  2. export const getDistanceAttenuation = tslFn( ( inputs ) => {
  3. const { lightDistance, cutoffDistance, decayExponent } = inputs;
  4. // based upon Frostbite 3 Moving to Physically-based Rendering
  5. // page 32, equation 26: E[window1]
  6. // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  7. const distanceFalloff = lightDistance.pow( decayExponent ).max( 0.01 ).reciprocal();
  8. return cutoffDistance.greaterThan( 0 ).cond(
  9. distanceFalloff.mul( lightDistance.div( cutoffDistance ).pow4().oneMinus().clamp().pow2() ),
  10. distanceFalloff
  11. );
  12. } ); // validated