Ver Fonte

Fix pixel swimming

Garrett Johnson há 5 anos atrás
pai
commit
6c687f4c8f
1 ficheiros alterados com 7 adições e 2 exclusões
  1. 7 2
      examples/jsm/csm/CSM.js

+ 7 - 2
examples/jsm/csm/CSM.js

@@ -181,9 +181,8 @@ export default class CSM {
 			_bbox.getSize( _size );
 			_bbox.getCenter( _center );
 			_center.z = _bbox.max.z + this.lightMargin;
-			_center.applyMatrix4( light.shadow.camera.matrixWorld );
 
-			let squaredBBWidth = Math.max( _size.x, _size.y );
+			let squaredBBWidth = _lightSpaceFrustum.vertices.far[ 0 ].distanceTo( _lightSpaceFrustum.vertices.far[ 2 ] );
 			if ( this.fade ) {
 
 				// expand the shadow extents by the fade margin if fade is enabled.
@@ -196,6 +195,12 @@ export default class CSM {
 
 			}
 
+			const texelSize = squaredBBWidth / this.shadowMapSize;
+			_center.x = Math.floor( _center.x / texelSize ) * texelSize;
+			_center.y = Math.floor( _center.y / texelSize ) * texelSize;
+			_center.z = Math.floor( _center.z / texelSize ) * texelSize;
+			_center.applyMatrix4( light.shadow.camera.matrixWorld );
+
 			light.shadow.camera.left = - squaredBBWidth / 2;
 			light.shadow.camera.right = squaredBBWidth / 2;
 			light.shadow.camera.top = squaredBBWidth / 2;