UNPKG

1.45 kBJavaScriptView Raw
1import { Light } from './Light.js';
2import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
3import { LightShadow } from './LightShadow.js';
4
5/**
6 * @author mrdoob / http://mrdoob.com/
7 */
8
9
10function PointLight( color, intensity, distance, decay ) {
11
12 Light.call( this, color, intensity );
13
14 this.type = 'PointLight';
15
16 Object.defineProperty( this, 'power', {
17 get: function () {
18
19 // intensity = power per solid angle.
20 // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
21 return this.intensity * 4 * Math.PI;
22
23 },
24 set: function ( power ) {
25
26 // intensity = power per solid angle.
27 // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
28 this.intensity = power / ( 4 * Math.PI );
29
30 }
31 } );
32
33 this.distance = ( distance !== undefined ) ? distance : 0;
34 this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
35
36 this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
37
38}
39
40PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
41
42 constructor: PointLight,
43
44 isPointLight: true,
45
46 copy: function ( source ) {
47
48 Light.prototype.copy.call( this, source );
49
50 this.distance = source.distance;
51 this.decay = source.decay;
52
53 this.shadow = source.shadow.clone();
54
55 return this;
56
57 }
58
59} );
60
61
62export { PointLight };