|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
' L- J2 X, n+ `. V4 v
+ K: y! s( @7 h. J& }) c4 [ }
官方提供的实例如下 + ~1 O- G0 R4 u' ?
1 h( W, J# U6 n) ? D
1。 首先在Scene里面激活 渲染 ShadowMap
) t ^' s& g' s) ` e: F//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.PCFShadowMap
1 {) G% m0 u2 F [+ {6 H
, @& F2 y3 ]! k1 K2。 创建平行光,并可以投射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 );! F+ U8 A% c, q# i% Q+ ?
6 Q9 ]( T1 b" E/ a2 y8 R' A8 k
//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
8 ?+ t$ W8 j# H3 I/ t
) H- U" W1 u' p6 }8 G2 r3. 创建接受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 );
# N$ J- k9 T' D% |" T3 a; R2 F+ | U* U
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 );
/ e2 ?' f4 w! O* U4 {" S5 r0 c2 Y7 s. l) V" a6 h9 J
D0 e) e3 g9 Y
9 b) ?# j" L6 \' H0 X
' h. p& }$ B {5 f, I" b效果如下!+ C" O( T' c# s0 n7 c. y- I' W: J1 X) x
! A4 \# B+ x, |
" \9 K. y- c+ E: ~+ k0 M
/ h- H, ^* D* G; \% D |
|