babylon.convolutionPostProcess.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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, /** Array of 9 values corrisponding to the 3x3 kernel to be applied */ public kernel: number[], options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
  20. super(name, "convolution", ["kernel", "screenSize"], null, options, camera, samplingMode, engine, reusable, null, textureType);
  21. this.onApply = (effect: Effect) => {
  22. effect.setFloat2("screenSize", this.width, this.height);
  23. effect.setArray("kernel", this.kernel);
  24. };
  25. }
  26. // Statics
  27. /**
  28. * Edge detection 0 see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  29. */
  30. public static EdgeDetect0Kernel = [1, 0, -1, 0, 0, 0, -1, 0, 1];
  31. /**
  32. * Edge detection 1 see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  33. */
  34. public static EdgeDetect1Kernel = [0, 1, 0, 1, -4, 1, 0, 1, 0];
  35. /**
  36. * Edge detection 2 see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  37. */
  38. public static EdgeDetect2Kernel = [-1, -1, -1, -1, 8, -1, -1, -1, -1];
  39. /**
  40. * Kernel to sharpen an image see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  41. */
  42. public static SharpenKernel = [0, -1, 0, -1, 5, -1, 0, -1, 0];
  43. /**
  44. * Kernel to emboss an image see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  45. */
  46. public static EmbossKernel = [-2, -1, 0, -1, 1, 1, 0, 1, 2];
  47. /**
  48. * Kernel to blur an image see https://en.wikipedia.org/wiki/Kernel_(image_processing)
  49. */
  50. public static GaussianKernel = [0, 1, 0, 1, 1, 1, 0, 1, 0];
  51. }
  52. }