updateMatrices method

  1. @override
void updateMatrices(
  1. Light light, {
  2. int viewportIndex = 0,
})
override

Update the matrices for the camera and shadow, used internally by the renderer.

light - the light for which the shadow is being rendered.

viewportIndex - calculates the matrix for this viewport

Implementation

@override
void updateMatrices(light, {viewportIndex = 0}) {
  final camera = this.camera;
  final shadowMatrix = matrix;

  final far = light.distance ?? camera!.far;

  if (far != camera!.far) {
    camera.far = far;
    camera.updateProjectionMatrix();
  }

  lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  camera.position.setFrom(lightPositionWorld);

  lookTarget.setFrom(camera.position);
  lookTarget.add(_cubeDirections[viewportIndex]);
  camera.up.setFrom(_cubeUps[viewportIndex]);
  camera.lookAt(lookTarget);
  camera.updateMatrixWorld(false);

  shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  projScreenMatrix.multiply2(camera.projectionMatrix, camera.matrixWorldInverse);
  frustum.setFromMatrix(projScreenMatrix);
}