Garrett Johnson 5 лет назад
Родитель
Сommit
bb0168be04
2 измененных файлов с 24 добавлено и 4 удалено
  1. 12 1
      examples/jsm/csm/Frustum.js
  2. 12 3
      examples/webgl_shadowmap_csm.html

+ 12 - 1
examples/jsm/csm/Frustum.js

@@ -25,6 +25,9 @@ export default class Frustum {
 	getViewSpaceVertices() {
 
 		const maxFar = this.maxFar;
+		const projectionMatrix = this.projectionMatrix;
+		const isOrthographic = projectionMatrix.elements[ 2 * 4 + 3 ] === 0;
+
 		inverseProjectionMatrix.getInverse( this.projectionMatrix );
 
 		// 3 --- 0  vertices.near/far order
@@ -55,7 +58,15 @@ export default class Frustum {
 			v.applyMatrix4( inverseProjectionMatrix );
 
 			const absZ = Math.abs( v.z );
-			v.multiplyScalar( Math.min( maxFar / absZ, 1.0 ) );
+			if ( isOrthographic ) {
+
+				v.z *= Math.min( maxFar / absZ, 1.0 );
+
+			} else {
+
+				v.multiplyScalar( Math.min( maxFar / absZ, 1.0 ) );
+
+			}
 
 		} );
 

+ 12 - 3
examples/webgl_shadowmap_csm.html

@@ -216,9 +216,18 @@
 
 				csm.update( camera.matrix );
 				controls.update();
-				updateOrthoCamera();
-				
-				renderer.render( scene, params.orthographic ? orthoCamera : camera );
+
+				if ( params.orthographic ) {
+
+					updateOrthoCamera();
+					csm.updateFrustums();
+					renderer.render( scene, orthoCamera );
+
+				} else {
+	
+					renderer.render( scene, camera );
+
+				}
 
 			}