bloomMergePostProcess.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { PostProcess, PostProcessOptions } from "./postProcess";
  2. import { Nullable } from "../types";
  3. import { Engine } from "../Engines/engine";
  4. import { Effect } from "../Materials/effect";
  5. import { Camera } from "../Cameras/camera";
  6. import { Constants } from "../Engines/constants";
  7. import "../Shaders/bloomMerge.fragment";
  8. /**
  9. * The BloomMergePostProcess merges blurred images with the original based on the values of the circle of confusion.
  10. */
  11. export class BloomMergePostProcess extends PostProcess {
  12. /**
  13. * Creates a new instance of @see BloomMergePostProcess
  14. * @param name The name of the effect.
  15. * @param originalFromInput Post process which's input will be used for the merge.
  16. * @param blurred Blurred highlights post process which's output will be used.
  17. * @param weight Weight of the bloom to be added to the original input.
  18. * @param options The required width/height ratio to downsize to before computing the render pass.
  19. * @param camera The camera to apply the render pass to.
  20. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  21. * @param engine The engine which the post process will be applied. (default: current engine)
  22. * @param reusable If the post process can be reused on the same frame. (default: false)
  23. * @param textureType Type of textures used when performing the post process. (default: 0)
  24. * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
  25. */
  26. constructor(name: string, originalFromInput: PostProcess, blurred: PostProcess,
  27. /** Weight of the bloom to be added to the original input. */
  28. public weight: number,
  29. options: number | PostProcessOptions,
  30. camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  31. super(name, "bloomMerge", ["bloomWeight"], ["circleOfConfusionSampler", "blurStep0", "blurStep1", "blurStep2", "bloomBlur"], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, true);
  32. this.onApplyObservable.add((effect: Effect) => {
  33. effect.setTextureFromPostProcess("textureSampler", originalFromInput);
  34. effect.setTextureFromPostProcessOutput("bloomBlur", blurred);
  35. effect.setFloat("bloomWeight", this.weight);
  36. });
  37. if (!blockCompilation) {
  38. this.updateEffect();
  39. }
  40. }
  41. }