supereggbert 6 سال پیش
والد
کامیت
2e145a55a8

+ 8 - 8
src/lights/DirectionalLightShadow.js

@@ -17,22 +17,22 @@ DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.pro
 
 
 	isDirectionalLightShadow: true,
 	isDirectionalLightShadow: true,
 
 
-  updateMatrices: function ( light, viewCamera, viewportIndex ) { 
+	updateMatrices: function ( light, viewCamera, viewportIndex ) {
 
 
-    var camera = this.camera,
-      lightPositionWorld = this._lightPositionWorld,
-      lookTarget = this._lookTarget;
+		var camera = this.camera,
+			lightPositionWorld = this._lightPositionWorld,
+			lookTarget = this._lookTarget;
 
 
-    lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
+		lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
 		camera.position.copy( lightPositionWorld );
 		camera.position.copy( lightPositionWorld );
 
 
-    lookTarget.setFromMatrixPosition( light.target.matrixWorld );
+		lookTarget.setFromMatrixPosition( light.target.matrixWorld );
 		camera.lookAt( lookTarget );
 		camera.lookAt( lookTarget );
 		camera.updateMatrixWorld();
 		camera.updateMatrixWorld();
 
 
-    LightShadow.prototype.updateMatrices.call( this, light, viewCamera, viewportIndex );
+		LightShadow.prototype.updateMatrices.call( this, light, viewCamera, viewportIndex );
 
 
-  }
+	}
 
 
 } );
 } );
 
 

+ 28 - 28
src/lights/LightShadow.js

@@ -20,49 +20,49 @@ function LightShadow( camera ) {
 	this.map = null;
 	this.map = null;
 	this.matrix = new Matrix4();
 	this.matrix = new Matrix4();
 
 
-  this._frustum = new Frustum();
-  this._frameExtents = new Vector2( 1, 1 );
+	this._frustum = new Frustum();
+	this._frameExtents = new Vector2( 1, 1 );
 
 
-  this._viewportCount = 1;
+	this._viewportCount = 1;
 
 
-  this._viewports = [
+	this._viewports = [
 
 
-    new Vector4( 0, 0, 1, 1)
+		new Vector4( 0, 0, 1, 1 )
 
 
-  ];
+	];
 
 
 }
 }
 
 
 Object.assign( LightShadow.prototype, {
 Object.assign( LightShadow.prototype, {
 
 
-  _projScreenMatrix: new Matrix4(),
+	_projScreenMatrix: new Matrix4(),
 
 
-  _lightPositionWorld: new Vector3(),
+	_lightPositionWorld: new Vector3(),
 
 
-  _lookTarget: new Vector3(),
+	_lookTarget: new Vector3(),
 
 
-  getViewportCount: function () {
+	getViewportCount: function () {
 
 
-    return this._viewportCount;
+		return this._viewportCount;
 
 
-  },
+	},
 
 
-  getFrustum: function() {
+	getFrustum: function () {
 
 
-    return this._frustum;
+		return this._frustum;
 
 
-  },
+	},
 
 
-  updateMatrices: function ( light, viewCamera, viewportIndex ) {
+	updateMatrices: function ( light, viewCamera, viewportIndex ) {
 
 
-    var shadowCamera = this.camera,
-      shadowMatrix = this.matrix,
-      projScreenMatrix = this._projScreenMatrix;
+		var shadowCamera = this.camera,
+			shadowMatrix = this.matrix,
+			projScreenMatrix = this._projScreenMatrix;
 
 
-    projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
+		projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
 		this._frustum.setFromMatrix( projScreenMatrix );
 		this._frustum.setFromMatrix( projScreenMatrix );
 
 
-    shadowMatrix.set(
+		shadowMatrix.set(
 			0.5, 0.0, 0.0, 0.5,
 			0.5, 0.0, 0.0, 0.5,
 			0.0, 0.5, 0.0, 0.5,
 			0.0, 0.5, 0.0, 0.5,
 			0.0, 0.0, 0.5, 0.5,
 			0.0, 0.0, 0.5, 0.5,
@@ -72,19 +72,19 @@ Object.assign( LightShadow.prototype, {
 		shadowMatrix.multiply( shadowCamera.projectionMatrix );
 		shadowMatrix.multiply( shadowCamera.projectionMatrix );
 		shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
 		shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
 
 
-  },
+	},
 
 
-  getViewport: function ( viewportIndex ) {
+	getViewport: function ( viewportIndex ) {
 
 
-    return this._viewports[ viewportIndex ];
+		return this._viewports[ viewportIndex ];
 
 
-  },
+	},
 
 
-  getFrameExtents: function () {
+	getFrameExtents: function () {
 
 
-    return this._frameExtents;
+		return this._frameExtents;
 
 
-  },
+	},
 
 
 	copy: function ( source ) {
 	copy: function ( source ) {
 
 

+ 0 - 1
src/lights/PointLight.js

@@ -1,5 +1,4 @@
 import { Light } from './Light.js';
 import { Light } from './Light.js';
-import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
 import { PointLightShadow } from './PointLightShadow.js';
 import { PointLightShadow } from './PointLightShadow.js';
 
 
 /**
 /**

+ 44 - 45
src/lights/PointLightShadow.js

@@ -8,40 +8,39 @@ function PointLightShadow() {
 
 
 	LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
 	LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
 
 
+	this._frameExtents = new Vector2( 4, 2 );
+
+	this._viewportCount = 6;
+
+	this._viewports = [
+		// These viewports map a cube-map onto a 2D texture with the
+		// following orientation:
+		//
+		//  xzXZ
+		//   y Y
+		//
+		// X - Positive x direction
+		// x - Negative x direction
+		// Y - Positive y direction
+		// y - Negative y direction
+		// Z - Positive z direction
+		// z - Negative z direction
+
+		// positive X
+		new Vector4( 2, 1, 1, 1 ),
+		// negative X
+		new Vector4( 0, 1, 1, 1 ),
+		// positive Z
+		new Vector4( 3, 1, 1, 1 ),
+		// negative Z
+		new Vector4( 1, 1, 1, 1 ),
+		// positive Y
+		new Vector4( 3, 0, 1, 1 ),
+		// negative Y
+		new Vector4( 1, 0, 1, 1 )
+	];
 
 
-  this._frameExtents = new Vector2( 4, 2 );
-
-  this._viewportCount = 6;
-
-  this._viewports = [
-      // These viewports map a cube-map onto a 2D texture with the
-			// following orientation:
-			//
-			//  xzXZ
-			//   y Y
-			//
-			// X - Positive x direction
-			// x - Negative x direction
-			// Y - Positive y direction
-			// y - Negative y direction
-			// Z - Positive z direction
-			// z - Negative z direction
-
-      // positive X
-      new Vector4( 2, 1, 1, 1 ),
-      // negative X
-      new Vector4( 0, 1, 1, 1 ),
-      // positive Z
-      new Vector4( 3, 1, 1, 1 ),
-      // negative Z
-      new Vector4( 1, 1, 1, 1 ),
-      // positive Y
-      new Vector4( 3, 0, 1, 1 ),
-      // negative Y
-      new Vector4( 1, 0, 1, 1 )
-  ];
-
-  this._cubeDirections = [
+	this._cubeDirections = [
 		new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
 		new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
 		new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
 		new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
 	];
 	];
@@ -59,30 +58,30 @@ PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype
 
 
 	isPointLightShadow: true,
 	isPointLightShadow: true,
 
 
-  updateMatrices: function ( light, viewCamera, viewportIndex ) { 
+	updateMatrices: function ( light, viewCamera, viewportIndex ) {
 
 
-    var camera = this.camera,
-      shadowMatrix = this.matrix,
-      lightPositionWorld = this._lightPositionWorld,
-      lookTarget = this._lookTarget,
-      shadowMatrix = this.matrix,
-      projScreenMatrix = this._projScreenMatrix;
+		var camera = this.camera,
+			shadowMatrix = this.matrix,
+			lightPositionWorld = this._lightPositionWorld,
+			lookTarget = this._lookTarget,
+			shadowMatrix = this.matrix,
+			projScreenMatrix = this._projScreenMatrix;
 
 
-    lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
+		lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
 		camera.position.copy( lightPositionWorld );
 		camera.position.copy( lightPositionWorld );
 
 
-    lookTarget.copy( camera.position );
+		lookTarget.copy( camera.position );
 		lookTarget.add( this._cubeDirections[ viewportIndex ] );
 		lookTarget.add( this._cubeDirections[ viewportIndex ] );
 		camera.up.copy( this._cubeUps[ viewportIndex ] );
 		camera.up.copy( this._cubeUps[ viewportIndex ] );
 		camera.lookAt( lookTarget );
 		camera.lookAt( lookTarget );
 		camera.updateMatrixWorld();
 		camera.updateMatrixWorld();
 
 
-    shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
+		shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
 
 
-    projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
+		projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
 		this._frustum.setFromMatrix( projScreenMatrix );
 		this._frustum.setFromMatrix( projScreenMatrix );
 
 
-  }
+	}
 
 
 } );
 } );
 
 

+ 7 - 7
src/lights/SpotLightShadow.js

@@ -18,11 +18,11 @@ SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype
 
 
 	isSpotLightShadow: true,
 	isSpotLightShadow: true,
 
 
-  updateMatrices: function ( light, viewCamera, viewportIndex ) { 
+	updateMatrices: function ( light, viewCamera, viewportIndex ) {
 
 
 		var camera = this.camera,
 		var camera = this.camera,
-      lookTarget = this._lookTarget,
-      lightPositionWorld = this._lightPositionWorld;
+			lookTarget = this._lookTarget,
+			lightPositionWorld = this._lightPositionWorld;
 
 
 		var fov = _Math.RAD2DEG * 2 * light.angle;
 		var fov = _Math.RAD2DEG * 2 * light.angle;
 		var aspect = this.mapSize.width / this.mapSize.height;
 		var aspect = this.mapSize.width / this.mapSize.height;
@@ -37,16 +37,16 @@ SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype
 
 
 		}
 		}
 
 
-    lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
+		lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
 		camera.position.copy( lightPositionWorld );
 		camera.position.copy( lightPositionWorld );
 
 
-    lookTarget.setFromMatrixPosition( light.target.matrixWorld );
+		lookTarget.setFromMatrixPosition( light.target.matrixWorld );
 		camera.lookAt( lookTarget );
 		camera.lookAt( lookTarget );
 		camera.updateMatrixWorld();
 		camera.updateMatrixWorld();
 
 
-    LightShadow.prototype.updateMatrices.call( this, light, viewCamera, viewportIndex );
+		LightShadow.prototype.updateMatrices.call( this, light, viewCamera, viewportIndex );
 
 
-  }
+	}
 
 
 } );
 } );
 
 

+ 26 - 28
src/renderers/webgl/WebGLShadowMap.js

@@ -8,7 +8,6 @@ import { WebGLRenderTarget } from '../WebGLRenderTarget.js';
 import { MeshDepthMaterial } from '../../materials/MeshDepthMaterial.js';
 import { MeshDepthMaterial } from '../../materials/MeshDepthMaterial.js';
 import { MeshDistanceMaterial } from '../../materials/MeshDistanceMaterial.js';
 import { MeshDistanceMaterial } from '../../materials/MeshDistanceMaterial.js';
 import { Vector4 } from '../../math/Vector4.js';
 import { Vector4 } from '../../math/Vector4.js';
-import { Vector3 } from '../../math/Vector3.js';
 import { Vector2 } from '../../math/Vector2.js';
 import { Vector2 } from '../../math/Vector2.js';
 import { Matrix4 } from '../../math/Matrix4.js';
 import { Matrix4 } from '../../math/Matrix4.js';
 import { Frustum } from '../../math/Frustum.js';
 import { Frustum } from '../../math/Frustum.js';
@@ -16,12 +15,11 @@ import { Frustum } from '../../math/Frustum.js';
 function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
 function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
 
 
 	var _frustum = new Frustum(),
 	var _frustum = new Frustum(),
-		_projScreenMatrix = new Matrix4(),
 
 
 		_shadowMapSize = new Vector2(),
 		_shadowMapSize = new Vector2(),
 		_viewportSize = new Vector2(),
 		_viewportSize = new Vector2(),
 
 
-    _viewport = new Vector4(),
+		_viewport = new Vector4(),
 
 
 		_MorphingFlag = 1,
 		_MorphingFlag = 1,
 		_SkinningFlag = 2,
 		_SkinningFlag = 2,
@@ -108,33 +106,33 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
 
 
 			_shadowMapSize.copy( shadow.mapSize );
 			_shadowMapSize.copy( shadow.mapSize );
 
 
-      var shadowFrameExtents = shadow.getFrameExtents(); 
+			var shadowFrameExtents = shadow.getFrameExtents();
 
 
-      _shadowMapSize.multiply( shadowFrameExtents );
+			_shadowMapSize.multiply( shadowFrameExtents );
 
 
 			_viewportSize.copy( shadow.mapSize );
 			_viewportSize.copy( shadow.mapSize );
 
 
-      if( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ){
-        
-        console.warn( 'THREE.WebGLShadowMap:', light, 'has shadow exceeding max texture size, reducing' );
-				
-        if ( _shadowMapSize.x > maxTextureSize ) {
+			if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
 
 
-          _viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
-          _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
-          shadow.mapSize.x = _viewportSize.x;
+				console.warn( 'THREE.WebGLShadowMap:', light, 'has shadow exceeding max texture size, reducing' );
 
 
-        }
+				if ( _shadowMapSize.x > maxTextureSize ) {
 
 
-        if ( _shadowMapSize.y > maxTextureSize ) {
+					_viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
+					_shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
+					shadow.mapSize.x = _viewportSize.x;
 
 
-          _viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
-          _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
-          shadow.mapSize.y = _viewportSize.y;
+				}
+
+				if ( _shadowMapSize.y > maxTextureSize ) {
 
 
-        }
+					_viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
+					_shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
+					shadow.mapSize.y = _viewportSize.y;
 
 
-      }
+				}
+
+			}
 
 
 			if ( shadow.map === null ) {
 			if ( shadow.map === null ) {
 
 
@@ -154,18 +152,18 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
 
 
 				var viewport = shadow.getViewport( vp );
 				var viewport = shadow.getViewport( vp );
 
 
-        _viewport.set( 
-        	_viewportSize.x * viewport.x, 
-        	_viewportSize.y * viewport.y, 
-        	_viewportSize.x * viewport.z, 
-        	_viewportSize.y * viewport.w 
-        );
+				_viewport.set(
+					_viewportSize.x * viewport.x,
+					_viewportSize.y * viewport.y,
+					_viewportSize.x * viewport.z,
+					_viewportSize.y * viewport.w
+				);
 
 
-        _state.viewport( _viewport );
+				_state.viewport( _viewport );
 
 
 				shadow.updateMatrices( light, camera, vp );
 				shadow.updateMatrices( light, camera, vp );
 
 
-        _frustum = shadow.getFrustum();
+				_frustum = shadow.getFrustum();
 
 
 				renderObject( scene, camera, shadow.camera, light );
 				renderObject( scene, camera, shadow.camera, light );