var ambientLight =newTHREE.AmbientLight("#606008",1);scene.add(ambientLight);
functioninit(){// use the defaultsvar stats =initStats();var renderer =initRenderer();var camera =initCamera();// create a scene, that will hold all our elements such as objects, cameras and lights.var scene =newTHREE.Scene();// add ambient lightingvar ambientLight =newTHREE.AmbientLight("#606008",1); scene.add(ambientLight);// add spotlight for the shadowsvar spotLight =newTHREE.SpotLight(0xffffff,1,180,Math.PI/4); spotLight.shadow.mapSize.set(2048,2048); spotLight.position.set(-30,40,-10); spotLight.castShadow=true; scene.add(spotLight);// add a simple sceneaddHouseAndTree(scene)// add controlsvar controls =setupControls();// call the render functionrender();functionrender(){ stats.update();requestAnimationFrame(render); renderer.render(scene, camera);}functionsetupControls(){var controls =newfunction(){this.intensity= ambientLight.intensity;this.ambientColor= ambientLight.color.getStyle();this.disableSpotlight=false;};var gui =newdat.GUI(); gui.add(controls,'intensity',0,3,0.1).onChange(function(e){ ambientLight.color=newTHREE.Color(controls.ambientColor); ambientLight.intensity= controls.intensity;}); gui.addColor(controls,'ambientColor').onChange(function(e){ ambientLight.color=newTHREE.Color(controls.ambientColor); ambientLight.intensity= controls.intensity;}); gui.add(controls,'disableSpotlight').onChange(function(e){ spotLight.visible=!e;});return controls;}}
THREE.SpotLight聚光灯
创建聚光灯SpotLight的经典步骤
var spotLight =newTHREE.SpotLight("#ffffff");spotLight.position.set(-40,60,-10);spotLight.castShadow=true;spotLight.shadow.camera.near=1;spotLight.shadow.camera.far=100;spotLight.target= plane;spotLight.distance=0;spotLight.angle=0.4;spotLight.shadow.camera.fov=120;
functioninit(){// use the defaultsvar stats =initStats();var renderer =initRenderer();var camera =initCamera();// create a scene, that will hold all our elements such as objects, cameras and lights.var scene =newTHREE.Scene();var cubeAndSphere =addDefaultCubeAndSphere(scene);var cube = cubeAndSphere.cube;var sphere = cubeAndSphere.sphere;var plane =addGroundPlane(scene);// add subtle ambient lightingvar ambiColor ="#1c1c1c";var ambientLight =newTHREE.AmbientLight(ambiColor); scene.add(ambientLight);// add spotlight for a bit of lightvar spotLight0 =newTHREE.SpotLight(0xcccccc); spotLight0.position.set(-40,30,-10); spotLight0.lookAt(plane); scene.add(spotLight0);// add target and lightvar target =newTHREE.Object3D(); target.position=newTHREE.Vector3(5,0,0);var spotLight =newTHREE.SpotLight("#ffffff"); spotLight.position.set(-40,60,-10); spotLight.castShadow=true; spotLight.shadow.camera.near=1; spotLight.shadow.camera.far=100; spotLight.target= plane; spotLight.distance=0; spotLight.angle=0.4; spotLight.shadow.camera.fov=120; scene.add(spotLight);var debugCamera =newTHREE.CameraHelper(spotLight.shadow.camera);var pp =newTHREE.SpotLightHelper(spotLight) scene.add(pp)// add a small sphere simulating the pointlightvar sphereLight =newTHREE.SphereGeometry(0.2);var sphereLightMaterial =newTHREE.MeshBasicMaterial({color:0xac6c25});var sphereLightMesh =newTHREE.Mesh(sphereLight, sphereLightMaterial); sphereLightMesh.castShadow=true; sphereLightMesh.position=newTHREE.Vector3(3,20,3); scene.add(sphereLightMesh);// for controlling the renderingvar step =0;var invert =1;var phase =0;var controls =setupControls();render();functionrender(){ stats.update();// rotate the cube around its axes cube.rotation.x+= controls.rotationSpeed; cube.rotation.y+= controls.rotationSpeed; cube.rotation.z+= controls.rotationSpeed;// bounce the sphere up and down step += controls.bouncingSpeed; sphere.position.x=20+(10*(Math.cos(step))); sphere.position.y=2+(10*Math.abs(Math.sin(step)));// move the light simulationif(!controls.stopMovingLight){if(phase >2*Math.PI){ invert = invert *-1; phase -=2*Math.PI;}else{ phase += controls.rotationSpeed;} sphereLightMesh.position.z=+(7*(Math.sin(phase))); sphereLightMesh.position.x=+(14*(Math.cos(phase))); sphereLightMesh.position.y=15;if(invert <0){var pivot =14; sphereLightMesh.position.x=(invert *(sphereLightMesh.position.x- pivot))+ pivot;} spotLight.position.copy(sphereLightMesh.position);} pp.update();// render using requestAnimationFramerequestAnimationFrame(render); renderer.render(scene, camera);}functionsetupControls(){var controls =newfunction(){this.rotationSpeed=0.03;this.bouncingSpeed=0.03;this.ambientColor= ambiColor;this.pointColor= spotLight.color.getStyle();this.intensity=1;this.distance=0;this.angle=0.1;this.shadowDebug=false;this.castShadow=true;this.target="Plane";this.stopMovingLight=false;this.penumbra=0;};var gui =newdat.GUI(); gui.addColor(controls,'ambientColor').onChange(function(e){ ambientLight.color=newTHREE.Color(e);}); gui.addColor(controls,'pointColor').onChange(function(e){ spotLight.color=newTHREE.Color(e);}); gui.add(controls,'angle',0,Math.PI*2).onChange(function(e){ spotLight.angle= e;}); gui.add(controls,'intensity',0,5).onChange(function(e){ spotLight.intensity= e;}); gui.add(controls,'penumbra',0,1).onChange(function(e){ spotLight.penumbra= e;}); gui.add(controls,'distance',0,200).onChange(function(e){ spotLight.distance= e;}); gui.add(controls,'shadowDebug').onChange(function(e){if(e){ scene.add(debugCamera);}else{ scene.remove(debugCamera);}}); gui.add(controls,'castShadow').onChange(function(e){ spotLight.castShadow= e;}); gui.add(controls,'target',['Plane','Sphere','Cube']).onChange(function(e){switch(e){case"Plane": spotLight.target= plane;break;case"Sphere": spotLight.target= sphere;break;case"Cube": spotLight.target= cube;break;}}); gui.add(controls,'stopMovingLight').onChange(function(e){ stopMovingLight = e;});return controls;}}
var pointColor ="#ccffcc";var pointLight =newTHREE.PointLight(pointColor);pointLight.decay=0.1pointLight.castShadow=true;scene.add(pointLight);
THREE.DirectionalLight平行光
functioninit(){// use the defaultsvar stats =initStats();var renderer =initRenderer();var camera =initCamera(); camera.position.set(-80,80,80);var trackballControls =initTrackballControls(camera, renderer);var clock =newTHREE.Clock();// create a scene, that will hold all our elements such as objects, cameras and lights.var scene =newTHREE.Scene();// create the ground planevar planeGeometry =newTHREE.PlaneGeometry(600,200,20,20);var planeMaterial =newTHREE.MeshLambertMaterial({color:0xffffff});var plane =newTHREE.Mesh(planeGeometry, planeMaterial); plane.receiveShadow=true;// rotate and position the plane plane.rotation.x=-0.5*Math.PI; plane.position.x=15; plane.position.y=-5; plane.position.z=0;// add the plane to the scene scene.add(plane);// create a cubevar cubeGeometry =newTHREE.BoxGeometry(4,4,4);var cubeMaterial =newTHREE.MeshLambertMaterial({color:0xff3333});var cube =newTHREE.Mesh(cubeGeometry, cubeMaterial); cube.castShadow=true;// position the cube cube.position.x=-4; cube.position.y=3; cube.position.z=0;// add the cube to the scene scene.add(cube);var sphereGeometry =newTHREE.SphereGeometry(4,20,20);var sphereMaterial =newTHREE.MeshLambertMaterial({color:0x7777ff});var sphere =newTHREE.Mesh(sphereGeometry, sphereMaterial);// position the sphere sphere.position.x=20; sphere.position.y=0; sphere.position.z=2; sphere.castShadow=true;// add the sphere to the scene scene.add(sphere);// add subtle ambient lightingvar ambiColor ="#1c1c1c";var ambientLight =newTHREE.AmbientLight(ambiColor); scene.add(ambientLight);var target =newTHREE.Object3D(); target.position=newTHREE.Vector3(5,0,0);var pointColor ="#ff5808";var directionalLight =newTHREE.DirectionalLight(pointColor); directionalLight.position.set(-40,60,-10); directionalLight.castShadow=true; directionalLight.shadow.camera.near=2; directionalLight.shadow.camera.far=80; directionalLight.shadow.camera.left=-30; directionalLight.shadow.camera.right=30; directionalLight.shadow.camera.top=30; directionalLight.shadow.camera.bottom=-30; directionalLight.intensity=0.5; directionalLight.shadow.mapSize.width=1024; directionalLight.shadow.mapSize.height=1024; scene.add(directionalLight);var shadowCamera =newTHREE.CameraHelper(directionalLight.shadow.camera)// add a small sphere simulating the pointlightvar sphereLight =newTHREE.SphereGeometry(0.2);var sphereLightMaterial =newTHREE.MeshBasicMaterial({color:0xac6c25});var sphereLightMesh =newTHREE.Mesh(sphereLight, sphereLightMaterial); sphereLightMesh.castShadow=true; sphereLightMesh.position=newTHREE.Vector3(3,20,3); scene.add(sphereLightMesh);// call the render functionvar step =0;var invert =1;var phase =0;var controls =newfunction(){this.rotationSpeed=0.03;this.bouncingSpeed=0.03;this.ambientColor= ambiColor;this.pointColor= pointColor;this.intensity=0.5;this.debug=false;this.castShadow=true;this.onlyShadow=false;this.target="Plane";};var gui =newdat.GUI(); gui.addColor(controls,'ambientColor').onChange(function(e){ ambientLight.color=newTHREE.Color(e);}); gui.addColor(controls,'pointColor').onChange(function(e){ directionalLight.color=newTHREE.Color(e);}); gui.add(controls,'intensity',0,5).onChange(function(e){ directionalLight.intensity= e;}); gui.add(controls,'debug').onChange(function(e){ e ? scene.add(shadowCamera): scene.remove(shadowCamera);}); gui.add(controls,'castShadow').onChange(function(e){ directionalLight.castShadow= e;}); gui.add(controls,'onlyShadow').onChange(function(e){ directionalLight.onlyShadow= e;}); gui.add(controls,'target',['Plane','Sphere','Cube']).onChange(function(e){console.log(e);switch(e){case"Plane": directionalLight.target= plane;break;case"Sphere": directionalLight.target= sphere;break;case"Cube": directionalLight.target= cube;break;}});render();functionrender(){ stats.update(); trackballControls.update(clock.getDelta());// rotate the cube around its axes cube.rotation.x+= controls.rotationSpeed; cube.rotation.y+= controls.rotationSpeed; cube.rotation.z+= controls.rotationSpeed;// bounce the sphere up and down step += controls.bouncingSpeed; sphere.position.x=20+(10*(Math.cos(step))); sphere.position.y=2+(10*Math.abs(Math.sin(step))); sphereLightMesh.position.z=-8; sphereLightMesh.position.y=+(27*(Math.sin(step /3))); sphereLightMesh.position.x=10+(26*(Math.cos(step /3))); directionalLight.position.copy(sphereLightMesh.position);// render using requestAnimationFramerequestAnimationFrame(render); renderer.render(scene, camera);}}
functioninit(){var stats =initStats();var renderer =initRenderer();var camera =initCamera();var trackballControls =initTrackballControls(camera, renderer);var clock =newTHREE.Clock();// create a scene, that will hold all our elements such as objects, cameras and lights.var scene =newTHREE.Scene();// create the ground planevar textureGrass =newTHREE.TextureLoader().load("/assets/threejs/assets/textures/ground/grasslight-big.jpg"); textureGrass.wrapS=THREE.RepeatWrapping; textureGrass.wrapT=THREE.RepeatWrapping; textureGrass.repeat.set(10,10);var planeGeometry =newTHREE.PlaneGeometry(1000,1000,20,20);var planeMaterial =newTHREE.MeshLambertMaterial({map: textureGrass
});// var planeMaterial = new THREE.MeshLambertMaterial();var plane =newTHREE.Mesh(planeGeometry, planeMaterial); plane.receiveShadow=true;// rotate and position the plane plane.rotation.x=-0.5*Math.PI; plane.position.x=15; plane.position.y=0; plane.position.z=0;// add the plane to the scene scene.add(plane);// create a cubevar cubeGeometry =newTHREE.BoxGeometry(4,4,4);var cubeMaterial =newTHREE.MeshLambertMaterial({color:0xff3333});var cube =newTHREE.Mesh(cubeGeometry, cubeMaterial); cube.castShadow=true;// position the cube cube.position.x=-4; cube.position.y=3; cube.position.z=0;// add the cube to the scene scene.add(cube);var sphereGeometry =newTHREE.SphereGeometry(4,25,25);var sphereMaterial =newTHREE.MeshPhongMaterial({color:0x7777ff});var sphere =newTHREE.Mesh(sphereGeometry, sphereMaterial);// position the sphere sphere.position.x=10; sphere.position.y=5; sphere.position.z=10; sphere.castShadow=true;// add the sphere to the scene scene.add(sphere);// add spotlight for a bit of lightvar spotLight0 =newTHREE.SpotLight(0xcccccc); spotLight0.position.set(-40,60,-10); spotLight0.lookAt(plane); scene.add(spotLight0);var target =newTHREE.Object3D(); target.position=newTHREE.Vector3(5,0,0);var hemiLight =newTHREE.HemisphereLight(0x0000ff,0x00ff00,0.6); hemiLight.position.set(0,500,0); scene.add(hemiLight);var pointColor ="#ffffff";var dirLight =newTHREE.DirectionalLight(pointColor); dirLight.position.set(30,10,-50); dirLight.castShadow=true; dirLight.target= plane; dirLight.shadow.camera.near=0.1; dirLight.shadow.camera.far=200; dirLight.shadow.camera.left=-50; dirLight.shadow.camera.right=50; dirLight.shadow.camera.top=50; dirLight.shadow.camera.bottom=-50; dirLight.shadow.mapSize.width=2048; dirLight.shadow.mapSize.height=2048; scene.add(dirLight);// call the render functionvar step =0;// used to determine the switch point for the light animationvar invert =1;var phase =0;var controls =addControls();render();functionrender(){ stats.update(); trackballControls.update(clock.getDelta());// rotate the cube around its axes cube.rotation.x+= controls.rotationSpeed; cube.rotation.y+= controls.rotationSpeed; cube.rotation.z+= controls.rotationSpeed;// bounce the sphere up and down step += controls.bouncingSpeed; sphere.position.x=20+(10*(Math.cos(step))); sphere.position.y=2+(10*Math.abs(Math.sin(step)));requestAnimationFrame(render); renderer.render(scene, camera);}functionaddControls(){var controls =newfunction(){this.rotationSpeed=0.03;this.bouncingSpeed=0.03;this.hemisphere=true;this.color=0x0000ff;this.groundColor=0x00ff00;this.intensity=0.6;};var gui =newdat.GUI(); gui.add(controls,'hemisphere').onChange(function(e){if(!e){ hemiLight.intensity=0;}else{ hemiLight.intensity= controls.intensity;}}); gui.addColor(controls,'groundColor').onChange(function(e){ hemiLight.groundColor=newTHREE.Color(e);}); gui.addColor(controls,'color').onChange(function(e){ hemiLight.color=newTHREE.Color(e);}); gui.add(controls,'intensity',0,5).onChange(function(e){ hemiLight.intensity= e;});return controls;}}
仔细观察,上述场景中球体表面底部有接近草地的绿色,而顶部有接近天空的蓝色(设置color).
创建THREE.HemisphereLight半球光光源:
var hemiLight =newTHREE.HemisphereLight(0x0000ff,0x00ff00,0.6);hemiLight.position.set(0,500,0);scene.add(hemiLight);
THREE.HemisphereLight属性
Column 2
groundColor
从地面发出光线的颜色
color
从天空发出的光线的颜色
intensity
光线照射的强度
THREE.AreaLight区域光
functioninit(){var stats =initStats();var renderer =initRenderer({antialias:true});var camera =initCamera(); camera.position.set(-50,30,50)// camera.lookAt(new THREE.Vector3(0, 0, -35));var trackballControls =initTrackballControls(camera, renderer);var clock =newTHREE.Clock();// create a scene, that will hold all our elements such as objects, cameras and lights.var scene =newTHREE.Scene();// create the ground planevar planeGeometry =newTHREE.PlaneGeometry(70,70,1,1);var planeMaterial =newTHREE.MeshStandardMaterial({roughness:0.044676705160855,// calculated from shininess = 1000metalness:0.0});var plane =newTHREE.Mesh(planeGeometry, planeMaterial);// plane.receiveShadow = true;// rotate and position the plane plane.rotation.x=-0.5*Math.PI; plane.position.x=0; plane.position.y=0; plane.position.z=0;// add the plane to the scene scene.add(plane);// call the render functionvar step =0;var spotLight0 =newTHREE.SpotLight(0xcccccc); spotLight0.position.set(-40,60,-10); spotLight0.intensity=0.1; spotLight0.lookAt(plane); scene.add(spotLight0);var areaLight1 =newTHREE.RectAreaLight(0xff0000,500,4,10); areaLight1.position.set(-10,10,-35); scene.add(areaLight1);var areaLight2 =newTHREE.RectAreaLight(0x00ff00,500,4,10); areaLight2.position.set(0,10,-35); scene.add(areaLight2);var areaLight3 =newTHREE.RectAreaLight(0x0000ff,500,4,10); areaLight3.position.set(10,10,-35); scene.add(areaLight3);var planeGeometry1 =newTHREE.BoxGeometry(4,10,0);var planeGeometry1Mat =newTHREE.MeshBasicMaterial({color:0xff0000});var plane1 =newTHREE.Mesh(planeGeometry1, planeGeometry1Mat); plane1.position.copy(areaLight1.position); scene.add(plane1);var planeGeometry2 =newTHREE.BoxGeometry(4,10,0);var planeGeometry2Mat =newTHREE.MeshBasicMaterial({color:0x00ff00,});var plane2 =newTHREE.Mesh(planeGeometry2, planeGeometry2Mat); plane2.position.copy(areaLight2.position); scene.add(plane2);var planeGeometry3 =newTHREE.BoxGeometry(4,10,0);var planeGeometry3Mat =newTHREE.MeshBasicMaterial({color:0x0000ff});var plane3 =newTHREE.Mesh(planeGeometry3, planeGeometry3Mat); plane3.position.copy(areaLight3.position); scene.add(plane3);var controls =newfunction(){this.rotationSpeed=0.02;this.color1=0xff0000;this.intensity1=500;this.color2=0x00ff00;this.intensity2=500;this.color3=0x0000ff;this.intensity3=500;};var gui =newdat.GUI(); gui.addColor(controls,'color1').onChange(function(e){ areaLight1.color=newTHREE.Color(e); planeGeometry1Mat.color=newTHREE.Color(e); scene.remove(plane1); plane1 =newTHREE.Mesh(planeGeometry1, planeGeometry1Mat); plane1.position.copy(areaLight1.position); scene.add(plane1);}); gui.add(controls,'intensity1',0,1000).onChange(function(e){ areaLight1.intensity= e;}); gui.addColor(controls,'color2').onChange(function(e){ areaLight2.color=newTHREE.Color(e); planeGeometry2Mat.color=newTHREE.Color(e); scene.remove(plane2); plane2 =newTHREE.Mesh(planeGeometry2, planeGeometry2Mat); plane2.position.copy(areaLight2.position); scene.add(plane2);}); gui.add(controls,'intensity2',0,1000).onChange(function(e){ areaLight2.intensity= e;}); gui.addColor(controls,'color3').onChange(function(e){ areaLight3.color=newTHREE.Color(e); planeGeometry3Mat.color=newTHREE.Color(e); scene.remove(plane3); plane3 =newTHREE.Mesh(planeGeometry1, planeGeometry3Mat); plane3.position.copy(areaLight3.position); scene.add(plane3);}); gui.add(controls,'intensity3',0,1000).onChange(function(e){ areaLight3.intensity= e;});render();functionrender(){ stats.update(); trackballControls.update(clock.getDelta());// render using requestAnimationFramerequestAnimationFrame(render); renderer.render(scene, camera);}}
functioninit(){var stats =initStats();var renderer =initRenderer({alpha:true});var camera =initCamera(); camera.position.x=-20; camera.position.y=10; camera.position.z=45; camera.lookAt(newTHREE.Vector3(10,0,0));var trackballControls =initTrackballControls(camera, renderer);var clock =newTHREE.Clock();// create a scene, that will hold all our elements such as objects, cameras and lights.var scene =newTHREE.Scene();// create the ground planevar textureGrass =newTHREE.TextureLoader().load("/assets/threejs/assets/textures/ground/grasslight-big.jpg"); textureGrass.wrapS=THREE.RepeatWrapping; textureGrass.wrapT=THREE.RepeatWrapping; textureGrass.repeat.set(10,10);var planeGeometry =newTHREE.PlaneGeometry(1000,1000,20,20);var planeMaterial =newTHREE.MeshLambertMaterial({map: textureGrass
});var plane =newTHREE.Mesh(planeGeometry, planeMaterial); plane.receiveShadow=true;// rotate and position the plane plane.rotation.x=-0.5*Math.PI; plane.position.x=15; plane.position.y=0; plane.position.z=0;// add the plane to the scene scene.add(plane);// create a cubevar cubeGeometry =newTHREE.BoxGeometry(4,4,4);var cubeMaterial =newTHREE.MeshLambertMaterial({color:0xff3333});var cube =newTHREE.Mesh(cubeGeometry, cubeMaterial); cube.castShadow=true;// position the cube cube.position.x=-4; cube.position.y=3; cube.position.z=0;// add the cube to the scene scene.add(cube);var sphereGeometry =newTHREE.SphereGeometry(4,25,25);var sphereMaterial =newTHREE.MeshLambertMaterial({color:0x7777ff});var sphere =newTHREE.Mesh(sphereGeometry, sphereMaterial);// position the sphere sphere.position.x=10; sphere.position.y=5; sphere.position.z=10; sphere.castShadow=true;// add the sphere to the scene scene.add(sphere);// add subtle ambient lightingvar ambiColor ="#1c1c1c";var ambientLight =newTHREE.AmbientLight(ambiColor); scene.add(ambientLight);// add spotlight for a bit of lightvar spotLight0 =newTHREE.SpotLight(0xcccccc); spotLight0.position.set(-40,60,-10); spotLight0.lookAt(plane); scene.add(spotLight0);var target =newTHREE.Object3D(); target.position=newTHREE.Vector3(5,0,0);var pointColor ="#ffffff";// var spotLight = new THREE.SpotLight( pointColor);var spotLight =newTHREE.DirectionalLight(pointColor); spotLight.position.set(30,10,-50); spotLight.castShadow=true; spotLight.shadowCameraNear=0.1; spotLight.shadowCameraFar=100; spotLight.shadowCameraFov=50; spotLight.target= plane; spotLight.distance=0; spotLight.shadowCameraNear=2; spotLight.shadowCameraFar=200; spotLight.shadowCameraLeft=-100; spotLight.shadowCameraRight=100; spotLight.shadowCameraTop=100; spotLight.shadowCameraBottom=-100; spotLight.shadowMapWidth=2048; spotLight.shadowMapHeight=2048; scene.add(spotLight);// call the render functionvar step =0;// used to determine the switch point for the light animationvar invert =1;var phase =0;var controls =newfunction(){this.rotationSpeed=0.03;this.bouncingSpeed=0.03;this.ambientColor= ambiColor;this.pointColor= pointColor;this.intensity=0.1;this.distance=0;this.exponent=30;this.angle=0.1;this.debug=false;this.castShadow=true;this.onlyShadow=false;this.target="Plane";};var gui =newdat.GUI(); gui.addColor(controls,'ambientColor').onChange(function(e){ ambientLight.color=newTHREE.Color(e);}); gui.addColor(controls,'pointColor').onChange(function(e){ spotLight.color=newTHREE.Color(e);}); gui.add(controls,'intensity',0,5).onChange(function(e){ spotLight.intensity= e;});var textureFlare0 =THREE.ImageUtils.loadTexture("/assets/threejs/assets/textures/flares/lensflare0.png");var textureFlare3 =THREE.ImageUtils.loadTexture("/assets/threejs/assets/textures/flares/lensflare3.png");var flareColor =newTHREE.Color(0xffaacc);var lensFlare =newTHREE.Lensflare(); lensFlare.addElement(newTHREE.LensflareElement(textureFlare0,350,0.0, flareColor)); lensFlare.addElement(newTHREE.LensflareElement(textureFlare3,60,0.6, flareColor)); lensFlare.addElement(newTHREE.LensflareElement(textureFlare3,70,0.7, flareColor)); lensFlare.addElement(newTHREE.LensflareElement(textureFlare3,120,0.9, flareColor)); lensFlare.addElement(newTHREE.LensflareElement(textureFlare3,70,1.0, flareColor)); spotLight.add(lensFlare);render();functionrender(){ stats.update(); trackballControls.update(clock.getDelta());// rotate the cube around its axes cube.rotation.x+= controls.rotationSpeed; cube.rotation.y+= controls.rotationSpeed; cube.rotation.z+= controls.rotationSpeed;// bounce the sphere up and down step += controls.bouncingSpeed; sphere.position.x=20+(10*(Math.cos(step))); sphere.position.y=2+(10*Math.abs(Math.sin(step)));requestAnimationFrame(render); renderer.render(scene, camera);}};
创建镜头光晕:
var lensFlare =newTHREE.Lensflare(texture, size, distance, blending, color, opacity);