|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; e- {5 U* ?) y+ c1 u
" v3 v) X# e+ a% V0 t; V官方提供的实例如下 / J& P: s/ z7 [% R1 Q9 I
?# i- t7 q4 f$ Y
1。 首先在Scene里面激活 渲染 ShadowMap- T8 q O9 }( {0 L9 b; b- t
//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
* X, t# l$ A5 F+ e+ K5 L V L+ H) n. g* i$ ]/ o P
2。 创建平行光,并可以投射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 );4 [+ ?2 @' u. {: ?- M; i* d: c$ [
: p+ a" r6 V) X1 C' N
//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 k: E5 r q( Z, K" ~, r
4 `/ C) G0 W# N) G3. 创建接受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 );
+ ^ o) k2 c* n( }+ d
; ~! ?4 l% d' B' t4 U4. 创建获取投影的平面 //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 );& e) x" a2 N: W" K
3 N) ]5 {9 G' Y$ n% A& z; J2 b
X: E. v% B! h9 ?$ P9 V5 ~) J2 c( R# m! Y1 i' R& a y7 l. A
; j$ z' w7 E2 h4 c( t! t效果如下!
* ]; g6 m0 X- d) c, V* d
6 x1 K" v( a c1 i8 }$ C2 j+ T) [" G
, |* s0 j" O5 n" J# `
/ [0 j% U1 j+ T$ s" [ |
|