學習threeJS(三)--光源

1、光源的類型code

  • AmbientLight(環境光)
  • PointLight(點光源)
  • SpotLight(聚光燈光源,錐形光源)
  • DirectionLight(方向光,太陽光,平行光)
  • HemisphereLight(半球光)
  • AreaLight(面光源)
  • LensFlare(鏡頭炫光)

2、基礎光源get

一、AmbientLightit

沒有特定來源,不會產生陰影,不能單獨使用,與其餘光源一塊兒使用,目的是弱化陰影或添加顏色。io

var ambientLight = new THREE.AmbientLight('#0c0c0c');
scene.add(ambientLight);

不須要指定光源位置ast

二、PointLight基礎

new THREE.PointLight(color顏色,  intensity強度,  distance距離,  position位置, visible光源開閉)渲染

var pointColor = '#ccffcc';
  var pointLight = new THREE.PointLight(pointColor, 2, 100);
  pointLight.position.x = -20;
  pointLight.position.y = 10;
  pointLight.position.z = 0;
  pointLight.visible = true;
  scene.add(pointLight);

*點光源不會產生投影,由於點光源向全部方向發射光,計算負擔太重。di

三、SpotLightpoi

  • castShadow 是否生成陰影
  • shadowCameraNear 投影近點
  • shadowCameraFar 投影遠點
  • shadowCameraFov 投影視場(我理解爲視角)
  • target 目標,決定光照方向
  • shadowBias 陰影偏移
  • angle 角度、光柱的寬度
  • exponent 光強衰減指數
  • onlyShadow 沒有光照只有陰影
  • shadowCameraVisible 投影方式可見
  • shadowDarkness 陰影暗度--場景渲染以後不能修改
  • shadowMapWidth 陰影映射寬度(像素)
  • shadowMapHeight 陰影映射高度(像素)
var spotLight = new THREE.SpotLight('#FFFFFF');
spotLight.position.set(-40, 60, -10);
spotLight.castShadow = true;
spotLight.target = plane;
scene.add(spotLight);

若想指向其餘地方,空間其餘點位,能夠建立一個空的THREE.Object3D()實例vi

var target = new THREE.Object3D();
target.position = new THREE.Vector3(5, 0, 0);

spotlight.target  = target;

其餘屬性有待研究

四、DirectinalLight

var directionalLight = new THREE.DirectionalLight('#FFFFFF');
directionalLight.position.set(-20, 50, -20);
directionalLight.castShadow = true;
directionalLight.shadowCameraNear = 2;
directionalLight.shadowCameraFar = 200;
directionalLight.shadowCameraTop = 50;
directionalLight.shadowCameraBottom = -50;
directionalLight.shadowCameraLeft = -50;
directionalLight.shadowCameraRight = 50;
scene.add(directionalLight);

3、特殊光源

待更

相關文章
相關標籤/搜索