|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
0 X4 K* |* S* e7 p; w% a6 J8 u0 S
% e" W- Y- s* y官方提供的实例如下
7 ?' j# k7 n) N5 r
- ]8 d) ]+ O0 k0 {8 z$ q1。 首先在Scene里面激活 渲染 ShadowMap( m0 b d" Y2 o) A# J' S& B& ]2 L
//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: m2 N- J& x! O0 |/ M8 b
) N" ` C0 k! E4 M4 T# E4 l
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 );1 } w7 A0 B" k
0 r7 ?' t; c4 d4 l* W
//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
+ n- X$ F: ~" t
7 @7 |3 M m4 _, w, ~: F3. 创建接受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 );* k7 ]% u7 B# K; O' b9 G6 _1 v k
$ N& f* U ]5 ^" a2 Z" v6 T4. 创建获取投影的平面 //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, l/ b5 [6 A' j$ J# w) @7 [8 y
7 j/ R) Z, n4 [1 x' v# e9 Q, W/ F& z1 e' K3 a5 h% ?
P9 H7 }) k8 o( a( o) {) C. V g e8 H& i5 A+ L# F
效果如下!
; H, u! D/ _/ V6 U
: b( _( L' J- }8 ]) B
% e5 q8 P1 z2 e
+ F% M% C- B1 |3 ]: v3 E; \6 C
|
|