extractHighlightsPostProcess.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Nullable } from "../types";
  2. import { Camera } from "../Cameras/camera";
  3. import { Effect } from "../Materials/effect";
  4. import { PostProcess, PostProcessOptions } from "./postProcess";
  5. import { Engine } from "../Engines/engine";
  6. import { ToGammaSpace } from "../Maths/math.constants";
  7. import { Constants } from "../Engines/constants";
  8. import "../Shaders/extractHighlights.fragment";
  9. /**
  10. * The extract highlights post process sets all pixels to black except pixels above the specified luminance threshold. Used as the first step for a bloom effect.
  11. */
  12. export class ExtractHighlightsPostProcess extends PostProcess {
  13. /**
  14. * The luminance threshold, pixels below this value will be set to black.
  15. */
  16. public threshold = 0.9;
  17. /** @hidden */
  18. public _exposure = 1;
  19. /**
  20. * Post process which has the input texture to be used when performing highlight extraction
  21. * @hidden
  22. */
  23. public _inputPostProcess: Nullable<PostProcess> = null;
  24. constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  25. super(name, "extractHighlights", ["threshold", "exposure"], null, options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, blockCompilation);
  26. this.onApplyObservable.add((effect: Effect) => {
  27. if (this._inputPostProcess) {
  28. effect.setTextureFromPostProcess("textureSampler", this._inputPostProcess);
  29. }
  30. effect.setFloat('threshold', Math.pow(this.threshold, ToGammaSpace));
  31. effect.setFloat('exposure', this._exposure);
  32. });
  33. }
  34. }