|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
3 e- B" X ~& l
1 T2 W5 U1 @# d$ U& n, |官方提供的实例如下 . O8 `/ S3 R; c6 _
- N! \- D8 X" {& C/ a1。 首先在Scene里面激活 渲染 ShadowMap- m' B' @/ v5 ]* m1 ~6 L$ [' W& _
//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.PCFShadowMap7 Q+ W# \) V9 O0 C& G. L9 n0 m
% l- u2 t% ~6 E7 p/ S# i" X" q* z- V2。 创建平行光,并可以投射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 );
& M6 `$ H! Z" Z! g
) \" W! f8 ?' V1 R6 U J. v& J//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
7 s; E% P% A% u& t0 _- Y' o# B" `
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 );+ x) y8 M+ ]+ w1 r9 _9 N) P
, f0 D) x/ x( m8 ` N2 M) @0 C
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 );8 a& i% m, C% k; ^$ s
5 c3 x+ o5 _. p6 Z
# l1 k& i1 N4 t8 a( r" U: H A
* s8 G8 W* t+ P1 B. l- d* F1 @6 D$ }5 Z- H2 ]' ]+ P
效果如下!
! S- e3 H! ]4 B- X. a. Y: @9 H& U
) o. o! `, X% ~: R& Y, j! B B s4 m6 Y2 u& U: D( [
: K! E e; l% r; x4 c+ R |
|