Przeglądaj źródła

CSMShadowNode: Fix inconsistency in frustum split (#33510)

Shota Matsuda 1 miesiąc temu
rodzic
commit
f614aaa248
1 zmienionych plików z 9 dodań i 2 usunięć
  1. 9 2
      examples/jsm/csm/CSMFrustum.js

+ 9 - 2
examples/jsm/csm/CSMFrustum.js

@@ -145,6 +145,9 @@ class CSMFrustum {
 
 		target.length = breaks.length;
 
+		const near = this.vertices.near[ 0 ].z;
+		const far = this.vertices.far[ 0 ].z;
+
 		for ( let i = 0; i < breaks.length; i ++ ) {
 
 			const cascade = target[ i ];
@@ -159,9 +162,11 @@ class CSMFrustum {
 
 			} else {
 
+				const alpha = ( breaks[ i - 1 ] * far - near ) / ( far - near );
+
 				for ( let j = 0; j < 4; j ++ ) {
 
-					cascade.vertices.near[ j ].lerpVectors( this.vertices.near[ j ], this.vertices.far[ j ], breaks[ i - 1 ] );
+					cascade.vertices.near[ j ].lerpVectors( this.vertices.near[ j ], this.vertices.far[ j ], alpha );
 
 				}
 
@@ -177,9 +182,11 @@ class CSMFrustum {
 
 			} else {
 
+				const alpha = ( breaks[ i ] * far - near ) / ( far - near );
+
 				for ( let j = 0; j < 4; j ++ ) {
 
-					cascade.vertices.far[ j ].lerpVectors( this.vertices.near[ j ], this.vertices.far[ j ], breaks[ i ] );
+					cascade.vertices.far[ j ].lerpVectors( this.vertices.near[ j ], this.vertices.far[ j ], alpha );
 
 				}
 

粤ICP备19079148号