|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# z8 p0 V4 i" g6 [! z# g
5 b/ X5 E6 V+ \& V官方提供的实例如下 1 M' L6 q' X+ g; |4 d( }
! ?) E2 b: ]" n0 S w1。 首先在Scene里面激活 渲染 ShadowMap+ X2 E- Y: h9 f+ z
//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
$ n, b1 H, s* R/ O% f7 K
a- i& s0 h+ k' J0 j2。 创建平行光,并可以投射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 );" u/ W* t8 O% o
* ~5 R5 W4 b$ {. l$ A& k
//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
% u- O2 J" I+ G. R
& S! J% s2 ]& s$ U% x3. 创建接受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 );
5 r; \3 i0 Q# X9 `
$ n! p; Z" x. r+ \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 );. H2 }0 `) U' u# m7 }3 M& G
5 p2 {1 r8 }% f( m! B0 l/ r
: X) `3 J1 F w7 d5 z" g) w! }
4 C# @. ^( {" \3 W# W
; H6 J' V: u- K效果如下!
! Q2 t; r* g7 {9 M4 i$ k+ [/ N$ D( x8 b' f% _0 F" }, T, A
( u F5 R2 y0 j4 h3 K T
( j7 b9 I) J4 T$ U# y1 _$ C |
|