CSM.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CSM - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <h1 translate="no">CSM</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>An implementation of Cascade Shadow Maps (CSM).</p>
  16. <p>This module can only be used with <a href="WebGLRenderer.html">WebGLRenderer</a>. When using <a href="WebGPURenderer.html">WebGPURenderer</a>,
  17. use <a href="CSMShadowNode.html">CSMShadowNode</a> instead.</p></div>
  18. </header>
  19. <article>
  20. <h2 class="subsection-title">Import</h2>
  21. <p><span translate="no">CSM</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  22. <pre><code class="language-js">import { CSM } from 'three/addons/csm/CSM.js';</code></pre>
  23. <div class="container-overview">
  24. <h2>Constructor</h2>
  25. <h3 class="name name-method" id="CSM" translate="no">new <a href="#CSM">CSM</a><span class="signature">( data : <span class="param-type">CSM~Data</span> )</span> </h3>
  26. <div class="method">
  27. <div class="description">
  28. <p>Constructs a new CSM instance.</p>
  29. </div>
  30. <table class="params">
  31. <tbody>
  32. <tr>
  33. <td class="name"><code>data</code></td>
  34. <td class="description last"><p>The CSM data.</p></td>
  35. </tr>
  36. </tbody>
  37. </table>
  38. </div>
  39. </div>
  40. <h2 class="subsection-title">Classes</h2>
  41. <dl>
  42. <dt><a href="CSM.html">CSM</a></dt>
  43. <dd></dd>
  44. </dl>
  45. <h2 class="subsection-title">Properties</h2>
  46. <div class="member">
  47. <h3 class="name" id="breaks" translate="no">.<a href="#breaks">breaks</a><span class="type-signature"> : Array.&lt;number></span> </h3>
  48. <div class="description">
  49. <p>An array of numbers in the range <code>[0,1]</code> the defines how the
  50. mainCSM frustum should be split up.</p>
  51. </div>
  52. </div>
  53. <div class="member">
  54. <h3 class="name" id="camera" translate="no">.<a href="#camera">camera</a><span class="type-signature"> : <a href="Camera.html">Camera</a></span> </h3>
  55. <div class="description">
  56. <p>The scene's camera.</p>
  57. </div>
  58. </div>
  59. <div class="member">
  60. <h3 class="name" id="cascades" translate="no">.<a href="#cascades">cascades</a><span class="type-signature"> : number</span> </h3>
  61. <div class="description">
  62. <p>The number of cascades.<br/>Default is <code>3</code>.</p>
  63. </div>
  64. </div>
  65. <div class="member">
  66. <h3 class="name" id="customSplitsCallback" translate="no">.<a href="#customSplitsCallback">customSplitsCallback</a><span class="type-signature"> : function</span> </h3>
  67. <div class="description">
  68. <p>Custom split callback when using <code>mode='custom'</code>.</p>
  69. </div>
  70. </div>
  71. <div class="member">
  72. <h3 class="name" id="fade" translate="no">.<a href="#fade">fade</a><span class="type-signature"> : boolean</span> </h3>
  73. <div class="description">
  74. <p>Whether to fade between cascades or not.<br/>Default is <code>false</code>.</p>
  75. </div>
  76. </div>
  77. <div class="member">
  78. <h3 class="name" id="frustums" translate="no">.<a href="#frustums">frustums</a><span class="type-signature"> : Array.&lt;<a href="CSMFrustum.html">CSMFrustum</a>></span> </h3>
  79. <div class="description">
  80. <p>An array of frustums representing the cascades.</p>
  81. </div>
  82. </div>
  83. <div class="member">
  84. <h3 class="name" id="lightDirection" translate="no">.<a href="#lightDirection">lightDirection</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
  85. <div class="description">
  86. <p>The light direction.</p>
  87. </div>
  88. </div>
  89. <div class="member">
  90. <h3 class="name" id="lightFar" translate="no">.<a href="#lightFar">lightFar</a><span class="type-signature"> : number</span> </h3>
  91. <div class="description">
  92. <p>The light far value.<br/>Default is <code>2000</code>.</p>
  93. </div>
  94. </div>
  95. <div class="member">
  96. <h3 class="name" id="lightIntensity" translate="no">.<a href="#lightIntensity">lightIntensity</a><span class="type-signature"> : number</span> </h3>
  97. <div class="description">
  98. <p>The light intensity.<br/>Default is <code>3</code>.</p>
  99. </div>
  100. </div>
  101. <div class="member">
  102. <h3 class="name" id="lightMargin" translate="no">.<a href="#lightMargin">lightMargin</a><span class="type-signature"> : number</span> </h3>
  103. <div class="description">
  104. <p>The light margin.<br/>Default is <code>200</code>.</p>
  105. </div>
  106. </div>
  107. <div class="member">
  108. <h3 class="name" id="lightNear" translate="no">.<a href="#lightNear">lightNear</a><span class="type-signature"> : number</span> </h3>
  109. <div class="description">
  110. <p>The light near value.<br/>Default is <code>1</code>.</p>
  111. </div>
  112. </div>
  113. <div class="member">
  114. <h3 class="name" id="lights" translate="no">.<a href="#lights">lights</a><span class="type-signature"> : Array.&lt;<a href="DirectionalLight.html">DirectionalLight</a>></span> </h3>
  115. <div class="description">
  116. <p>An array of directional lights which cast the shadows for
  117. the different cascades. There is one directional light for each
  118. cascade.</p>
  119. </div>
  120. </div>
  121. <div class="member">
  122. <h3 class="name" id="mainFrustum" translate="no">.<a href="#mainFrustum">mainFrustum</a><span class="type-signature"> : <a href="CSMFrustum.html">CSMFrustum</a></span> </h3>
  123. <div class="description">
  124. <p>The main frustum.</p>
  125. </div>
  126. </div>
  127. <div class="member">
  128. <h3 class="name" id="maxFar" translate="no">.<a href="#maxFar">maxFar</a><span class="type-signature"> : number</span> </h3>
  129. <div class="description">
  130. <p>The maximum far value.<br/>Default is <code>100000</code>.</p>
  131. </div>
  132. </div>
  133. <div class="member">
  134. <h3 class="name" id="mode" translate="no">.<a href="#mode">mode</a><span class="type-signature"> : 'practical' | 'uniform' | 'logarithmic' | 'custom'</span> </h3>
  135. <div class="description">
  136. <p>The frustum split mode.<br/>Default is <code>'practical'</code>.</p>
  137. </div>
  138. </div>
  139. <div class="member">
  140. <h3 class="name" id="parent" translate="no">.<a href="#parent">parent</a><span class="type-signature"> : <a href="Object3D.html">Object3D</a></span> </h3>
  141. <div class="description">
  142. <p>The parent object, usually the scene.</p>
  143. </div>
  144. </div>
  145. <div class="member">
  146. <h3 class="name" id="shaders" translate="no">.<a href="#shaders">shaders</a><span class="type-signature"> : Map.&lt;<a href="Material.html">Material</a>, Object></span> </h3>
  147. <div class="description">
  148. <p>A Map holding enhanced material shaders.</p>
  149. </div>
  150. </div>
  151. <div class="member">
  152. <h3 class="name" id="shadowBias" translate="no">.<a href="#shadowBias">shadowBias</a><span class="type-signature"> : number</span> </h3>
  153. <div class="description">
  154. <p>The shadow bias.<br/>Default is <code>0.000001</code>.</p>
  155. </div>
  156. </div>
  157. <div class="member">
  158. <h3 class="name" id="shadowMapSize" translate="no">.<a href="#shadowMapSize">shadowMapSize</a><span class="type-signature"> : number</span> </h3>
  159. <div class="description">
  160. <p>The shadow map size.<br/>Default is <code>2048</code>.</p>
  161. </div>
  162. </div>
  163. <h2 class="subsection-title">Methods</h2>
  164. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  165. <div class="method">
  166. <div class="description">
  167. <p>Frees the GPU-related resources allocated by this instance. Call this
  168. method whenever this instance is no longer used in your app.</p>
  169. </div>
  170. </div>
  171. <h3 class="name name-method" id="remove" translate="no">.<a href="#remove">remove</a><span class="signature">()</span> </h3>
  172. <div class="method">
  173. <div class="description">
  174. <p>Applications must call this method when they remove the CSM usage from their scene.</p>
  175. </div>
  176. </div>
  177. <h3 class="name name-method" id="setupMaterial" translate="no">.<a href="#setupMaterial">setupMaterial</a><span class="signature">( material : <span class="param-type">Material</span> )</span> </h3>
  178. <div class="method">
  179. <div class="description">
  180. <p>Applications must call this method for all materials that should be affected by CSM.</p>
  181. </div>
  182. <table class="params">
  183. <tbody>
  184. <tr>
  185. <td class="name"><code>material</code></td>
  186. <td class="description last"><p>The material to setup for CSM support.</p></td>
  187. </tr>
  188. </tbody>
  189. </table>
  190. </div>
  191. <h3 class="name name-method" id="update" translate="no">.<a href="#update">update</a><span class="signature">()</span> </h3>
  192. <div class="method">
  193. <div class="description">
  194. <p>Updates the CSM. This method must be called in your animation loop before
  195. calling <code>renderer.render()</code>.</p>
  196. </div>
  197. </div>
  198. <h3 class="name name-method" id="updateFrustums" translate="no">.<a href="#updateFrustums">updateFrustums</a><span class="signature">()</span> </h3>
  199. <div class="method">
  200. <div class="description">
  201. <p>Applications must call this method every time they change camera or CSM settings.</p>
  202. </div>
  203. </div>
  204. <h2 class="subsection-title">Type Definitions</h2>
  205. <div class="member">
  206. <h3 class="name" id="~Data" translate="no">.<a href="#~Data">Data</a> </h3>
  207. <div class="description">
  208. <p>Constructor data of <code>CSM</code>.</p>
  209. </div>
  210. <h5 class="subsection-title">Properties:</h5>
  211. <table class="props">
  212. <thead>
  213. <tr>
  214. <th>Name</th>
  215. <th>Type</th>
  216. <th>Attributes</th>
  217. <th>Default</th>
  218. <th class="last">Description</th>
  219. </tr>
  220. </thead>
  221. <tbody>
  222. <tr>
  223. <td class="name"><code>camera</code></td>
  224. <td class="type">
  225. <span class="param-type"><a href="Camera.html">Camera</a></span>
  226. </td>
  227. <td class="attributes">
  228. </td>
  229. <td class="default">
  230. </td>
  231. <td class="description last"><p>The scene's camera.</p></td>
  232. </tr>
  233. <tr>
  234. <td class="name"><code>parent</code></td>
  235. <td class="type">
  236. <span class="param-type"><a href="Object3D.html">Object3D</a></span>
  237. </td>
  238. <td class="attributes">
  239. </td>
  240. <td class="default">
  241. </td>
  242. <td class="description last"><p>The parent object, usually the scene.</p></td>
  243. </tr>
  244. <tr>
  245. <td class="name"><code>cascades</code></td>
  246. <td class="type">
  247. <span class="param-type">number</span>
  248. </td>
  249. <td class="attributes">
  250. &lt;optional><br>
  251. </td>
  252. <td class="default">
  253. 3
  254. </td>
  255. <td class="description last"><p>The number of cascades.</p></td>
  256. </tr>
  257. <tr>
  258. <td class="name"><code>maxFar</code></td>
  259. <td class="type">
  260. <span class="param-type">number</span>
  261. </td>
  262. <td class="attributes">
  263. &lt;optional><br>
  264. </td>
  265. <td class="default">
  266. 100000
  267. </td>
  268. <td class="description last"><p>The maximum far value.</p></td>
  269. </tr>
  270. <tr>
  271. <td class="name"><code>mode</code></td>
  272. <td class="type">
  273. <span class="param-type">'practical'</span>
  274. |
  275. <span class="param-type">'uniform'</span>
  276. |
  277. <span class="param-type">'logarithmic'</span>
  278. |
  279. <span class="param-type">'custom'</span>
  280. </td>
  281. <td class="attributes">
  282. &lt;optional><br>
  283. </td>
  284. <td class="default">
  285. 'practical'
  286. </td>
  287. <td class="description last"><p>The frustum split mode.</p></td>
  288. </tr>
  289. <tr>
  290. <td class="name"><code>customSplitsCallback</code></td>
  291. <td class="type">
  292. <span class="param-type">function</span>
  293. </td>
  294. <td class="attributes">
  295. &lt;optional><br>
  296. </td>
  297. <td class="default">
  298. </td>
  299. <td class="description last"><p>Custom split callback when using <code>mode='custom'</code>.</p></td>
  300. </tr>
  301. <tr>
  302. <td class="name"><code>shadowMapSize</code></td>
  303. <td class="type">
  304. <span class="param-type">number</span>
  305. </td>
  306. <td class="attributes">
  307. &lt;optional><br>
  308. </td>
  309. <td class="default">
  310. 2048
  311. </td>
  312. <td class="description last"><p>The shadow map size.</p></td>
  313. </tr>
  314. <tr>
  315. <td class="name"><code>shadowBias</code></td>
  316. <td class="type">
  317. <span class="param-type">number</span>
  318. </td>
  319. <td class="attributes">
  320. &lt;optional><br>
  321. </td>
  322. <td class="default">
  323. 0.000001
  324. </td>
  325. <td class="description last"><p>The shadow bias.</p></td>
  326. </tr>
  327. <tr>
  328. <td class="name"><code>lightDirection</code></td>
  329. <td class="type">
  330. <span class="param-type"><a href="Vector3.html">Vector3</a></span>
  331. </td>
  332. <td class="attributes">
  333. &lt;optional><br>
  334. </td>
  335. <td class="default">
  336. </td>
  337. <td class="description last"><p>The light direction.</p></td>
  338. </tr>
  339. <tr>
  340. <td class="name"><code>lightIntensity</code></td>
  341. <td class="type">
  342. <span class="param-type">number</span>
  343. </td>
  344. <td class="attributes">
  345. &lt;optional><br>
  346. </td>
  347. <td class="default">
  348. 3
  349. </td>
  350. <td class="description last"><p>The light intensity.</p></td>
  351. </tr>
  352. <tr>
  353. <td class="name"><code>lightNear</code></td>
  354. <td class="type">
  355. <span class="param-type">number</span>
  356. </td>
  357. <td class="attributes">
  358. &lt;optional><br>
  359. </td>
  360. <td class="default">
  361. 1
  362. </td>
  363. <td class="description last"><p>The light near value.</p></td>
  364. </tr>
  365. <tr>
  366. <td class="name"><code>lightNear</code></td>
  367. <td class="type">
  368. <span class="param-type">number</span>
  369. </td>
  370. <td class="attributes">
  371. &lt;optional><br>
  372. </td>
  373. <td class="default">
  374. 2000
  375. </td>
  376. <td class="description last"><p>The light far value.</p></td>
  377. </tr>
  378. <tr>
  379. <td class="name"><code>lightMargin</code></td>
  380. <td class="type">
  381. <span class="param-type">number</span>
  382. </td>
  383. <td class="attributes">
  384. &lt;optional><br>
  385. </td>
  386. <td class="default">
  387. 200
  388. </td>
  389. <td class="description last"><p>The light margin.</p></td>
  390. </tr>
  391. </tbody>
  392. </table>
  393. </div>
  394. <h2 class="subsection-title">Source</h2>
  395. <p>
  396. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/csm/CSM.js" target="_blank" rel="noopener" translate="no">examples/jsm/csm/CSM.js</a>
  397. </p>
  398. </article>
  399. </section>
  400. <script src="../scripts/linenumber.js"></script>
  401. <script src="../scripts/page.js"></script>
  402. </body>
  403. </html>
粤ICP备19079148号