FunctionNode.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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;Node></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"><code>code</code></td>
  51. <td class="description last"><p>The native code.<br/>Default is <code>''</code>.</p></td>
  52. </tr>
  53. <tr>
  54. <td class="name"><code>includes</code></td>
  55. <td class="description last"><p>An array of includes.<br/>Default is <code>[]</code>.</p></td>
  56. </tr>
  57. <tr>
  58. <td class="name"><code>language</code></td>
  59. <td class="description last"><p>The used language.<br/>Default is <code>''</code>.</p></td>
  60. </tr>
  61. </tbody>
  62. </table>
  63. </div>
  64. </div>
  65. <h2 class="subsection-title">Methods</h2>
  66. <h3 class="name name-method" id="getInputs" translate="no">.<a href="#getInputs">getInputs</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : Array.&lt;<a href="NodeFunctionInput.html">NodeFunctionInput</a>></span> </h3>
  67. <div class="method">
  68. <div class="description">
  69. <p>Returns the inputs of this function node.</p>
  70. </div>
  71. <table class="params">
  72. <tbody>
  73. <tr>
  74. <td class="name"><code>builder</code></td>
  75. <td class="description last"><p>The current node builder.</p></td>
  76. </tr>
  77. </tbody>
  78. </table>
  79. <dl class="details">
  80. <dt class="tag-returns"><strong>Returns:</strong> The inputs.</dt>
  81. </dl>
  82. </div>
  83. <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>
  84. <div class="method">
  85. <div class="description">
  86. <p>Returns the type of a member of this function node.</p>
  87. </div>
  88. <table class="params">
  89. <tbody>
  90. <tr>
  91. <td class="name"><code>builder</code></td>
  92. <td class="description last"><p>The current node builder.</p></td>
  93. </tr>
  94. <tr>
  95. <td class="name"><code>name</code></td>
  96. <td class="description last"><p>The name of the member.</p></td>
  97. </tr>
  98. </tbody>
  99. </table>
  100. <dl class="details">
  101. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="CodeNode.html#getMemberType">CodeNode#getMemberType</a></dt>
  102. </dl>
  103. <dl class="details">
  104. <dt class="tag-returns"><strong>Returns:</strong> The type of the member.</dt>
  105. </dl>
  106. </div>
  107. <h3 class="name name-method" id="getNodeFunction" translate="no">.<a href="#getNodeFunction">getNodeFunction</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : <a href="NodeFunction.html">NodeFunction</a></span> </h3>
  108. <div class="method">
  109. <div class="description">
  110. <p>Returns the node function for this function node.</p>
  111. </div>
  112. <table class="params">
  113. <tbody>
  114. <tr>
  115. <td class="name"><code>builder</code></td>
  116. <td class="description last"><p>The current node builder.</p></td>
  117. </tr>
  118. </tbody>
  119. </table>
  120. <dl class="details">
  121. <dt class="tag-returns"><strong>Returns:</strong> The node function.</dt>
  122. </dl>
  123. </div>
  124. <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>
  125. <div class="method">
  126. <div class="description">
  127. <p>Returns the type of this function node.</p>
  128. </div>
  129. <table class="params">
  130. <tbody>
  131. <tr>
  132. <td class="name"><code>builder</code></td>
  133. <td class="description last"><p>The current node builder.</p></td>
  134. </tr>
  135. </tbody>
  136. </table>
  137. <dl class="details">
  138. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="CodeNode.html#getNodeType">CodeNode#getNodeType</a></dt>
  139. </dl>
  140. <dl class="details">
  141. <dt class="tag-returns"><strong>Returns:</strong> The type.</dt>
  142. </dl>
  143. </div>
  144. <h2 class="subsection-title">Source</h2>
  145. <p>
  146. <a href="https://github.com/mrdoob/three.js/blob/master/src/nodes/code/FunctionNode.js" target="_blank" rel="noopener" translate="no">src/nodes/code/FunctionNode.js</a>
  147. </p>
  148. </article>
  149. </section>
  150. <script src="../scripts/linenumber.js"></script>
  151. <script src="../scripts/page.js"></script>
  152. </body>
  153. </html>
粤ICP备19079148号