1 | import { LightShadow } from './LightShadow.js';
|
2 | import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
|
3 | import { Matrix4 } from '../math/Matrix4.js';
|
4 | import { Vector2 } from '../math/Vector2.js';
|
5 | import { Vector3 } from '../math/Vector3.js';
|
6 | import { Vector4 } from '../math/Vector4.js';
|
7 |
|
8 | const _projScreenMatrix = new Matrix4();
|
9 | const _lightPositionWorld = new Vector3();
|
10 | const _lookTarget = new Vector3();
|
11 |
|
12 | class PointLightShadow extends LightShadow {
|
13 |
|
14 | constructor() {
|
15 |
|
16 | super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
|
17 |
|
18 | this._frameExtents = new Vector2( 4, 2 );
|
19 |
|
20 | this._viewportCount = 6;
|
21 |
|
22 | this._viewports = [
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | new Vector4( 2, 1, 1, 1 ),
|
38 |
|
39 | new Vector4( 0, 1, 1, 1 ),
|
40 |
|
41 | new Vector4( 3, 1, 1, 1 ),
|
42 |
|
43 | new Vector4( 1, 1, 1, 1 ),
|
44 |
|
45 | new Vector4( 3, 0, 1, 1 ),
|
46 |
|
47 | new Vector4( 1, 0, 1, 1 )
|
48 | ];
|
49 |
|
50 | this._cubeDirections = [
|
51 | new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
|
52 | new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
|
53 | ];
|
54 |
|
55 | this._cubeUps = [
|
56 | new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
|
57 | new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
|
58 | ];
|
59 |
|
60 | }
|
61 |
|
62 | updateMatrices( light, viewportIndex = 0 ) {
|
63 |
|
64 | const camera = this.camera;
|
65 | const shadowMatrix = this.matrix;
|
66 |
|
67 | const far = light.distance || camera.far;
|
68 |
|
69 | if ( far !== camera.far ) {
|
70 |
|
71 | camera.far = far;
|
72 | camera.updateProjectionMatrix();
|
73 |
|
74 | }
|
75 |
|
76 | _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
|
77 | camera.position.copy( _lightPositionWorld );
|
78 |
|
79 | _lookTarget.copy( camera.position );
|
80 | _lookTarget.add( this._cubeDirections[ viewportIndex ] );
|
81 | camera.up.copy( this._cubeUps[ viewportIndex ] );
|
82 | camera.lookAt( _lookTarget );
|
83 | camera.updateMatrixWorld();
|
84 |
|
85 | shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
|
86 |
|
87 | _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
|
88 | this._frustum.setFromProjectionMatrix( _projScreenMatrix );
|
89 |
|
90 | }
|
91 |
|
92 | }
|
93 |
|
94 | PointLightShadow.prototype.isPointLightShadow = true;
|
95 |
|
96 | export { PointLightShadow };
|