EffectComposer.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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" rel="noopener">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"><a href="WebGLRenderer.html">WebGLRenderer</a></span>, renderTarget : <span class="param-type"><a href="WebGLRenderTarget.html">WebGLRenderTarget</a></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">
  49. <strong>renderer</strong>
  50. </td>
  51. <td class="description last">
  52. <p>The renderer.</p>
  53. </td>
  54. </tr>
  55. <tr>
  56. <td class="name">
  57. <strong>renderTarget</strong>
  58. </td>
  59. <td class="description last">
  60. <p>This render target and a clone will
  61. be used as the internal read and write buffers. If not given, the composer creates
  62. the buffers automatically.</p>
  63. </td>
  64. </tr>
  65. </tbody>
  66. </table>
  67. </div>
  68. </div>
  69. <h2 class="subsection-title">Properties</h2>
  70. <div class="member">
  71. <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>
  72. <div class="description">
  73. <p>An array representing the (ordered) chain of post-processing passes.</p>
  74. </div>
  75. </div>
  76. <div class="member">
  77. <h3 class="name" id="readBuffer" translate="no">.<a href="#readBuffer">readBuffer</a><span class="type-signature"> : <a href="WebGLRenderTarget.html">WebGLRenderTarget</a></span> </h3>
  78. <div class="description">
  79. <p>A reference to the internal read buffer. Passes usually read
  80. the previous render result from this buffer.</p>
  81. </div>
  82. </div>
  83. <div class="member">
  84. <h3 class="name" id="renderToScreen" translate="no">.<a href="#renderToScreen">renderToScreen</a><span class="type-signature"> : boolean</span> </h3>
  85. <div class="description">
  86. <p>Whether the final pass is rendered to the screen (default framebuffer) or not.</p>
  87. <p>Default is <code>true</code>.</p>
  88. </div>
  89. </div>
  90. <div class="member">
  91. <h3 class="name" id="renderer" translate="no">.<a href="#renderer">renderer</a><span class="type-signature"> : <a href="WebGLRenderer.html">WebGLRenderer</a></span> </h3>
  92. <div class="description">
  93. <p>The renderer.</p>
  94. </div>
  95. </div>
  96. <div class="member">
  97. <h3 class="name" id="writeBuffer" translate="no">.<a href="#writeBuffer">writeBuffer</a><span class="type-signature"> : <a href="WebGLRenderTarget.html">WebGLRenderTarget</a></span> </h3>
  98. <div class="description">
  99. <p>A reference to the internal write buffer. Passes usually write
  100. their result into this buffer.</p>
  101. </div>
  102. </div>
  103. <h2 class="subsection-title">Methods</h2>
  104. <h3 class="name name-method" id="addPass" translate="no">.<a href="#addPass">addPass</a><span class="signature">( pass : <span class="param-type"><a href="Pass.html">Pass</a></span> )</span> </h3>
  105. <div class="method">
  106. <div class="description">
  107. <p>Adds the given pass to the pass chain.</p>
  108. </div>
  109. <table class="params">
  110. <tbody>
  111. <tr>
  112. <td class="name">
  113. <strong>pass</strong>
  114. </td>
  115. <td class="description last">
  116. <p>The pass to add.</p>
  117. </td>
  118. </tr>
  119. </tbody>
  120. </table>
  121. </div>
  122. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  123. <div class="method">
  124. <div class="description">
  125. <p>Frees the GPU-related resources allocated by this instance. Call this
  126. method whenever the composer is no longer used in your app.</p>
  127. </div>
  128. </div>
  129. <h3 class="name name-method" id="insertPass" translate="no">.<a href="#insertPass">insertPass</a><span class="signature">( pass : <span class="param-type"><a href="Pass.html">Pass</a></span>, index : <span class="param-type">number</span> )</span> </h3>
  130. <div class="method">
  131. <div class="description">
  132. <p>Inserts the given pass at a given index.</p>
  133. </div>
  134. <table class="params">
  135. <tbody>
  136. <tr>
  137. <td class="name">
  138. <strong>pass</strong>
  139. </td>
  140. <td class="description last">
  141. <p>The pass to insert.</p>
  142. </td>
  143. </tr>
  144. <tr>
  145. <td class="name">
  146. <strong>index</strong>
  147. </td>
  148. <td class="description last">
  149. <p>The index into the pass chain.</p>
  150. </td>
  151. </tr>
  152. </tbody>
  153. </table>
  154. </div>
  155. <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>
  156. <div class="method">
  157. <div class="description">
  158. <p>Returns <code>true</code> if the pass for the given index is the last enabled pass in the pass chain.</p>
  159. </div>
  160. <table class="params">
  161. <tbody>
  162. <tr>
  163. <td class="name">
  164. <strong>passIndex</strong>
  165. </td>
  166. <td class="description last">
  167. <p>The pass index.</p>
  168. </td>
  169. </tr>
  170. </tbody>
  171. </table>
  172. <dl class="details">
  173. <dt class="tag-returns"><strong>Returns:</strong> Whether the pass for the given index is the last pass in the pass chain.</dt>
  174. </dl>
  175. </div>
  176. <h3 class="name name-method" id="removePass" translate="no">.<a href="#removePass">removePass</a><span class="signature">( pass : <span class="param-type"><a href="Pass.html">Pass</a></span> )</span> </h3>
  177. <div class="method">
  178. <div class="description">
  179. <p>Removes the given pass from the pass chain.</p>
  180. </div>
  181. <table class="params">
  182. <tbody>
  183. <tr>
  184. <td class="name">
  185. <strong>pass</strong>
  186. </td>
  187. <td class="description last">
  188. <p>The pass to remove.</p>
  189. </td>
  190. </tr>
  191. </tbody>
  192. </table>
  193. </div>
  194. <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>
  195. <div class="method">
  196. <div class="description">
  197. <p>Executes all enabled post-processing passes in order to produce the final frame.</p>
  198. </div>
  199. <table class="params">
  200. <tbody>
  201. <tr>
  202. <td class="name">
  203. <strong>deltaTime</strong>
  204. </td>
  205. <td class="description last">
  206. <p>The delta time in seconds. If not given, the composer computes
  207. its own time delta value.</p>
  208. </td>
  209. </tr>
  210. </tbody>
  211. </table>
  212. </div>
  213. <h3 class="name name-method" id="reset" translate="no">.<a href="#reset">reset</a><span class="signature">( renderTarget : <span class="param-type"><a href="WebGLRenderTarget.html">WebGLRenderTarget</a></span> )</span> </h3>
  214. <div class="method">
  215. <div class="description">
  216. <p>Resets the internal state of the EffectComposer.</p>
  217. </div>
  218. <table class="params">
  219. <tbody>
  220. <tr>
  221. <td class="name">
  222. <strong>renderTarget</strong>
  223. </td>
  224. <td class="description last">
  225. <p>This render target has the same purpose like
  226. the one from the constructor. If set, it is used to setup the read and write buffers.</p>
  227. </td>
  228. </tr>
  229. </tbody>
  230. </table>
  231. </div>
  232. <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>
  233. <div class="method">
  234. <div class="description">
  235. <p>Sets device pixel ratio. This is usually used for HiDPI device to prevent blurring output.
  236. Setting the pixel ratio will automatically resize the composer.</p>
  237. </div>
  238. <table class="params">
  239. <tbody>
  240. <tr>
  241. <td class="name">
  242. <strong>pixelRatio</strong>
  243. </td>
  244. <td class="description last">
  245. <p>The pixel ratio to set.</p>
  246. </td>
  247. </tr>
  248. </tbody>
  249. </table>
  250. </div>
  251. <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>
  252. <div class="method">
  253. <div class="description">
  254. <p>Resizes the internal read and write buffers as well as all passes. Similar to <a href="WebGLRenderer.html#setSize">WebGLRenderer#setSize</a>,
  255. this method honors the current pixel ration.</p>
  256. </div>
  257. <table class="params">
  258. <tbody>
  259. <tr>
  260. <td class="name">
  261. <strong>width</strong>
  262. </td>
  263. <td class="description last">
  264. <p>The width in logical pixels.</p>
  265. </td>
  266. </tr>
  267. <tr>
  268. <td class="name">
  269. <strong>height</strong>
  270. </td>
  271. <td class="description last">
  272. <p>The height in logical pixels.</p>
  273. </td>
  274. </tr>
  275. </tbody>
  276. </table>
  277. </div>
  278. <h3 class="name name-method" id="swapBuffers" translate="no">.<a href="#swapBuffers">swapBuffers</a><span class="signature">()</span> </h3>
  279. <div class="method">
  280. <div class="description">
  281. <p>Swaps the internal read/write buffers.</p>
  282. </div>
  283. </div>
  284. <h2 class="subsection-title">Source</h2>
  285. <p>
  286. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/postprocessing/EffectComposer.js" translate="no" target="_blank" rel="noopener">examples/jsm/postprocessing/EffectComposer.js</a>
  287. </p>
  288. </article>
  289. </section>
  290. <script src="../scripts/linenumber.js"></script>
  291. <script src="../scripts/page.js"></script>
  292. </body>
  293. </html>
粤ICP备19079148号