StorageBufferNode.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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">StorageBufferAttribute | StorageInstancedBufferAttribute | BufferAttribute</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"><code>value</code></td>
  47. <td class="description last"><p>The buffer data.</p></td>
  48. </tr>
  49. <tr>
  50. <td class="name"><code>bufferType</code></td>
  51. <td class="description last"><p>The buffer type (e.g. <code>'vec3'</code>).<br/>Default is <code>null</code>.</p></td>
  52. </tr>
  53. <tr>
  54. <td class="name"><code>bufferCount</code></td>
  55. <td class="description last"><p>The buffer count.<br/>Default is <code>0</code>.</p></td>
  56. </tr>
  57. </tbody>
  58. </table>
  59. </div>
  60. </div>
  61. <h2 class="subsection-title">Properties</h2>
  62. <div class="member">
  63. <h3 class="name" id="_attribute" translate="no">.<a href="#_attribute">_attribute</a><span class="type-signature"> : <a href="BufferAttributeNode.html">BufferAttributeNode</a></span> </h3>
  64. <div class="description">
  65. <p>A reference to the internal buffer attribute node.<br/>Default is <code>null</code>.</p>
  66. </div>
  67. </div>
  68. <div class="member">
  69. <h3 class="name" id="_varying" translate="no">.<a href="#_varying">_varying</a><span class="type-signature"> : <a href="VaryingNode.html">VaryingNode</a></span> </h3>
  70. <div class="description">
  71. <p>A reference to the internal varying node.<br/>Default is <code>null</code>.</p>
  72. </div>
  73. </div>
  74. <div class="member">
  75. <h3 class="name" id="access" translate="no">.<a href="#access">access</a><span class="type-signature"> : string</span> </h3>
  76. <div class="description">
  77. <p>The access type of the texture node.<br/>Default is <code>'readWrite'</code>.</p>
  78. </div>
  79. </div>
  80. <div class="member">
  81. <h3 class="name" id="global" translate="no">.<a href="#global">global</a><span class="type-signature"> : boolean</span> </h3>
  82. <div class="description">
  83. <p><code>StorageBufferNode</code> sets this property to <code>true</code> by default.<br/>Default is <code>true</code>.</p>
  84. </div>
  85. <dl class="details">
  86. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#global">BufferNode#global</a></dt>
  87. </dl>
  88. </div>
  89. <div class="member">
  90. <h3 class="name" id="isAtomic" translate="no">.<a href="#isAtomic">isAtomic</a><span class="type-signature"> : boolean</span> </h3>
  91. <div class="description">
  92. <p>Whether the node is atomic or not.<br/>Default is <code>false</code>.</p>
  93. </div>
  94. </div>
  95. <div class="member">
  96. <h3 class="name" id="isPBO" translate="no">.<a href="#isPBO">isPBO</a><span class="type-signature"> : boolean</span> </h3>
  97. <div class="description">
  98. <p>Whether the node represents a PBO or not.
  99. Only relevant for WebGL.<br/>Default is <code>false</code>.</p>
  100. </div>
  101. </div>
  102. <div class="member">
  103. <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>
  104. <div class="description">
  105. <p>This flag can be used for type testing.<br/>Default is <code>true</code>.</p>
  106. </div>
  107. </div>
  108. <div class="member">
  109. <h3 class="name" id="structTypeNode" translate="no">.<a href="#structTypeNode">structTypeNode</a><span class="type-signature"> : <a href="StructTypeNode.html">StructTypeNode</a></span> </h3>
  110. <div class="description">
  111. <p>The buffer struct type.<br/>Default is <code>null</code>.</p>
  112. </div>
  113. </div>
  114. <h2 class="subsection-title">Methods</h2>
  115. <h3 class="name name-method" id="element" translate="no">.<a href="#element">element</a><span class="signature">( indexNode : <span class="param-type">IndexNode</span> )</span><span class="type-signature"> : <a href="StorageArrayElementNode.html">StorageArrayElementNode</a></span> </h3>
  116. <div class="method">
  117. <div class="description">
  118. <p>Enables element access with the given index node.</p>
  119. </div>
  120. <table class="params">
  121. <tbody>
  122. <tr>
  123. <td class="name"><code>indexNode</code></td>
  124. <td class="description last"><p>The index node.</p></td>
  125. </tr>
  126. </tbody>
  127. </table>
  128. <dl class="details">
  129. <dt class="tag-returns"><strong>Returns:</strong> A node representing the element access.</dt>
  130. </dl>
  131. </div>
  132. <h3 class="name name-method" id="generate" translate="no">.<a href="#generate">generate</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : string</span> </h3>
  133. <div class="method">
  134. <div class="description">
  135. <p>Generates the code snippet of the storage buffer node.</p>
  136. </div>
  137. <table class="params">
  138. <tbody>
  139. <tr>
  140. <td class="name"><code>builder</code></td>
  141. <td class="description last"><p>The current node builder.</p></td>
  142. </tr>
  143. </tbody>
  144. </table>
  145. <dl class="details">
  146. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#generate">BufferNode#generate</a></dt>
  147. </dl>
  148. <dl class="details">
  149. <dt class="tag-returns"><strong>Returns:</strong> The generated code snippet.</dt>
  150. </dl>
  151. </div>
  152. <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>
  153. <div class="method">
  154. <div class="description">
  155. <p>Returns attribute data for this storage buffer node.</p>
  156. </div>
  157. <dl class="details">
  158. <dt class="tag-returns"><strong>Returns:</strong> The attribute data.</dt>
  159. </dl>
  160. </div>
  161. <h3 class="name name-method" id="getHash" translate="no">.<a href="#getHash">getHash</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : string</span> </h3>
  162. <div class="method">
  163. <div class="description">
  164. <p>This method is overwritten since the buffer data might be shared
  165. and thus the hash should be shared as well.</p>
  166. </div>
  167. <table class="params">
  168. <tbody>
  169. <tr>
  170. <td class="name"><code>builder</code></td>
  171. <td class="description last"><p>The current node builder.</p></td>
  172. </tr>
  173. </tbody>
  174. </table>
  175. <dl class="details">
  176. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#getHash">BufferNode#getHash</a></dt>
  177. </dl>
  178. <dl class="details">
  179. <dt class="tag-returns"><strong>Returns:</strong> The hash.</dt>
  180. </dl>
  181. </div>
  182. <h3 class="name name-method" id="getInputType" translate="no">.<a href="#getInputType">getInputType</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : string</span> </h3>
  183. <div class="method">
  184. <div class="description">
  185. <p>Overwrites the default implementation to return a fixed value <code>'indirectStorageBuffer'</code> or <code>'storageBuffer'</code>.</p>
  186. </div>
  187. <table class="params">
  188. <tbody>
  189. <tr>
  190. <td class="name"><code>builder</code></td>
  191. <td class="description last"><p>The current node builder.</p></td>
  192. </tr>
  193. </tbody>
  194. </table>
  195. <dl class="details">
  196. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#getInputType">BufferNode#getInputType</a></dt>
  197. </dl>
  198. <dl class="details">
  199. <dt class="tag-returns"><strong>Returns:</strong> The input type.</dt>
  200. </dl>
  201. </div>
  202. <h3 class="name name-method" id="getMemberType" translate="no">.<a href="#getMemberType">getMemberType</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span>, name : <span class="param-type">string</span> )</span><span class="type-signature"> : string</span> </h3>
  203. <div class="method">
  204. <div class="description">
  205. <p>Returns the type of a member of the struct.</p>
  206. </div>
  207. <table class="params">
  208. <tbody>
  209. <tr>
  210. <td class="name"><code>builder</code></td>
  211. <td class="description last"><p>The current node builder.</p></td>
  212. </tr>
  213. <tr>
  214. <td class="name"><code>name</code></td>
  215. <td class="description last"><p>The name of the member.</p></td>
  216. </tr>
  217. </tbody>
  218. </table>
  219. <dl class="details">
  220. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#getMemberType">BufferNode#getMemberType</a></dt>
  221. </dl>
  222. <dl class="details">
  223. <dt class="tag-returns"><strong>Returns:</strong> The type of the member.</dt>
  224. </dl>
  225. </div>
  226. <h3 class="name name-method" id="getNodeType" translate="no">.<a href="#getNodeType">getNodeType</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : string</span> </h3>
  227. <div class="method">
  228. <div class="description">
  229. <p>This method is overwritten since the node type from the availability of storage buffers
  230. and the attribute data.</p>
  231. </div>
  232. <table class="params">
  233. <tbody>
  234. <tr>
  235. <td class="name"><code>builder</code></td>
  236. <td class="description last"><p>The current node builder.</p></td>
  237. </tr>
  238. </tbody>
  239. </table>
  240. <dl class="details">
  241. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="BufferNode.html#getNodeType">BufferNode#getNodeType</a></dt>
  242. </dl>
  243. <dl class="details">
  244. <dt class="tag-returns"><strong>Returns:</strong> The node type.</dt>
  245. </dl>
  246. </div>
  247. <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>
  248. <div class="method">
  249. <div class="description">
  250. <p>Returns the <code>isPBO</code> value.</p>
  251. </div>
  252. <dl class="details">
  253. <dt class="tag-returns"><strong>Returns:</strong> Whether the node represents a PBO or not.</dt>
  254. </dl>
  255. </div>
  256. <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>
  257. <div class="method">
  258. <div class="description">
  259. <p>Defines the node access.</p>
  260. </div>
  261. <table class="params">
  262. <tbody>
  263. <tr>
  264. <td class="name"><code>value</code></td>
  265. <td class="description last"><p>The node access.</p></td>
  266. </tr>
  267. </tbody>
  268. </table>
  269. <dl class="details">
  270. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  271. </dl>
  272. </div>
  273. <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>
  274. <div class="method">
  275. <div class="description">
  276. <p>Defines whether the node is atomic or not.</p>
  277. </div>
  278. <table class="params">
  279. <tbody>
  280. <tr>
  281. <td class="name"><code>value</code></td>
  282. <td class="description last"><p>The atomic flag.</p></td>
  283. </tr>
  284. </tbody>
  285. </table>
  286. <dl class="details">
  287. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  288. </dl>
  289. </div>
  290. <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>
  291. <div class="method">
  292. <div class="description">
  293. <p>Defines whether this node is a PBO or not. Only relevant for WebGL.</p>
  294. </div>
  295. <table class="params">
  296. <tbody>
  297. <tr>
  298. <td class="name"><code>value</code></td>
  299. <td class="description last"><p>The value so set.</p></td>
  300. </tr>
  301. </tbody>
  302. </table>
  303. <dl class="details">
  304. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  305. </dl>
  306. </div>
  307. <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>
  308. <div class="method">
  309. <div class="description">
  310. <p>Convenience method for making this node atomic.</p>
  311. </div>
  312. <dl class="details">
  313. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  314. </dl>
  315. </div>
  316. <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>
  317. <div class="method">
  318. <div class="description">
  319. <p>Convenience method for configuring a read-only node access.</p>
  320. </div>
  321. <dl class="details">
  322. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  323. </dl>
  324. </div>
  325. <h2 class="subsection-title">Source</h2>
  326. <p>
  327. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/accessors/StorageBufferNode.js" target="_blank" rel="noopener" translate="no">src/nodes/accessors/StorageBufferNode.js</a>
  328. </p>
  329. </article>
  330. </section>
  331. <script src="../scripts/linenumber.js"></script>
  332. <script src="../scripts/page.js"></script>
  333. </body>
  334. </html>
粤ICP备19079148号