three.js源码翻译-DirectionalLightShadow.js

three.js源码翻译-DirectionalLightShadow.js

说明

DirectionalLightShadow类是方向光的阴影,DirectionalLightShadow的创建可以在DirectionalLight的源码翻译部分看到,总体来说就是创建了一个正交摄像机传到LightShadow中来,但是一般默认值创建出的阴影很模糊,各种不行,需要具体的设置各个参数来创建出一个清晰的阴影。

源码位置及翻译

源码位置

src/light/DirectionalLightShadow.js

源码翻译

/**
 * 方向光的阴影,基本上就是传了一个正交摄像机
 *
 */
function DirectionalLightShadow( ) {

	LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );

}

DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {

	constructor: DirectionalLightShadow

} );

示例及案例

创建

let directionLight = new THREE.DirectionalLight(0xffffff) 
directionLight.position.set(0, 100, 50);
directionLight.castShadow = true;
directionLight.shadow.camera.top = 64;
directionLight.shadow.camera.bottom = -64;
directionLight.shadow.camera.left = 64;
directionLight.shadow.camera.right = -64;
scene.add(directionLight);

注意的点

  • 主要的点就是创建出的默认阴影效果不行,需要具体的传值来设置阴影。
  • 需要将光源的.castShadow设置为true,同时需要将接受阴影的mesh的.receiveShadow设置为true,然后还有渲染器中的.shadowMap.enabled也要设置为true。表格如下
操作物体/属性光源(eg:THREE.DirectionalLight)接受阴影的物体(THREE.Mesh)渲染器(THREE.WebGLRenderer)
.castShadow✅ Yes
.receiveShadow✅ Yes
.shadowMap.enabled✅ Yes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值