extractHighlightsPostProcess.ts 1.7 KB

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