EffectComposer.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>EffectComposer - 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. <h1 translate="no">EffectComposer</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>Used to implement post-processing effects in three.js.
  16. The class manages a chain of post-processing passes to produce the final visual result.
  17. Post-processing passes are executed in order of their addition/insertion.
  18. The last pass is automatically rendered to screen.</p>
  19. <p>This module can only be used with <a href="WebGLRenderer.html">WebGLRenderer</a>.</p></div>
  20. <h2>Code Example</h2>
  21. <div translate="no"><pre><code class="language-js">const composer = new EffectComposer( renderer );
  22. // adding some passes
  23. const renderPass = new RenderPass( scene, camera );
  24. composer.addPass( renderPass );
  25. const glitchPass = new GlitchPass();
  26. composer.addPass( glitchPass );
  27. const outputPass = new OutputPass()
  28. composer.addPass( outputPass );
  29. function animate() {
  30. composer.render(); // instead of renderer.render()
  31. }
  32. </code></pre></div>
  33. </header>
  34. <article>
  35. <h2 class="subsection-title">Import</h2>
  36. <p><span translate="no">EffectComposer</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  37. <pre><code class="language-js">import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';</code></pre>
  38. <div class="container-overview">
  39. <h2>Constructor</h2>
  40. <h3 class="name name-method" id="EffectComposer" translate="no">new <a href="#EffectComposer">EffectComposer</a><span class="signature">( renderer : <span class="param-type">WebGLRenderer</span>, renderTarget : <span class="param-type">WebGLRenderTarget</span> )</span> </h3>
  41. <div class="method">
  42. <div class="description">
  43. <p>Constructs a new effect composer.</p>
  44. </div>
  45. <table class="params">
  46. <tbody>
  47. <tr>
  48. <td class="name"><code>renderer</code></td>
  49. <td class="description last"><p>The renderer.</p></td>
  50. </tr>
  51. <tr>
  52. <td class="name"><code>renderTarget</code></td>
  53. <td class="description last"><p>This render target and a clone will
  54. be used as the internal read and write buffers. If not given, the composer creates
  55. the buffers automatically.</p></td>
  56. </tr>
  57. </tbody>
  58. </table>
  59. </div>
  60. </div>
  61. <h2 class="subsection-title">Properties</h2>
  62. <div class="member">
  63. <h3 class="name" id="passes" translate="no">.<a href="#passes">passes</a><span class="type-signature"> : Array.&lt;<a href="Pass.html">Pass</a>></span> </h3>
  64. <div class="description">
  65. <p>An array representing the (ordered) chain of post-processing passes.</p>
  66. </div>
  67. </div>
  68. <div class="member">
  69. <h3 class="name" id="readBuffer" translate="no">.<a href="#readBuffer">readBuffer</a><span class="type-signature"> : <a href="WebGLRenderTarget.html">WebGLRenderTarget</a></span> </h3>
  70. <div class="description">
  71. <p>A reference to the internal read buffer. Passes usually read
  72. the previous render result from this buffer.</p>
  73. </div>
  74. </div>
  75. <div class="member">
  76. <h3 class="name" id="renderToScreen" translate="no">.<a href="#renderToScreen">renderToScreen</a><span class="type-signature"> : boolean</span> </h3>
  77. <div class="description">
  78. <p>Whether the final pass is rendered to the screen (default framebuffer) or not.<br/>Default is <code>true</code>.</p>
  79. </div>
  80. </div>
  81. <div class="member">
  82. <h3 class="name" id="renderer" translate="no">.<a href="#renderer">renderer</a><span class="type-signature"> : <a href="WebGLRenderer.html">WebGLRenderer</a></span> </h3>
  83. <div class="description">
  84. <p>The renderer.</p>
  85. </div>
  86. </div>
  87. <div class="member">
  88. <h3 class="name" id="writeBuffer" translate="no">.<a href="#writeBuffer">writeBuffer</a><span class="type-signature"> : <a href="WebGLRenderTarget.html">WebGLRenderTarget</a></span> </h3>
  89. <div class="description">
  90. <p>A reference to the internal write buffer. Passes usually write
  91. their result into this buffer.</p>
  92. </div>
  93. </div>
  94. <h2 class="subsection-title">Methods</h2>
  95. <h3 class="name name-method" id="addPass" translate="no">.<a href="#addPass">addPass</a><span class="signature">( pass : <span class="param-type">Pass</span> )</span> </h3>
  96. <div class="method">
  97. <div class="description">
  98. <p>Adds the given pass to the pass chain.</p>
  99. </div>
  100. <table class="params">
  101. <tbody>
  102. <tr>
  103. <td class="name"><code>pass</code></td>
  104. <td class="description last"><p>The pass to add.</p></td>
  105. </tr>
  106. </tbody>
  107. </table>
  108. </div>
  109. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  110. <div class="method">
  111. <div class="description">
  112. <p>Frees the GPU-related resources allocated by this instance. Call this
  113. method whenever the composer is no longer used in your app.</p>
  114. </div>
  115. </div>
  116. <h3 class="name name-method" id="insertPass" translate="no">.<a href="#insertPass">insertPass</a><span class="signature">( pass : <span class="param-type">Pass</span>, index : <span class="param-type">number</span> )</span> </h3>
  117. <div class="method">
  118. <div class="description">
  119. <p>Inserts the given pass at a given index.</p>
  120. </div>
  121. <table class="params">
  122. <tbody>
  123. <tr>
  124. <td class="name"><code>pass</code></td>
  125. <td class="description last"><p>The pass to insert.</p></td>
  126. </tr>
  127. <tr>
  128. <td class="name"><code>index</code></td>
  129. <td class="description last"><p>The index into the pass chain.</p></td>
  130. </tr>
  131. </tbody>
  132. </table>
  133. </div>
  134. <h3 class="name name-method" id="isLastEnabledPass" translate="no">.<a href="#isLastEnabledPass">isLastEnabledPass</a><span class="signature">( passIndex : <span class="param-type">number</span> )</span><span class="type-signature"> : boolean</span> </h3>
  135. <div class="method">
  136. <div class="description">
  137. <p>Returns <code>true</code> if the pass for the given index is the last enabled pass in the pass chain.</p>
  138. </div>
  139. <table class="params">
  140. <tbody>
  141. <tr>
  142. <td class="name"><code>passIndex</code></td>
  143. <td class="description last"><p>The pass index.</p></td>
  144. </tr>
  145. </tbody>
  146. </table>
  147. <dl class="details">
  148. <dt class="tag-returns"><strong>Returns:</strong> Whether the pass for the given index is the last pass in the pass chain.</dt>
  149. </dl>
  150. </div>
  151. <h3 class="name name-method" id="removePass" translate="no">.<a href="#removePass">removePass</a><span class="signature">( pass : <span class="param-type">Pass</span> )</span> </h3>
  152. <div class="method">
  153. <div class="description">
  154. <p>Removes the given pass from the pass chain.</p>
  155. </div>
  156. <table class="params">
  157. <tbody>
  158. <tr>
  159. <td class="name"><code>pass</code></td>
  160. <td class="description last"><p>The pass to remove.</p></td>
  161. </tr>
  162. </tbody>
  163. </table>
  164. </div>
  165. <h3 class="name name-method" id="render" translate="no">.<a href="#render">render</a><span class="signature">( deltaTime : <span class="param-type">number</span> )</span> </h3>
  166. <div class="method">
  167. <div class="description">
  168. <p>Executes all enabled post-processing passes in order to produce the final frame.</p>
  169. </div>
  170. <table class="params">
  171. <tbody>
  172. <tr>
  173. <td class="name"><code>deltaTime</code></td>
  174. <td class="description last"><p>The delta time in seconds. If not given, the composer computes
  175. its own time delta value.</p></td>
  176. </tr>
  177. </tbody>
  178. </table>
  179. </div>
  180. <h3 class="name name-method" id="reset" translate="no">.<a href="#reset">reset</a><span class="signature">( renderTarget : <span class="param-type">WebGLRenderTarget</span> )</span> </h3>
  181. <div class="method">
  182. <div class="description">
  183. <p>Resets the internal state of the EffectComposer.</p>
  184. </div>
  185. <table class="params">
  186. <tbody>
  187. <tr>
  188. <td class="name"><code>renderTarget</code></td>
  189. <td class="description last"><p>This render target has the same purpose like
  190. the one from the constructor. If set, it is used to setup the read and write buffers.</p></td>
  191. </tr>
  192. </tbody>
  193. </table>
  194. </div>
  195. <h3 class="name name-method" id="setPixelRatio" translate="no">.<a href="#setPixelRatio">setPixelRatio</a><span class="signature">( pixelRatio : <span class="param-type">number</span> )</span> </h3>
  196. <div class="method">
  197. <div class="description">
  198. <p>Sets device pixel ratio. This is usually used for HiDPI device to prevent blurring output.
  199. Setting the pixel ratio will automatically resize the composer.</p>
  200. </div>
  201. <table class="params">
  202. <tbody>
  203. <tr>
  204. <td class="name"><code>pixelRatio</code></td>
  205. <td class="description last"><p>The pixel ratio to set.</p></td>
  206. </tr>
  207. </tbody>
  208. </table>
  209. </div>
  210. <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>
  211. <div class="method">
  212. <div class="description">
  213. <p>Resizes the internal read and write buffers as well as all passes. Similar to <a href="WebGLRenderer.html#setSize">WebGLRenderer#setSize</a>,
  214. this method honors the current pixel ration.</p>
  215. </div>
  216. <table class="params">
  217. <tbody>
  218. <tr>
  219. <td class="name"><code>width</code></td>
  220. <td class="description last"><p>The width in logical pixels.</p></td>
  221. </tr>
  222. <tr>
  223. <td class="name"><code>height</code></td>
  224. <td class="description last"><p>The height in logical pixels.</p></td>
  225. </tr>
  226. </tbody>
  227. </table>
  228. </div>
  229. <h3 class="name name-method" id="swapBuffers" translate="no">.<a href="#swapBuffers">swapBuffers</a><span class="signature">()</span> </h3>
  230. <div class="method">
  231. <div class="description">
  232. <p>Swaps the internal read/write buffers.</p>
  233. </div>
  234. </div>
  235. <h2 class="subsection-title">Source</h2>
  236. <p>
  237. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/postprocessing/EffectComposer.js" target="_blank" rel="noopener" translate="no">examples/jsm/postprocessing/EffectComposer.js</a>
  238. </p>
  239. </article>
  240. </section>
  241. <script src="../scripts/linenumber.js"></script>
  242. <script src="../scripts/page.js"></script>
  243. </body>
  244. </html>
粤ICP备19079148号