|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, @0 R1 ^4 b/ W& B! l
/ o) c- L2 h3 {" ]6 ~
官方提供的实例如下 0 @, t$ z- X1 W& N
* q; C6 n$ U/ w2 b: d* f+ o2 D0 T
1。 首先在Scene里面激活 渲染 ShadowMap* B4 G1 o+ c+ e. M9 p2 h9 p2 w- `
//Create a WebGLRenderer and turn on shadows in the renderervar renderer = new THREE.WebGLRenderer();renderer.shadowMap.enabled = true;renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap6 x2 l) z+ n$ C) U1 m5 R
+ h; @6 S1 E1 Q: R/ \1 P2。 创建平行光,并可以投射Shadow//Create a DirectionalLight and turn on shadows for the lightvar light = new THREE.DirectionalLight( 0xffffff, 1, 100 );light.position.set( 0, 1, 0 ); //default; light shining from toplight.castShadow = true; // default falsescene.add( light );9 _1 c0 q) u7 ]3 [% j
5 ]4 K; q; ]% O4 g+ r
//Set up shadow properties for the lightlight.shadow.mapSize.width = 512; // defaultlight.shadow.mapSize.height = 512; // defaultlight.shadow.camera.near = 0.5; // defaultlight.shadow.camera.far = 500; // default$ z g; g/ e/ m
4 G8 g- c2 L* k' T" N, |3. 创建接受shadow的物体 //Create a sphere that cast shadows (but does not receive them)var sphereGeometry = new THREE.SphereBufferGeometry( 5, 32, 32 );var sphereMaterial = new THREE.MeshStandardMaterial( { color: 0xff0000 } );var sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );sphere.castShadow = true; //default is falsesphere.receiveShadow = false; //defaultscene.add( sphere );7 z# i- M7 `4 ^; ]* A
8 x& E; I/ f- U9 l, q0 S3 ~
4. 创建获取投影的平面 //Create a plane that receives shadows (but does not cast them)var planeGeometry = new THREE.PlaneBufferGeometry( 20, 20, 32, 32 );var planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )var plane = new THREE.Mesh( planeGeometry, planeMaterial );plane.receiveShadow = true;scene.add( plane );//Create a helper for the shadow camera (optional)var helper = new THREE.CameraHelper( light.shadow.camera );scene.add( helper );- T- o- t" E6 o' d1 e
/ T$ R9 ]2 S# V2 A+ s$ W Q& G, ~- e0 @' T' G9 _: \, z+ z
, o2 ?* z/ ]3 W0 j! x$ j, H7 L$ N3 z P' G
效果如下!0 b# q/ \. M9 q( T: E0 b
) z# X G( ?# @* e1 V0 ?" \
) e4 q# r& G! P
6 R8 G) d% } y) J: q k! e |
|