filterPostProcess.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. /**
  9. * Applies a kernel filter to the image
  10. */
  11. export class FilterPostProcess extends PostProcess {
  12. /**
  13. *
  14. * @param name The name of the effect.
  15. * @param kernelMatrix The matrix to be applied to the image
  16. * @param options The required width/height ratio to downsize to before computing the render pass.
  17. * @param camera The camera to apply the render pass to.
  18. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  19. * @param engine The engine which the post process will be applied. (default: current engine)
  20. * @param reusable If the post process can be reused on the same frame. (default: false)
  21. */
  22. constructor(name: string,
  23. /** The matrix to be applied to the image */
  24. public kernelMatrix: Matrix,
  25. options: number | PostProcessOptions,
  26. camera: Nullable<Camera>,
  27. samplingMode?: number,
  28. engine?: Engine,
  29. reusable?: boolean
  30. ) {
  31. super(name, "filter", ["kernelMatrix"], null, options, camera, samplingMode, engine, reusable);
  32. this.onApply = (effect: Effect) => {
  33. effect.setMatrix("kernelMatrix", this.kernelMatrix);
  34. };
  35. }
  36. }