SpotLightShadow.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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>Example</h2>
  17. <p>
  18. <code>
  19. //Create a WebGLRenderer and turn on shadows in the renderer
  20. var renderer = new THREE.WebGLRenderer();
  21. renderer.shadowMap.enabled = true;
  22. renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
  23. //Create a SpotLight and turn on shadows for the light
  24. var light = new THREE.SpotLight( 0xffffff );
  25. light.castShadow = true; // default false
  26. scene.add( light );
  27. //Set up shadow properties for the light
  28. light.shadow.mapSize.width = 512; // default
  29. light.shadow.mapSize.height = 512; // default
  30. light.shadow.camera.near = 0.5; // default
  31. light.shadow.camera.far = 500 // 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. </p>
  50. <h2>Constructor</h2>
  51. The constructor creates a [param:PerspectiveCamera PerspectiveCamera] to manage the shadow's view of the world.
  52. <h2>Properties</h2>
  53. See the base [page:LightShadow LightShadow] class for common properties.
  54. <h3>[property:Camera camera]</h3>
  55. <p>
  56. The light's view of the world. This is used to generate a depth map of the scene; objects behind
  57. other objects from the light's perspective will be in shadow.<br /><br />
  58. The default is a [page:PerspectiveCamera] with [page:PerspectiveCamera.near near] clipping plane at 0.5.
  59. The [page:PerspectiveCamera.fov fov] will track the [page:SpotLight.angle angle] property of the owning
  60. [page:SpotLight SpotLight] via the [page:SpotLightShadow.update update] method. Similarly, the
  61. [page:PerspectiveCamera.aspect aspect] property will track the aspect of the
  62. [page:LightShadow.mapSize mapSize]. If the [page:SpotLight.distance distance] property of the light is
  63. set, the [page:PerspectiveCamera.far far] clipping plane will track that, otherwise it defaults to 500.
  64. </p>
  65. <h3>[property:Boolean isSpotLightShadow]</h3>
  66. <p>
  67. Used to check whether this or derived classes are spot light shadows. Default is *true*.<br /><br />
  68. You should not change this, as it used internally for optimisation.
  69. </p>
  70. <h2>Methods</h2>
  71. See the base [page:LightShadow LightShadow] class for common methods.
  72. <h3>[method:SpotLightShadow update]( [param:SpotLight light] )</h3>
  73. <p>
  74. Updates the internal perspective [page:.camera camera] based on the passed in [page:SpotLight light].
  75. </p>
  76. <h2>Source</h2>
  77. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  78. </body>
  79. </html>