PointLight.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Light } from './Light.js';
  2. import { PointLightShadow } from './PointLightShadow.js';
  3. class PointLight extends Light {
  4. constructor( color, intensity, distance = 0, decay = 1 ) {
  5. super( color, intensity );
  6. this.type = 'PointLight';
  7. this.distance = distance;
  8. this.decay = decay; // for physically correct lights, should be 2.
  9. this.shadow = new PointLightShadow();
  10. }
  11. get power() {
  12. // intensity = power per solid angle.
  13. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  14. return this.intensity * 4 * Math.PI;
  15. }
  16. set power( power ) {
  17. // intensity = power per solid angle.
  18. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  19. this.intensity = power / ( 4 * Math.PI );
  20. }
  21. dispose() {
  22. this.shadow.dispose();
  23. }
  24. copy( source ) {
  25. super.copy( source );
  26. this.distance = source.distance;
  27. this.decay = source.decay;
  28. this.shadow = source.shadow.clone();
  29. return this;
  30. }
  31. }
  32. PointLight.prototype.isPointLight = true;
  33. export { PointLight };