Sha256: 5de2111bdeafe62be27f09d3523e5a6ba19db2878a398c583286dbdecfec6bad

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

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

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

  /**
   * Afterimage shader
   * I created this effect inspired by a demo on codepen:
   * https://codepen.io/brunoimbrizi/pen/MoRJaN?page=1&
   */
  var AfterimageShader = {
    uniforms: {
      'damp': {
        value: 0.96
      },
      'tOld': {
        value: null
      },
      'tNew': {
        value: null
      }
    },
    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\tuniform float damp;\n\n\t\tuniform sampler2D tOld;\n\t\tuniform sampler2D tNew;\n\n\t\tvarying vec2 vUv;\n\n\t\tvec4 when_gt( vec4 x, float y ) {\n\n\t\t\treturn max( sign( x - y ), 0.0 );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvec4 texelOld = texture2D( tOld, vUv );\n\t\t\tvec4 texelNew = texture2D( tNew, vUv );\n\n\t\t\ttexelOld *= damp * when_gt( texelOld, 0.1 );\n\n\t\t\tgl_FragColor = max(texelNew, texelOld);\n\n\t\t}"
  };
  _exports.AfterimageShader = AfterimageShader;
});

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/AfterimageShader.js
opal-js_wrap-three-0.1.4 lib-opal/js_wrap/three/shaders/AfterimageShader.js
opal-js_wrap-three-0.1.3 lib-opal/js_wrap/three/shaders/AfterimageShader.js
opal-js_wrap-three-0.1.2 lib-opal/js_wrap/three/shaders/AfterimageShader.js