filterPostProcess.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Nullable } from "../types";
  2. import { Matrix } from "../Maths/math.vector";
  3. import { Camera } from "../Cameras/camera";
  4. import { Effect } from "../Materials/effect";
  5. import { PostProcess, PostProcessOptions } from "./postProcess";
  6. import { Engine } from "../Engines/engine";
  7. import "../Shaders/filter.fragment";
  8. import { _TypeStore } from '../Misc/typeStore';
  9. import { serializeAsMatrix, SerializationHelper } from '../Misc/decorators';
  10. declare type Scene = import("../scene").Scene;
  11. /**
  12. * Applies a kernel filter to the image
  13. */
  14. export class FilterPostProcess extends PostProcess {
  15. /** The matrix to be applied to the image */
  16. @serializeAsMatrix()
  17. public kernelMatrix: Matrix;
  18. /**
  19. * Gets a string identifying the name of the class
  20. * @returns "FilterPostProcess" string
  21. */
  22. public getClassName(): string {
  23. return "FilterPostProcess";
  24. }
  25. /**
  26. *
  27. * @param name The name of the effect.
  28. * @param kernelMatrix The matrix to be applied to the image
  29. * @param options The required width/height ratio to downsize to before computing the render pass.
  30. * @param camera The camera to apply the render pass to.
  31. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  32. * @param engine The engine which the post process will be applied. (default: current engine)
  33. * @param reusable If the post process can be reused on the same frame. (default: false)
  34. */
  35. constructor(name: string,
  36. kernelMatrix: Matrix,
  37. options: number | PostProcessOptions,
  38. camera: Nullable<Camera>,
  39. samplingMode?: number,
  40. engine?: Engine,
  41. reusable?: boolean
  42. ) {
  43. super(name, "filter", ["kernelMatrix"], null, options, camera, samplingMode, engine, reusable);
  44. this.kernelMatrix = kernelMatrix;
  45. this.onApply = (effect: Effect) => {
  46. effect.setMatrix("kernelMatrix", this.kernelMatrix);
  47. };
  48. }
  49. /** @hidden */
  50. public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string): Nullable<FilterPostProcess> {
  51. return SerializationHelper.Parse(() => {
  52. return new FilterPostProcess(
  53. parsedPostProcess.name, parsedPostProcess.kernelMatrix,
  54. parsedPostProcess.options, targetCamera,
  55. parsedPostProcess.renderTargetSamplingMode,
  56. scene.getEngine(), parsedPostProcess.reusable);
  57. }, parsedPostProcess, scene, rootUrl);
  58. }
  59. }
  60. _TypeStore.RegisteredTypes["BABYLON.FilterPostProcess"] = FilterPostProcess;