DirectionalLightShadow.html 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html>
  2. <html lang="en">
  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. This is used internally by [page:DirectionalLight DirectionalLights] for calculating shadows.<br /><br />
  14. Unlike the other shadow classes, this uses an [page:OrthographicCamera] to calculate the shadows,
  15. rather than a [page:PerspectiveCamera]. This is because light rays from a [page:DirectionalLight]
  16. are parallel.
  17. </p>
  18. <h2>Code Example</h2>
  19. <code>
  20. //Create a WebGLRenderer and turn on shadows in the renderer
  21. const renderer = new THREE.WebGLRenderer();
  22. renderer.shadowMap.enabled = true;
  23. renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
  24. //Create a DirectionalLight and turn on shadows for the light
  25. const light = new THREE.DirectionalLight( 0xffffff, 1, 100 );
  26. light.position.set( 0, 1, 0 ); //default; light shining from top
  27. light.castShadow = true; // default false
  28. scene.add( light );
  29. //Set up shadow properties for the light
  30. light.shadow.mapSize.width = 512; // default
  31. light.shadow.mapSize.height = 512; // default
  32. light.shadow.camera.near = 0.5; // default
  33. light.shadow.camera.far = 500; // default
  34. //Create a sphere that cast shadows (but does not receive them)
  35. const sphereGeometry = new THREE.SphereGeometry( 5, 32, 32 );
  36. const sphereMaterial = new THREE.MeshStandardMaterial( { color: 0xff0000 } );
  37. const sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
  38. sphere.castShadow = true; //default is false
  39. sphere.receiveShadow = false; //default
  40. scene.add( sphere );
  41. //Create a plane that receives shadows (but does not cast them)
  42. const planeGeometry = new THREE.PlaneGeometry( 20, 20, 32, 32 );
  43. const planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )
  44. const plane = new THREE.Mesh( planeGeometry, planeMaterial );
  45. plane.receiveShadow = true;
  46. scene.add( plane );
  47. //Create a helper for the shadow camera (optional)
  48. const helper = new THREE.CameraHelper( light.shadow.camera );
  49. scene.add( helper );
  50. </code>
  51. <h2>Constructor</h2>
  52. <h3>[name]( )</h3>
  53. <p>
  54. Creates a new [name]. This is not intended to be called directly - it is called
  55. internally by [page:DirectionalLight].
  56. </p>
  57. <h2>Properties</h2>
  58. <p>
  59. See the base [page:LightShadow LightShadow] class for common properties.
  60. </p>
  61. <h3>[property:Camera camera]</h3>
  62. <p>
  63. The light's view of the world. This is used to generate a depth map of the scene; objects behind
  64. other objects from the light's perspective will be in shadow.<br /><br />
  65. The default is an [page:OrthographicCamera] with [page:OrthographicCamera.left left] and
  66. [page:OrthographicCamera.bottom bottom] set to -5, [page:OrthographicCamera.right right]
  67. and [page:OrthographicCamera.top top] set to 5, the [page:OrthographicCamera.near near]
  68. clipping plane at 0.5 and the [page:OrthographicCamera.far far] clipping plane at 500.
  69. </p>
  70. <h2>Methods</h2>
  71. <p>
  72. See the base [page:LightShadow LightShadow] class for common methods.
  73. </p>
  74. <h2>Source</h2>
  75. <p>
  76. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  77. </p>
  78. </body>
  79. </html>