blackAndWhitePostProcess.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { PostProcess, PostProcessOptions } from "./postProcess";
  2. import { Camera } from "../Cameras/camera";
  3. import { Effect } from "../Materials/effect";
  4. import { Engine } from "../Engines/engine";
  5. import "../Shaders/blackAndWhite.fragment";
  6. import { _TypeStore } from '../Misc/typeStore';
  7. import { serialize, SerializationHelper } from '../Misc/decorators';
  8. import { Nullable } from '../types';
  9. declare type Scene = import("../scene").Scene;
  10. /**
  11. * Post process used to render in black and white
  12. */
  13. export class BlackAndWhitePostProcess extends PostProcess {
  14. /**
  15. * Linear about to convert he result to black and white (default: 1)
  16. */
  17. @serialize()
  18. public degree = 1;
  19. /**
  20. * Gets a string identifying the name of the class
  21. * @returns "BlackAndWhitePostProcess" string
  22. */
  23. public getClassName(): string {
  24. return "BlackAndWhitePostProcess";
  25. }
  26. /**
  27. * Creates a black and white post process
  28. * @see https://doc.babylonjs.com/how_to/how_to_use_postprocesses#black-and-white
  29. * @param name The name of the effect.
  30. * @param options The required width/height ratio to downsize to before computing the render pass.
  31. * @param camera The camera to apply the render pass to.
  32. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  33. * @param engine The engine which the post process will be applied. (default: current engine)
  34. * @param reusable If the post process can be reused on the same frame. (default: false)
  35. */
  36. constructor(name: string, options: number | PostProcessOptions, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean) {
  37. super(name, "blackAndWhite", ["degree"], null, options, camera, samplingMode, engine, reusable);
  38. this.onApplyObservable.add((effect: Effect) => {
  39. effect.setFloat("degree", this.degree);
  40. });
  41. }
  42. /** @hidden */
  43. public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string): Nullable<BlackAndWhitePostProcess> {
  44. return SerializationHelper.Parse(() => {
  45. return new BlackAndWhitePostProcess(
  46. parsedPostProcess.name, parsedPostProcess.options,
  47. targetCamera, parsedPostProcess.renderTargetSamplingMode,
  48. scene.getEngine(), parsedPostProcess.reusable);
  49. }, parsedPostProcess, scene, rootUrl);
  50. }
  51. }
  52. _TypeStore.RegisteredTypes["BABYLON.BlackAndWhitePostProcess"] = BlackAndWhitePostProcess;