瀏覽代碼

Add extra lights to the webgl_shadowmap_pointlight example

The extra point lights demonstrate that it's possible to have lots of non-shadow casting lights in the same scene as the shadow casting lights.
Olli Etuaho 6 年之前
父節點
當前提交
705010517a
共有 1 個文件被更改,包括 26 次插入0 次删除
  1. 26 0
      examples/webgl_shadowmap_pointlight.html

+ 26 - 0
examples/webgl_shadowmap_pointlight.html

@@ -22,6 +22,8 @@
 			var camera, scene, renderer, stats;
 			var pointLight, pointLight2;
 
+			var extraPointLights;
+
 			init();
 			animate();
 
@@ -86,6 +88,30 @@
 				pointLight2 = createLight( 0xff8888 );
 				scene.add( pointLight2 );
 
+				// The extra point lights demonstrate that it's possible to have lots of non-shadow-casting lights in
+				// the same scene as the shadow casting lights.
+				var createExtraLight = function() {
+					var pointLight = new THREE.PointLight( 0xffffff, 0.1, 20 );
+					pointLight.position.x = (Math.random() - 0.5) * 29;
+					pointLight.position.y = (Math.random() - 0.5) * 29;
+					pointLight.position.z = (Math.random() - 0.5) * 29;
+
+					var geometry = new THREE.SphereBufferGeometry( 0.1, 10, 6 );
+					var material = new THREE.MeshBasicMaterial( { color: 0xffffff } );
+					var sphere = new THREE.Mesh( geometry, material );
+					pointLight.add( sphere );
+
+					return pointLight;
+				};
+
+				var extraPointLights = new THREE.Object3D();
+				scene.add( extraPointLights );
+				extraPointLights.position.set( 0, 10, 0 );
+
+				for ( var i = 0; i < 20; ++i ) {
+					extraPointLights.add( createExtraLight() );
+				}
+
 				//
 
 				var geometry = new THREE.BoxBufferGeometry( 30, 30, 30 );