updateShadowBounds method
void
updateShadowBounds()
Implementation
void updateShadowBounds() {
final frustums = this.frustums;
for (int i = 0; i < frustums.length; i ++ ) {
final light = lights[ i ];
final shadowCam = light.shadow?.camera;
final frustum = this.frustums[ i ];
// Get the two points that represent that furthest points on the frustum assuming
// that's either the diagonal across the far plane or the diagonal across the whole
// frustum itself.
final nearVerts = frustum.vertices.near;
final farVerts = frustum.vertices.far;
final point1 = farVerts[ 0 ];
late Vector3 point2;
if ( point1.distanceTo( farVerts[ 2 ] ) > point1.distanceTo( nearVerts[ 2 ] ) ) {
point2 = farVerts[ 2 ];
} else {
point2 = nearVerts[ 2 ];
}
double squaredBBWidth = point1.distanceTo( point2 );
if ( fade ) {
// expand the shadow extents by the fade margin if fade is enabled.
final camera = data.camera;
final far = math.max( camera.far, data.maxFar );
final linearDepth = frustum.vertices.far[ 0 ].z / ( far - camera.near );
final margin = 0.25 * math.pow( linearDepth, 2.0 ) * ( far - camera.near );
squaredBBWidth += margin;
}
shadowCam?.left = - squaredBBWidth / 2;
shadowCam?.right = squaredBBWidth / 2;
shadowCam?.top = squaredBBWidth / 2;
shadowCam?.bottom = - squaredBBWidth / 2;
shadowCam?.updateProjectionMatrix();
}
}