学习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、特殊光源

待更

相关文章
相关标签/搜索