|
@@ -135,6 +135,10 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
|
|
|
}
|
|
|
|
|
|
var shadowCamera = shadow.camera;
|
|
|
+ var shadowMatrix = shadow.matrix;
|
|
|
+
|
|
|
+ _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
|
|
|
+ shadowCamera.position.copy( _lightPositionWorld );
|
|
|
|
|
|
_shadowMapSize.copy( shadow.mapSize );
|
|
|
_shadowMapSize.min( _maxShadowMapSize );
|
|
@@ -176,11 +180,34 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
|
|
|
_shadowMapSize.x *= 4.0;
|
|
|
_shadowMapSize.y *= 2.0;
|
|
|
|
|
|
+
|
|
|
+ // for point lights we set the shadow matrix to be a translation-only matrix
|
|
|
+ // equal to inverse of the light's position
|
|
|
+
|
|
|
+ shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
faceCount = 1;
|
|
|
isPointLight = false;
|
|
|
|
|
|
+ _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
|
|
|
+ shadowCamera.lookAt( _lookTarget );
|
|
|
+ shadowCamera.updateMatrixWorld();
|
|
|
+ shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
|
|
|
+
|
|
|
+ // compute shadow matrix
|
|
|
+
|
|
|
+ shadowMatrix.set(
|
|
|
+ 0.5, 0.0, 0.0, 0.5,
|
|
|
+ 0.0, 0.5, 0.0, 0.5,
|
|
|
+ 0.0, 0.0, 0.5, 0.5,
|
|
|
+ 0.0, 0.0, 0.0, 1.0
|
|
|
+ );
|
|
|
+
|
|
|
+ shadowMatrix.multiply( shadowCamera.projectionMatrix );
|
|
|
+ shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if ( shadow.map === null ) {
|
|
@@ -201,10 +228,6 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
|
|
|
}
|
|
|
|
|
|
var shadowMap = shadow.map;
|
|
|
- var shadowMatrix = shadow.matrix;
|
|
|
-
|
|
|
- _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
|
|
|
- shadowCamera.position.copy( _lightPositionWorld );
|
|
|
|
|
|
_renderer.setRenderTarget( shadowMap );
|
|
|
_renderer.clear();
|
|
@@ -220,32 +243,14 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
|
|
|
_lookTarget.add( cubeDirections[ face ] );
|
|
|
shadowCamera.up.copy( cubeUps[ face ] );
|
|
|
shadowCamera.lookAt( _lookTarget );
|
|
|
+ shadowCamera.updateMatrixWorld();
|
|
|
+ shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
|
|
|
|
|
|
var vpDimensions = cube2DViewPorts[ face ];
|
|
|
_state.viewport( vpDimensions );
|
|
|
|
|
|
- } else {
|
|
|
-
|
|
|
- _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
|
|
|
- shadowCamera.lookAt( _lookTarget );
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- shadowCamera.updateMatrixWorld();
|
|
|
- shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
|
|
|
-
|
|
|
- // compute shadow matrix
|
|
|
-
|
|
|
- shadowMatrix.set(
|
|
|
- 0.5, 0.0, 0.0, 0.5,
|
|
|
- 0.0, 0.5, 0.0, 0.5,
|
|
|
- 0.0, 0.0, 0.5, 0.5,
|
|
|
- 0.0, 0.0, 0.0, 1.0
|
|
|
- );
|
|
|
-
|
|
|
- shadowMatrix.multiply( shadowCamera.projectionMatrix );
|
|
|
- shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
|
|
|
-
|
|
|
// update camera matrices and frustum
|
|
|
|
|
|
_projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
|