PointLightShadow.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. <h1>[name]</h1>
  11. <p class="desc">
  12. This is used internally by [page:PointLight PointLights] for calculating shadows.
  13. </p>
  14. <h2>Code Example</h2>
  15. <code>
  16. //Create a WebGLRenderer and turn on shadows in the renderer
  17. const renderer = new THREE.WebGLRenderer();
  18. renderer.shadowMap.enabled = true;
  19. renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
  20. //Create a PointLight and turn on shadows for the light
  21. const light = new THREE.PointLight( 0xffffff, 1, 100 );
  22. light.position.set( 0, 10, 4 );
  23. light.castShadow = true; // default false
  24. scene.add( light );
  25. //Set up shadow properties for the light
  26. light.shadow.mapSize.width = 512; // default
  27. light.shadow.mapSize.height = 512; // default
  28. light.shadow.camera.near = 0.5; // default
  29. light.shadow.camera.far = 500; // default
  30. //Create a sphere that cast shadows (but does not receive them)
  31. const sphereGeometry = new THREE.SphereGeometry( 5, 32, 32 );
  32. const sphereMaterial = new THREE.MeshStandardMaterial( { color: 0xff0000 } );
  33. const sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
  34. sphere.castShadow = true; //default is false
  35. sphere.receiveShadow = false; //default
  36. scene.add( sphere );
  37. //Create a plane that receives shadows (but does not cast them)
  38. const planeGeometry = new THREE.PlaneGeometry( 20, 20, 32, 32 );
  39. const planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )
  40. const plane = new THREE.Mesh( planeGeometry, planeMaterial );
  41. plane.receiveShadow = true;
  42. scene.add( plane );
  43. //Create a helper for the shadow camera (optional)
  44. const helper = new THREE.CameraHelper( light.shadow.camera );
  45. scene.add( helper );
  46. </code>
  47. <h2>Constructor</h2>
  48. <h3>[name]( )</h3>
  49. <p>
  50. Creates a new [name]. This is not intended to be called directly - it is called
  51. internally by [page:PointLight].
  52. </p>
  53. <h2>Properties</h2>
  54. <p>
  55. See the base [page:LightShadow LightShadow] class for common properties.
  56. </p>
  57. <h3>[property:Boolean isPointLightShadow]</h3>
  58. <p>
  59. Read-only flag to check if a given object is of type [name].
  60. </p>
  61. <h2>Methods</h2>
  62. <p>
  63. See the base [page:LightShadow LightShadow] class for common methods.
  64. </p>
  65. <h3>[method:undefined updateMatrices]( [param:Light light], [param:number viewportIndex])</h3>
  66. <p>
  67. Update the matrices for the camera and shadow, used internally by the renderer.<br /><br />
  68. light -- the light for which the shadow is being rendered.<br />
  69. viewportIndex -- calculates the matrix for this viewport
  70. </p>
  71. <h2>Source</h2>
  72. <p>
  73. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  74. </p>
  75. </body>
  76. </html>