DirectionalLightShadow.html 3.4 KB

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