1
0

SpotLightShadow.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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:SpotLight SpotLights] for calculating
  14. shadows.
  15. </p>
  16. <h2>Code Example</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 SpotLight and turn on shadows for the light
  23. const 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. 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>Constructor</h2>
  50. <p>
  51. The constructor creates a [param:PerspectiveCamera PerspectiveCamera] to
  52. manage the shadow's view of the world.
  53. </p>
  54. <h2>Properties</h2>
  55. <p>
  56. See the base [page:LightShadow LightShadow] class for common properties.
  57. </p>
  58. <h3>[property:Camera camera]</h3>
  59. <p>
  60. The light's view of the world. This is used to generate a depth map of the
  61. scene; objects behind other objects from the light's perspective will be
  62. in shadow.<br /><br />
  63. The default is a [page:PerspectiveCamera] with
  64. [page:PerspectiveCamera.near near] clipping plane at `0.5`. The
  65. [page:PerspectiveCamera.fov fov] will track the [page:SpotLight.angle angle]
  66. property of the owning [page:SpotLight SpotLight] via the
  67. [page:SpotLightShadow.update update] method. Similarly, the
  68. [page:PerspectiveCamera.aspect aspect] property will track the aspect of
  69. the [page:LightShadow.mapSize mapSize]. If the [page:SpotLight.distance distance]
  70. property of the light is set, the [page:PerspectiveCamera.far far]
  71. clipping plane will track that, otherwise it defaults to `500`.
  72. </p>
  73. <h3>[property:Number focus]</h3>
  74. <p>
  75. Used to focus the shadow camera. The camera's field of view is set as a
  76. percentage of the spotlight's field-of-view. Range is `[0, 1]`. Default is
  77. `1.0`.<br />
  78. </p>
  79. <h3>[property:Boolean isSpotLightShadow]</h3>
  80. <p>Read-only flag to check if a given object is of type [name].</p>
  81. <h2>Methods</h2>
  82. <p>See the base [page:LightShadow LightShadow] class for common methods.</p>
  83. <h2>Source</h2>
  84. <p>
  85. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  86. </p>
  87. </body>
  88. </html>