|
|
@@ -9,12 +9,28 @@ import { BufferGeometry } from '../../core/BufferGeometry.js';
|
|
|
import { Mesh } from '../../objects/Mesh.js';
|
|
|
import { Vector4 } from '../../math/Vector4.js';
|
|
|
import { Vector2 } from '../../math/Vector2.js';
|
|
|
+import { Matrix4 } from '../../math/Matrix4.js';
|
|
|
import { Frustum } from '../../math/Frustum.js';
|
|
|
import { DepthTexture } from '../../textures/DepthTexture.js';
|
|
|
import { CubeDepthTexture } from '../../textures/CubeDepthTexture.js';
|
|
|
|
|
|
import * as vsm from '../shaders/ShaderLib/vsm.glsl.js';
|
|
|
import { warn } from '../../utils.js';
|
|
|
+import { Vector3 } from '../../math/Vector3.js';
|
|
|
+
|
|
|
+const _cubeDirections = [
|
|
|
+ /*@__PURE__*/ new Vector3( 1, 0, 0 ), /*@__PURE__*/ new Vector3( - 1, 0, 0 ), /*@__PURE__*/ new Vector3( 0, 1, 0 ),
|
|
|
+ /*@__PURE__*/ new Vector3( 0, - 1, 0 ), /*@__PURE__*/ new Vector3( 0, 0, 1 ), /*@__PURE__*/ new Vector3( 0, 0, - 1 )
|
|
|
+];
|
|
|
+
|
|
|
+const _cubeUps = [
|
|
|
+ /*@__PURE__*/ new Vector3( 0, - 1, 0 ), /*@__PURE__*/ new Vector3( 0, - 1, 0 ), /*@__PURE__*/ new Vector3( 0, 0, 1 ),
|
|
|
+ /*@__PURE__*/ new Vector3( 0, 0, - 1 ), /*@__PURE__*/ new Vector3( 0, - 1, 0 ), /*@__PURE__*/ new Vector3( 0, - 1, 0 )
|
|
|
+];
|
|
|
+
|
|
|
+const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
|
|
|
+const _lightPositionWorld = /*@__PURE__*/ new Vector3();
|
|
|
+const _lookTarget = /*@__PURE__*/ new Vector3();
|
|
|
|
|
|
function WebGLShadowMap( renderer, objects, capabilities ) {
|
|
|
|
|
|
@@ -295,7 +311,39 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- shadow.updateMatrices( light, face );
|
|
|
+ if ( light.isPointLight ) {
|
|
|
+
|
|
|
+ const camera = shadow.camera;
|
|
|
+ const shadowMatrix = shadow.matrix;
|
|
|
+
|
|
|
+ const far = light.distance || camera.far;
|
|
|
+
|
|
|
+ if ( far !== camera.far ) {
|
|
|
+
|
|
|
+ camera.far = far;
|
|
|
+ camera.updateProjectionMatrix();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
|
|
|
+ camera.position.copy( _lightPositionWorld );
|
|
|
+
|
|
|
+ _lookTarget.copy( camera.position );
|
|
|
+ _lookTarget.add( _cubeDirections[ face ] );
|
|
|
+ camera.up.copy( _cubeUps[ face ] );
|
|
|
+ camera.lookAt( _lookTarget );
|
|
|
+ camera.updateMatrixWorld();
|
|
|
+
|
|
|
+ shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
|
|
|
+
|
|
|
+ _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
|
|
|
+ shadow._frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ shadow.updateMatrices( light );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
_frustum = shadow.getFrustum();
|
|
|
|