Browse Source

Updated code formatting.

Mark Kellogg 10 years ago
parent
commit
ebe6e29939

+ 26 - 51
examples/webgl_shadowmap_omnidirectional.html

@@ -69,9 +69,9 @@
 				scene.add( ambient );
 
 				pointLight = new THREE.PointLight( 0xffffff );
-				pointLight.position.set(0,11,4);
+				pointLight.position.set( 0, 11, 4 );
 				pointLight.castShadow = true;
-				pointLight.shadowCameraNear = .05;
+				pointLight.shadowCameraNear = 1;
 				pointLight.shadowCameraFar = 30;
 				pointLight.shadowDarkness = 0.5;
 				pointLight.shadowCameraVisible = true;
@@ -87,7 +87,7 @@
 				dirLight.shadowCameraFar = 100;
 				dirLight.shadowCameraRight = 15;
 				dirLight.shadowCameraLeft = -15;
-				dirLight.shadowCameraTop	= 15;
+				dirLight.shadowCameraTop = 15;
 				dirLight.shadowCameraBottom = -15;
 				dirLight.shadowDarkness = 0.5;
 				dirLight.shadowCameraVisible = true;
@@ -135,85 +135,69 @@
 			
 				wallMaterial = new THREE.MeshPhongMaterial( {
 					color: 0xa0adaf,
-					shininess: 150,
-					specular: 0xffffff,
+					shininess: 10,
+					specular: 0x111111,
 					shading: THREE.SmoothShading
 				} );				
 
-				var groundGeometry = new THREE.BoxGeometry( 10, 0.15, 10 );
-				ground = new THREE.Mesh( groundGeometry, wallMaterial );
+				var wallGeometry = new THREE.BoxGeometry( 10, 0.15, 10 );
+				ground = new THREE.Mesh( wallGeometry, wallMaterial );
 				ground.name = "ground";
 				ground.scale.multiplyScalar( 3 );
 				ground.castShadow = false;
 				ground.receiveShadow = true;
 				scene.add( ground );
-				ground.position.set(0,-5,0);
+				ground.position.set( 0, -5, 0 );
 
-				var ceiling = new THREE.Mesh( groundGeometry, wallMaterial );
+				var ceiling = new THREE.Mesh( wallGeometry, wallMaterial );
 				ceiling.name = "ceiling";
 				ceiling.scale.multiplyScalar( 3 );
 				ceiling.castShadow = false;
 				ceiling.receiveShadow = true;
 				scene.add( ceiling );
-				ceiling.position.set(0,24,0);
+				ceiling.position.set( 0, 24, 0 );
 
-				var wall = new THREE.Mesh( groundGeometry, wallMaterial );
+				var wall = new THREE.Mesh( wallGeometry, wallMaterial );
 				wall.name = "left wall";
 				wall.scale.multiplyScalar( 3 );
 				wall.castShadow = false;
 				wall.receiveShadow = true;				
 				scene.add( wall );
-				wall.position.set(-14,10,0);
-				rotateAroundWorldAxis(wall, new THREE.Vector3(0,0,-1), Math.PI / 180 * 90);
+				wall.position.set( -14, 10, 0 );
+				wall.rotation.z = Math.PI / 2;
 
-				wall = new THREE.Mesh( groundGeometry, wallMaterial );
+				wall = new THREE.Mesh( wallGeometry, wallMaterial );
 				wall.name = "right wall";
 				wall.scale.multiplyScalar( 3 );
 				wall.castShadow = false;
 				wall.receiveShadow = true;				
 				scene.add( wall );
 				wall.position.set(14,10,0);
-				rotateAroundWorldAxis(wall, new THREE.Vector3(0,0,-1), Math.PI / 180 * 90);
+				wall.rotation.z = Math.PI / 2;
 
-				wall = new THREE.Mesh( groundGeometry, wallMaterial );
+				wall = new THREE.Mesh( wallGeometry, wallMaterial );
 				wall.name = "back wall";
 				wall.scale.multiplyScalar( 3 );
 				wall.castShadow = false;
 				wall.receiveShadow = true;				
 				scene.add( wall );
-				wall.position.set(0,10,-14);
-				rotateAroundWorldAxis(wall, new THREE.Vector3(1,0,0), Math.PI / 180 * 90);
+				wall.position.set( 0, 10, -14 );
+				wall.rotation.y = Math.PI / 2;
+				wall.rotation.z = Math.PI / 2;
 
 				var sphereGeometry = new THREE.SphereGeometry( 1, 32, 32 );
-				var material = new THREE.MeshBasicMaterial( {color: 0xffffff} );
+				var material = new THREE.MeshBasicMaterial( { color: 0xffffff } );
 				var sphere = new THREE.Mesh( sphereGeometry, material );
 				sphere.castShadow = false;
 				sphere.receiveShadow = false;	
-				sphere.position.set(0,11,4);
+				sphere.position.set( 0, 11, 4 );
 				scene.add( sphere );
 
 				pointLightParent = new THREE.Object3D();
-				pointLightParent.add(pointLight);
-				pointLightParent.add(sphere);
-				scene.add(pointLightParent);			
-			}
+				pointLightParent.add( pointLight );
+				pointLightParent.add( sphere );
+				scene.add( pointLightParent );	
 
-			// Rotate an object around an arbitrary axis in world space       
-			function rotateAroundWorldAxis(object, axis, radians) {
-			    var rotWorldMatrix = new THREE.Matrix4();
-			    rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
-			    rotWorldMatrix.multiply(object.matrix);            
-			    object.matrix = rotWorldMatrix;
-			    object.rotation.setFromRotationMatrix(object.matrix);
-			}
-
-			// Rotate an object around an arbitrary axis in world space       
-			function rotateAroundWorldAxis(object, axis, radians) {
-			    var rotWorldMatrix = new THREE.Matrix4();
-			    rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
-			    rotWorldMatrix.multiply(object.matrix);               
-			    object.matrix = rotWorldMatrix;
-			    object.rotation.setFromRotationMatrix(object.matrix);
 			}
 
 			function initMisc() {
@@ -243,7 +227,6 @@
 
 				camera.aspect = window.innerWidth / window.innerHeight;
 				camera.updateProjectionMatrix();
-
 				renderer.setSize( window.innerWidth, window.innerHeight );
 
 			}
@@ -252,22 +235,20 @@
 
 				requestAnimationFrame( animate );
 				render();
-
 				stats.update();
 
 			}
 
 			function renderScene() {
+
 				renderer.render( scene, camera );
 			}
 
-
-			var updateCount = 0;
 			function render() {
 
 				var delta = clock.getDelta();
 
-				pointLightParent.rotation.y += .05;
+				pointLightParent.rotation.y += delta * 2;
 				renderScene();
 
 				cube.rotation.x += 0.25 * delta;
@@ -282,12 +263,6 @@
 				cube3.rotation.y += 2 * delta;
 				cube3.rotation.z += 1 * delta;
 
-				//var pos = new THREE.Vector3();
-				//pos.setFromMatrixPosition(pointLight.matrixWorld);
-				//console.log(pos.x +","+pos.y+","+pos.z);
-
-				updateCount++;
-
 			}
 
 		</script>

+ 10 - 5
src/renderers/WebGLRenderer.js

@@ -1967,15 +1967,18 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if ( light instanceof THREE.PointLight || light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight  ) {
 
-					if( light instanceof THREE.PointLight){
+					if( light instanceof THREE.PointLight ){
+
 						uniforms.shadowCube.value[ j ] = light.shadowMap;
 						uniforms.shadowMap.value[ j ] = null;
 						uniforms.isShadowCube.value[ j ] = 1;
 
 					} else {
+
 						uniforms.shadowMap.value[ j ] = light.shadowMap;
 						uniforms.isShadowCube.value[ j ] = 0;
 						uniforms.shadowCube.value[ j ] = null;
+
 					}					
 
 					uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
@@ -1985,10 +1988,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 					uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
 					uniforms.shadowBias.value[ j ] = light.shadowBias;
 
-					_vector3.setFromMatrixPosition(light.matrixWorld);
-					uniforms.shadowLightPosition.value[ j * 3] = _vector3.x;
-					uniforms.shadowLightPosition.value[ j * 3 + 1] = _vector3.y;
-					uniforms.shadowLightPosition.value[ j * 3 + 2] = _vector3.z;
+					_vector3.setFromMatrixPosition( light.matrixWorld );
+					uniforms.shadowLightPosition.value[ j * 3 ] = _vector3.x;
+					uniforms.shadowLightPosition.value[ j * 3 + 1 ] = _vector3.y;
+					uniforms.shadowLightPosition.value[ j * 3 + 2 ] = _vector3.z;
 
 					j ++;
 
@@ -3152,8 +3155,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 		}
 
 		if( isCube ){
+
 			var renderTargetProperties = properties.get( renderTarget );
 			_gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0,  _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, renderTargetProperties.__webglTexture , 0 );
+
 		}
 
 		_currentWidth = width;

File diff suppressed because it is too large
+ 0 - 0
src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl


+ 14 - 11
src/renderers/shaders/ShaderLib.js

@@ -883,24 +883,27 @@ THREE.ShaderLib = {
 
 			THREE.ShaderChunk[ "common" ],
 
-			"vec4 pack1K (float depth) {",
+			"vec4 pack1K ( float depth ) {",
+
 			"   depth /= 1000.0;",
-			"   const vec4 bitSh = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);",
-  			"	const vec4 bitMsk = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);",
-   			"	vec4 res = fract(depth * bitSh);",
+			"   const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
+  			"	const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
+   			"	vec4 res = fract( depth * bitSh );",
    			"	res -= res.xxyz * bitMsk;",
    			"	return res; ",
-			"}",
-			
+
+			"}",			
 			
-			"float unpack1K (vec4 color) {",
-			"	const vec4 bitSh = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);",
-			"	return dot(color, bitSh) * 1000.0;",
+			"float unpack1K ( vec4 color ) {",
+
+			"	const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
+			"	return dot( color, bitSh ) * 1000.0;",
+
 			"}",
 
+			"void main () {",
 
-			"void main() {",
-			"	gl_FragColor = pack1K( length(vWorldPosition.xyz - lightPos.xyz) );",
+			"	gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
 
 			"}"
 

+ 36 - 16
src/renderers/webgl/WebGLShadowMap.js

@@ -150,11 +150,15 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 			var light = _lights[ i ];
 
 			if ( light instanceof THREE.PointLight ) {
+
 				faceCount = 6;
 				isCube = true;
+
 			} else {
+
 				faceCount = 1;
 				isCube = false;
+
 			}
 
 			if ( ! light.castShadow ) continue;
@@ -172,11 +176,15 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 				var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
 
 				if ( isCube ) {
+
 					light.shadowMap = new THREE.WebGLRenderTargetCube( light.shadowMapWidth, light.shadowMapWidth, pars );
 					light.shadowMapSize = new  THREE.Vector2( light.shadowMapWidth, light.shadowMapWidth );
+
 				} else {
+
 					light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
 					light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
+
 				}	
 
 				light.shadowMatrix = new THREE.Matrix4();
@@ -217,21 +225,25 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 			var shadowCamera = light.shadowCamera;
 
 			_lightPosition.setFromMatrixPosition( light.matrixWorld );
-			shadowCamera.position.copy(_lightPosition);
+			shadowCamera.position.copy( _lightPosition);
 
 			// render shadow map for each cube face (if omni-directional) or
 			// run a single pass if not
 
-			for(var face = 0; face < faceCount; face ++){				
+			for ( var face = 0; face < faceCount; face++ ){				
 		
-				if( isCube){
-					_lookTarget.copy(shadowCamera.position);
-					_lookTarget.add(cubeDirections[face]);
-					shadowCamera.up.copy(cubeUps[face]);
-					shadowCamera.lookAt(_lookTarget);				
+				if( isCube ){
+
+					_lookTarget.copy( shadowCamera.position );
+					_lookTarget.add( cubeDirections[face] );
+					shadowCamera.up.copy( cubeUps[face] );
+					shadowCamera.lookAt( _lookTarget );	
+
 				} else {
+
 					_lookTarget.setFromMatrixPosition( light.target.matrixWorld );
-					shadowCamera.lookAt( _lookTarget);
+					shadowCamera.lookAt( _lookTarget );
+
 				}	
 
 				shadowCamera.updateMatrixWorld();
@@ -259,8 +271,10 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 
 				// render shadow map
 
-				if(isCube){
+				if( isCube ){
+
 					shadowMap.activeCubeFace = face;
+
 				}	
 
 				_renderer.setRenderTarget( shadowMap );
@@ -292,7 +306,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 
 							if ( groupMaterial.visible === true ) {
 
-								var depthMaterial = getDepthMaterial( object, groupMaterial, isCube, _lightPosition);
+								var depthMaterial = getDepthMaterial( object, groupMaterial, isCube, _lightPosition );
 								_renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial , object, group );
 
 							}
@@ -300,8 +314,10 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 						}
 
 					} else {
+
 						var depthMaterial = getDepthMaterial( object, material, isCube, _lightPosition);						
 						_renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, null );
+
 					}
 
 				}
@@ -344,17 +360,21 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 		var depthMaterialMorphSkin = _depthMaterialMorphSkin;
 
 		if ( isCube ){
+
 			depthMaterial = _distanceMaterial;
 			depthMaterialMorph = _distanceMaterialMorph; 
 			depthMaterialSkin = _distanceMaterialSkin; 
 			depthMaterialMorphSkin = _distanceMaterialMorphSkin;
 		}
 
-		if ( object.customDepthMaterial || object.customDistanceMaterial) {
+		if ( object.customDepthMaterial || object.customDistanceMaterial ) {
+
+			if ( isCube ){
 
-			if( isCube ){
 				newMaterial = object.customDistanceMaterial;
+
 			} else {
+
 				newMaterial = object.customDepthMaterial;
 			}
 
@@ -377,9 +397,10 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 		newMaterial.wireframeLinewidth = material.wireframeLinewidth;
 
 		if ( isCube ){
-			if(newMaterial.uniforms.lightPos)
-			{
-				newMaterial.uniforms.lightPos.value.copy(lightPosition);
+
+			if( newMaterial.uniforms.lightPos ){
+
+				newMaterial.uniforms.lightPos.value.copy( lightPosition );
 			}
 		}
 
@@ -389,7 +410,6 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 
 	function projectObject( object, camera ) {
 
-
 		if ( object.visible === false ) return;
 
 		if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {

Some files were not shown because too many files changed in this diff