Quellcode durchsuchen

Simplified spotlight examples and made them less GPU intense.

Mr.doob vor 9 Jahren
Ursprung
Commit
9b39ec281c
2 geänderte Dateien mit 17 neuen und 25 gelöschten Zeilen
  1. 5 5
      examples/webgl_lights_spotlight.html
  2. 12 20
      examples/webgl_lights_spotlights.html

+ 5 - 5
examples/webgl_lights_spotlight.html

@@ -89,8 +89,8 @@
 				spt.penumbra = 0.05;
 				spt.decay = 2;
 				spt.distance = 500;
-				spt.shadow.mapSize.width = 8192;
-				spt.shadow.mapSize.height = 8192;
+				spt.shadow.mapSize.width = 1024;
+				spt.shadow.mapSize.height = 1024;
 				// shadow camera helper
 				spt.shadowCameraHelper = new THREE.CameraHelper( spt.shadow.camera ); // colored lines
 				spt.shadow.camera.near = 0.1;
@@ -150,7 +150,7 @@
 				gStyle.position = "absolute";
 				gStyle.top = "48px";
 				gStyle.height = "220px";
-				
+
 				gui.open();
 			}
 
@@ -220,7 +220,7 @@
 				if( event.type === 'mousedown' ) {
 
 					mouseDown.x = ( event.clientX / rndDom.clientWidth ) * 2 - 1;
-					
+
 					mouseDown.y = - ( event.clientY / rndDom.clientHeight ) * 2 + 1;
 
 				}
@@ -243,7 +243,7 @@
 							else found[0].object.material.color.set( 0xffffff );
 
 							render();
-							
+
 						}
 
 					}

+ 12 - 20
examples/webgl_lights_spotlights.html

@@ -64,9 +64,9 @@
 			var mshFloor = new THREE.Mesh(geoFloor, matFloor);
 			var mshBox = new THREE.Mesh(geoBox, matBox);
 			var amb = new THREE.AmbientLight(0x121422);
-			var spt1 = createSpotlight( { color: 0xFF7F00, angle:0.3 } );
-			var spt2 = createSpotlight( { color: 0x00FF7F, angle:0.3 } );
-			var spt3 = createSpotlight( { color: 0x7F00FF, angle:0.3 } );
+			var spt1 = createSpotlight( 0xFF7F00 );
+			var spt2 = createSpotlight( 0x00FF7F );
+			var spt3 = createSpotlight( 0x7F00FF );
 			var lightHelper1, lightHelper2, lightHelper3;
 			var ray = new THREE.Raycaster();
 			var mouseDown = new THREE.Vector2();
@@ -127,20 +127,15 @@
 				orb.update();
 			};
 
-			function createSpotlight( object ) {
-				var newObj = new THREE.SpotLight(object.color || 0xFFFFFF);
-				newObj.castShadow = object.castShadow || true;
-				newObj.angle = object.angle || 0.777;
-				newObj.exponent = object.exponent || 2.0;
-				newObj.penumbra = object.penumbra || 0.2;
-				newObj.decay = object.decay || 10;
-				newObj.distance = object.distance || 0.0;
-				newObj.shadow.mapSize.width = object.shadowWidth || 2048;
-				newObj.shadow.mapSize.height = object.shadowHeight || 2048;
-				// shadow camera helper
-				newObj.shadowCameraHelper = new THREE.CameraHelper( newObj.shadow.camera ); // colored lines
-				newObj.shadow.camera.near = 0.1;
-				newObj.shadow.camera.far = 20000;
+			function createSpotlight( color ) {
+				var newObj = new THREE.SpotLight( color, 2 );
+				newObj.castShadow = true;
+				newObj.angle = 0.3;
+				newObj.penumbra = 0.2;
+				newObj.decay = 2;
+				newObj.distance = 50;
+				newObj.shadow.mapSize.width = 1024;
+				newObj.shadow.mapSize.height = 1024;
 
 				return newObj;
 			};
@@ -174,9 +169,6 @@
 				if ( lightHelper1 ) lightHelper1.update();
 				if ( lightHelper2 ) lightHelper2.update();
 				if ( lightHelper3 ) lightHelper3.update();
-				if ( spt1.shadowCameraHelper ) spt1.shadowCameraHelper.update();
-				if ( spt2.shadowCameraHelper ) spt2.shadowCameraHelper.update();
-				if ( spt3.shadowCameraHelper ) spt3.shadowCameraHelper.update();
 
 				rnd.render(scn, cam);