SpotLightShadow.html 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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:SpotLight SpotLights] for calculating shadows.
  15. </p>
  16. <h2>Code Example</h2>
  17. <code>
  18. //Create a WebGLRenderer and turn on shadows in the renderer
  19. var renderer = new THREE.WebGLRenderer();
  20. renderer.shadowMap.enabled = true;
  21. renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
  22. //Create a SpotLight and turn on shadows for the light
  23. var light = new THREE.SpotLight( 0xffffff );
  24. light.castShadow = true; // default false
  25. scene.add( light );
  26. //Set up shadow properties for the light
  27. light.shadow.mapSize.width = 512; // default
  28. light.shadow.mapSize.height = 512; // default
  29. light.shadow.camera.near = 0.5; // default
  30. light.shadow.camera.far = 500 // default
  31. light.shadow.focus = 1; // default
  32. //Create a sphere that cast shadows (but does not receive them)
  33. var sphereGeometry = new THREE.SphereBufferGeometry( 5, 32, 32 );
  34. var sphereMaterial = new THREE.MeshStandardMaterial( { color: 0xff0000 } );
  35. var 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. var planeGeometry = new THREE.PlaneBufferGeometry( 20, 20, 32, 32 );
  41. var planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )
  42. var plane = new THREE.Mesh( planeGeometry, planeMaterial );
  43. plane.receiveShadow = true;
  44. scene.add( plane );
  45. //Create a helper for the shadow camera (optional)
  46. var helper = new THREE.CameraHelper( light.shadow.camera );
  47. scene.add( helper );
  48. </code>
  49. <h2>Constructor</h2>
  50. <p>The constructor creates a [param:PerspectiveCamera PerspectiveCamera] to manage the shadow's view of the world.</p>
  51. <h2>Properties</h2>
  52. <p>See the base [page:LightShadow LightShadow] class for common properties.</p>
  53. <h3>[property:Camera camera]</h3>
  54. <p>
  55. The light's view of the world. This is used to generate a depth map of the scene; objects behind
  56. other objects from the light's perspective will be in shadow.<br /><br />
  57. The default is a [page:PerspectiveCamera] with [page:PerspectiveCamera.near near] clipping plane at 0.5.
  58. The [page:PerspectiveCamera.fov fov] will track the [page:SpotLight.angle angle] property of the owning
  59. [page:SpotLight SpotLight] via the [page:SpotLightShadow.update update] method. Similarly, the
  60. [page:PerspectiveCamera.aspect aspect] property will track the aspect of the
  61. [page:LightShadow.mapSize mapSize]. If the [page:SpotLight.distance distance] property of the light is
  62. set, the [page:PerspectiveCamera.far far] clipping plane will track that, otherwise it defaults to 500.
  63. </p>
  64. <h3>[property:Number focus]</h3>
  65. <p>
  66. Used to focus the shadow camera. The camera's field of view is set as a percentage of the spotlight's field-of-view. Range is [0, 1]. Default is 1.0.<br/>
  67. </p>
  68. <h2>Methods</h2>
  69. <p>See the base [page:LightShadow LightShadow] class for common methods.</p>
  70. <h2>Source</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>