FunctionNode.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>FunctionNode - 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="CodeNode.html">CodeNode</a> → </p>
  13. <h1 translate="no">FunctionNode</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>This class represents a native shader function. It can be used to implement
  17. certain aspects of a node material with native shader code. There are two predefined
  18. TSL functions for easier usage.</p>
  19. <ul>
  20. <li><code>wgslFn</code>: Creates a WGSL function node.</li>
  21. <li><code>glslFn</code>: Creates a GLSL function node.</li>
  22. </ul>
  23. <p>A basic example with one include looks like so:</p></div>
  24. <h2>Code Example</h2>
  25. <div translate="no"><pre><code class="language-js">const desaturateWGSLFn = wgslFn( `
  26. fn desaturate( color:vec3&lt;f32> ) -> vec3&lt;f32> {
  27. let lum = vec3&lt;f32>( 0.299, 0.587, 0.114 );
  28. return vec3&lt;f32>( dot( lum, color ) );
  29. }`
  30. );
  31. const someWGSLFn = wgslFn( `
  32. fn someFn( color:vec3&lt;f32> ) -> vec3&lt;f32> {
  33. return desaturate( color );
  34. }
  35. `, [ desaturateWGSLFn ] );
  36. material.colorNode = someWGSLFn( { color: texture( map ) } );
  37. </code></pre></div>
  38. </header>
  39. <article>
  40. <div class="container-overview">
  41. <h2>Constructor</h2>
  42. <h3 class="name name-method" id="FunctionNode" translate="no">new <a href="#FunctionNode">FunctionNode</a><span class="signature">( code : <span class="param-type">string</span>, includes : <span class="param-type">Array.&lt;<a href="Node.html">Node</a>></span>, language : <span class="param-type">'js' | 'wgsl' | 'glsl'</span> )</span> </h3>
  43. <div class="method">
  44. <div class="description">
  45. <p>Constructs a new function node.</p>
  46. </div>
  47. <table class="params">
  48. <tbody>
  49. <tr>
  50. <td class="name">
  51. <strong>code</strong>
  52. </td>
  53. <td class="description last">
  54. <p>The native code.</p>
  55. <p>Default is <code>''</code>.</p>
  56. </td>
  57. </tr>
  58. <tr>
  59. <td class="name">
  60. <strong>includes</strong>
  61. </td>
  62. <td class="description last">
  63. <p>An array of includes.</p>
  64. <p>Default is <code>[]</code>.</p>
  65. </td>
  66. </tr>
  67. <tr>
  68. <td class="name">
  69. <strong>language</strong>
  70. </td>
  71. <td class="description last">
  72. <p>The used language.</p>
  73. <p>Default is <code>''</code>.</p>
  74. </td>
  75. </tr>
  76. </tbody>
  77. </table>
  78. </div>
  79. </div>
  80. <h2 class="subsection-title">Methods</h2>
  81. <h3 class="name name-method" id="getInputs" translate="no">.<a href="#getInputs">getInputs</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : Array.&lt;<a href="NodeFunctionInput.html">NodeFunctionInput</a>></span> </h3>
  82. <div class="method">
  83. <div class="description">
  84. <p>Returns the inputs of this function node.</p>
  85. </div>
  86. <table class="params">
  87. <tbody>
  88. <tr>
  89. <td class="name">
  90. <strong>builder</strong>
  91. </td>
  92. <td class="description last">
  93. <p>The current node builder.</p>
  94. </td>
  95. </tr>
  96. </tbody>
  97. </table>
  98. <dl class="details">
  99. <dt class="tag-returns"><strong>Returns:</strong> The inputs.</dt>
  100. </dl>
  101. </div>
  102. <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>
  103. <div class="method">
  104. <div class="description">
  105. <p>Returns the type of a member of this function node.</p>
  106. </div>
  107. <table class="params">
  108. <tbody>
  109. <tr>
  110. <td class="name">
  111. <strong>builder</strong>
  112. </td>
  113. <td class="description last">
  114. <p>The current node builder.</p>
  115. </td>
  116. </tr>
  117. <tr>
  118. <td class="name">
  119. <strong>name</strong>
  120. </td>
  121. <td class="description last">
  122. <p>The name of the member.</p>
  123. </td>
  124. </tr>
  125. </tbody>
  126. </table>
  127. <dl class="details">
  128. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="CodeNode.html#getMemberType">CodeNode#getMemberType</a></dt>
  129. </dl>
  130. <dl class="details">
  131. <dt class="tag-returns"><strong>Returns:</strong> The type of the member.</dt>
  132. </dl>
  133. </div>
  134. <h3 class="name name-method" id="getNodeFunction" translate="no">.<a href="#getNodeFunction">getNodeFunction</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : <a href="NodeFunction.html">NodeFunction</a></span> </h3>
  135. <div class="method">
  136. <div class="description">
  137. <p>Returns the node function for this function node.</p>
  138. </div>
  139. <table class="params">
  140. <tbody>
  141. <tr>
  142. <td class="name">
  143. <strong>builder</strong>
  144. </td>
  145. <td class="description last">
  146. <p>The current node builder.</p>
  147. </td>
  148. </tr>
  149. </tbody>
  150. </table>
  151. <dl class="details">
  152. <dt class="tag-returns"><strong>Returns:</strong> The node function.</dt>
  153. </dl>
  154. </div>
  155. <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>
  156. <div class="method">
  157. <div class="description">
  158. <p>Returns the type of this function node.</p>
  159. </div>
  160. <table class="params">
  161. <tbody>
  162. <tr>
  163. <td class="name">
  164. <strong>builder</strong>
  165. </td>
  166. <td class="description last">
  167. <p>The current node builder.</p>
  168. </td>
  169. </tr>
  170. </tbody>
  171. </table>
  172. <dl class="details">
  173. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="CodeNode.html#getNodeType">CodeNode#getNodeType</a></dt>
  174. </dl>
  175. <dl class="details">
  176. <dt class="tag-returns"><strong>Returns:</strong> The type.</dt>
  177. </dl>
  178. </div>
  179. <h2 class="subsection-title">Source</h2>
  180. <p>
  181. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/code/FunctionNode.js" translate="no" target="_blank" rel="noopener">src/nodes/code/FunctionNode.js</a>
  182. </p>
  183. </article>
  184. </section>
  185. <script src="../scripts/linenumber.js"></script>
  186. <script src="../scripts/page.js"></script>
  187. </body>
  188. </html>
粤ICP备19079148号