Explorar el Código

correctly extend the frustum points

Garrett Johnson hace 5 años
padre
commit
8224016195
Se han modificado 2 ficheros con 12 adiciones y 10 borrados
  1. 5 6
      examples/jsm/csm/CSM.js
  2. 7 4
      examples/jsm/csm/Frustum.js

+ 5 - 6
examples/jsm/csm/CSM.js

@@ -72,14 +72,13 @@ export default class CSM {
 
 	initCascades() {
 
-		// TODO: Handle orthographic camera
 		const camera = this.camera;
-		const far = Math.min(camera.far, this.maxFar);
+		camera.updateProjectionMatrix();
 		this.mainFrustum = new Frustum( {
-			fov: camera.fov,
-			near: camera.near,
-			far: far,
-			aspect: camera.aspect
+
+			maxFar: this.maxFar,
+			projectionMatrix: camera.projectionMatrix
+
 		} );
 
 		this.mainFrustum.getViewSpaceVertices();

+ 7 - 4
examples/jsm/csm/Frustum.js

@@ -37,10 +37,10 @@ export default class Frustum {
 			new Vector3( 1, - 1, - 1 ),
 			new Vector3( - 1, - 1, - 1 ),
 			new Vector3( - 1, 1, - 1 )
-		).forEach( function( v ) {
+		);
+		this.vertices.near.forEach( function( v ) {
 
 			v.applyMatrix4( inverseProjectionMatrix );
-			v.multiplyScalar( Math.min( v.z / maxFar, 1.0 ) );
 
 		} );
 
@@ -49,10 +49,13 @@ export default class Frustum {
 			new Vector3( 1, - 1, 1 ),
 			new Vector3( - 1, - 1, 1 ),
 			new Vector3( - 1, 1, 1 )
-		).forEach( function( v ) {
+		)
+		this.vertices.far.forEach( function( v ) {
 
 			v.applyMatrix4( inverseProjectionMatrix );
-			v.multiplyScalar( Math.min( v.z / maxFar, 1.0 ) );
+
+			const absZ = Math.abs( v.z );
+			v.multiplyScalar( Math.min( maxFar / absZ, 1.0 ) );
 
 		} );