|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
9 e t' q6 J2 ^# O# }- o0 A
8 n0 I3 o! ]! K' M& `官方提供的实例如下
S( E# K8 M" i- _- }2 u3 V8 I1 i) W; K& K' F
1。 首先在Scene里面激活 渲染 ShadowMap9 r6 T0 [1 m: x7 u/ I2 v
//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.PCFShadowMap9 B" n9 h% W+ a! p
5 G2 ~7 c* }5 g2。 创建平行光,并可以投射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 );0 q* `4 u& l7 ^& A8 a
& S1 i7 ]2 u2 z! F8 ^5 X//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
) ?. h! {& P/ o5 N) I' f/ u3 P8 k3 g8 N" l, L) j$ w% E
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 );
2 |! G5 S7 X4 s* x5 C8 U. d* \# f; T5 e
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 );
' |" o" _' x3 C* `# e7 R. a) e" ]1 ^3 R
6 Q6 \* A8 ^- C b) |7 E% ^3 t" M* m) \" P- u- W5 \ i; l
' ^( \. v6 r* H n* N
效果如下!
% [# [( \2 \8 x( L" M" P% E7 v
- v i/ o* V3 ^/ b; C" S- R
" {% Q. Q- W N0 n# W5 V+ E- f
5 K# H" R* H; n ^/ [ |
|