babylon.convolutionPostProcess.js 1.2 KB

123456789101112131415161718192021222324252627
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.ConvolutionPostProcess = function (name, kernel, ratio, camera, samplingMode, engine, reusable) {
  5. BABYLON.PostProcess.call(this, name, "convolution", ["kernel", "screenSize"], null, ratio, camera, samplingMode, engine, reusable);
  6. this.kernel = kernel;
  7. var that = this;
  8. this.onApply = function (effect) {
  9. effect.setFloat2("screenSize", that.width, that.height);
  10. effect.setArray("kernel", that.kernel);
  11. };
  12. };
  13. BABYLON.ConvolutionPostProcess.prototype = Object.create(BABYLON.PostProcess.prototype);
  14. // Based on http://en.wikipedia.org/wiki/Kernel_(image_processing)
  15. BABYLON.ConvolutionPostProcess.EdgeDetect0Kernel = [1, 0, -1, 0, 0, 0, -1, 0, 1];
  16. BABYLON.ConvolutionPostProcess.EdgeDetect1Kernel = [0, 1, 0, 1, -4, 1, 0, 1, 0];
  17. BABYLON.ConvolutionPostProcess.EdgeDetect2Kernel = [-1, -1, -1, -1, 8, -1, -1, -1, -1];
  18. BABYLON.ConvolutionPostProcess.SharpenKernel = [0, -1, 0, -1, 5, -1, 0, -1, 0];
  19. BABYLON.ConvolutionPostProcess.EmbossKernel = [-2, -1, 0, -1, 1, 1, 0, 1, 2];
  20. BABYLON.ConvolutionPostProcess.GaussianKernel = [0, 1, 0, 1, 1, 1, 0, 1, 0];
  21. })();