|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) y& l) }# n% _/ E& y: \. q
# {+ C: |( `6 j0 R+ @官方提供的实例如下 $ w9 I' J% Y b; b, E8 r- t
) u' V" H5 m1 d. F0 p" _ k* B
1。 首先在Scene里面激活 渲染 ShadowMap1 x$ f/ h, L6 V" q, t& v8 z
//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. O# B2 ^1 I) t% C
- X4 s( L* N, b( Q- H2。 创建平行光,并可以投射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 );/ J) L2 i1 \7 k/ j/ l. g& f
! {) q+ [1 O h' W0 y0 X: Y
//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
6 D9 r. k% i) a y
) @; m S- |# {% g% a. Y- Y3. 创建接受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 );9 d; O! t# X6 }3 I* S: O
0 G6 x& v3 P( |" r% \1 \3 ]
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 );
" z- k3 C6 c J* S8 y( ~+ w9 Q5 ~0 G% E; t9 \ D) O
, I$ i! q" n. c) j9 H
) j2 G9 v/ I' U6 ^
; [2 @3 _2 m- i* A3 R" x
效果如下!
; g+ r" x) b6 l- t; x: p# {9 b, v3 R! \( w7 q3 _
9 I6 x7 X# e' [+ x7 |+ `
5 W0 f% s0 ]. l+ {4 `' j |
|