|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( d5 J6 n, W0 V; n( e4 \7 Z0 C- p; H+ F
官方提供的实例如下
& o0 s0 ?4 r5 y( q& C- {1 Y. Q2 }, s# Z# y t9 b' @
1。 首先在Scene里面激活 渲染 ShadowMap. n$ K9 j; P- I5 N- c
//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
) e% m5 R$ K. H* i7 M* ?0 A" b/ s2 V o( y. j9 S
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 );& Q3 I" Z. X+ [- w
- P, p I4 {: @# ~' a
//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; // default6 r% o! V9 `+ }( S
7 y4 @$ Q0 W/ I2 a* q3. 创建接受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 );7 }3 v3 O4 J) ] I& |
% w V8 U/ I( ~5 ?
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 );5 B# W# S9 \; B% n( V8 J
~+ E8 Y, e! [
- x+ o6 u7 d3 m7 O+ j4 L3 B
9 `$ S0 \& Q$ U: k7 g1 h8 }
6 C( f5 [5 l( d1 ?+ n! C效果如下!
$ o4 }. O/ J1 X& @/ W, u( P5 Z7 y! H" [' ~
( g& i7 e6 \* _
; {; e: H, \) u, B, y% I |
|