StorageTextureNode.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>StorageTextureNode - 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="TextureNode.html">TextureNode</a> → </p>
  13. <h1 translate="no">StorageTextureNode</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>This special version of a texture node can be used to
  17. write data into a storage texture with a compute shader.</p>
  18. <p>This node can only be used with a WebGPU backend.</p></div>
  19. <h2>Code Example</h2>
  20. <div translate="no"><pre><code class="language-js">const storageTexture = new THREE.StorageTexture( width, height );
  21. const computeTexture = Fn( ( { storageTexture } ) => {
  22. const posX = instanceIndex.mod( width );
  23. const posY = instanceIndex.div( width );
  24. const indexUV = uvec2( posX, posY );
  25. // generate RGB values
  26. const r = 1;
  27. const g = 1;
  28. const b = 1;
  29. textureStore( storageTexture, indexUV, vec4( r, g, b, 1 ) ).toWriteOnly();
  30. } );
  31. const computeNode = computeTexture( { storageTexture } ).compute( width * height );
  32. renderer.computeAsync( computeNode );
  33. </code></pre></div>
  34. </header>
  35. <article>
  36. <div class="container-overview">
  37. <h2>Constructor</h2>
  38. <h3 class="name name-method" id="StorageTextureNode" translate="no">new <a href="#StorageTextureNode">StorageTextureNode</a><span class="signature">( value : <span class="param-type">StorageTexture</span>, uvNode : <span class="param-type">Node.&lt;(vec2|vec3)></span>, storeNode : <span class="param-type">Node</span> )</span> </h3>
  39. <div class="method">
  40. <div class="description">
  41. <p>Constructs a new storage texture 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 storage texture.</p></td>
  48. </tr>
  49. <tr>
  50. <td class="name"><code>uvNode</code></td>
  51. <td class="description last"><p>The uv node.</p></td>
  52. </tr>
  53. <tr>
  54. <td class="name"><code>storeNode</code></td>
  55. <td class="description last"><p>The value node that should be stored in the texture.<br/>Default is <code>null</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="access" translate="no">.<a href="#access">access</a><span class="type-signature"> : string</span> </h3>
  64. <div class="description">
  65. <p>The access type of the texture node.<br/>Default is <code>'writeOnly'</code>.</p>
  66. </div>
  67. </div>
  68. <div class="member">
  69. <h3 class="name" id="isStorageTextureNode" translate="no">.<a href="#isStorageTextureNode">isStorageTextureNode</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  70. <div class="description">
  71. <p>This flag can be used for type testing.<br/>Default is <code>true</code>.</p>
  72. </div>
  73. </div>
  74. <div class="member">
  75. <h3 class="name" id="mipLevel" translate="no">.<a href="#mipLevel">mipLevel</a><span class="type-signature"> : number</span> </h3>
  76. <div class="description">
  77. <p>The mip level to write to for storage textures.<br/>Default is <code>0</code>.</p>
  78. </div>
  79. </div>
  80. <div class="member">
  81. <h3 class="name" id="storeNode" translate="no">.<a href="#storeNode">storeNode</a><span class="type-signature"> : <a href="Node.html">Node</a></span> </h3>
  82. <div class="description">
  83. <p>The value node that should be stored in the texture.<br/>Default is <code>null</code>.</p>
  84. </div>
  85. </div>
  86. <h2 class="subsection-title">Methods</h2>
  87. <h3 class="name name-method" id="generate" translate="no">.<a href="#generate">generate</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span>, output : <span class="param-type">string</span> )</span><span class="type-signature"> : string</span> </h3>
  88. <div class="method">
  89. <div class="description">
  90. <p>Generates the code snippet of the storage node. If no <code>storeNode</code>
  91. is defined, the texture node is generated as normal texture.</p>
  92. </div>
  93. <table class="params">
  94. <tbody>
  95. <tr>
  96. <td class="name"><code>builder</code></td>
  97. <td class="description last"><p>The current node builder.</p></td>
  98. </tr>
  99. <tr>
  100. <td class="name"><code>output</code></td>
  101. <td class="description last"><p>The current output.</p></td>
  102. </tr>
  103. </tbody>
  104. </table>
  105. <dl class="details">
  106. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TextureNode.html#generate">TextureNode#generate</a></dt>
  107. </dl>
  108. <dl class="details">
  109. <dt class="tag-returns"><strong>Returns:</strong> The generated code snippet.</dt>
  110. </dl>
  111. </div>
  112. <h3 class="name name-method" id="generateStore" translate="no">.<a href="#generateStore">generateStore</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span> </h3>
  113. <div class="method">
  114. <div class="description">
  115. <p>Generates the code snippet of the storage texture node.</p>
  116. </div>
  117. <table class="params">
  118. <tbody>
  119. <tr>
  120. <td class="name"><code>builder</code></td>
  121. <td class="description last"><p>The current node builder.</p></td>
  122. </tr>
  123. </tbody>
  124. </table>
  125. </div>
  126. <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>
  127. <div class="method">
  128. <div class="description">
  129. <p>Overwrites the default implementation to return a fixed value <code>'storageTexture'</code>.</p>
  130. </div>
  131. <table class="params">
  132. <tbody>
  133. <tr>
  134. <td class="name"><code>builder</code></td>
  135. <td class="description last"><p>The current node builder.</p></td>
  136. </tr>
  137. </tbody>
  138. </table>
  139. <dl class="details">
  140. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TextureNode.html#getInputType">TextureNode#getInputType</a></dt>
  141. </dl>
  142. <dl class="details">
  143. <dt class="tag-returns"><strong>Returns:</strong> The input type.</dt>
  144. </dl>
  145. </div>
  146. <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="StorageTextureNode.html">StorageTextureNode</a></span> </h3>
  147. <div class="method">
  148. <div class="description">
  149. <p>Defines the node access.</p>
  150. </div>
  151. <table class="params">
  152. <tbody>
  153. <tr>
  154. <td class="name"><code>value</code></td>
  155. <td class="description last"><p>The node access.</p></td>
  156. </tr>
  157. </tbody>
  158. </table>
  159. <dl class="details">
  160. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  161. </dl>
  162. </div>
  163. <h3 class="name name-method" id="setMipLevel" translate="no">.<a href="#setMipLevel">setMipLevel</a><span class="signature">( level : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="StorageTextureNode.html">StorageTextureNode</a></span> </h3>
  164. <div class="method">
  165. <div class="description">
  166. <p>Sets the mip level to write to.</p>
  167. </div>
  168. <table class="params">
  169. <tbody>
  170. <tr>
  171. <td class="name"><code>level</code></td>
  172. <td class="description last"><p>The mip level.</p></td>
  173. </tr>
  174. </tbody>
  175. </table>
  176. <dl class="details">
  177. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  178. </dl>
  179. </div>
  180. <h3 class="name name-method" id="toReadOnly" translate="no">.<a href="#toReadOnly">toReadOnly</a><span class="signature">()</span><span class="type-signature"> : <a href="StorageTextureNode.html">StorageTextureNode</a></span> </h3>
  181. <div class="method">
  182. <div class="description">
  183. <p>Convenience method for configuring a read-only node access.</p>
  184. </div>
  185. <dl class="details">
  186. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  187. </dl>
  188. </div>
  189. <h3 class="name name-method" id="toReadWrite" translate="no">.<a href="#toReadWrite">toReadWrite</a><span class="signature">()</span><span class="type-signature"> : <a href="StorageTextureNode.html">StorageTextureNode</a></span> </h3>
  190. <div class="method">
  191. <div class="description">
  192. <p>Convenience method for configuring a read/write node access.</p>
  193. </div>
  194. <dl class="details">
  195. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  196. </dl>
  197. </div>
  198. <h3 class="name name-method" id="toWriteOnly" translate="no">.<a href="#toWriteOnly">toWriteOnly</a><span class="signature">()</span><span class="type-signature"> : <a href="StorageTextureNode.html">StorageTextureNode</a></span> </h3>
  199. <div class="method">
  200. <div class="description">
  201. <p>Convenience method for configuring a write-only node access.</p>
  202. </div>
  203. <dl class="details">
  204. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  205. </dl>
  206. </div>
  207. <h2 class="subsection-title">Source</h2>
  208. <p>
  209. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/accessors/StorageTextureNode.js" target="_blank" rel="noopener" translate="no">src/nodes/accessors/StorageTextureNode.js</a>
  210. </p>
  211. </article>
  212. </section>
  213. <script src="../scripts/linenumber.js"></script>
  214. <script src="../scripts/page.js"></script>
  215. </body>
  216. </html>
粤ICP备19079148号