PointLight.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.isPointLight = true;
  7. this.type = 'PointLight';
  8. this.distance = distance;
  9. this.decay = decay; // for physically correct lights, should be 2.
  10. this.shadow = new PointLightShadow();
  11. }
  12. get 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. return this.intensity * 4 * Math.PI;
  16. }
  17. set power( power ) {
  18. // intensity = power per solid angle.
  19. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20. this.intensity = power / ( 4 * Math.PI );
  21. }
  22. copy( source ) {
  23. super.copy( source );
  24. this.distance = source.distance;
  25. this.decay = source.decay;
  26. this.shadow = source.shadow.clone();
  27. return this;
  28. }
  29. }
  30. export { PointLight };
粤ICP备19079148号