GodraysNode.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>GodraysNode - 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="TempNode.html">TempNode</a> → </p>
  13. <h1 translate="no">GodraysNode</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>Post-Processing node for apply Screen-space raymarched godrays to a scene.</p>
  17. <p>After the godrays have been computed, it's recommened to apply a Bilateral
  18. Blur to the result to mitigate raymarching and noise artifacts.</p>
  19. <p>The composite with the scene pass is ideally done with <code>depthAwareBlend()</code>,
  20. which mitigates aliasing and light leaking.</p>
  21. <p>Limitations:</p>
  22. <ul>
  23. <li>Only point and directional lights are currently supported.</li>
  24. <li>The effect requires a full shadow setup. Meaning shadows must be enabled in the renderer,
  25. 3D objects must cast and receive shadows and the main light must cast shadows.</li>
  26. </ul>
  27. <p>Reference: This Node is a part of <a href="https://github.com/Ameobea/three-good-godrays" target="_blank" rel="noopener">three-good-godrays</a>.</p></div>
  28. <h2>Code Example</h2>
  29. <div translate="no"><pre><code class="language-js">const godraysPass = godrays( scenePassDepth, camera, light );
  30. const blurPass = bilateralBlur( godraysPassColor ); // optional blur
  31. const outputBlurred = depthAwareBlend( scenePassColor, blurPassColor, scenePassDepth, camera, { blendColor, edgeRadius, edgeStrength } ); // composite
  32. </code></pre></div>
  33. </header>
  34. <article>
  35. <h2 class="subsection-title">Import</h2>
  36. <p><span translate="no">GodraysNode</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank" rel="noopener">Installation#Addons</a>.</p>
  37. <pre><code class="language-js">import { godrays } from 'three/addons/tsl/display/GodraysNode.js';</code></pre>
  38. <div class="container-overview">
  39. <h2>Constructor</h2>
  40. <h3 class="name name-method" id="GodraysNode" translate="no">new <a href="#GodraysNode">GodraysNode</a><span class="signature">( depthNode : <span class="param-type"><a href="TextureNode.html">TextureNode</a></span>, camera : <span class="param-type"><a href="Camera.html">Camera</a></span>, light : <span class="param-type"><a href="DirectionalLight.html">DirectionalLight</a> | <a href="PointLight.html">PointLight</a></span> )</span> </h3>
  41. <div class="method">
  42. <div class="description">
  43. <p>Constructs a new Godrays node.</p>
  44. </div>
  45. <table class="params">
  46. <tbody>
  47. <tr>
  48. <td class="name">
  49. <strong translate="no">depthNode</strong>
  50. </td>
  51. <td class="description last">
  52. <p>A texture node that represents the scene's depth.</p>
  53. </td>
  54. </tr>
  55. <tr>
  56. <td class="name">
  57. <strong translate="no">camera</strong>
  58. </td>
  59. <td class="description last">
  60. <p>The camera the scene is rendered with.</p>
  61. </td>
  62. </tr>
  63. <tr>
  64. <td class="name">
  65. <strong translate="no">light</strong>
  66. </td>
  67. <td class="description last">
  68. <p>The light the godrays are rendered for.</p>
  69. </td>
  70. </tr>
  71. </tbody>
  72. </table>
  73. </div>
  74. </div>
  75. <h2 class="subsection-title">Properties</h2>
  76. <div class="member">
  77. <h3 class="name" id="density" translate="no">.<a href="#density">density</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;float></span> </h3>
  78. <div class="description">
  79. <p>The rate of accumulation for the godrays. Higher values roughly equate to more humid air/denser fog.</p>
  80. <p>Default is <code>0.7</code>.</p>
  81. </div>
  82. </div>
  83. <div class="member">
  84. <h3 class="name" id="depthNode" translate="no">.<a href="#depthNode">depthNode</a><span class="type-signature"> : <a href="TextureNode.html">TextureNode</a></span> </h3>
  85. <div class="description">
  86. <p>A node that represents the beauty pass's depth.</p>
  87. </div>
  88. </div>
  89. <div class="member">
  90. <h3 class="name" id="distanceAttenuation" translate="no">.<a href="#distanceAttenuation">distanceAttenuation</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;float></span> </h3>
  91. <div class="description">
  92. <p>Higher values decrease the accumulation of godrays the further away they are from the light source.</p>
  93. <p>Default is <code>2</code>.</p>
  94. </div>
  95. </div>
  96. <div class="member">
  97. <h3 class="name" id="maxDensity" translate="no">.<a href="#maxDensity">maxDensity</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;float></span> </h3>
  98. <div class="description">
  99. <p>The maximum density of the godrays. Limits the maximum brightness of the godrays.</p>
  100. <p>Default is <code>0.5</code>.</p>
  101. </div>
  102. </div>
  103. <div class="member">
  104. <h3 class="name" id="raymarchSteps" translate="no">.<a href="#raymarchSteps">raymarchSteps</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;uint></span> </h3>
  105. <div class="description">
  106. <p>The number of raymarching steps</p>
  107. <p>Default is <code>60</code>.</p>
  108. </div>
  109. </div>
  110. <div class="member">
  111. <h3 class="name" id="resolutionScale" translate="no">.<a href="#resolutionScale">resolutionScale</a><span class="type-signature"> : number</span> </h3>
  112. <div class="description">
  113. <p>The resolution scale.</p>
  114. </div>
  115. </div>
  116. <div class="member">
  117. <h3 class="name" id="updateBeforeType" translate="no">.<a href="#updateBeforeType">updateBeforeType</a><span class="type-signature"> : string</span> </h3>
  118. <div class="description">
  119. <p>The <code>updateBeforeType</code> is set to <code>NodeUpdateType.FRAME</code> since the node renders
  120. its effect once per frame in <code>updateBefore()</code>.</p>
  121. <p>Default is <code>'frame'</code>.</p>
  122. </div>
  123. <dl class="details">
  124. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#updateBeforeType">TempNode#updateBeforeType</a></dt>
  125. </dl>
  126. </div>
  127. <h2 class="subsection-title">Methods</h2>
  128. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  129. <div class="method">
  130. <div class="description">
  131. <p>Frees internal resources. This method should be called
  132. when the effect is no longer required.</p>
  133. </div>
  134. <dl class="details">
  135. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#dispose">TempNode#dispose</a></dt>
  136. </dl>
  137. </div>
  138. <h3 class="name name-method" id="getTextureNode" translate="no">.<a href="#getTextureNode">getTextureNode</a><span class="signature">()</span><span class="type-signature"> : <a href="PassTextureNode.html">PassTextureNode</a></span> </h3>
  139. <div class="method">
  140. <div class="description">
  141. <p>Returns the result of the effect as a texture node.</p>
  142. </div>
  143. <dl class="details">
  144. <dt class="tag-returns"><strong>Returns:</strong> A texture node that represents the result of the effect.</dt>
  145. </dl>
  146. </div>
  147. <h3 class="name name-method" id="setSize" translate="no">.<a href="#setSize">setSize</a><span class="signature">( width : <span class="param-type">number</span>, height : <span class="param-type">number</span> )</span> </h3>
  148. <div class="method">
  149. <div class="description">
  150. <p>Sets the size of the effect.</p>
  151. </div>
  152. <table class="params">
  153. <tbody>
  154. <tr>
  155. <td class="name">
  156. <strong translate="no">width</strong>
  157. </td>
  158. <td class="description last">
  159. <p>The width of the effect.</p>
  160. </td>
  161. </tr>
  162. <tr>
  163. <td class="name">
  164. <strong translate="no">height</strong>
  165. </td>
  166. <td class="description last">
  167. <p>The height of the effect.</p>
  168. </td>
  169. </tr>
  170. </tbody>
  171. </table>
  172. </div>
  173. <h3 class="name name-method" id="setup" translate="no">.<a href="#setup">setup</a><span class="signature">( builder : <span class="param-type"><a href="NodeBuilder.html">NodeBuilder</a></span> )</span><span class="type-signature"> : <a href="PassTextureNode.html">PassTextureNode</a></span> </h3>
  174. <div class="method">
  175. <div class="description">
  176. <p>This method is used to setup the effect's TSL code.</p>
  177. </div>
  178. <table class="params">
  179. <tbody>
  180. <tr>
  181. <td class="name">
  182. <strong translate="no">builder</strong>
  183. </td>
  184. <td class="description last">
  185. <p>The current node builder.</p>
  186. </td>
  187. </tr>
  188. </tbody>
  189. </table>
  190. <dl class="details">
  191. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#setup">TempNode#setup</a></dt>
  192. </dl>
  193. </div>
  194. <h3 class="name name-method" id="updateBefore" translate="no">.<a href="#updateBefore">updateBefore</a><span class="signature">( frame : <span class="param-type"><a href="NodeFrame.html">NodeFrame</a></span> )</span> </h3>
  195. <div class="method">
  196. <div class="description">
  197. <p>This method is used to render the effect once per frame.</p>
  198. </div>
  199. <table class="params">
  200. <tbody>
  201. <tr>
  202. <td class="name">
  203. <strong translate="no">frame</strong>
  204. </td>
  205. <td class="description last">
  206. <p>The current node frame.</p>
  207. </td>
  208. </tr>
  209. </tbody>
  210. </table>
  211. <dl class="details">
  212. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#updateBefore">TempNode#updateBefore</a></dt>
  213. </dl>
  214. </div>
  215. <h2 class="subsection-title">Source</h2>
  216. <p>
  217. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/tsl/display/GodraysNode.js" translate="no" target="_blank" rel="noopener">examples/jsm/tsl/display/GodraysNode.js</a>
  218. </p>
  219. </article>
  220. </section>
  221. <script src="../scripts/linenumber.js"></script>
  222. <script src="../scripts/page.js"></script>
  223. </body>
  224. </html>
粤ICP备19079148号