1
0

DirectionalLightShadow.html 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:LightShadow] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. 这是用于在[page:DirectionalLight DirectionalLights]内部计算阴影<br /><br />
  14. 与其他阴影类不同,它是使用OrthographicCamera来计算阴影,而不是PerspectiveCamera。这是因为来自DirectionalLight的光线是平行的。
  15. </p>
  16. <h2>代码示例</h2>
  17. <code>
  18. //Create a WebGLRenderer and turn on shadows in the renderer
  19. const renderer = new THREE.WebGLRenderer();
  20. renderer.shadowMap.enabled = true;
  21. renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
  22. //Create a DirectionalLight and turn on shadows for the light
  23. const light = new THREE.DirectionalLight( 0xffffff, 1 );
  24. light.position.set( 0, 1, 0 ); //default; light shining from top
  25. light.castShadow = true; // default false
  26. scene.add( light );
  27. //Set up shadow properties for the light
  28. light.shadow.mapSize.width = 512; // default
  29. light.shadow.mapSize.height = 512; // default
  30. light.shadow.camera.near = 0.5; // default
  31. light.shadow.camera.far = 500; // default
  32. //Create a sphere that cast shadows (but does not receive them)
  33. const sphereGeometry = new THREE.SphereGeometry( 5, 32, 32 );
  34. const sphereMaterial = new THREE.MeshStandardMaterial( { color: 0xff0000 } );
  35. const sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
  36. sphere.castShadow = true; //default is false
  37. sphere.receiveShadow = false; //default
  38. scene.add( sphere );
  39. //Create a plane that receives shadows (but does not cast them)
  40. const planeGeometry = new THREE.PlaneGeometry( 20, 20, 32, 32 );
  41. const planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )
  42. const plane = new THREE.Mesh( planeGeometry, planeMaterial );
  43. plane.receiveShadow = true;
  44. scene.add( plane );
  45. //Create a helper for the shadow camera (optional)
  46. const helper = new THREE.CameraHelper( light.shadow.camera );
  47. scene.add( helper );
  48. </code>
  49. <h2>构造函数</h2>
  50. <h3>[name]( )</h3>
  51. <p>
  52. 创建一个新的[name],不能直接调用-它是在[page:DirectionalLight DirectionalLights]内部调用使用
  53. </p>
  54. <h2>属性</h2>
  55. <p>
  56. 参阅[page:LightShadow LightShadow]类来了解常用的基本属性
  57. </p>
  58. <h3>[property:Camera camera]</h3>
  59. <p>
  60. 在光的世界里。这用于生成场景的深度图;从光的角度来看,其他物体背后的物体将处于阴影中。<br /><br />
  61. </p>
  62. <h3>[property:Boolean isDirectionalLightShadow]</h3>
  63. <p>
  64. Read-only flag to check if a given object is of type [name].
  65. </p>
  66. <h2>方法</h2>
  67. <p>
  68. 有关常用方法,请参阅基础[page:LightShadow LightShadow]类。
  69. </p>
  70. <h2>源码</h2>
  71. <p>
  72. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  73. </p>
  74. </body>
  75. </html>