|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
8 a6 Z* |0 a! H' x5 M% z9 V( t: s5 P- A# K1 a! M. j" U y+ b
官方提供的实例如下 ) W$ y: [. @ N2 x
' J0 ~) L& q" q- x$ b
1。 首先在Scene里面激活 渲染 ShadowMap8 }7 s" j% I1 b- f* t7 D2 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) B" {, S+ f& ^" I- i5 [
_* ~- p7 t% Z2 |1 c
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 ); v8 y4 z$ c5 V9 P
o7 B q9 c( a5 T9 ^
//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: C( h6 u' `: c% ?* ^" A
8 @% J5 g& o, [7 p, o# N- v
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 );
* N7 V7 h1 f& P# Q
+ t, U7 A5 v9 ? ~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 );" h- |' g+ I; A3 k" W
6 d/ e9 k' m& A- P7 G% t5 N
6 F0 M$ p# q+ a. J7 ]# T# f5 f: O v4 L# _
5 a% e/ h9 d4 v0 N
效果如下!
2 j4 ^# d0 d! Z" @& A! Z |- y
( m3 b* s8 e& {7 `( Y2 w! W _+ x! x4 d# c( @" O( _( h' _1 x
; t: y- ]0 T5 H9 e |
|