PointLightShadow.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, 0 );
  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. <h2>Methods</h2>
  58. <p>
  59. See the base [page:LightShadow LightShadow] class for common methods.
  60. </p>
  61. <h3>[method:null updateMatrices]( [param:Light light], [param:number viewportIndex])</h3>
  62. <p>
  63. Update the matrices for the camera and shadow, used internally by the renderer.<br /><br />
  64. light -- the light for which the shadow is being rendered.<br />
  65. viewportIndex -- calculates the matrix for this viewport
  66. </p>
  67. <h2>Source</h2>
  68. <p>
  69. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  70. </p>
  71. </body>
  72. </html>