prePassRenderTarget.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { MultiRenderTarget } from "./multiRenderTarget.js";
  2. import { ImageProcessingPostProcess } from "../../PostProcesses/imageProcessingPostProcess.js";
  3. /**
  4. * A multi render target designed to render the prepass.
  5. * Prepass is a scene component used to render information in multiple textures
  6. * alongside with the scene materials rendering.
  7. * Note : This is an internal class, and you should NOT need to instanciate this.
  8. * Only the `PrePassRenderer` should instanciate this class.
  9. * It is more likely that you need a regular `MultiRenderTarget`
  10. * @internal
  11. */
  12. export class PrePassRenderTarget extends MultiRenderTarget {
  13. constructor(name, renderTargetTexture, size, count, scene, options) {
  14. super(name, size, count, scene, options);
  15. /**
  16. * @internal
  17. */
  18. this._beforeCompositionPostProcesses = [];
  19. /**
  20. * @internal
  21. */
  22. this._internalTextureDirty = false;
  23. /**
  24. * Is this render target enabled for prepass rendering
  25. */
  26. this.enabled = false;
  27. /**
  28. * Render target associated with this prePassRenderTarget
  29. * If this is `null`, it means this prePassRenderTarget is associated with the scene
  30. */
  31. this.renderTargetTexture = null;
  32. this.renderTargetTexture = renderTargetTexture;
  33. }
  34. /**
  35. * Creates a composition effect for this RT
  36. * @internal
  37. */
  38. _createCompositionEffect() {
  39. this.imageProcessingPostProcess = new ImageProcessingPostProcess("prePassComposition", 1, null, undefined, this._engine);
  40. this.imageProcessingPostProcess._updateParameters();
  41. }
  42. /**
  43. * Checks that the size of this RT is still adapted to the desired render size.
  44. * @internal
  45. */
  46. _checkSize() {
  47. const requiredWidth = this._engine.getRenderWidth(true);
  48. const requiredHeight = this._engine.getRenderHeight(true);
  49. const width = this.getRenderWidth();
  50. const height = this.getRenderHeight();
  51. if (width !== requiredWidth || height !== requiredHeight) {
  52. this.resize({ width: requiredWidth, height: requiredHeight });
  53. this._internalTextureDirty = true;
  54. }
  55. }
  56. /**
  57. * Changes the number of render targets in this MRT
  58. * Be careful as it will recreate all the data in the new texture.
  59. * @param count new texture count
  60. * @param options Specifies texture types and sampling modes for new textures
  61. * @param textureNames Specifies the names of the textures (optional)
  62. */
  63. updateCount(count, options, textureNames) {
  64. super.updateCount(count, options, textureNames);
  65. this._internalTextureDirty = true;
  66. }
  67. /**
  68. * Resets the post processes chains applied to this RT.
  69. * @internal
  70. */
  71. _resetPostProcessChain() {
  72. this._beforeCompositionPostProcesses.length = 0;
  73. }
  74. /**
  75. * Diposes this render target
  76. */
  77. dispose() {
  78. const scene = this._scene;
  79. super.dispose();
  80. if (scene && scene.prePassRenderer) {
  81. const index = scene.prePassRenderer.renderTargets.indexOf(this);
  82. if (index !== -1) {
  83. scene.prePassRenderer.renderTargets.splice(index, 1);
  84. }
  85. }
  86. if (this.imageProcessingPostProcess) {
  87. this.imageProcessingPostProcess.dispose();
  88. }
  89. if (this.renderTargetTexture) {
  90. this.renderTargetTexture._prePassRenderTarget = null;
  91. }
  92. if (this._outputPostProcess) {
  93. this._outputPostProcess.autoClear = true;
  94. this._outputPostProcess.restoreDefaultInputTexture();
  95. }
  96. }
  97. }
  98. //# sourceMappingURL=prePassRenderTarget.js.map