PointLight.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Light } from './Light';
  2. import { PerspectiveCamera } from '../cameras/PerspectiveCamera';
  3. import { LightShadow } from './LightShadow';
  4. /**
  5. * @author mrdoob / http://mrdoob.com/
  6. */
  7. function PointLight( color, intensity, distance, decay ) {
  8. Light.call( this, color, intensity );
  9. this.type = 'PointLight';
  10. Object.defineProperty( this, 'power', {
  11. get: function () {
  12. // intensity = power per solid angle.
  13. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  14. return this.intensity * 4 * Math.PI;
  15. },
  16. set: function ( power ) {
  17. // intensity = power per solid angle.
  18. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  19. this.intensity = power / ( 4 * Math.PI );
  20. }
  21. } );
  22. this.distance = ( distance !== undefined ) ? distance : 0;
  23. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  24. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  25. }
  26. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  27. constructor: PointLight,
  28. isPointLight: true,
  29. copy: function ( source ) {
  30. Light.prototype.copy.call( this, source );
  31. this.distance = source.distance;
  32. this.decay = source.decay;
  33. this.shadow = source.shadow.clone();
  34. return this;
  35. }
  36. } );
  37. export { PointLight };