babylon.convolutionPostProcess.ts 1.0 KB

123456789101112131415161718192021
  1. module BABYLON {
  2. export class ConvolutionPostProcess extends PostProcess{
  3. constructor(name: string, public kernel: number[], ratio: number, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean) {
  4. super(name, "convolution", ["kernel", "screenSize"], null, ratio, camera, samplingMode, engine, reusable);
  5. this.onApply = (effect: Effect) => {
  6. effect.setFloat2("screenSize", this.width, this.height);
  7. effect.setArray("kernel", this.kernel);
  8. };
  9. }
  10. // Statics
  11. // Based on http://en.wikipedia.org/wiki/Kernel_(image_processing)
  12. public static EdgeDetect0Kernel = [1, 0, -1, 0, 0, 0, -1, 0, 1];
  13. public static EdgeDetect1Kernel = [0, 1, 0, 1, -4, 1, 0, 1, 0];
  14. public static EdgeDetect2Kernel = [-1, -1, -1, -1, 8, -1, -1, -1, -1];
  15. public static SharpenKernel = [0, -1, 0, -1, 5, -1, 0, -1, 0];
  16. public static EmbossKernel = [-2, -1, 0, -1, 1, 1, 0, 1, 2];
  17. public static GaussianKernel = [0, 1, 0, 1, 1, 1, 0, 1, 0];
  18. }
  19. }