StorageBufferNode.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>StorageBufferNode - 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. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Node.html">Node</a> → <a href="InputNode.html">InputNode</a> → <a href="UniformNode.html">UniformNode</a> → <a href="BufferNode.html">BufferNode</a> → </p>
  13. <h1 translate="no">StorageBufferNode</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>This node is used in context of compute shaders and allows to define a
  17. storage buffer for data. A typical workflow is to create instances of
  18. this node with the convenience functions <code>attributeArray()</code> or <code>instancedArray()</code>,
  19. setup up a compute shader that writes into the buffers and then convert
  20. the storage buffers to attribute nodes for rendering.</p></div>
  21. <h2>Code Example</h2>
  22. <div translate="no"><pre><code class="language-js">const positionBuffer = instancedArray( particleCount, 'vec3' ); // the storage buffer node
  23. const computeInit = Fn( () => { // the compute shader
  24. const position = positionBuffer.element( instanceIndex );
  25. // compute position data
  26. position.x = 1;
  27. position.y = 1;
  28. position.z = 1;
  29. } )().compute( particleCount );
  30. const particleMaterial = new THREE.SpriteNodeMaterial();
  31. particleMaterial.positionNode = positionBuffer.toAttribute();
  32. renderer.computeAsync( computeInit );
  33. </code></pre></div>
  34. </header>
  35. <article>
  36. <div class="container-overview">
  37. <h2>Constructor</h2>
  38. <h3 class="name name-method" id="StorageBufferNode" translate="no">new <a href="#StorageBufferNode">StorageBufferNode</a><span class="signature">( value : <span class="param-type"><a href="StorageBufferAttribute.html">StorageBufferAttribute</a> | <a href="StorageInstancedBufferAttribute.html">StorageInstancedBufferAttribute</a> | <a href="BufferAttribute.html">BufferAttribute</a></span>, bufferType : <span class="param-type">string | Struct</span>, bufferCount : <span class="param-type">number</span> )</span> </h3>
  39. <div class="method">
  40. <div class="description">
  41. <p>Constructs a new storage buffer node.</p>
  42. </div>
  43. <table class="params">
  44. <tbody>
  45. <tr>
  46. <td class="name">
  47. <strong>value</strong>
  48. </td>
  49. <td class="description last">
  50. <p>The buffer data.</p>
  51. </td>
  52. </tr>
  53. <tr>
  54. <td class="name">
  55. <strong>bufferType</strong>
  56. </td>
  57. <td class="description last">
  58. <p>The buffer type (e.g. <code>'vec3'</code>).</p>
  59. <p>Default is <code>null</code>.</p>
  60. </td>
  61. </tr>
  62. <tr>
  63. <td class="name">
  64. <strong>bufferCount</strong>
  65. </td>
  66. <td class="description last">
  67. <p>The buffer count.</p>
  68. <p>Default is <code>0</code>.</p>
  69. </td>
  70. </tr>
  71. </tbody>
  72. </table>
  73. </div>
  74. </div>
  75. <h2 class="subsection-title">Properties</h2>
  76. <div class="member">
  77. <h3 class="name" id="access" translate="no">.<a href="#access">access</a><span class="type-signature"> : string</span> </h3>
  78. <div class="description">
  79. <p>The access type of the texture node.</p>
  80. <p>Default is <code>'readWrite'</code>.</p>
  81. </div>
  82. </div>
  83. <div class="member">
  84. <h3 class="name" id="global" translate="no">.<a href="#global">global</a><span class="type-signature"> : boolean</span> </h3>
  85. <div class="description">
  86. <p><code>StorageBufferNode</code> sets this property to <code>true</code> by default.</p>
  87. <p>Default is <code>true</code>.</p>
  88. </div>
  89. <dl class="details">
  90. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#global">BufferNode#global</a></dt>
  91. </dl>
  92. </div>
  93. <div class="member">
  94. <h3 class="name" id="isAtomic" translate="no">.<a href="#isAtomic">isAtomic</a><span class="type-signature"> : boolean</span> </h3>
  95. <div class="description">
  96. <p>Whether the node is atomic or not.</p>
  97. <p>Default is <code>false</code>.</p>
  98. </div>
  99. </div>
  100. <div class="member">
  101. <h3 class="name" id="isPBO" translate="no">.<a href="#isPBO">isPBO</a><span class="type-signature"> : boolean</span> </h3>
  102. <div class="description">
  103. <p>Whether the node represents a PBO or not.
  104. Only relevant for WebGL.</p>
  105. <p>Default is <code>false</code>.</p>
  106. </div>
  107. </div>
  108. <div class="member">
  109. <h3 class="name" id="isStorageBufferNode" translate="no">.<a href="#isStorageBufferNode">isStorageBufferNode</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  110. <div class="description">
  111. <p>This flag can be used for type testing.</p>
  112. <p>Default is <code>true</code>.</p>
  113. </div>
  114. </div>
  115. <div class="member">
  116. <h3 class="name" id="structTypeNode" translate="no">.<a href="#structTypeNode">structTypeNode</a><span class="type-signature"> : <a href="StructTypeNode.html">StructTypeNode</a></span> </h3>
  117. <div class="description">
  118. <p>The buffer struct type.</p>
  119. <p>Default is <code>null</code>.</p>
  120. </div>
  121. </div>
  122. <h2 class="subsection-title">Methods</h2>
  123. <h3 class="name name-method" id="element" translate="no">.<a href="#element">element</a><span class="signature">( indexNode : <span class="param-type"><a href="IndexNode.html">IndexNode</a></span> )</span><span class="type-signature"> : <a href="StorageArrayElementNode.html">StorageArrayElementNode</a></span> </h3>
  124. <div class="method">
  125. <div class="description">
  126. <p>Enables element access with the given index node.</p>
  127. </div>
  128. <table class="params">
  129. <tbody>
  130. <tr>
  131. <td class="name">
  132. <strong>indexNode</strong>
  133. </td>
  134. <td class="description last">
  135. <p>The index node.</p>
  136. </td>
  137. </tr>
  138. </tbody>
  139. </table>
  140. <dl class="details">
  141. <dt class="tag-returns"><strong>Returns:</strong> A node representing the element access.</dt>
  142. </dl>
  143. </div>
  144. <h3 class="name name-method" id="generate" translate="no">.<a href="#generate">generate</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : string</span> </h3>
  145. <div class="method">
  146. <div class="description">
  147. <p>Generates the code snippet of the storage buffer node.</p>
  148. </div>
  149. <table class="params">
  150. <tbody>
  151. <tr>
  152. <td class="name">
  153. <strong>builder</strong>
  154. </td>
  155. <td class="description last">
  156. <p>The current node builder.</p>
  157. </td>
  158. </tr>
  159. </tbody>
  160. </table>
  161. <dl class="details">
  162. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#generate">BufferNode#generate</a></dt>
  163. </dl>
  164. <dl class="details">
  165. <dt class="tag-returns"><strong>Returns:</strong> The generated code snippet.</dt>
  166. </dl>
  167. </div>
  168. <h3 class="name name-method" id="getAttributeData" translate="no">.<a href="#getAttributeData">getAttributeData</a><span class="signature">()</span><span class="type-signature"> : Object</span> </h3>
  169. <div class="method">
  170. <div class="description">
  171. <p>Returns attribute data for this storage buffer node.</p>
  172. </div>
  173. <dl class="details">
  174. <dt class="tag-returns"><strong>Returns:</strong> The attribute data.</dt>
  175. </dl>
  176. </div>
  177. <h3 class="name name-method" id="getHash" translate="no">.<a href="#getHash">getHash</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : string</span> </h3>
  178. <div class="method">
  179. <div class="description">
  180. <p>This method is overwritten since the buffer data might be shared
  181. and thus the hash should be shared as well.</p>
  182. </div>
  183. <table class="params">
  184. <tbody>
  185. <tr>
  186. <td class="name">
  187. <strong>builder</strong>
  188. </td>
  189. <td class="description last">
  190. <p>The current node builder.</p>
  191. </td>
  192. </tr>
  193. </tbody>
  194. </table>
  195. <dl class="details">
  196. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#getHash">BufferNode#getHash</a></dt>
  197. </dl>
  198. <dl class="details">
  199. <dt class="tag-returns"><strong>Returns:</strong> The hash.</dt>
  200. </dl>
  201. </div>
  202. <h3 class="name name-method" id="getInputType" translate="no">.<a href="#getInputType">getInputType</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : string</span> </h3>
  203. <div class="method">
  204. <div class="description">
  205. <p>Overwrites the default implementation to return a fixed value <code>'indirectStorageBuffer'</code> or <code>'storageBuffer'</code>.</p>
  206. </div>
  207. <table class="params">
  208. <tbody>
  209. <tr>
  210. <td class="name">
  211. <strong>builder</strong>
  212. </td>
  213. <td class="description last">
  214. <p>The current node builder.</p>
  215. </td>
  216. </tr>
  217. </tbody>
  218. </table>
  219. <dl class="details">
  220. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#getInputType">BufferNode#getInputType</a></dt>
  221. </dl>
  222. <dl class="details">
  223. <dt class="tag-returns"><strong>Returns:</strong> The input type.</dt>
  224. </dl>
  225. </div>
  226. <h3 class="name name-method" id="getMemberType" translate="no">.<a href="#getMemberType">getMemberType</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span>, name : <span class="param-type">string</span> )</span><span class="type-signature"> : string</span> </h3>
  227. <div class="method">
  228. <div class="description">
  229. <p>Returns the type of a member of the struct.</p>
  230. </div>
  231. <table class="params">
  232. <tbody>
  233. <tr>
  234. <td class="name">
  235. <strong>builder</strong>
  236. </td>
  237. <td class="description last">
  238. <p>The current node builder.</p>
  239. </td>
  240. </tr>
  241. <tr>
  242. <td class="name">
  243. <strong>name</strong>
  244. </td>
  245. <td class="description last">
  246. <p>The name of the member.</p>
  247. </td>
  248. </tr>
  249. </tbody>
  250. </table>
  251. <dl class="details">
  252. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#getMemberType">BufferNode#getMemberType</a></dt>
  253. </dl>
  254. <dl class="details">
  255. <dt class="tag-returns"><strong>Returns:</strong> The type of the member.</dt>
  256. </dl>
  257. </div>
  258. <h3 class="name name-method" id="getNodeType" translate="no">.<a href="#getNodeType">getNodeType</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : string</span> </h3>
  259. <div class="method">
  260. <div class="description">
  261. <p>This method is overwritten since the node type from the availability of storage buffers
  262. and the attribute data.</p>
  263. </div>
  264. <table class="params">
  265. <tbody>
  266. <tr>
  267. <td class="name">
  268. <strong>builder</strong>
  269. </td>
  270. <td class="description last">
  271. <p>The current node builder.</p>
  272. </td>
  273. </tr>
  274. </tbody>
  275. </table>
  276. <dl class="details">
  277. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#getNodeType">BufferNode#getNodeType</a></dt>
  278. </dl>
  279. <dl class="details">
  280. <dt class="tag-returns"><strong>Returns:</strong> The node type.</dt>
  281. </dl>
  282. </div>
  283. <h3 class="name name-method" id="getPBO" translate="no">.<a href="#getPBO">getPBO</a><span class="signature">()</span><span class="type-signature"> : boolean</span> </h3>
  284. <div class="method">
  285. <div class="description">
  286. <p>Returns the <code>isPBO</code> value.</p>
  287. </div>
  288. <dl class="details">
  289. <dt class="tag-returns"><strong>Returns:</strong> Whether the node represents a PBO or not.</dt>
  290. </dl>
  291. </div>
  292. <h3 class="name name-method" id="setAccess" translate="no">.<a href="#setAccess">setAccess</a><span class="signature">( value : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="StorageBufferNode.html">StorageBufferNode</a></span> </h3>
  293. <div class="method">
  294. <div class="description">
  295. <p>Defines the node access.</p>
  296. </div>
  297. <table class="params">
  298. <tbody>
  299. <tr>
  300. <td class="name">
  301. <strong>value</strong>
  302. </td>
  303. <td class="description last">
  304. <p>The node access.</p>
  305. </td>
  306. </tr>
  307. </tbody>
  308. </table>
  309. <dl class="details">
  310. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  311. </dl>
  312. </div>
  313. <h3 class="name name-method" id="setAtomic" translate="no">.<a href="#setAtomic">setAtomic</a><span class="signature">( value : <span class="param-type">boolean</span> )</span><span class="type-signature"> : <a href="StorageBufferNode.html">StorageBufferNode</a></span> </h3>
  314. <div class="method">
  315. <div class="description">
  316. <p>Defines whether the node is atomic or not.</p>
  317. </div>
  318. <table class="params">
  319. <tbody>
  320. <tr>
  321. <td class="name">
  322. <strong>value</strong>
  323. </td>
  324. <td class="description last">
  325. <p>The atomic flag.</p>
  326. </td>
  327. </tr>
  328. </tbody>
  329. </table>
  330. <dl class="details">
  331. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  332. </dl>
  333. </div>
  334. <h3 class="name name-method" id="setPBO" translate="no">.<a href="#setPBO">setPBO</a><span class="signature">( value : <span class="param-type">boolean</span> )</span><span class="type-signature"> : <a href="StorageBufferNode.html">StorageBufferNode</a></span> </h3>
  335. <div class="method">
  336. <div class="description">
  337. <p>Defines whether this node is a PBO or not. Only relevant for WebGL.</p>
  338. </div>
  339. <table class="params">
  340. <tbody>
  341. <tr>
  342. <td class="name">
  343. <strong>value</strong>
  344. </td>
  345. <td class="description last">
  346. <p>The value so set.</p>
  347. </td>
  348. </tr>
  349. </tbody>
  350. </table>
  351. <dl class="details">
  352. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  353. </dl>
  354. </div>
  355. <h3 class="name name-method" id="toAtomic" translate="no">.<a href="#toAtomic">toAtomic</a><span class="signature">()</span><span class="type-signature"> : <a href="StorageBufferNode.html">StorageBufferNode</a></span> </h3>
  356. <div class="method">
  357. <div class="description">
  358. <p>Convenience method for making this node atomic.</p>
  359. </div>
  360. <dl class="details">
  361. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  362. </dl>
  363. </div>
  364. <h3 class="name name-method" id="toReadOnly" translate="no">.<a href="#toReadOnly">toReadOnly</a><span class="signature">()</span><span class="type-signature"> : <a href="StorageBufferNode.html">StorageBufferNode</a></span> </h3>
  365. <div class="method">
  366. <div class="description">
  367. <p>Convenience method for configuring a read-only node access.</p>
  368. </div>
  369. <dl class="details">
  370. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  371. </dl>
  372. </div>
  373. <h2 class="subsection-title">Source</h2>
  374. <p>
  375. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/accessors/StorageBufferNode.js" translate="no" target="_blank" rel="noopener">src/nodes/accessors/StorageBufferNode.js</a>
  376. </p>
  377. </article>
  378. </section>
  379. <script src="../scripts/linenumber.js"></script>
  380. <script src="../scripts/page.js"></script>
  381. </body>
  382. </html>
粤ICP备19079148号