Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSM: Replace FrustumBoundingBox with Box3 #18755

Merged
merged 3 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions examples/jsm/csm/CSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ import {
BufferGeometry,
BufferAttribute,
Line,
Matrix4
Matrix4,
Box3
} from '../../../build/three.module.js';
import Frustum from './Frustum.js';
import FrustumBoundingBox from './FrustumBoundingBox.js';
import Shader from './Shader.js';

const _cameraToLightMatrix = new Matrix4();
const _lightSpaceFrustum = new Frustum();
const _frustum = new Frustum();
const _center = new Vector3();
const _bbox = new FrustumBoundingBox();
const _size = new Vector3();
const _bbox = new Box3();
const _uniformArray = [];
const _logArray = [];

Expand Down Expand Up @@ -163,20 +164,25 @@ export default class CSM {
for ( let i = 0; i < this.frustums.length; i ++ ) {

const light = this.lights[ i ];
light.shadow.camera.updateMatrixWorld( true );
_cameraToLightMatrix.multiplyMatrices( light.shadow.camera.matrixWorldInverse, cameraMatrix );
this.frustums[ i ].toSpace( _cameraToLightMatrix, _lightSpaceFrustum );

light.shadow.camera.updateMatrixWorld( true );
_bbox.makeEmpty();
for ( let j = 0; j < 4; j ++ ) {

_bbox.fromFrustum( _lightSpaceFrustum );
_bbox.getSize();
_bbox.getCenter( this.lightMargin );
_bbox.expandByPoint( _lightSpaceFrustum.vertices.near[ j ] );
_bbox.expandByPoint( _lightSpaceFrustum.vertices.far[ j ] );

}

const squaredBBWidth = Math.max( _bbox.size.x, _bbox.size.y );
_bbox.getSize( _size );
_bbox.getCenter( _center );
_center.z = _bbox.max.z + this.lightMargin;

_center.copy( _bbox.center );
_center.applyMatrix4( light.shadow.camera.matrixWorld );

const squaredBBWidth = Math.max( _size.x, _size.y );
light.shadow.camera.left = - squaredBBWidth / 2;
light.shadow.camera.right = squaredBBWidth / 2;
light.shadow.camera.top = squaredBBWidth / 2;
Expand Down
83 changes: 0 additions & 83 deletions examples/jsm/csm/FrustumBoundingBox.js

This file was deleted.