Sha256: e59ca30dc9e96c3bd9fff98ea501bbb9f571d56e11c18575cfe2ed602069a074

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(["exports", "three"], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require("three"));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.three);
    global.TriangleBlurShader = mod.exports;
  }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.TriangleBlurShader = void 0;

  /**
   * Triangle blur shader
   * based on glfx.js triangle blur shader
   * https://github.com/evanw/glfx.js
   *
   * A basic blur filter, which convolves the image with a
   * pyramid filter. The pyramid filter is separable and is applied as two
   * perpendicular triangle filters.
   */
  var TriangleBlurShader = {
    uniforms: {
      'texture': {
        value: null
      },
      'delta': {
        value: new _three.Vector2(1, 1)
      }
    },
    vertexShader:
    /* glsl */
    "\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",
    fragmentShader:
    /* glsl */
    "\n\n\t\t#include <common>\n\n\t\t#define ITERATIONS 10.0\n\n\t\tuniform sampler2D texture;\n\t\tuniform vec2 delta;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvec4 color = vec4( 0.0 );\n\n\t\t\tfloat total = 0.0;\n\n\t\t// randomize the lookup values to hide the fixed number of samples\n\n\t\t\tfloat offset = rand( vUv );\n\n\t\t\tfor ( float t = -ITERATIONS; t <= ITERATIONS; t ++ ) {\n\n\t\t\t\tfloat percent = ( t + offset - 0.5 ) / ITERATIONS;\n\t\t\t\tfloat weight = 1.0 - abs( percent );\n\n\t\t\t\tcolor += texture2D( texture, vUv + delta * percent ) * weight;\n\t\t\t\ttotal += weight;\n\n\t\t\t}\n\n\t\t\tgl_FragColor = color / total;\n\n\t\t}"
  };
  _exports.TriangleBlurShader = TriangleBlurShader;
});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opal-js_wrap-three-0.1.5 lib-opal/js_wrap/three/shaders/TriangleBlurShader.js
opal-js_wrap-three-0.1.4 lib-opal/js_wrap/three/shaders/TriangleBlurShader.js
opal-js_wrap-three-0.1.3 lib-opal/js_wrap/three/shaders/TriangleBlurShader.js
opal-js_wrap-three-0.1.2 lib-opal/js_wrap/three/shaders/TriangleBlurShader.js