PointLight.js 1.3 KB

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