|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: c2 h; j8 ]9 t0 v7 ~& a: r2 Q' m3 R. d7 I4 e0 u* ^. C
官方提供的实例如下
/ H% T: ^( n* }: h
3 R* X: y3 S6 z1。 首先在Scene里面激活 渲染 ShadowMap, j4 Q" _1 {! Z* \' Y/ S* g0 I! k
//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.PCFShadowMap1 o3 \" q& o( k# g: z! p; X
' A1 ]5 ?" \ R. s! Z0 v0 B5 |4 o2。 创建平行光,并可以投射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 );
! I$ f% W5 N7 I5 T
% x& X2 g) u3 R1 q; C//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 \9 B- c& `7 ], M
: Z$ \8 S3 u1 b3. 创建接受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 );
! T; R6 p, d! [$ n& o
+ |, B/ ~( j0 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 );
' o" Y/ l7 f0 c9 a# ~
. o' b4 i- G6 B$ X
+ d8 F: I; A/ t! _% G: v$ e! n: t
& \! [7 H5 A+ I2 I效果如下!2 j' y9 I: p9 m9 T* g
0 g b% c" [1 ]% ~2 L" {- A4 q4 y1 ]
) b9 Y7 d0 H: g& K* z
/ Z" j0 g' C7 J9 E6 E4 Z& ]% i8 z: h: p |
|