-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
/
Copy pathSpotLightShadow.js
72 lines (51 loc) · 1.34 KB
/
SpotLightShadow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { LightShadow } from './LightShadow.js';
import { RAD2DEG } from '../math/MathUtils.js';
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
/**
* Represents the shadow configuration of directional lights.
*
* @augments LightShadow
*/
class SpotLightShadow extends LightShadow {
/**
* Constructs a new spot light shadow.
*/
constructor() {
super( new PerspectiveCamera( 50, 1, 0.5, 500 ) );
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isSpotLightShadow = true;
/**
* Used to focus the shadow camera. The camera's field of view is set as a
* percentage of the spotlight's field-of-view. Range is `[0, 1]`.
*
* @type {number}
* @default 1
*/
this.focus = 1;
}
updateMatrices( light ) {
const camera = this.camera;
const fov = RAD2DEG * 2 * light.angle * this.focus;
const aspect = this.mapSize.width / this.mapSize.height;
const far = light.distance || camera.far;
if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
camera.fov = fov;
camera.aspect = aspect;
camera.far = far;
camera.updateProjectionMatrix();
}
super.updateMatrices( light );
}
copy( source ) {
super.copy( source );
this.focus = source.focus;
return this;
}
}
export { SpotLightShadow };