ambientLight = new THREE.AmbientLight(0xDFDFDF, 0.3); scene.add(ambientLight);DirectionalLight(平行光)
lightDirect = new THREE.DirectionalLight(0xf2f2f2, 0.8); lightDirect.position.set(20, 20, -20); scene.add(lightDirect);PointLight(点光源)
lightPoint = new THREE.PointLight(0xE9E9E9, 0.9); lightPoint.position.set(0, 10, -5); scene.add(lightPoint);SpotLight(聚光灯光源)
lightSpot = new THREE.SpotLight(0xE9E9E9); lightSpot.position.set(0, 20, -20); lightSpot.castShadow = true; lightSpot.angle = Math.PI / 4; lightSpot.penumbra = 0.3; scene.add(lightSpot);HemisphereLight(半球光源)
// 堆代码 duidaima.com var light = new THREE.HemisphereLight( 0xffffbb, 0x080820, 1 ); scene.add( light );
第一个参数是天空的光线颜色,第二个参数是地面反射光的颜色,第三个参数是强度
renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap;设置光线开启阴影
light.castShadow = true;设置需要产生阴影的mesh
cube.castShadow = true;设置接收阴影的mesh(如地面等)
plane.receiveShadow = true;
// 堆代码 duidaima.com let mesh = gltf.scene//模型对象 mesh.material = new THREE.MeshStandardMaterial({ // 默认 0.5. 0.0到1.0之间的值可用于生锈的金属外观 metalness: 0.5, // 材料的粗糙程度. 0.0表示平滑的镜面反射,1.0表示完全漫反射. 默认 0.5 roughness: 0.5, }) gltf.scene.material.shininess = 1; gltf.scene.castShadow = true; gltf.scene.receiveShadow