convolutionPostProcess.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { __decorate } from "../tslib.es6.js";
  2. import { PostProcess } from "./postProcess.js";
  3. import "../Shaders/convolution.fragment.js";
  4. import { RegisterClass } from "../Misc/typeStore.js";
  5. import { serialize } from "../Misc/decorators.js";
  6. import { SerializationHelper } from "../Misc/decorators.serialization.js";
  7. /**
  8. * The ConvolutionPostProcess applies a 3x3 kernel to every pixel of the
  9. * input texture to perform effects such as edge detection or sharpening
  10. * See http://en.wikipedia.org/wiki/Kernel_(image_processing)
  11. */
  12. export class ConvolutionPostProcess extends PostProcess {
  13. /**
  14. * Gets a string identifying the name of the class
  15. * @returns "ConvolutionPostProcess" string
  16. */
  17. getClassName() {
  18. return "ConvolutionPostProcess";
  19. }
  20. /**
  21. * Creates a new instance ConvolutionPostProcess
  22. * @param name The name of the effect.
  23. * @param kernel Array of 9 values corresponding to the 3x3 kernel to be applied
  24. * @param options The required width/height ratio to downsize to before computing the render pass.
  25. * @param camera The camera to apply the render pass to.
  26. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  27. * @param engine The engine which the post process will be applied. (default: current engine)
  28. * @param reusable If the post process can be reused on the same frame. (default: false)
  29. * @param textureType Type of textures used when performing the post process. (default: 0)
  30. */
  31. constructor(name, kernel, options, camera, samplingMode, engine, reusable, textureType = 0) {
  32. super(name, "convolution", ["kernel", "screenSize"], null, options, camera, samplingMode, engine, reusable, null, textureType);
  33. this.kernel = kernel;
  34. this.onApply = (effect) => {
  35. effect.setFloat2("screenSize", this.width, this.height);
  36. effect.setArray("kernel", this.kernel);
  37. };
  38. }
  39. /**
  40. * @internal
  41. */
  42. static _Parse(parsedPostProcess, targetCamera, scene, rootUrl) {
  43. return SerializationHelper.Parse(() => {
  44. return new ConvolutionPostProcess(parsedPostProcess.name, parsedPostProcess.kernel, parsedPostProcess.options, targetCamera, parsedPostProcess.renderTargetSamplingMode, scene.getEngine(), parsedPostProcess.reusable, parsedPostProcess.textureType);
  45. }, parsedPostProcess, scene, rootUrl);
  46. }
  47. }
  48. // Statics
  49. /**
  50. * Edge detection 0 see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  51. */
  52. ConvolutionPostProcess.EdgeDetect0Kernel = [1, 0, -1, 0, 0, 0, -1, 0, 1];
  53. /**
  54. * Edge detection 1 see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  55. */
  56. ConvolutionPostProcess.EdgeDetect1Kernel = [0, 1, 0, 1, -4, 1, 0, 1, 0];
  57. /**
  58. * Edge detection 2 see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  59. */
  60. ConvolutionPostProcess.EdgeDetect2Kernel = [-1, -1, -1, -1, 8, -1, -1, -1, -1];
  61. /**
  62. * Kernel to sharpen an image see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  63. */
  64. ConvolutionPostProcess.SharpenKernel = [0, -1, 0, -1, 5, -1, 0, -1, 0];
  65. /**
  66. * Kernel to emboss an image see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  67. */
  68. ConvolutionPostProcess.EmbossKernel = [-2, -1, 0, -1, 1, 1, 0, 1, 2];
  69. /**
  70. * Kernel to blur an image see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  71. */
  72. ConvolutionPostProcess.GaussianKernel = [0, 1, 0, 1, 1, 1, 0, 1, 0];
  73. __decorate([
  74. serialize()
  75. ], ConvolutionPostProcess.prototype, "kernel", void 0);
  76. RegisterClass("BABYLON.ConvolutionPostProcess", ConvolutionPostProcess);
  77. //# sourceMappingURL=convolutionPostProcess.js.map