LightShadow.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. <h1>[name]</h1>
  12. <p class="desc">
  13. This is used internally by [page:PointLight PointLights] for calculating shadows, and also serves as
  14. a base class for the other shadow classes.
  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 PointLight and turn on shadows for the light
  24. var light = new THREE.PointLight( 0xffffff, 1, 100 );
  25. light.position.set( 0, 10, 0 );
  26. light.castShadow = true; // default false
  27. scene.add( light );
  28. //Set up shadow properties for the light
  29. light.shadow.mapSize.width = 512; // default
  30. light.shadow.mapSize.height = 512; // default
  31. light.shadow.camera.near = 0.5; // default
  32. light.shadow.camera.far = 500 // default
  33. //Create a sphere that cast shadows (but does not receive them)
  34. var sphereGeometry = new THREE.SphereBufferGeometry( 5, 32, 32 );
  35. var sphereMaterial = new THREE.MeshStandardMaterial( { color: 0xff0000 } );
  36. var sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
  37. sphere.castShadow = true; //default is false
  38. sphere.receiveShadow = false; //default
  39. scene.add( sphere );
  40. //Create a plane that receives shadows (but does not cast them)
  41. var planeGeometry = new THREE.PlaneBufferGeometry( 20, 20, 32, 32 );
  42. var planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )
  43. var plane = new THREE.Mesh( planeGeometry, planeMaterial );
  44. plane.receiveShadow = true;
  45. scene.add( plane );
  46. //Create a helper for the shadow camera (optional)
  47. var helper = new THREE.CameraHelper( light.shadow.camera );
  48. scene.add( helper );
  49. </code>
  50. </p>
  51. <h2>Constructor</h2>
  52. <h3>[name]( [param:Camera camera] )</h3>
  53. <p>
  54. [page:Camera camera] - the light's view of the world.<br /><br />
  55. Create a new [name]. This is not intended to be called directly - it is called
  56. internally by [page:PointLight] or used as a base class by other light shadows.
  57. </p>
  58. <h2>Properties</h2>
  59. <h3>[property:Camera camera]</h3>
  60. <p>
  61. The light's view of the world. This is used to generate a depth map of the scene; objects behind
  62. other objects from the light's perspective will be in shadow.
  63. </p>
  64. <h3>[property:Float bias]</h3>
  65. <p>
  66. Shadow map bias, how much to add or subtract from the normalized depth when deciding whether a surface is in shadow.<br />
  67. The default is 0. Very tiny adjustments here (in the order of 0.0001) may help reduce artefacts in shadows
  68. </p>
  69. <h3>[property:WebGLRenderTarget map]</h3>
  70. <p>
  71. The depth map generated using the internal camera; a location beyond a pixel's depth is
  72. in shadow. Computed internally during rendering.
  73. </p>
  74. <h3>[property:Vector2 mapSize]</h3>
  75. <p>
  76. A [Page:Vector2] defining the width and height of the shadow map.<br /><br />
  77. Higher values give better quality shadows at the cost of computation time. Values must be
  78. powers of 2, up to the [page:WebGLRenderer.capabilities].maxTextureSize for a given device,
  79. although the width and height don't have to be the same (so, for example, (512, 1024) is valid).
  80. The default is *( 512, 512 )*.
  81. </p>
  82. <h3>[property:Matrix4 matrix]</h3>
  83. <p>
  84. Model to shadow camera space, to compute location and depth in shadow map. Stored
  85. in a [page:Matrix4 Matrix4]. This is computed internally during rendering.
  86. </p>
  87. <h3>[property:Float radius]</h3>
  88. <p>
  89. Setting this to values greater than 1 will blur the edges of the shadow.<br />
  90. High values will cause unwanted banding effects in the shadows - a greater [page:.mapSize mapSize]
  91. will allow for a higher value to be used here before these effects become visible.<br /><br />
  92. Note that this has no effect if the [page:WebGLRenderer.shadowMap.type] is set to [page:Renderer BasicShadowMap].
  93. </p>
  94. <h2>Methods</h2>
  95. <h3>[method:LightShadow copy]( [param:LightShadow source] )</h3>
  96. <p>
  97. Copies value of all the properties from the [page:LightShadow source] to this
  98. SpotLight.
  99. </p>
  100. <h3>[method:LightShadow clone]()</h3>
  101. <p>
  102. Creates a new LightShadow with the same properties as this one.
  103. </p>
  104. <h3>[method:Object toJSON]()</h3>
  105. <p>
  106. Serialize this LightShadow.
  107. </p>
  108. <h2>Source</h2>
  109. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  110. </body>
  111. </html>