extractHighlightsPostProcess.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  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 "Engine/engine";
  6. import { ToGammaSpace } from "Math/math";
  7. import { Constants } from "Engine/constants";
  8. /**
  9. * 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.
  10. */
  11. export class ExtractHighlightsPostProcess extends PostProcess {
  12. /**
  13. * The luminance threshold, pixels below this value will be set to black.
  14. */
  15. public threshold = 0.9;
  16. /** @hidden */
  17. public _exposure = 1;
  18. /**
  19. * Post process which has the input texture to be used when performing highlight extraction
  20. * @hidden
  21. */
  22. public _inputPostProcess: Nullable<PostProcess> = null;
  23. constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  24. super(name, "extractHighlights", ["threshold", "exposure"], null, options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, blockCompilation);
  25. this.onApplyObservable.add((effect: Effect) => {
  26. if (this._inputPostProcess) {
  27. effect.setTextureFromPostProcess("textureSampler", this._inputPostProcess);
  28. }
  29. effect.setFloat('threshold', Math.pow(this.threshold, ToGammaSpace));
  30. effect.setFloat('exposure', this._exposure);
  31. });
  32. }
  33. }