浏览代码

Lensflare: Perform early out if the lensflare is behind the camera

Mugen87 6 年之前
父节点
当前提交
77dec21736
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      examples/js/objects/Lensflare.js

+ 6 - 3
examples/js/objects/Lensflare.js

@@ -14,6 +14,7 @@ THREE.Lensflare = function () {
 	//
 
 	var positionScreen = new THREE.Vector3();
+	var positionView = new THREE.Vector3();
 
 	// textures
 
@@ -175,10 +176,12 @@ THREE.Lensflare = function () {
 
 		// calculate position in screen space
 
-		positionScreen.setFromMatrixPosition( this.matrixWorld );
+		positionView.setFromMatrixPosition( this.matrixWorld );
+		positionView.applyMatrix4( camera.matrixWorldInverse );
 
-		positionScreen.applyMatrix4( camera.matrixWorldInverse );
-		positionScreen.applyMatrix4( camera.projectionMatrix );
+		if ( positionView.z > 0 ) return; // lensflare is behind the camera
+
+		positionScreen.copy( positionView ).applyMatrix4( camera.projectionMatrix );
 
 		// horizontal and vertical coordinate of the lower left corner of the pixels to copy