PointLightAttenuation.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //! Returns point light source attenuation factor
  2. float occRangedPointLightAttenuation (in float theDistance, in float theRange)
  3. {
  4. if (theDistance <= theRange)
  5. {
  6. float aResult = theDistance / theRange;
  7. aResult *= aResult;
  8. aResult *= aResult;
  9. aResult = 1.0 - aResult;
  10. aResult = clamp(aResult, 0.0, 1.0);
  11. aResult /= max(0.0001, theDistance * theDistance);
  12. return aResult;
  13. }
  14. return -1.0;
  15. }
  16. //! Returns point light source attenuation factor with quadratic attenuation in case of zero range.
  17. float occPointLightAttenuation (in float theDistance, in float theRange)
  18. {
  19. if (theRange == 0.0)
  20. {
  21. return 1.0 / max(0.0001, theDistance * theDistance);
  22. }
  23. return occRangedPointLightAttenuation (theDistance, theRange);
  24. }
  25. //! Returns point light source attenuation factor with linear attenuation in case of zero range.
  26. float occPointLightAttenuation (in float theDistance, in float theRange, in float theLinearAttenuation, in float theConstAttenuation)
  27. {
  28. if (theRange == 0.0)
  29. {
  30. return 1.0 / (theConstAttenuation + theLinearAttenuation * theDistance);
  31. }
  32. return occRangedPointLightAttenuation (theDistance, theRange);
  33. }