sharpenPostProcess.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 { Constants } from "../Engines/constants";
  6. import "../Shaders/sharpen.fragment";
  7. import { _TypeStore } from '../Misc/typeStore';
  8. import { serialize, SerializationHelper } from '../Misc/decorators';
  9. declare type Engine = import("../Engines/engine").Engine;
  10. declare type Scene = import("../scene").Scene;
  11. /**
  12. * The SharpenPostProcess applies a sharpen kernel to every pixel
  13. * See http://en.wikipedia.org/wiki/Kernel_(image_processing)
  14. */
  15. export class SharpenPostProcess extends PostProcess {
  16. /**
  17. * How much of the original color should be applied. Setting this to 0 will display edge detection. (default: 1)
  18. */
  19. @serialize()
  20. public colorAmount: number = 1.0;
  21. /**
  22. * How much sharpness should be applied (default: 0.3)
  23. */
  24. @serialize()
  25. public edgeAmount: number = 0.3;
  26. /**
  27. * Gets a string identifying the name of the class
  28. * @returns "SharpenPostProcess" string
  29. */
  30. public getClassName(): string {
  31. return "SharpenPostProcess";
  32. }
  33. /**
  34. * Creates a new instance ConvolutionPostProcess
  35. * @param name The name of the effect.
  36. * @param options The required width/height ratio to downsize to before computing the render pass.
  37. * @param camera The camera to apply the render pass to.
  38. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  39. * @param engine The engine which the post process will be applied. (default: current engine)
  40. * @param reusable If the post process can be reused on the same frame. (default: false)
  41. * @param textureType Type of textures used when performing the post process. (default: 0)
  42. * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
  43. */
  44. constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
  45. super(name, "sharpen", ["sharpnessAmounts", "screenSize"], null, options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, blockCompilation);
  46. this.onApply = (effect: Effect) => {
  47. effect.setFloat2("screenSize", this.width, this.height);
  48. effect.setFloat2("sharpnessAmounts", this.edgeAmount, this.colorAmount);
  49. };
  50. }
  51. /** @hidden */
  52. public static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {
  53. return SerializationHelper.Parse(() => {
  54. return new SharpenPostProcess(
  55. parsedPostProcess.name,
  56. parsedPostProcess.options, targetCamera,
  57. parsedPostProcess.renderTargetSamplingMode,
  58. scene.getEngine(), parsedPostProcess.textureType, parsedPostProcess.reusable);
  59. }, parsedPostProcess, scene, rootUrl);
  60. }
  61. }
  62. _TypeStore.RegisteredTypes["BABYLON.SharpenPostProcess"] = SharpenPostProcess;