1
0

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. [page:LightShadow] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. This is used internally by [page:PointLight PointLights] 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 PointLight and turn on shadows for the light
  23. const light = new THREE.PointLight( 0xffffff, 1, 100 );
  24. light.position.set( 0, 10, 4 );
  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. 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. <h3>[name]( )</h3>
  51. <p>
  52. Creates a new [name]. This is not intended to be called directly - it is
  53. called internally by [page:PointLight].
  54. </p>
  55. <h2>Properties</h2>
  56. <p>
  57. See the base [page:LightShadow LightShadow] class for common properties.
  58. </p>
  59. <h3>[property:Boolean isPointLightShadow]</h3>
  60. <p>Read-only flag to check if a given object is of type [name].</p>
  61. <h2>Methods</h2>
  62. <p>See the base [page:LightShadow LightShadow] class for common methods.</p>
  63. <h3>
  64. [method:undefined updateMatrices]( [param:Light light], [param:number viewportIndex])
  65. </h3>
  66. <p>
  67. Update the matrices for the camera and shadow, used internally by the
  68. renderer.<br /><br />
  69. light -- the light for which the shadow is being rendered.<br />
  70. viewportIndex -- calculates the matrix for this viewport
  71. </p>
  72. <h2>Source</h2>
  73. <p>
  74. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  75. </p>
  76. </body>
  77. </html>