1
0

StorageTextureNode.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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"><a href="StorageTexture.html">StorageTexture</a></span>, uvNode : <span class="param-type"><a href="Node.html">Node</a>.&lt;(vec2|vec3)></span>, storeNode : <span class="param-type"><a href="Node.html">Node</a></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">
  47. <strong translate="no">value</strong>
  48. </td>
  49. <td class="description last">
  50. <p>The storage texture.</p>
  51. </td>
  52. </tr>
  53. <tr>
  54. <td class="name">
  55. <strong translate="no">uvNode</strong>
  56. </td>
  57. <td class="description last">
  58. <p>The uv node.</p>
  59. </td>
  60. </tr>
  61. <tr>
  62. <td class="name">
  63. <strong translate="no">storeNode</strong>
  64. </td>
  65. <td class="description last">
  66. <p>The value node that should be stored in the texture.</p>
  67. <p>Default is <code>null</code>.</p>
  68. </td>
  69. </tr>
  70. </tbody>
  71. </table>
  72. </div>
  73. </div>
  74. <h2 class="subsection-title">Properties</h2>
  75. <div class="member">
  76. <h3 class="name" id="access" translate="no">.<a href="#access">access</a><span class="type-signature"> : string</span> </h3>
  77. <div class="description">
  78. <p>The access type of the texture node.</p>
  79. <p>Default is <code>'writeOnly'</code>.</p>
  80. </div>
  81. </div>
  82. <div class="member">
  83. <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>
  84. <div class="description">
  85. <p>This flag can be used for type testing.</p>
  86. <p>Default is <code>true</code>.</p>
  87. </div>
  88. </div>
  89. <div class="member">
  90. <h3 class="name" id="mipLevel" translate="no">.<a href="#mipLevel">mipLevel</a><span class="type-signature"> : number</span> </h3>
  91. <div class="description">
  92. <p>The mip level to write to for storage textures.</p>
  93. <p>Default is <code>0</code>.</p>
  94. </div>
  95. </div>
  96. <div class="member">
  97. <h3 class="name" id="storeNode" translate="no">.<a href="#storeNode">storeNode</a><span class="type-signature"> : <a href="Node.html">Node</a></span> </h3>
  98. <div class="description">
  99. <p>The value node that should be stored in the texture.</p>
  100. <p>Default is <code>null</code>.</p>
  101. </div>
  102. </div>
  103. <h2 class="subsection-title">Methods</h2>
  104. <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>, output : <span class="param-type">string</span> )</span><span class="type-signature"> : string</span> </h3>
  105. <div class="method">
  106. <div class="description">
  107. <p>Generates the code snippet of the storage node. If no <code>storeNode</code>
  108. is defined, the texture node is generated as normal texture.</p>
  109. </div>
  110. <table class="params">
  111. <tbody>
  112. <tr>
  113. <td class="name">
  114. <strong translate="no">builder</strong>
  115. </td>
  116. <td class="description last">
  117. <p>The current node builder.</p>
  118. </td>
  119. </tr>
  120. <tr>
  121. <td class="name">
  122. <strong translate="no">output</strong>
  123. </td>
  124. <td class="description last">
  125. <p>The current output.</p>
  126. </td>
  127. </tr>
  128. </tbody>
  129. </table>
  130. <dl class="details">
  131. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TextureNode.html#generate">TextureNode#generate</a></dt>
  132. </dl>
  133. <dl class="details">
  134. <dt class="tag-returns"><strong>Returns:</strong> The generated code snippet.</dt>
  135. </dl>
  136. </div>
  137. <h3 class="name name-method" id="generateSnippet" translate="no">.<a href="#generateSnippet">generateSnippet</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span>, textureProperty : <span class="param-type">string</span>, uvSnippet : <span class="param-type">string</span>, levelSnippet : <span class="param-type">string</span>, biasSnippet : <span class="param-type">string</span>, depthSnippet : <span class="param-type">string</span>, compareSnippet : <span class="param-type">string</span>, gradSnippet : <span class="param-type">Array.&lt;string></span>, offsetSnippet : <span class="param-type">string</span> )</span><span class="type-signature"> : string</span> </h3>
  138. <div class="method">
  139. <div class="description">
  140. <p>Generates the snippet for the storage texture.</p>
  141. </div>
  142. <table class="params">
  143. <tbody>
  144. <tr>
  145. <td class="name">
  146. <strong translate="no">builder</strong>
  147. </td>
  148. <td class="description last">
  149. <p>The current node builder.</p>
  150. </td>
  151. </tr>
  152. <tr>
  153. <td class="name">
  154. <strong translate="no">textureProperty</strong>
  155. </td>
  156. <td class="description last">
  157. <p>The texture property.</p>
  158. </td>
  159. </tr>
  160. <tr>
  161. <td class="name">
  162. <strong translate="no">uvSnippet</strong>
  163. </td>
  164. <td class="description last">
  165. <p>The uv snippet.</p>
  166. </td>
  167. </tr>
  168. <tr>
  169. <td class="name">
  170. <strong translate="no">levelSnippet</strong>
  171. </td>
  172. <td class="description last">
  173. <p>The level snippet.</p>
  174. </td>
  175. </tr>
  176. <tr>
  177. <td class="name">
  178. <strong translate="no">biasSnippet</strong>
  179. </td>
  180. <td class="description last">
  181. <p>The bias snippet.</p>
  182. </td>
  183. </tr>
  184. <tr>
  185. <td class="name">
  186. <strong translate="no">depthSnippet</strong>
  187. </td>
  188. <td class="description last">
  189. <p>The depth snippet.</p>
  190. </td>
  191. </tr>
  192. <tr>
  193. <td class="name">
  194. <strong translate="no">compareSnippet</strong>
  195. </td>
  196. <td class="description last">
  197. <p>The compare snippet.</p>
  198. </td>
  199. </tr>
  200. <tr>
  201. <td class="name">
  202. <strong translate="no">gradSnippet</strong>
  203. </td>
  204. <td class="description last">
  205. <p>The grad snippet.</p>
  206. </td>
  207. </tr>
  208. <tr>
  209. <td class="name">
  210. <strong translate="no">offsetSnippet</strong>
  211. </td>
  212. <td class="description last">
  213. <p>The offset snippet.</p>
  214. </td>
  215. </tr>
  216. </tbody>
  217. </table>
  218. <dl class="details">
  219. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TextureNode.html#generateSnippet">TextureNode#generateSnippet</a></dt>
  220. </dl>
  221. <dl class="details">
  222. <dt class="tag-returns"><strong>Returns:</strong> The generated code snippet.</dt>
  223. </dl>
  224. </div>
  225. <h3 class="name name-method" id="generateStore" translate="no">.<a href="#generateStore">generateStore</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span> </h3>
  226. <div class="method">
  227. <div class="description">
  228. <p>Generates the code snippet of the storage texture node.</p>
  229. </div>
  230. <table class="params">
  231. <tbody>
  232. <tr>
  233. <td class="name">
  234. <strong translate="no">builder</strong>
  235. </td>
  236. <td class="description last">
  237. <p>The current node builder.</p>
  238. </td>
  239. </tr>
  240. </tbody>
  241. </table>
  242. </div>
  243. <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>
  244. <div class="method">
  245. <div class="description">
  246. <p>Overwrites the default implementation to return a fixed value <code>'storageTexture'</code>.</p>
  247. </div>
  248. <table class="params">
  249. <tbody>
  250. <tr>
  251. <td class="name">
  252. <strong translate="no">builder</strong>
  253. </td>
  254. <td class="description last">
  255. <p>The current node builder.</p>
  256. </td>
  257. </tr>
  258. </tbody>
  259. </table>
  260. <dl class="details">
  261. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TextureNode.html#getInputType">TextureNode#getInputType</a></dt>
  262. </dl>
  263. <dl class="details">
  264. <dt class="tag-returns"><strong>Returns:</strong> The input type.</dt>
  265. </dl>
  266. </div>
  267. <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>
  268. <div class="method">
  269. <div class="description">
  270. <p>Defines the node access.</p>
  271. </div>
  272. <table class="params">
  273. <tbody>
  274. <tr>
  275. <td class="name">
  276. <strong translate="no">value</strong>
  277. </td>
  278. <td class="description last">
  279. <p>The node access.</p>
  280. </td>
  281. </tr>
  282. </tbody>
  283. </table>
  284. <dl class="details">
  285. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  286. </dl>
  287. </div>
  288. <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>
  289. <div class="method">
  290. <div class="description">
  291. <p>Sets the mip level to write to.</p>
  292. </div>
  293. <table class="params">
  294. <tbody>
  295. <tr>
  296. <td class="name">
  297. <strong translate="no">level</strong>
  298. </td>
  299. <td class="description last">
  300. <p>The mip level.</p>
  301. </td>
  302. </tr>
  303. </tbody>
  304. </table>
  305. <dl class="details">
  306. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  307. </dl>
  308. </div>
  309. <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>
  310. <div class="method">
  311. <div class="description">
  312. <p>Convenience method for configuring a read-only node access.</p>
  313. </div>
  314. <dl class="details">
  315. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  316. </dl>
  317. </div>
  318. <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>
  319. <div class="method">
  320. <div class="description">
  321. <p>Convenience method for configuring a read/write node access.</p>
  322. </div>
  323. <dl class="details">
  324. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  325. </dl>
  326. </div>
  327. <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>
  328. <div class="method">
  329. <div class="description">
  330. <p>Convenience method for configuring a write-only node access.</p>
  331. </div>
  332. <dl class="details">
  333. <dt class="tag-returns"><strong>Returns:</strong> A reference to this node.</dt>
  334. </dl>
  335. </div>
  336. <h2 class="subsection-title">Source</h2>
  337. <p>
  338. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/accessors/StorageTextureNode.js" translate="no" target="_blank" rel="noopener">src/nodes/accessors/StorageTextureNode.js</a>
  339. </p>
  340. </article>
  341. </section>
  342. <script src="../scripts/linenumber.js"></script>
  343. <script src="../scripts/page.js"></script>
  344. </body>
  345. </html>
粤ICP备19079148号