|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ z; \( V R3 q- A# x: [+ y5 A" B! p
/ Z# n. d3 n+ B" u8 K
官方提供的实例如下 + l# S# O# @( P0 r+ d
6 l7 Y* }9 e6 n7 p/ b
1。 首先在Scene里面激活 渲染 ShadowMap
, c+ R9 D' D8 l, k1 U) H//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
, v7 m' q( D- c3 k5 s. l; V o' _/ D
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 );
Q$ l5 |! B" ?4 E# h3 x. Z" n E Y3 X+ ]' d" K/ 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; // default9 D& p& I, R; L) x5 r
. y3 S( r' s! @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 );4 G' _) q9 ? J+ R- c" E: z
8 u) S% Q# |6 H4. 创建获取投影的平面 //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 );% }( m4 e% o8 F" m$ d" F
$ K- F# e$ m# e- A& W8 R
6 r0 S/ P6 @2 h/ m& q8 a8 A! W( l: A& {
2 e0 ~1 a/ A5 j( b- i0 m2 B f
效果如下!
; [0 k: G+ a. X1 u# r1 ^+ }9 g- c, ~3 I
& z9 }; i8 G& J7 c% y
5 |* b& m! ^. f# v/ e |
|