attenuation.glsl 423 B

1234567891011121314
  1. // by Tom Madams
  2. // Simple:
  3. // https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/
  4. //
  5. // Improved
  6. // https://imdoingitwrong.wordpress.com/2011/02/10/improved-light-attenuation/
  7. float attenuation(float r, float f, float d) {
  8. float denom = d / r + 1.0;
  9. float attenuation = 1.0 / (denom*denom);
  10. float t = (attenuation - f) / (1.0 - f);
  11. return max(t, 0.0);
  12. }
  13. #pragma glslify: export(attenuation)