1
0

SSSNode.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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/" target="_blank" rel="noopener">https://panoskarabelas.com/posts/screen_space_shadows/</a>.</li>
  37. <li><a href="https://www.bendstudio.com/blog/inside-bend-screen-space-shadows/" target="_blank" rel="noopener">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" rel="noopener">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"><a href="TextureNode.html">TextureNode</a></span>, camera : <span class="param-type"><a href="Camera.html">Camera</a></span>, mainLight : <span class="param-type"><a href="DirectionalLight.html">DirectionalLight</a></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">
  59. <strong>depthNode</strong>
  60. </td>
  61. <td class="description last">
  62. <p>A texture node that represents the scene's depth.</p>
  63. </td>
  64. </tr>
  65. <tr>
  66. <td class="name">
  67. <strong>camera</strong>
  68. </td>
  69. <td class="description last">
  70. <p>The camera the scene is rendered with.</p>
  71. </td>
  72. </tr>
  73. <tr>
  74. <td class="name">
  75. <strong>mainLight</strong>
  76. </td>
  77. <td class="description last">
  78. <p>The main directional light of the scene.</p>
  79. </td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. </div>
  84. </div>
  85. <h2 class="subsection-title">Properties</h2>
  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.</p>
  97. <p>Default is <code>0.1</code>.</p>
  98. </div>
  99. </div>
  100. <div class="member">
  101. <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>
  102. <div class="description">
  103. <p>This parameter controls how detailed the raymarching process works.
  104. The value ranges is <code>[0,1]</code> where <code>1</code> means best quality (the maximum number
  105. of raymarching iterations/samples) and <code>0</code> means no samples at all.</p>
  106. <p>A quality of <code>0.5</code> is usually sufficient for most use cases. Try to keep
  107. this parameter as low as possible. Larger values result in noticeable more
  108. overhead.</p>
  109. <p>Default is <code>0.5</code>.</p>
  110. </div>
  111. </div>
  112. <div class="member">
  113. <h3 class="name" id="resolutionScale" translate="no">.<a href="#resolutionScale">resolutionScale</a><span class="type-signature"> : number</span> </h3>
  114. <div class="description">
  115. <p>The resolution scale. Valid values are in the range
  116. <code>[0,1]</code>. <code>1</code> means best quality but also results in
  117. more computational overhead. Setting to <code>0.5</code> means
  118. the effect is computed in half-resolution.</p>
  119. <p>Default is <code>1</code>.</p>
  120. </div>
  121. </div>
  122. <div class="member">
  123. <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>
  124. <div class="description">
  125. <p>Shadow intensity. Must be in the range <code>[0, 1]</code>.</p>
  126. <p>Default is <code>1.0</code>.</p>
  127. </div>
  128. </div>
  129. <div class="member">
  130. <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>
  131. <div class="description">
  132. <p>Depth testing thickness.</p>
  133. <p>Default is <code>0.01</code>.</p>
  134. </div>
  135. </div>
  136. <div class="member">
  137. <h3 class="name" id="updateBeforeType" translate="no">.<a href="#updateBeforeType">updateBeforeType</a><span class="type-signature"> : string</span> </h3>
  138. <div class="description">
  139. <p>The <code>updateBeforeType</code> is set to <code>NodeUpdateType.FRAME</code> since the node renders
  140. its effect once per frame in <code>updateBefore()</code>.</p>
  141. <p>Default is <code>'frame'</code>.</p>
  142. </div>
  143. <dl class="details">
  144. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#updateBeforeType">TempNode#updateBeforeType</a></dt>
  145. </dl>
  146. </div>
  147. <div class="member">
  148. <h3 class="name" id="useTemporalFiltering" translate="no">.<a href="#useTemporalFiltering">useTemporalFiltering</a><span class="type-signature"> : boolean</span> </h3>
  149. <div class="description">
  150. <p>Whether to use temporal filtering or not. Setting this property to
  151. <code>true</code> requires the usage of <code>TRAANode</code>. This will help to reduce noice
  152. although it introduces typical TAA artifacts like ghosting and temporal
  153. instabilities.</p>
  154. <p>Default is <code>false</code>.</p>
  155. </div>
  156. </div>
  157. <h2 class="subsection-title">Methods</h2>
  158. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  159. <div class="method">
  160. <div class="description">
  161. <p>Frees internal resources. This method should be called
  162. when the effect is no longer required.</p>
  163. </div>
  164. <dl class="details">
  165. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#dispose">TempNode#dispose</a></dt>
  166. </dl>
  167. </div>
  168. <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>
  169. <div class="method">
  170. <div class="description">
  171. <p>Returns the result of the effect as a texture node.</p>
  172. </div>
  173. <dl class="details">
  174. <dt class="tag-returns"><strong>Returns:</strong> A texture node that represents the result of the effect.</dt>
  175. </dl>
  176. </div>
  177. <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>
  178. <div class="method">
  179. <div class="description">
  180. <p>Sets the size of the effect.</p>
  181. </div>
  182. <table class="params">
  183. <tbody>
  184. <tr>
  185. <td class="name">
  186. <strong>width</strong>
  187. </td>
  188. <td class="description last">
  189. <p>The width of the effect.</p>
  190. </td>
  191. </tr>
  192. <tr>
  193. <td class="name">
  194. <strong>height</strong>
  195. </td>
  196. <td class="description last">
  197. <p>The height of the effect.</p>
  198. </td>
  199. </tr>
  200. </tbody>
  201. </table>
  202. </div>
  203. <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>
  204. <div class="method">
  205. <div class="description">
  206. <p>This method is used to setup the effect's TSL code.</p>
  207. </div>
  208. <table class="params">
  209. <tbody>
  210. <tr>
  211. <td class="name">
  212. <strong>builder</strong>
  213. </td>
  214. <td class="description last">
  215. <p>The current node builder.</p>
  216. </td>
  217. </tr>
  218. </tbody>
  219. </table>
  220. <dl class="details">
  221. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#setup">TempNode#setup</a></dt>
  222. </dl>
  223. </div>
  224. <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>
  225. <div class="method">
  226. <div class="description">
  227. <p>This method is used to render the effect once per frame.</p>
  228. </div>
  229. <table class="params">
  230. <tbody>
  231. <tr>
  232. <td class="name">
  233. <strong>frame</strong>
  234. </td>
  235. <td class="description last">
  236. <p>The current node frame.</p>
  237. </td>
  238. </tr>
  239. </tbody>
  240. </table>
  241. <dl class="details">
  242. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="TempNode.html#updateBefore">TempNode#updateBefore</a></dt>
  243. </dl>
  244. </div>
  245. <h2 class="subsection-title">Source</h2>
  246. <p>
  247. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/tsl/display/SSSNode.js" translate="no" target="_blank" rel="noopener">examples/jsm/tsl/display/SSSNode.js</a>
  248. </p>
  249. </article>
  250. </section>
  251. <script src="../scripts/linenumber.js"></script>
  252. <script src="../scripts/page.js"></script>
  253. </body>
  254. </html>
粤ICP备19079148号