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