灯光
# AmbientLight (opens new window)
环境光
# DirectionalLight (opens new window)
平行光(直接照明)
# 属性
# position (opens new window)
光源位置,光源必须设置位置,这样光源是个点,目标物体是个点,形成一条光线(平行光)
# castShadow (opens new window)
是否产生阴影,默认false,需要阴影的话,必须打开
# shadow (opens new window)
对阴影进行设置
- radius (opens new window)
设置阴影贴图模糊度 - mapSize (opens new window)
设置阴影贴图的分辨率 - camera (opens new window)
设置阴影渲染区域。
对于平行光,需要设置 (opens new window) shadowCameraNear 、 shadowCameraFar 、 shadowCameraLeft 、shadowCameraRight 、 shadowCameraTop 以及 shadowCameraBottom 六个值,相当于正交投影照相机的六个面。同样,只有在这六个面围成的长方体内的物体才会产生阴影效果。
参考
// 灯光
// 环境光
const light = new THREE.AmbientLight(0xffffff, 0.5); // soft white light
scene.add(light);
//直线光源
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(5, 5, 5);
directionalLight.castShadow = true;
// 设置阴影贴图模糊度
directionalLight.shadow.radius = 20;
// 设置阴影贴图的分辨率
directionalLight.shadow.mapSize.set(4096, 4096);
// console.log(directionalLight.shadow);
// 设置平行光投射相机的属性
directionalLight.shadow.camera.near = 8;
directionalLight.shadow.camera.far = 11;
directionalLight.shadow.camera.top = 1;
directionalLight.shadow.camera.bottom = -1;
directionalLight.shadow.camera.left = -1;
directionalLight.shadow.camera.right = 1;
scene.add(directionalLight);
const cameraHelper = new THREE.CameraHelper(directionalLight.shadow.camera)
scene.add(cameraHelper)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# SpotLight (opens new window)
聚光灯
# 属性
# angle (opens new window)
设置聚光灯弧度
# castShadow (opens new window)
灯光是否开启阴影
# decay (opens new window)
沿光照距离衰减量
# penumbra (opens new window)
聚光锥半影衰减比
# intensity (opens new window)
光照强度(该参数在构造函数中)
# shadow (opens new window)
对光照阴影进行一些设置
const spotLight = new THREE.SpotLight(0xffffff, 1);
// 设置阴影贴图模糊度
spotLight.shadow.radius = 20;
// 设置阴影贴图的分辨率
spotLight.shadow.mapSize.set(512, 512);
// 设置投射相机的属性(参照透视相机构造器)
spotLight.shadow.camera.near = 500;
spotLight.shadow.camera.far = 4000;
spotLight.shadow.camera.fov = 30;
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# target (opens new window)
光照对象
# distance (opens new window)
光照距离(在构造函数中)
# PointLight (opens new window)
点光源(萤火虫)
与其他灯光属性类似
编辑 (opens new window)
上次更新: 2022/09/23