-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcss-shader.min.js
11 lines (10 loc) · 1.65 KB
/
css-shader.min.js
1
2
3
4
5
6
7
8
9
10
11
/*
CSSShader - A JavaScript wrapper for Custom CSS GLSL Shaders
Copyright (c) 2012 - 2013 Jens Arps
http://jensarps.de/
Licensed under the MIT (X11) license
*/
(function(c,a,b){"function"===typeof define?define(a):"undefined"!==typeof module&&module.exports?module.exports=a():b[c]=a()})("CSSShader",function(){var c=function(){this.boundAnimate=this.animate.bind(this)};c.prototype={paused:!1,vertexShader:"",fragmentShader:"",renderTarget:null,shaderArgs:null,blendMode:"normal",alphaCompositing:"source-atop",vertexMesh:"40 40",setVertexShaderByNode:function(a){this._setShader("vertex",this._getNode(a).innerHTML)},setVertexShader:function(a){this._setShader("vertex",
a)},setFragmentShaderByNode:function(a){this._setShader("fragment",this._getNode(a).innerHTML)},setFragmentShader:function(a){this._setShader("fragment",a)},_setShader:function(a,b){this[a+"Shader"]="url(data:text/plain;charset=utf-8;base64,"+btoa(b)+")"},setShaderArgs:function(a){this.shaderArgs=a},setShaderArg:function(a,b){this.shaderArgs[a]=b},setRenderTarget:function(a){this.renderTarget=this._getNode(a)},render:function(a){var b="custom( "+(this.vertexShader+" mix("+this.fragmentShader+" "+
this.blendMode+" "+this.alphaCompositing+")")+", "+this.vertexMesh;this.shaderArgs||(this.shaderArgs={});this.shaderArgs.time=0.1+(a||0);for(var c in this.shaderArgs)b+=", "+c+" "+this.shaderArgs[c];this.renderTarget.style.webkitFilter=b+")"},animate:function(a){this.paused||(requestAnimationFrame(this.boundAnimate),this.render(a))},pause:function(){this.paused=!0},resume:function(){this.paused=!1;this.animate()},_getNode:function(a){return"string"==typeof a?document.getElementById(a):a}};return c},
this);