threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

render-pipeline.md 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ---
  2. prev:
  3. text: 'Exporting Files'
  4. link: './exporting-files'
  5. next:
  6. text: 'Material Extension'
  7. link: './material-extension'
  8. ---
  9. # Render pipeline
  10. Threepipe includes a [RenderManager](https://threepipe.org/docs/classes/RenderManager.html) for managing the composition pipeline, and provides helpers for rendering and render target management.
  11. The `RenderManager` includes an [EffectComposer](https://threejs.org/docs/#api/en/postprocessing/EffectComposer) from three.js for rendering passes and a [WebGLRenderer](https://threejs.org/docs/#api/en/renderers/WebGLRenderer) for rendering, but the pass management and sorting is managed by the `RenderManager` itself.
  12. The `RenderManager` inherits from [RenderTargetManager](https://threepipe.org/docs/classes/RenderTargetManager.html)
  13. which provides utilities for creating, tracking and destroying dedicated and temporary render targets.
  14. The main render pipeline supports progressive rendering and is fully configurable. Plugins and applications can add custom passes, effects, and shaders to the pipeline.
  15. Plugins like [GBufferPlugin](https://threepipe.org/docs/classes/GBufferPlugin.html), [SSAOPlugin](https://threepipe.org/docs/classes/SSAOPlugin.html), [TonemapPlugin](https://threepipe.org/docs/classes/TonemapPlugin.html), etc. interact and extend the render pipeline by adding custom passes to the render pipeline and material extensions to the material manager.
  16. ## Render Targets
  17. Render targets can be created
  18. using the `viewer.renderManager.createTarget` and `viewer.renderManager.createTargetCustom` methods.
  19. These can then be disposed using the `viewer.renderManager.disposeTarget` method when not needed anymore.
  20. Or to create temp targets for one time/temporary use `viewer.renderManager.getTempTarget` and `viewer.renderManager.releaseTempTarget` methods can be used. All created render targets are tracked in the `RenderManager`, and are resized and disposed automatically when needed along with the viewer.
  21. ```typescript
  22. const newTarget = viewer.renderManager.createTarget({sizeMultiplier: 1})
  23. // or
  24. const newTarget2 = viewer.renderManager.createTarget({size: {
  25. width: 1024,
  26. height: 1024,
  27. },
  28. type: HalfFloatType
  29. })
  30. // or clone an existing target
  31. const newTarget3 = viewer.renderManager.composerTarget.clone()
  32. // for multi-sample render target
  33. const newTarget4 = viewer.renderManager.createTarget({sizeMultiplier: 1, samples: 4})
  34. // or create a custom target
  35. const newTarget5 = viewer.renderManager.createTargetCustom(
  36. {width: 1024, height: 1024},
  37. {type: HalfFloatType},
  38. WebGLCubeRenderTarget
  39. )
  40. // dispose targets
  41. viewer.renderManager.disposeTarget(newTarget)
  42. viewer.renderManager.disposeTarget(newTarget2)
  43. viewer.renderManager.disposeTarget(newTarget3)
  44. viewer.renderManager.disposeTarget(newTarget4)
  45. viewer.renderManager.disposeTarget(newTarget5)
  46. // get a temporary target
  47. const tempTarget = viewer.renderManager.getTempTarget({sizeMultiplier: 1})
  48. // release the temporary target
  49. viewer.renderManager.releaseTempTarget(tempTarget)
  50. ```
  51. ::: tip
  52. Render targets created with a `sizeMultiplier` are automatically resized when the canvas is resized.
  53. :::
  54. ## Passes
  55. By default, the render pipeline([`ViewerRenderManager`](https://threepipe.org/docs/classes/ViewerRenderManager.html) includes 2 passes -
  56. [RenderPass](https://threepipe.org/docs/classes/ExtendedRenderPass.html) for rendering the scene hierarchy and [ScreenPass](https://threepipe.org/docs/classes/ScreenPass.html) for rendering the final output on the canvas.
  57. More passes can be added and removed from the pipeline
  58. using the [registerPass](https://threepipe.org/docs/classes/RenderManager.html#registerPass) and [unregisterPass](https://threepipe.org/docs/classes/RenderManager.html#unregisterPass) methods.
  59. The pipeline passes need to follow the interface of [IPipelinePass](https://threepipe.org/docs/interfaces/IPipelinePass.html) and [PipelinePassPlugin](https://threepipe.org/docs/classes/PipelinePassPlugin.html).
  60. Which adds some important parameters over the three.js Pass,
  61. like pass id and support for defining where the pass should be added in the pipeline and it's dependants.
  62. ```typescript
  63. const pass = new GBufferRenderPass('customPass', viewer.renderManager.createTarget({sizeMultiplier: 1}))
  64. pass.before = ['render'] // Add the pass before the render pass
  65. pass.after = [] // Add the pass after these passes (none in this case)
  66. pass.required = ['render'] // render pass is required to be in the pipeline for this. throws an error if not found
  67. viewer.renderManager.registerPass(pass)
  68. ```
  69. ::: info
  70. See [PipelinePassPlugin](https://threepipe.org/docs/classes/PipelinePassPlugin.html) for an abstract plugin
  71. that provides the boilerplate to create a plugin that registers a custom pass in the pipeline.
  72. Check [NormalBufferPlugin](https://threepipe.org/docs/classes/NormalBufferPlugin.html) for an example of that.
  73. :::
  74. ::: tip
  75. All effects in post-processing or material extension need not be a separate pass in the pipeline.
  76. Most effects can be achieved with either extending the scene object material shaders or the Screen Pass material shader using [Material extension](./material-extension) system
  77. :::