SSSNode.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>SSSNode - 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">SSSNode</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>Post processing node for applying Screen-Space Shadows (SSS) to a scene.</p>
  17. <p>Screen-Space Shadows (also known as Contact Shadows) should ideally be used to complement
  18. traditional shadow maps. They are best suited for rendering detailed shadows of smaller
  19. objects at a closer scale like intricate shadowing on highly detailed models. In other words:
  20. Use Shadow Maps for the foundation and Screen-Space Shadows for the details.</p>
  21. <p>The shadows produced by this implementation might have too hard edges for certain use cases.
  22. Use a box, gaussian or hash blur to soften the edges before doing the composite with the
  23. beauty pass. Code example:</p>
  24. <p>Limitations:</p>
  25. <ul>
  26. <li>Ideally the maximum shadow length should not exceed <code>1</code> meter. Otherwise the effect gets
  27. computationally very expensive since more samples during the ray marching process are evaluated.
  28. You can mitigate this issue by reducing the <code>quality</code> paramter.</li>
  29. <li>The effect can only be used with a single directional light, the main light of your scene.
  30. This main light usually represents the sun or daylight.</li>
  31. <li>Like other Screen-Space techniques SSS can only honor objects in the shadowing computation that
  32. are currently visible within the camera's view.</li>
  33. </ul>
  34. <p>References:</p>
  35. <ul>
  36. <li><a href="https://panoskarabelas.com/posts/screen_space_shadows/">https://panoskarabelas.com/posts/screen_space_shadows/</a>.</li>
  37. <li><a href="https://www.bendstudio.com/blog/inside-bend-screen-space-shadows/">https://www.bendstudio.com/blog/inside-bend-screen-space-shadows/</a>.</li>
  38. </ul></div>
  39. <h2>Code Example</h2>
  40. <div translate="no"><pre><code class="language-js">const sssPass = sss( scenePassDepth, camera, mainLight );
  41. const sssBlur = boxBlur( sssPass.r, { size: 2, separation: 1 } ); // optional blur
  42. </code></pre></div>
  43. </header>
  44. <article>
  45. <h2 class="subsection-title">Import</h2>
  46. <p><span translate="no">SSSNode</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  47. <pre><code class="language-js">import { sss } from 'three/addons/tsl/display/SSSNode.js';</code></pre>
  48. <div class="container-overview">
  49. <h2>Constructor</h2>
  50. <h3 class="name name-method" id="SSSNode" translate="no">new <a href="#SSSNode">SSSNode</a><span class="signature">( depthNode : <span class="param-type">TextureNode</span>, camera : <span class="param-type">Camera</span>, mainLight : <span class="param-type">DirectionalLight</span> )</span> </h3>
  51. <div class="method">
  52. <div class="description">
  53. <p>Constructs a new SSS node.</p>
  54. </div>
  55. <table class="params">
  56. <tbody>
  57. <tr>
  58. <td class="name"><code>depthNode</code></td>
  59. <td class="description last"><p>A texture node that represents the scene's depth.</p></td>
  60. </tr>
  61. <tr>
  62. <td class="name"><code>camera</code></td>
  63. <td class="description last"><p>The camera the scene is rendered with.</p></td>
  64. </tr>
  65. <tr>
  66. <td class="name"><code>mainLight</code></td>
  67. <td class="description last"><p>The main directional light of the scene.</p></td>
  68. </tr>
  69. </tbody>
  70. </table>
  71. </div>
  72. </div>
  73. <h2 class="subsection-title">Properties</h2>
  74. <div class="member">
  75. <h3 class="name" id="_frameId" translate="no">.<a href="#_frameId">_frameId</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;uint></span> </h3>
  76. <div class="description">
  77. <p>The frame ID use when temporal filtering is enabled.</p>
  78. </div>
  79. </div>
  80. <div class="member">
  81. <h3 class="name" id="_temporalOffset" translate="no">.<a href="#_temporalOffset">_temporalOffset</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;float></span> </h3>
  82. <div class="description">
  83. <p>Temporal offset added to the initial ray step.</p>
  84. </div>
  85. </div>
  86. <div class="member">
  87. <h3 class="name" id="depthNode" translate="no">.<a href="#depthNode">depthNode</a><span class="type-signature"> : <a href="TextureNode.html">TextureNode</a></span> </h3>
  88. <div class="description">
  89. <p>A node that represents the beauty pass's depth.</p>
  90. </div>
  91. </div>
  92. <div class="member">
  93. <h3 class="name" id="maxDistance" translate="no">.<a href="#maxDistance">maxDistance</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;float></span> </h3>
  94. <div class="description">
  95. <p>Maximum shadow length in world units. Longer shadows result in more computational
  96. overhead.<br/>Default is <code>0.1</code>.</p>
  97. </div>
  98. </div>
  99. <div class="member">
  100. <h3 class="name" id="quality" translate="no">.<a href="#quality">quality</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;float></span> </h3>
  101. <div class="description">
  102. <p>This parameter controls how detailed the raymarching process works.
  103. The value ranges is <code>[0,1]</code> where <code>1</code> means best quality (the maximum number
  104. of raymarching iterations/samples) and <code>0</code> means no samples at all.</p>
  105. <p>A quality of <code>0.5</code> is usually sufficient for most use cases. Try to keep
  106. this parameter as low as possible. Larger values result in noticeable more
  107. overhead.<br/>Default is <code>0.5</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. Valid values are in the range
  114. <code>[0,1]</code>. <code>1</code> means best quality but also results in
  115. more computational overhead. Setting to <code>0.5</code> means
  116. the effect is computed in half-resolution.<br/>Default is <code>1</code>.</p>
  117. </div>
  118. </div>
  119. <div class="member">
  120. <h3 class="name" id="shadowIntensity" translate="no">.<a href="#shadowIntensity">shadowIntensity</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;float></span> </h3>
  121. <div class="description">
  122. <p>Shadow intensity. Must be in the range <code>[0, 1]</code>.<br/>Default is <code>0.5</code>.</p>
  123. </div>
  124. </div>
  125. <div class="member">
  126. <h3 class="name" id="thickness" translate="no">.<a href="#thickness">thickness</a><span class="type-signature"> : <a href="UniformNode.html">UniformNode</a>.&lt;float></span> </h3>
  127. <div class="description">
  128. <p>Depth testing thickness.<br/>Default is <code>0.01</code>.</p>
  129. </div>
  130. </div>
  131. <div class="member">
  132. <h3 class="name" id="updateBeforeType" translate="no">.<a href="#updateBeforeType">updateBeforeType</a><span class="type-signature"> : string</span> </h3>
  133. <div class="description">
  134. <p>The <code>updateBeforeType</code> is set to <code>NodeUpdateType.FRAME</code> since the node renders
  135. its effect once per frame in <code>updateBefore()</code>.<br/>Default is <code>'frame'</code>.</p>
  136. </div>
  137. <dl class="details">
  138. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#updateBeforeType">TempNode#updateBeforeType</a></dt>
  139. </dl>
  140. </div>
  141. <div class="member">
  142. <h3 class="name" id="useTemporalFiltering" translate="no">.<a href="#useTemporalFiltering">useTemporalFiltering</a><span class="type-signature"> : boolean</span> </h3>
  143. <div class="description">
  144. <p>Whether to use temporal filtering or not. Setting this property to
  145. <code>true</code> requires the usage of <code>TRAANode</code>. This will help to reduce noice
  146. although it introduces typical TAA artifacts like ghosting and temporal
  147. instabilities.<br/>Default is <code>false</code>.</p>
  148. </div>
  149. </div>
  150. <h2 class="subsection-title">Methods</h2>
  151. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  152. <div class="method">
  153. <div class="description">
  154. <p>Frees internal resources. This method should be called
  155. when the effect is no longer required.</p>
  156. </div>
  157. <dl class="details">
  158. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#dispose">TempNode#dispose</a></dt>
  159. </dl>
  160. </div>
  161. <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>
  162. <div class="method">
  163. <div class="description">
  164. <p>Returns the result of the effect as a texture node.</p>
  165. </div>
  166. <dl class="details">
  167. <dt class="tag-returns"><strong>Returns:</strong> A texture node that represents the result of the effect.</dt>
  168. </dl>
  169. </div>
  170. <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>
  171. <div class="method">
  172. <div class="description">
  173. <p>Sets the size of the effect.</p>
  174. </div>
  175. <table class="params">
  176. <tbody>
  177. <tr>
  178. <td class="name"><code>width</code></td>
  179. <td class="description last"><p>The width of the effect.</p></td>
  180. </tr>
  181. <tr>
  182. <td class="name"><code>height</code></td>
  183. <td class="description last"><p>The height of the effect.</p></td>
  184. </tr>
  185. </tbody>
  186. </table>
  187. </div>
  188. <h3 class="name name-method" id="setup" translate="no">.<a href="#setup">setup</a><span class="signature">( builder : <span class="param-type">NodeBuilder</span> )</span><span class="type-signature"> : <a href="PassTextureNode.html">PassTextureNode</a></span> </h3>
  189. <div class="method">
  190. <div class="description">
  191. <p>This method is used to setup the effect's TSL code.</p>
  192. </div>
  193. <table class="params">
  194. <tbody>
  195. <tr>
  196. <td class="name"><code>builder</code></td>
  197. <td class="description last"><p>The current node builder.</p></td>
  198. </tr>
  199. </tbody>
  200. </table>
  201. <dl class="details">
  202. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#setup">TempNode#setup</a></dt>
  203. </dl>
  204. <dl class="details">
  205. <dt class="tag-returns"><strong>Returns:</strong> </dt>
  206. </dl>
  207. </div>
  208. <h3 class="name name-method" id="updateBefore" translate="no">.<a href="#updateBefore">updateBefore</a><span class="signature">( frame : <span class="param-type">NodeFrame</span> )</span> </h3>
  209. <div class="method">
  210. <div class="description">
  211. <p>This method is used to render the effect once per frame.</p>
  212. </div>
  213. <table class="params">
  214. <tbody>
  215. <tr>
  216. <td class="name"><code>frame</code></td>
  217. <td class="description last"><p>The current node frame.</p></td>
  218. </tr>
  219. </tbody>
  220. </table>
  221. <dl class="details">
  222. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#updateBefore">TempNode#updateBefore</a></dt>
  223. </dl>
  224. </div>
  225. <h2 class="subsection-title">Source</h2>
  226. <p>
  227. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/tsl/display/SSSNode.js" target="_blank" rel="noopener" translate="no">examples/jsm/tsl/display/SSSNode.js</a>
  228. </p>
  229. </article>
  230. </section>
  231. <script src="../scripts/linenumber.js"></script>
  232. <script src="../scripts/page.js"></script>
  233. </body>
  234. </html>
粤ICP备19079148号