babylon.convolutionPostProcess.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. module BABYLON {
  2. /**
  3. * The ConvolutionPostProcess applies a 3x3 kernel to every pixel of the
  4. * input texture to perform effects such as edge detection or sharpening
  5. * See http://en.wikipedia.org/wiki/Kernel_(image_processing)
  6. */
  7. export class ConvolutionPostProcess extends PostProcess{
  8. /**
  9. * Creates a new instance ConvolutionPostProcess
  10. * @param name The name of the effect.
  11. * @param kernel Array of 9 values corrisponding to the 3x3 kernel to be applied
  12. * @param options The required width/height ratio to downsize to before computing the render pass.
  13. * @param camera The camera to apply the render pass to.
  14. * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
  15. * @param engine The engine which the post process will be applied. (default: current engine)
  16. * @param reusable If the post process can be reused on the same frame. (default: false)
  17. * @param textureType Type of textures used when performing the post process. (default: 0)
  18. */
  19. constructor(name: string,
  20. /** Array of 9 values corrisponding to the 3x3 kernel to be applied */
  21. public kernel: number[],
  22. options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
  23. super(name, "convolution", ["kernel", "screenSize"], null, options, camera, samplingMode, engine, reusable, null, textureType);
  24. this.onApply = (effect: Effect) => {
  25. effect.setFloat2("screenSize", this.width, this.height);
  26. effect.setArray("kernel", this.kernel);
  27. };
  28. }
  29. // Statics
  30. /**
  31. * Edge detection 0 see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  32. */
  33. public static EdgeDetect0Kernel = [1, 0, -1, 0, 0, 0, -1, 0, 1];
  34. /**
  35. * Edge detection 1 see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  36. */
  37. public static EdgeDetect1Kernel = [0, 1, 0, 1, -4, 1, 0, 1, 0];
  38. /**
  39. * Edge detection 2 see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  40. */
  41. public static EdgeDetect2Kernel = [-1, -1, -1, -1, 8, -1, -1, -1, -1];
  42. /**
  43. * Kernel to sharpen an image see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  44. */
  45. public static SharpenKernel = [0, -1, 0, -1, 5, -1, 0, -1, 0];
  46. /**
  47. * Kernel to emboss an image see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  48. */
  49. public static EmbossKernel = [-2, -1, 0, -1, 1, 1, 0, 1, 2];
  50. /**
  51. * Kernel to blur an image see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  52. */
  53. public static GaussianKernel = [0, 1, 0, 1, 1, 1, 0, 1, 0];
  54. }
  55. }