SpotLightShadow.html 3.2 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. <div class="desc">
  14. This is used internally by [page:SpotLight SpotLights] for calculating shadows.
  15. </div>
  16. <h2>Example</h2>
  17. <div>
  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. </div>
  50. <h2>Constructor</h2>
  51. The constructor creates a [page: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. <div>
  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.fov fov] of 90,
  59. [page:PerspectiveCamera.aspect aspect] of 1, [page:PerspectiveCamera.near near]
  60. clipping plane at 0.5 and [page:PerspectiveCamera.far far] clipping plane at 500.
  61. </div>
  62. <h3>[property:Boolean isSpotLightShadow]</h3>
  63. <div>
  64. Used to check whether this or derived classes are spot light shadows. Default is *true*.<br /><br />
  65. You should not change this, as it used internally for optimisation.
  66. </div>
  67. <h2>Methods</h2>
  68. See the base [page:LightShadow LightShadow] class for common methods.
  69. <h3>[method:SpotLightShadow update]( [page:SpotLight light] )</h3>
  70. <div>
  71. Updates the internal perspective [page:.camera camera] based on the passed in [page:SpotLight light].
  72. </div>
  73. <h2>Source</h2>
  74. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  75. </body>
  76. </html>