text: /*
   * Seriously.js
   *
   * Copyright (c) 2012-2014 Brian Chirls
   *
   * This software is released under the MIT License.
   * http://opensource.org/licenses/mit-license.php
   */
  !function(t,e){"use strict";"function"==typeof define&&define.amd?define("seriously",function(){var i=e(t);return t.Seriously||(t.Seriously=i),i}):"object"==typeof exports?module.exports=e(t):"function"!=typeof t.Seriously&&(t.Seriously=e(t))}(window,function(t){"use strict";var e,i,r,n,s,o,a,h,u=t.document,f=t.console,c={},l={},d={},p={},m=[],y={},g={},v={canvas:[],image:[],video:[]},x={},E=t.WeakMap&&new WeakMap,b=0,T=function(){},w={transparent:[0,0,0,0],black:[0,0,0,1],red:[1,0,0,1],green:[0,128/255,0,1],blue:[0,0,1,1],white:[1,1,1,1],silver:[192/255,192/255,192/255,1],gray:[128/255,128/255,128/255,1],maroon:[128/255,0,0,1],purple:[128/255,0,128/255,1],fuchsia:[1,0,1,1],lime:[0,1,0,1],olive:[128/255,128/255,0,1],yellow:[1,1,0,1],navy:[0,0,128/255,1],teal:[0,128/255,128/255,1],aqua:[0,1,1,1],orange:[1,165/255,0,1]},R=/^(rgb|hsl)a?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*(\d+(\.\d*)?)\s*)?\)/i,D=/^#(([0-9a-fA-F]{3,8}))/,A=["x","y","z","w"],_=["r","g","b","a"],N={srcRGB:770,dstRGB:771,srcAlpha:1,dstAlpha:771},P=["MAX_COMBINED_TEXTURE_IMAGE_UNITS","MAX_FRAGMENT_UNIFORM_VECTORS","MAX_TEXTURE_IMAGE_UNITS","MAX_VARYING_VECTORS","MAX_VERTEX_ATTRIBS","MAX_VERTEX_TEXTURE_IMAGE_UNITS","MAX_VERTEX_UNIFORM_VECTORS"],F=/^[\t ]*#define[\t ]+SHADER_NAME\s+([^$\n\r]+)/i,O={frustum:function(t,e,i,r,n,s,o){o||(o=O.create());var a=e-t,h=r-i,u=s-n;return o[0]=2*n/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*n/h,o[6]=0,o[7]=0,o[8]=(e+t)/a,o[9]=(r+i)/h,o[10]=-(s+n)/u,o[11]=-1,o[12]=0,o[13]=0,o[14]=-s*n*2/u,o[15]=0,o},perspective:function(t,e,i,r,n){var s=i*Math.tan(t*Math.PI/360),o=s*e;return O.frustum(-o,o,-s,s,i,r,n)},multiply:function(t,e,i){var r=e[0],n=e[1],s=e[2],o=e[3],a=e[4],h=e[5],u=e[6],f=e[7],c=e[8],l=e[9],d=e[10],p=e[11],m=e[12],y=e[13],g=e[14],v=e[15],x=i[0],E=i[1],b=i[2],T=i[3];return t[0]=x*r+E*a+b*c+T*m,t[1]=x*n+E*h+b*l+T*y,t[2]=x*s+E*u+b*d+T*g,t[3]=x*o+E*f+b*p+T*v,x=i[4],E=i[5],b=i[6],T=i[7],t[4]=x*r+E*a+b*c+T*m,t[5]=x*n+E*h+b*l+T*y,t[6]=x*s+E*u+b*d+T*g,t[7]=x*o+E*f+b*p+T*v,x=i[8],E=i[9],b=i[10],T=i[11],t[8]=x*r+E*a+b*c+T*m,t[9]=x*n+E*h+b*l+T*y,t[10]=x*s+E*u+b*d+T*g,t[11]=x*o+E*f+b*p+T*v,x=i[12],E=i[13],b=i[14],T=i[15],t[12]=x*r+E*a+b*c+T*m,t[13]=x*n+E*h+b*l+T*y,t[14]=x*s+E*u+b*d+T*g,t[15]=x*o+E*f+b*p+T*v,t},identity:function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}},U=(h=0,t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(e){var i,r,n;return i=(new Date).getTime(),r=Math.max(0,16-(i-h)),n=t.setTimeout(function(){e(i+r)},r),h=i+r,n}),S=t.cancelAnimationFrame||t.webkitCancelAnimationFrame||t.mozCancelAnimationFrame||t.oCancelAnimationFrame||t.msCancelAnimationFrame||function(e){t.cancelTimeout(e)},B=["alias","destroy","effect","id","initialize","inputs","isDestroyed","isReady","matte","off","on","readPixels","render","title","update"],L=["alias","destroy","id","inputs","isDestroyed","isReady","off","on","source","title","update"],I=["aliases","defaults","destroy","effect","go","id","incompatible","isDestroyed","isEffect","isNode","isSource","isTarget","isTransform","removeAlias","render","source","stop","target","transform"];function C(t,e){var i,r;if("string"==typeof t)i=u.querySelector(t);else if(!t)return!1;return t.tagName&&(i=t),i?(r=i.tagName.toLowerCase(),e&&e.indexOf(r)<0?t:i):t}function M(t,e){var i,r;for(i in t.prototype&&e.prototype&&t.prototype!==e.prototype&&M(t.prototype,e.prototype),e)e.hasOwnProperty(i)&&((r=Object.getOwnPropertyDescriptor(e,i)).get||r.set?Object.defineProperty(t,i,{configurable:!0,enumerable:!0,get:r.get,set:r.set}):t[i]=e[i]);return t}function z(t){var e;if(!f)return T;if("function"==typeof f[t])e=f[t];else{if("function"!=typeof f.log)return T;e=f.log}return e.bind?e.bind(f):function(){e.apply(f,arguments)}}function G(e,i){if(i||(i="HTMLElement"),e instanceof t[i])return!0;if(!e||"object"!=typeof e)return!1;for(;e;)if((e=Object.getPrototypeOf(e))&&e.constructor.name===i)return!0;return!1}function k(t,e,i,r,n){function s(t,e,i){return(i%=1)<0&&(i+=1),i<1/6?t+(e-t)*i*6:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t}var o,a;return o=2*i-(a=i<.5?i*(e+1):i+e-i*e),n||(n=[]),n[0]=s(o,a,t+1/3),n[1]=s(o,a,t),n[2]=s(o,a,t-1/3),n[3]=r,n}function X(t){var e,i,r,n="#",s=t[3]<1?4:3;for(e=0;e<s;e++)r=(i=Math.min(255,Math.round(255*t[e]||0))).toString(16),i<16&&(r="0"+r),n+=r;return n}function j(t){return Array.isArray(t)||t&&t.BYTES_PER_ELEMENT&&"length"in t}function W(e){if("function"!=typeof e)throw new Error("setTimeoutZero argument is not a function");m.push(e),"file:"!==t.location.protocol?t.postMessage("seriously-timeout-message",t.location):setTimeout(function(){m.length&&m.shift()()},0)}function V(e,i){var r;try{r=t.WebGLDebugUtils&&i&&i.debugContext?t.WebGLDebugUtils.makeDebugContext(e.getContext("webgl2",i)):e.getContext("webgl2",i)}catch(t){}if(!r)try{r=e.getContext("experimental-webgl",i)}catch(t){}return r}function H(){var i;return e&&e.getError()===e.CONTEXT_LOST_WEBGL&&(e=void 0),e||!t.WebGLRenderingContext||r?e:(i=u.createElement("canvas"),(e=V(i))?i.addEventListener("webglcontextlost",function t(r){r.preventDefault(),e&&e.canvas===this&&(e=void 0,i.removeEventListener("webglcontextlost",t,!1))},!1):K.logger.warn("Unable to access WebGL."),e)}function Y(t){var e,i,r;function n(t,r){var n,s;j(t)?(n=t[0],s=t[1]||n):n=t,"string"==typeof n?n=n.toLowerCase():"number"==typeof n?n=String(n):n||(n=""),i[n]=s,r||(e.firstValue=n)}function s(t){return t}for(r in t.inputs)if(t.inputs.hasOwnProperty(r)){if(t.reserved.indexOf(r)>=0||Object.prototype[r])throw new Error("Reserved input name: "+r);(e=t.inputs[r]).name=r,isNaN(e.min)&&(e.min=-1/0),isNaN(e.max)&&(e.max=1/0),isNaN(e.minCount)&&(e.minCount=-1/0),isNaN(e.maxCount)&&(e.maxCount=1/0),isNaN(e.step)&&(e.step=0),isNaN(e.mod)&&(e.mod=0),"enum"===e.type&&e.options&&j(e.options)&&e.options.length&&(i={},e.options.forEach(n),e.options=i),"vector"===e.type?e.dimensions<2?e.dimensions=2:e.dimensions>4?e.dimensions=4:!e.dimensions||isNaN(e.dimensions)?e.dimensions=4:e.dimensions=Math.round(e.dimensions):e.dimensions=1,e.shaderDirty=!!e.shaderDirty,"function"!=typeof e.validate&&(e.validate=K.inputValidators[e.type]||s),t.defaultImageInput||"image"!==e.type||(t.defaultImageInput=r)}}function q(t,e,i,r){var n,s,o,a;!0===r||r&&r.useFloat;this.type=t.UNSIGNED_BYTE,n=t.createFramebuffer(),t.bindFramebuffer(t.FRAMEBUFFER,n),r&&r.texture?(this.texture=r.texture,t.bindTexture(t.TEXTURE_2D,this.texture),this.ownTexture=!1):(this.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.texture),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),this.ownTexture=!0);try{this.type===t.FLOAT?(o=new Float32Array(e*i*4),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.FLOAT,o)):(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,null),this.type=t.UNSIGNED_BYTE)}catch(r){this.type=t.UNSIGNED_BYTE,o=new Uint8Array(e*i*4),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,o)}if(s=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,s),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT16,e,i),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,s),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.texture,0),(a=t.checkFramebufferStatus(t.FRAMEBUFFER))===t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");if(a===t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");if(a===t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");if(a===t.FRAMEBUFFER_UNSUPPORTED)throw new Error("Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");if(a!==t.FRAMEBUFFER_COMPLETE)throw new Error("Incomplete framebuffer: "+a);t.bindTexture(t.TEXTURE_2D,null),t.bindRenderbuffer(t.RENDERBUFFER,null),t.bindFramebuffer(t.FRAMEBUFFER,null),this.gl=t,this.frameBuffer=n,this.renderBuffer=s,this.width=e,this.height=i}function Z(t,e,i){var r,n,s,o,a,h,u,f,c="";function l(e,i){var r,n;if(r=i?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER),t.shaderSource(r,e),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){for(e=e.split(/[\n\r]/),n=0;n<e.length;n++)e[n]=n+1+":\t"+e[n];throw e.unshift("Error compiling "+(i?"fragment":"vertex")+" shader:"),K.logger.error(e.join("\n")),new Error("Shader error: "+t.getShaderInfoLog(r))}return r}function d(e,i){if(e.type===t.SAMPLER_2D)return function(r){e.glTexture=t["TEXTURE"+r],t.uniform1i(i,r)};if(e.type===t.BOOL||e.type===t.INT)return e.size>1?function(e){t.uniform1iv(i,e)}:function(e){t.uniform1i(i,e)};if(e.type===t.FLOAT)return e.size>1?function(e){t.uniform1fv(i,e)}:function(e){t.uniform1f(i,e)};if(e.type===t.FLOAT_VEC2)return function(e){t.uniform2f(i,e[0],e[1])};if(e.type===t.FLOAT_VEC3)return function(e){t.uniform3f(i,e[0],e[1],e[2])};if(e.type===t.FLOAT_VEC4)return function(e){t.uniform4f(i,e[0],e[1],e[2],e[3])};if(e.type===t.FLOAT_MAT3)return function(e){t.uniformMatrix3fv(i,!1,e)};if(e.type===t.FLOAT_MAT4)return function(e){t.uniformMatrix4fv(i,!1,e)};throw new Error("Unknown shader uniform type: "+e.type)}function p(e){return function(){return t.getUniform(r,e)}}if(n=l(e),s=l(i,!0),r=t.createProgram(),t.attachShader(r,n),(o=t.getShaderInfoLog(n))&&(c+="Vertex shader error: "+o+"\n"),t.attachShader(r,s),(o=t.getShaderInfoLog(s))&&(c+="Fragment shader error: "+o+"\n"),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS))throw c+=t.getProgramInfoLog(r),t.deleteProgram(r),t.deleteShader(n),t.deleteShader(s),(u=F.exec(e)||F.exec(i))&&(c="Shader = "+u[1]+"\n"+c),P.forEach(function(e){c+="\n"+e+": "+t.getParameter(t[e])}),new Error("Could not initialize shader:\n"+c);for(t.useProgram(r),this.uniforms={},h=t.getProgramParameter(r,t.ACTIVE_UNIFORMS),a=0;a<h;++a)(f={info:t.getActiveUniform(r,a)}).name=f.info.name.replace(/\[0\]$/,""),f.loc=t.getUniformLocation(r,f.name),f.set=d(f.info,f.loc),f.get=p(f.loc),this.uniforms[f.name]=f,this[f.name]||(this[f.name]=f);for(this.attributes={},this.location={},h=t.getProgramParameter(r,t.ACTIVE_ATTRIBUTES),a=0;a<h;++a)(f={info:t.getActiveAttrib(r,a)}).name=f.info.name,f.location=t.getAttribLocation(r,f.name),this.attributes[f.name]=f,this.location[f.name]=f.location;this.gl=t,this.program=r,this.destroy=function(){var e;for(e in t&&(t.deleteProgram(r),t.deleteShader(n),t.deleteShader(s)),this)this.hasOwnProperty(e)&&delete this[e];r=null,n=null,s=null}}function K(e){if(t===this||!(this instanceof K)||void 0!==this.id)return new K(e);var i,r,s,h,f,m,x,w,R,D,A,_,P,B,L,z=++b,k=this,j=[],H={},$=0,J=[],Q=[],tt=[],et=[],it={},rt=[],nt=[],st={},ot={},at=!1,ht=!1;function ut(t,e){var i,r,n;return!!e&&(i=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,t.vertices,e.STATIC_DRAW),i.size=3,r=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.bufferData(e.ELEMENT_ARRAY_BUFFER,t.indices,e.STATIC_DRAW),n=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,t.coords,e.STATIC_DRAW),n.size=2,{vertex:i,index:r,texCoord:n,length:t.indices.length,mode:t.mode||e.TRIANGLES})}function ft(t){var e={};return e.vertices=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),e.indices=new Uint16Array([0,1,2,0,2,3]),e.coords=new Float32Array([0,0,1,0,1,1,0,1]),ut(e,t)}function ct(t){var e,n;if(!r)if(t.canvas.addEventListener("webglcontextlost",dt,!1),t.canvas.addEventListener("webglcontextrestored",lt,!1),t.isContextLost())K.logger.warn("Unable to attach lost WebGL context. Will try again when context is restored.");else{for(r=t,i=t.canvas,h=ft(r),f=new Z(r,"#define SHADER_NAME seriously.base\n"+o,"#define SHADER_NAME seriously.base\n"+a),e=0;e<et.length;e++)(n=et[e]).gl=r,n.initialize(),n.buildShader();for(e=0;e<J.length;e++)(n=J[e]).initialize();for(e=0;e<Q.length;e++)(n=Q[e]).model||(n.model=h,n.shader=f)}}function lt(){var t,e,i,n;if(s&&!r){if(G(e=s.target,"WebGLFramebuffer"))return void K.logger.error("Unable to restore target built on WebGLFramebuffer");if(t=V(e,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,stencil:!0,debugContext:s.debugContext})){if(t.isContextLost())return void K.logger.error("Unable to restore WebGL Context");for(ct(t),s.renderToTexture?s.frameBuffer=new q(r,s.width,s.height,!1):s.frameBuffer={frameBuffer:null},i=0;i<j.length;i++)(n=j[i]).setDirty(),n.emit("webglcontextrestored");K.logger.log("WebGL context restored")}}}function dt(t){var e,n;for(t&&(K.logger.warn("WebGL context lost"),t.preventDefault()),L&&(S(L),L=0),i&&i.removeEventListener("webglcontextlost",dt,!1),e=0;e<et.length;e++)(n=et[e]).gl=null,n.initialized=!1,n.baseShader=null,n.model=null,n.frameBuffer=null,n.texture=null,n.shader&&n.shader.destroy&&(n.shader.destroy(),n.effect.commonShader&&delete ot[n.hook]),n.shaderDirty=!0,n.shader=null,n.effect.lostContext&&n.effect.lostContext.call(n),t&&n.emit("webglcontextlost");for(e=0;e<J.length;e++)(n=J[e]).texture=null,n.initialized=!1,n.allowRefresh=!1,t&&n.emit("webglcontextlost");for(e=0;e<tt.length;e++)(n=tt[e]).frameBuffer=null,n.texture=null,t&&n.emit("webglcontextlost");for(e=0;e<Q.length;e++)(n=Q[e]).model=!1,n.frameBuffer=null,t&&n.emit("webglcontextlost");f&&f.destroy&&f.destroy(),r&&(r.deleteBuffer(h.vertex),r.deleteBuffer(h.texCoord),r.deleteBuffer(h.index)),h&&(delete h.vertex,delete h.texCoord,delete h.index),h=null,f=null,r=null,i=null}function pt(t){var e,i,r=!1;if(L=0,rt.length)for(r=!0,e=0;e<rt.length;e++)rt[e].call(k,t);if(J&&J.length)for(r=!0,e=0;e<J.length;e++)((i=J[e]).dirty||i.checkDirty&&i.checkDirty())&&(i.dirty=!1,i.setDirty());for(e=0;e<Q.length;e++)(i=Q[e]).auto&&i.dirty&&i.render();if(nt.length)for(r=!0,e=0;e<nt.length;e++)nt[e].call(k);r&&!L&&(L=U(pt))}function mt(t,e,i,n,s,o){var a,h,u,f,c,l,d,p,m,y=0,g=s&&s.gl||r;if(g){for(a in s?(f=o&&o.width||s.width||g.canvas.width,c=o&&o.height||s.height||g.canvas.height):(f=o&&o.width||g.canvas.width,c=o&&o.height||g.canvas.height),t.use(),g.viewport(0,0,f,c),g.bindFramebuffer(g.FRAMEBUFFER,n),g.enableVertexAttribArray(t.location.position),g.enableVertexAttribArray(t.location.texCoord),e.texCoord&&(g.bindBuffer(g.ARRAY_BUFFER,e.texCoord),g.vertexAttribPointer(t.location.texCoord,e.texCoord.size,g.FLOAT,!1,0,0)),g.bindBuffer(g.ARRAY_BUFFER,e.vertex),g.vertexAttribPointer(t.location.position,e.vertex.size,g.FLOAT,!1,0,0),g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,e.index),o&&o.depth?r.enable(r.DEPTH_TEST):r.disable(r.DEPTH_TEST),o?void 0===o.blend||o.blend?(r.enable(r.BLEND),l=void 0===o.srcRGB?r.ONE:o.srcRGB,p=o.dstRGB||r.ZERO,d=void 0===o.srcAlpha?l:o.srcAlpha,m=void 0===o.dstAlpha?p:o.dstAlpha,r.blendFuncSeparate(l,p,d,m),r.blendEquation(o.blendEquation||r.FUNC_ADD)):r.disable(r.BLEND):(r.enable(r.BLEND),r.blendFunc(r.ONE,r.ZERO),r.blendEquation(r.FUNC_ADD)),i)i.hasOwnProperty(a)&&(h=i[a],(u=t.uniforms[a])&&(G(h,"WebGLTexture")?(g.activeTexture(g.TEXTURE0+y),g.bindTexture(g.TEXTURE_2D,h),u.set(y),y++):h instanceof x||h instanceof w||h instanceof R?h.texture&&(g.activeTexture(g.TEXTURE0+y),g.bindTexture(g.TEXTURE_2D,h.texture),u.set(y),y++):null!=h&&u.set(h)));o&&void 0!==o.clear&&!o.clear||(g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT|g.DEPTH_BUFFER_BIT)),g.drawElements(e.mode,e.length,g.UNSIGNED_SHORT,0),r.enable(r.DEPTH_TEST)}}function yt(t,e,i){var r,n;if(("string"!=typeof t||!e&&0!==e)&&(i&&"object"==typeof i||(i=e),e=t),"string"==typeof t&&d[t]||(t=null),e instanceof x||e instanceof w||e instanceof R)r=e;else if(e instanceof A||e instanceof _||e instanceof P){if(!(r=H[e.id]))throw new Error("Cannot connect a foreign node")}else{for("string"==typeof e&&isNaN(e)&&(e=C(e,["canvas","img","video"])),n=0;n<J.length;n++)if(r=J[n],(!t||t===r.hook)&&r.compare&&r.compare(e,i))return r;r=new x(t,e,i)}return r}function gt(t,e){var i,r,n;if(!(t instanceof w||t instanceof R))return!1;if(t===e)return!0;for(i in n=t.sources)if(n.hasOwnProperty(i)&&((r=n[i])===e||gt(r,e)))return!0;return!1}(m=function(){this.ready=!1,this.width=1,this.height=1,this.gl=r,this.uniforms={resolution:[this.width,this.height],transform:null},this.dirty=!0,this.isDestroyed=!1,this.seriously=k,this.listeners={},this.id=$,$++}).prototype.setReady=function(){var t;if(!this.ready&&(this.ready=!0,this.emit("ready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setReady()},m.prototype.setUnready=function(){var t;if(this.ready&&(this.ready=!1,this.emit("unready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setUnready()},m.prototype.setDirty=function(){var t;if(!this.dirty&&(this.emit("dirty"),this.dirty=!0,this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setDirty()},m.prototype.initFrameBuffer=function(t){r&&(this.frameBuffer=new q(r,this.width,this.height,t))},m.prototype.readPixels=function(t,e,i,n,s){var o=this.gl||r;if(!r)throw new Error("Cannot read pixels until a canvas is connected");if(this.frameBuffer||(this.initFrameBuffer(),this.setDirty()),this.render(),void 0===s)s=new Uint8Array(i*n*4);else if(!G(s,"Uint8Array"))throw new Error("Incompatible array type");return o.bindFramebuffer(r.FRAMEBUFFER,this.frameBuffer.frameBuffer),o.readPixels(t,e,i,n,r.RGBA,r.UNSIGNED_BYTE,s),s},m.prototype.resize=function(){var t,e;this.source?(t=this.source.width,e=this.source.height):this.sources&&this.sources.source?(t=this.sources.source.width,e=this.sources.source.height):this.inputs&&this.inputs.width?(t=this.inputs.width,e=this.inputs.height||t):this.inputs&&this.inputs.height?t=e=this.inputs.height:(t=1,e=1),t=Math.floor(t),e=Math.floor(e),this.width===t&&this.height===e||(this.width=t,this.height=e,this.emit("resize"),this.setDirty()),this.uniforms&&this.uniforms.resolution&&(this.uniforms.resolution[0]=t,this.uniforms.resolution[1]=e),this.frameBuffer&&this.frameBuffer.resize&&this.frameBuffer.resize(t,e)},m.prototype.on=function(t,e){var i,r=-1;t&&"function"==typeof e&&((i=this.listeners[t])?r=i.indexOf(e):i=this.listeners[t]=[],r<0&&i.push(e))},m.prototype.off=function(t,e){var i,r=-1;t&&"function"==typeof e&&(i=this.listeners[t])&&(r=i.indexOf(e))>=0&&i.splice(r,1)},m.prototype.emit=function(t){var e,i=this.listeners[t];if(i&&i.length)for(e=0;e<i.length;e++)W(i[e])},m.prototype.destroy=function(){var t,e;for(e in delete this.gl,delete this.seriously,this.listeners)this.listeners.hasOwnProperty(e)&&delete this.listeners[e];for(t in this.uniforms)this.uniforms.hasOwnProperty(t)&&delete this.uniforms[t];this.targets&&delete this.targets,this.frameBuffer&&this.frameBuffer.destroy&&(this.frameBuffer.destroy(),delete this.frameBuffer),(t=j.indexOf(this))>=0&&j.splice(t,1),delete H[this.id],this.isDestroyed=!0},A=function(t){var e,i=t;function r(t,e){var r,n,s,o,a;return s=i.effect.inputs[t],r=i.inputElements[t],"string"==typeof e&&isNaN(e)&&("enum"===s.type?s.options.hasOwnProperty(e)||(e=C(e,["select"])):"number"===s.type||"boolean"===s.type?e=C(e,["input","select"]):"image"===s.type&&(e=C(e,["canvas","img","video"]))),G(e,"HTMLInputElement")||G(e,"HTMLSelectElement")?(n=e.value,r&&r.element!==e&&(r.element.removeEventListener("change",r.listener,!0),r.element.removeEventListener("input",r.listener,!0),delete i.inputElements[t],r=null),r||(r={element:e,listener:(o=t,a=e,function(){var t,r;t="checkbox"===e.type?e.checked:a.value,r=i.setInput(o,t),"color"===s.type&&(r=X(r).substr(0,7)),r!==t&&(a.value=r)})},i.inputElements[t]=r,"range"===e.type?(e.addEventListener("input",r.listener,!0),e.addEventListener("change",r.listener,!0)):e.addEventListener("change",r.listener,!0)),r&&"checkbox"===e.type&&(n=e.checked)):(r&&(r.element.removeEventListener("change",r.listener,!0),r.element.removeEventListener("input",r.listener,!0),delete i.inputElements[t]),n=e),i.setInput(t,n),i.inputs[t]}function n(t){return function(e){var i=r(t,e);return i&&i.pub}}function s(t){return function(){var e=i.inputs[t];return e&&e.pub}}function o(t){return function(e){return r(t,e)}}function a(t){return function(){return i.inputs[t]}}for(e in i.effect.inputs)if(i.effect.inputs.hasOwnProperty(e)){if(void 0!==this[e])throw new Error("Cannot overwrite Seriously."+e);"image"===i.effect.inputs[e].type?Object.defineProperty(this,e,{configurable:!0,enumerable:!0,get:s(e),set:n(e)}):Object.defineProperty(this,e,{configurable:!0,enumerable:!0,get:a(e),set:o(e)})}Object.defineProperties(this,{effect:{enumerable:!0,configurable:!0,get:function(){return i.hook}},title:{enumerable:!0,configurable:!0,get:function(){return i.effect.title||i.hook}},width:{enumerable:!0,configurable:!0,get:function(){return i.width}},height:{enumerable:!0,configurable:!0,get:function(){return i.height}},id:{enumerable:!0,configurable:!0,get:function(){return i.id}}}),this.render=function(){return i.render(),this},this.readPixels=function(t,e,r,n,s){return i.readPixels(t,e,r,n,s)},this.on=function(t,e){i.on(t,e)},this.off=function(t,e){i.off(t,e)},this.inputs=function(t){var e,r,n,s;if(n=i.effect.inputs,t)return(r=n[t])?(e={type:r.type,defaultValue:r.defaultValue,title:r.title||t},"number"===r.type?(e.min=r.min,e.max=r.max,e.step=r.step,e.mod=r.mod):"enum"===r.type?e.options=M({},r.options):"vector"===r.type&&(e.dimensions=r.dimensions),r.description&&(e.description=r.description),e):null;for(s in e={},n)n.hasOwnProperty(s)&&(e[s]=this.inputs(s));return e},this.alias=function(t,e){return i.alias(t,e),this},this.matte=function(t){i.matte(t)},this.destroy=function(){var t,e;for(t in i.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=T)},this.isDestroyed=function(){return i.isDestroyed},this.isReady=function(){return i.ready}},(w=function(t,e){var i,s,o,a,h={};for(i in m.call(this,e),this.gl=r,this.effectRef=c[t],this.sources={},this.targets=[],this.inputElements={},this.dirty=!0,this.shaderDirty=!0,this.hook=t,this.options=e,this.transform=null,this.effect=M({},this.effectRef),this.effectRef.definition&&M(this.effect,this.effectRef.definition.call(this,e)),Y(this.effect),this.uniforms.transform=n,this.inputs={},a=st[t],this.effect.inputs)this.effect.inputs.hasOwnProperty(i)&&(void 0!==(s=this.effect.inputs[i]).defaultValue&&null!==s.defaultValue||("number"===s.type?s.defaultValue=Math.min(Math.max(0,s.min),s.max):"color"===s.type?s.defaultValue=[0,0,0,0]:"boolean"===s.type?s.defaultValue=!1:"string"===s.type?s.defaultValue="":"enum"===s.type&&(s.defaultValue=s.firstValue)),o=s.validate.call(this,s.defaultValue,s),a&&void 0!==a[i]&&(o=s.validate.call(this,a[i],s,s.defaultValue,o),a[i]=o,"image"===s.type&&(h[i]=o)),this.inputs[i]=o,s.uniform&&(this.uniforms[s.uniform]=s.defaultValue));for(i in r&&(this.initialize(),this.effect.commonShader&&this.buildShader()),this.updateReady(),this.inPlace=this.effect.inPlace,this.pub=new A(this),j.push(this),H[this.id]=this,et.push(this),y[t].push(this),h)h.hasOwnProperty(i)&&this.setInput(i,h[i])}).prototype=Object.create(m.prototype),w.prototype.constructor=w,w.prototype.initialize=function(){if(!this.initialized){var t=this;this.baseShader=f,this.shape?this.model=ut(this.shape,this.gl):this.model=h,"function"==typeof this.effect.initialize?this.effect.initialize.call(this,function(){t.initFrameBuffer(!0)},r):this.initFrameBuffer(!0),this.frameBuffer&&(this.texture=this.frameBuffer.texture),this.initialized=!0}},w.prototype.resize=function(){var t;for(m.prototype.resize.call(this),this.effect.resize&&this.effect.resize.call(this),t=0;t<this.targets.length;t++)this.targets[t].resize()},w.prototype.updateReady=function(){var t,e,i,r,n=!0;for(e in(i=this.effect).inputs)if(i.inputs.hasOwnProperty(e)&&"image"===this.effect.inputs[e].type&&(!this.sources[e]||!this.sources[e].ready)&&(!i.requires||i.requires.call(this,e,this.inputs))){n=!1;break}if(this.ready!==n&&(this.ready=n,this.emit(n?"ready":"unready"),r=n?"setReady":"setUnready",this.targets))for(t=0;t<this.targets.length;t++)this.targets[t][r]()},w.prototype.setReady=w.prototype.updateReady,w.prototype.setUnready=w.prototype.updateReady,w.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},w.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1)},w.prototype.removeSource=function(t){var e,i=t&&t.pub;for(e in this.inputs)!this.inputs.hasOwnProperty(e)||this.inputs[e]!==t&&this.inputs[e]!==i||(this.inputs[e]=null);for(e in this.sources)!this.sources.hasOwnProperty(e)||this.sources[e]!==t&&this.sources[e]!==i||(this.sources[e]=null)},w.prototype.buildShader=function(){var t,e=this.effect,i=this;function n(t){return F.test(t)?t:"#define SHADER_NAME seriously."+i.hook+"\n"+t}this.shaderDirty&&(e.commonShader&&ot[this.hook]?(this.shader||ot[this.hook].count++,this.shader=ot[this.hook].shader):e.shader?(this.shader&&!e.commonShader&&this.shader.destroy(),(t=e.shader.call(this,this.inputs,{vertex:o,fragment:a},K.util))instanceof Z?this.shader=t:t&&t.vertex&&t.fragment?this.shader=new Z(r,n(t.vertex),n(t.fragment)):this.shader=f,e.commonShader&&(ot[this.hook]={count:1,shader:this.shader})):this.shader=f,this.shaderDirty=!1)},w.prototype.render=function(){var t,e,i,n=this.effect,s=this;if(r){if(this.initialized||this.initialize(),this.shaderDirty&&this.buildShader(),this.dirty&&this.ready){for(t in this.sources)!this.sources.hasOwnProperty(t)||n.requires&&!n.requires.call(this,t,this.inputs)||(i="function"==typeof this.inPlace?this.inPlace(t):this.inPlace,this.sources[t].render(!i));this.frameBuffer&&(e=this.frameBuffer.frameBuffer),"function"==typeof n.draw?(n.draw.call(this,this.shader,this.model,this.uniforms,e,function(t,e,i,r,n,o){mt(t,e,i,r,n||s,o)}),this.emit("render")):e&&(mt(this.shader,this.model,this.uniforms,e,this),this.emit("render")),this.dirty=!1}return this.texture}},w.prototype.setInput=function(t,e){var i,r,s,o,a,h=this;if(this.effect.inputs.hasOwnProperty(t)){if("image"===(i=this.effect.inputs[t]).type){if(e){if((e=yt(e))!==this.sources[t]){if(function(){var e,i=h.sources[t];if(i){for(e in h.sources)if(e!==t&&h.sources.hasOwnProperty(e)&&h.sources[e]===i)return;i.removeTarget(h)}}(),gt(e,this))throw new Error("Attempt to make cyclical connection.");this.sources[t]=e,e.addTarget(this)}}else delete this.sources[t],e=!1;r=this.sources[t],s=Object.keys(this.sources),!0===this.inPlace&&1===s.length?(o=this.sources[s[0]],this.uniforms.transform=o&&o.cumulativeMatrix||n):this.uniforms.transform=n}else a=st[this.hook]&&void 0!==st[this.hook][t]?st[this.hook][t]:i.defaultValue,r=e=i.validate.call(this,e,i,a,this.inputs[t]);return this.inputs[t]===e&&"color"!==i.type&&"vector"!==i.type?e:(this.inputs[t]=e,i.uniform&&(this.uniforms[i.uniform]=r),"image"===i.type?(this.resize(),this.updateReady()):i.updateSources&&this.updateReady(),i.shaderDirty&&(this.shaderDirty=!0),this.setDirty(),i.update&&i.update.call(this,e),e)}},w.prototype.alias=function(t,e){var i=this;if(I.indexOf(e)>=0)throw new Error("'"+e+"' is a reserved name and cannot be used as an alias.");return this.effect.inputs.hasOwnProperty(t)&&(e||(e=t),k.removeAlias(e),it[e]={node:this,input:t},Object.defineProperty(k,e,{configurable:!0,enumerable:!0,get:function(){return i.inputs[t]},set:function(e){return i.setInput(t,e)}})),this},w.prototype.matte=function(t){var e,i,r,n,s,o,a,h=[],u=[],f={};function c(t){var e,i,r,n,s,o,a,f,c,l,d,p=[];if(!t.simple){for(e=0;e<t.edges.length;e++)for(r=t.edges[e],i=e+1;i<t.edges.length;i++)n=t.edges[i],m=r[0],y=r[1],g=n[0],v=n[1],x=void 0,E=void 0,b=void 0,T=void 0,w=void 0,x=(v.x-g.x)*(m.y-g.y)-(v.y-g.y)*(m.x-g.x),E=(y.x-m.x)*(m.y-g.y)-(y.y-m.y)*(m.x-g.x),(s=!!((b=(v.y-g.y)*(y.x-m.x)-(v.x-g.x)*(y.y-m.y))&&(w=E/b,(T=x/b)>0&&T<=1&&w>0&&w<=1))&&{x:m.x+T*(y.x-m.x),y:m.y+T*(y.y-m.y)})&&(s.edge1=r,s.edge2=n,p.push(s));var m,y,g,v,x,E,b,T,w;if(p.length){for(c=[],e=0;e<p.length;e++)r=(s=p[e]).edge1,n=s.edge2,l={x:s.x,y:s.y,prev:r[0],next:n[1],id:u.length},t.vertices.push(l),u.push(l),d={x:s.x,y:s.y,prev:n[0],next:r[1],id:u.length},t.vertices.push(d),u.push(l),l.prev.next=l,l.next.prev=l,d.prev.next=d,d.next.prev=d;do{o={edges:[],vertices:[],simple:!0},c.push(o),a=f=t.vertices[0];do{e=t.vertices.indexOf(f),t.vertices.splice(e,1),o.edges.push([f,f.next]),o.vertices.push(f),f=f.next}while(f!==a)}while(t.vertices.length);for(e=h.indexOf(t),h.splice(e,1),e=0;e<c.length;e++)h.push(c[e])}else t.simple=!0}}function l(t){var e,i,r,n,s=t.vertices.length,o=0;for(e=s-1,i=0;i<s;e=i,i++)r=t.vertices[e],n=t.vertices[i],o+=r.x*n.y-n.x*r.y;return o>0}function d(t){var e,r,n,s,o,a,h,u,f,c,l,d=t.vertices,p=[],m=[];function y(t,e,i,r){var n,s,o,a,h,u,f,c,l,d,p,m;return n=i.x-e.x,s=i.y-e.y,o=t.x-i.x,a=t.y-i.y,h=e.x-t.x,u=e.y-t.y,f=r.x-t.x,c=r.y-t.y,l=r.x-e.x,d=r.y-e.y,p=r.x-i.x,m=r.y-i.y,n*d-s*l>=0&&o*m-a*p>=0&&h*c-u*f>=0}function g(t,e,i,r,n){var s,o,a,h;if(o=d[n[t]],a=d[n[e]],h=d[n[i]],0>(a.x-o.x)*(h.y-o.y)-(a.y-o.y)*(h.x-o.x))return!1;for(s=0;s<r;s++)if(s!==t&&s!==e&&s!==i&&y(o,a,h,d[n[s]]))return!1;return!0}if(r=d.length,t.clockWise)for(e=0;e<r;e++)p[e]=e;else for(e=0;e<r;e++)p[e]=r-1-e;for(s=2*(n=r),0,e=n-1;n>2;){if(s--<=0)return m;if(n<=(o=e)&&(o=0),n<=(e=o+1)&&(e=0),n<(a=e+1)&&(a=0),g(o,e,a,n,p)){for(h=p[o],u=p[e],f=p[a],t.clockWise?(m.push(d[h]),m.push(d[u]),m.push(d[f])):(m.push(d[f]),m.push(d[u]),m.push(d[h])),0,c=e,l=e+1;l<n;c++,l++)p[c]=p[l];s=2*--n}}i.indices=m}for(e=function(t){return t&&t.length&&Array.isArray(t)?Array.isArray(t[0])?Array.isArray(t[0])&&!isNaN(t[0][0])?[t]:t:[t]:[]}(t),r=0;r<e.length;r++){for(t=e[r],a=null,i={vertices:[],edges:[]},n=0;n<t.length;n++)"object"!=typeof(s=t[n])||isNaN(s.x)||isNaN(s.y)?s.length>=2&&!isNaN(s[0])&&!isNaN(s[1])&&(o={x:s[0],y:s[1],id:u.length}):o={x:s.x,y:s.y,id:u.length},o&&(a?(a.next=o,o.prev=a,o.next=i.vertices[0],i.vertices[0].prev=o):(i.head=o,o.next=o,o.prev=o),u.push(o),i.vertices.push(o),a=o);if(i.vertices.length>2)for(3===i.vertices.length&&(i.simple=!0),h.push(i),n=0;n<i.vertices.length;n++)o=i.vertices[n],i.edges.push([o,o.next])}for(r=h.length-1;r>=0;r--)c(i=h[r]);for(r=0;r<h.length;r++)(i=h[r]).clockWise=l(i),d(i);for(f.vertices=[],f.coords=[],r=0;r<u.length;r++)s=u[r],f.vertices.push(2*s.x-1),f.vertices.push(-2*s.y+1),f.vertices.push(-1),f.coords.push(s.x),f.coords.push(-1*s.y+1);for(f.vertices=new Float32Array(f.vertices),f.coords=new Float32Array(f.coords),f.indices=[],r=0;r<h.length;r++)for(i=h[r],n=0;n<i.indices.length;n++)s=i.indices[n],f.indices.push(s.id);f.indices=new Uint16Array(f.indices),this.shape=f,this.gl&&ut(f,this.gl)},w.prototype.destroy=function(){var t,e,i,r=this.hook;for(e in this.effect.destroy&&"function"==typeof this.effect.destroy&&this.effect.destroy.call(this),delete this.effect,ot[r]&&(ot[r].count--,ot[r].count||delete ot[r]),this.shader&&this.shader.destroy&&this.shader!==f&&!ot[r]&&this.shader.destroy(),delete this.shader,this.inputElements)this.inputElements.hasOwnProperty(e)&&((i=this.inputElements[e]).element.removeEventListener("change",i.listener,!0),i.element.removeEventListener("input",i.listener,!0));for(e in this.sources)this.sources.hasOwnProperty(e)&&((i=this.sources[e])&&i.removeTarget&&i.removeTarget(this),delete this.sources[e]);for(;this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];for(e in it)it.hasOwnProperty(e)&&(i=it[e]).node===this&&k.removeAlias(e);(t=et.indexOf(this))>=0&&et.splice(t,1),(t=y[r].indexOf(this))>=0&&y[r].splice(t,1),m.prototype.destroy.call(this)},_=function(t){var e=t;Object.defineProperties(this,{original:{enumerable:!0,configurable:!0,get:function(){return e.source}},id:{enumerable:!0,configurable:!0,get:function(){return e.id}},width:{enumerable:!0,configurable:!0,get:function(){return e.width}},height:{enumerable:!0,configurable:!0,get:function(){return e.height}}}),this.render=function(){e.render()},this.update=function(){e.setDirty()},this.readPixels=function(t,i,r,n,s){return e.readPixels(t,i,r,n,s)},this.on=function(t,i){e.on(t,i)},this.off=function(t,i){e.off(t,i)},this.destroy=function(){var t,i;for(t in e.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((i=Object.getOwnPropertyDescriptor(this,t)).get||i.set||"function"!=typeof this[t]?delete this[t]:this[t]=T)},this.isDestroyed=function(){return e.isDestroyed},this.isReady=function(){return e.ready}},(x=function(t,e,i){var n,s,o=i||{},a=void 0===o.flip||o.flip,h=o.width,u=o.height,f=!1,c=this,l=!1;function p(t,e,i,r){var n=d[t];if(n.definition){if(!(n=n.definition.call(c,e,i,r)))return null;n=M(M({},d[t]),n)}return n}function y(t){return c.source===t}if(m.call(this),(t&&"string"!=typeof t||!e&&0!==e)&&(i&&"object"==typeof i||(i=e),e=t),"string"==typeof e&&isNaN(e)&&(e=C(e,["canvas","img","video"])),"string"==typeof t&&d[t]&&(s=p(t,e,i,!0))&&(this.hook=t,l=!0,f=s.deferTexture,this.plugin=s,this.compare=s.compare,this.checkDirty=s.checkDirty,s.source&&(e=s.source)),!s&&G(e))"CANVAS"===e.tagName?(this.width=e.width,this.height=e.height,this.render=this.renderImageCanvas,l=!0,this.hook="canvas",this.compare=y):"IMG"===e.tagName&&(this.width=e.naturalWidth||1,this.height=e.naturalHeight||1,e.complete&&e.naturalWidth||(f=!0),e.addEventListener("load",function(){c.isDestroyed||(c.width===e.naturalWidth&&c.height===e.naturalHeight||(c.width=e.naturalWidth,c.height=e.naturalHeight,c.resize()),c.setDirty(),c.setReady())},!0),this.render=this.renderImageCanvas,l=!0,this.hook="image",this.compare=y);else if(!s&&G(e,"WebGLTexture")){if(r&&!r.isTexture(e))throw new Error("Not a valid WebGL texture.");isNaN(h)?isNaN(u)||(h=u):isNaN(u)&&(u=h),this.width=h,this.height=u,void 0===o.flip&&(a=!1),l=!0,this.texture=e,this.initialized=!0,this.hook="texture",this.compare=y,this.render=function(){}}if(!l&&!s)for(n in d)if(d.hasOwnProperty(n)&&d[n]&&(s=p(n,e,i,!1))){this.hook=n,l=!0,f=s.deferTexture,this.plugin=s,this.compare=s.compare,this.checkDirty=s.checkDirty,s.source&&(e=s.source);break}if(!l)throw new Error("Unknown source type");this.source=e,void 0===this.flip&&(this.flip=a),this.targets=[],f||c.setReady(),this.pub=new _(this),j.push(this),H[this.id]=this,J.push(this),v[this.hook].push(this),J.length&&!L&&pt()}).prototype=Object.create(m.prototype),x.prototype.constructor=x,x.prototype.initialize=function(){var t;r&&!this.texture&&this.ready&&(t=r.createTexture(),r.bindTexture(r.TEXTURE_2D,t),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),this.texture=t,this.initialized=!0,this.allowRefresh=!0,this.setDirty())},x.prototype.initFrameBuffer=function(t){r&&(this.frameBuffer=new q(r,this.width,this.height,{texture:this.texture,useFloat:t}))},x.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},x.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1)},x.prototype.resize=function(){var t,e;if(this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,this.framebuffer&&this.framebuffer.resize(this.width,this.height),this.emit("resize"),this.setDirty(),this.targets)for(t=0;t<this.targets.length;t++)(e=this.targets[t]).resize(),e.setTransformDirty&&e.setTransformDirty()},x.prototype.setReady=function(){var t;if(!this.ready&&(this.ready=!0,this.resize(),this.initialize(),this.emit("ready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setReady()},x.prototype.render=function(){var t=this.source;r&&(t||0===t)&&this.ready&&(this.initialized||this.initialize(),this.allowRefresh&&this.plugin&&this.plugin.render&&(this.dirty||this.checkDirty&&this.checkDirty())&&this.plugin.render.call(this,r,mt,h,f)&&(this.dirty=!1,this.emit("render")))},x.prototype.renderImageCanvas=function(){var e=this.source;if(r&&e&&this.ready&&(this.initialized||this.initialize(),this.allowRefresh&&this.dirty)){r.bindTexture(r.TEXTURE_2D,this.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,this.flip),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);try{return r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),this.dirty=!1,this.emit("render"),!0}catch(e){e.code===t.DOMException.SECURITY_ERR&&(this.allowRefresh=!1,K.logger.error("Unable to access cross-domain image"))}return!1}},x.prototype.destroy=function(){var t,e,i;for(this.plugin&&this.plugin.destroy&&this.plugin.destroy.call(this),r&&this.texture&&r.deleteTexture(this.texture);this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in(t=J.indexOf(this))>=0&&J.splice(t,1),(t=v[this.hook].indexOf(this))>=0&&v[this.hook].splice(t,1),this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];m.prototype.destroy.call(this)},B=function(t){var e=t;Object.defineProperties(this,{source:{enumerable:!0,configurable:!0,get:function(){if(e.source)return e.source.pub},set:function(t){e.setSource(t)}},original:{enumerable:!0,configurable:!0,get:function(){return e.target}},width:{enumerable:!0,configurable:!0,get:function(){return e.width},set:function(t){!isNaN(t)&&t>0&&e.width!==t&&(e.width=t,e.resize(),e.setTransformDirty())}},height:{enumerable:!0,configurable:!0,get:function(){return e.height},set:function(t){!isNaN(t)&&t>0&&e.height!==t&&(e.height=t,e.resize(),e.setTransformDirty())}},id:{enumerable:!0,configurable:!0,get:function(){return e.id}}}),this.render=function(){e.render()},this.readPixels=function(t,i,r,n,s){return e.readPixels(t,i,r,n,s)},this.on=function(t,i){e.on(t,i)},this.off=function(t,i){e.off(t,i)},this.go=function(t){e.go(t)},this.stop=function(){e.stop()},this.getTexture=function(){return e.frameBuffer.texture},this.destroy=function(){var t,i;for(t in e.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((i=Object.getOwnPropertyDescriptor(this,t)).get||i.set||"function"!=typeof this[t]?delete this[t]:this[t]=T)},this.inputs=function(t){return{source:{type:"image"}}},this.isDestroyed=function(){return e.isDestroyed},this.isReady=function(){return e.ready}},((D=function(t,e,i){var n,u,c,l,d,y,g,v,x,b=this,w=!1;function R(t,e,i,n){var s=p[t];if(s.definition){if(!(s=s.definition.call(b,e,i,n)))return null;s=M(M({},p[t]),s),b.hook=x,w=!0,b.plugin=s,b.compare=s.compare,s.target&&(e=s.target),s.gl&&!b.gl&&(b.gl=s.gl,r||ct(s.gl)),b.gl===r&&(b.model=h,b.shader=f)}return s}if(m.call(this),(t&&"string"!=typeof t||!e&&0!==e)&&(i&&"object"==typeof i||(i=e),e=t),u=void 0===(n=i||{}).flip||n.flip,c=parseInt(n.width,10),l=parseInt(n.height,10),y=n.debugContext,"string"==typeof t&&p[t]&&R(t,e,n,!0),this.renderToTexture=n.renderToTexture,G(e,"WebGLFramebuffer"))if(g=e,G(n,"HTMLCanvasElement"))e=n;else if(G(n,"WebGLRenderingContext"))e=n.canvas;else if(G(n.canvas,"HTMLCanvasElement"))e=n.canvas;else{if(!G(n.context,"WebGLRenderingContext"))throw new Error("Must provide a canvas with WebGLFramebuffer target");e=n.context.canvas}if(G(e,"HTMLCanvasElement")){if(c=e.width,l=e.height,(!r||r.canvas!==e&&n.allowSecondaryWebGL)&&(!0,d=V(e,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,stencil:!0,debugContext:y})),d)r&&r!==d?(this.gl=d,this.frameBuffer={frameBuffer:g||null},this.shader=new Z(this.gl,o,a),this.model=ft.call(this,this.gl),this.pixels=null,this.texture=this.gl.createTexture(),this.gl.bindTexture(r.TEXTURE_2D,this.texture),this.gl.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),this.gl.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),this.gl.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),this.gl.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),this.render=this.renderSecondaryWebGL):(s||(s=this),r||ct(d),this.render=this.renderWebGL,n.renderToTexture?r&&(this.frameBuffer=new q(r,c,l,!1)):this.frameBuffer={frameBuffer:g||null});else{if(!n.allowSecondaryWebGL&&r&&r.canvas!==e)throw new Error("Only one WebGL target canvas allowed. Set allowSecondaryWebGL option to create secondary context.");this.render=T,K.logger.log("Unable to create WebGL context.")}w=!0}if(!w)for(x in p)if(p.hasOwnProperty(x)&&p[x]&&R(x,e,n,!1))break;if(!w)throw new Error("Unknown target type");E&&((v=E.get(e))?K.logger.warn("Target already in use by another instance",e,Object.keys(v).map(function(t){return v[t]})):(v={},E.set(e,v)),v[k.id]=k),this.target=e,this.transform=null,this.transformDirty=!0,this.flip=u,c&&(this.width=c),l&&(this.height=l),this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,void 0!==n.auto?this.auto=n.auto:this.auto=at,this.frames=0,this.pub=new B(this),j.push(this),H[this.id]=this,Q.push(this)}).prototype=Object.create(m.prototype)).constructor=D,D.prototype.setSource=function(t){var e;(e=yt(t))!==this.source&&(this.source&&this.source.removeTarget(this),this.source=e,e.addTarget(this),e&&(this.resize(),e.ready?this.setReady():this.setUnready()),this.setDirty())},D.prototype.setDirty=function(){this.dirty=!0,this.auto&&!L&&(L=U(pt))},D.prototype.resize=function(){G(this.target,"HTMLCanvasElement")?this.width===this.target.width&&this.height===this.target.height||(this.target.width=this.width,this.target.height=this.height,this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,this.emit("resize"),this.setTransformDirty()):this.plugin&&this.plugin.resize&&this.plugin.resize.call(this),!this.source||this.source.width===this.width&&this.source.height===this.height||this.transform||(this.transform=new Float32Array(16))},D.prototype.setTransformDirty=function(){this.transformDirty=!0,this.setDirty()},D.prototype.go=function(){this.auto=!0,this.setDirty()},D.prototype.stop=function(){this.auto=!1},D.prototype.render=function(){r&&this.plugin&&this.plugin.render&&this.plugin.render.call(this,mt,f,h)},D.prototype.renderWebGL=function(){var t,e,i;if(this.resize(),r&&this.dirty&&this.ready){if(!this.source)return;this.source.render(),this.uniforms.source=this.source.texture,this.source.width===this.width&&this.source.height===this.height?this.uniforms.transform=this.source.cumulativeMatrix||n:this.transformDirty&&(t=this.transform,O.copy(t,this.source.cumulativeMatrix||n),e=this.source.width/this.width,i=this.source.height/this.height,t[0]*=e,t[1]*=e,t[2]*=e,t[3]*=e,t[4]*=i,t[5]*=i,t[6]*=i,t[7]*=i,this.uniforms.transform=t,this.transformDirty=!1),mt(f,h,this.uniforms,this.frameBuffer.frameBuffer,this,N),this.emit("render"),this.dirty=!1}},D.prototype.renderSecondaryWebGL=function(){var t,e,i,r,s;this.dirty&&this.ready&&this.source&&(this.emit("render"),this.source.render(!0),t=this.source.width,e=this.source.height,this.pixels&&this.pixels.length===t*e*4||(this.pixels=new Uint8Array(t*e*4)),this.source.readPixels(0,0,t,e,this.pixels),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,t,e,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.pixels),t===this.width&&e===this.height?this.uniforms.transform=n:this.transformDirty&&(i=this.transform,O.copy(i,n),r=this.source.width/this.width,s=this.source.height/this.height,i[0]*=r,i[1]*=r,i[2]*=r,i[3]*=r,i[4]*=s,i[5]*=s,i[6]*=s,i[7]*=s,this.uniforms.transform=i,this.transformDirty=!1),this.uniforms.source=this.texture,mt(this.shader,this.model,this.uniforms,null,this,N),this.dirty=!1)},D.prototype.removeSource=function(t){this.source!==t&&this.source!==t.pub||(this.source=null)},D.prototype.destroy=function(){var t,e;this.source&&this.source.removeTarget&&this.source.removeTarget(this),E&&(delete(e=E.get(this.target))[k.id],Object.keys(e).length||E.delete(this.target)),this.plugin&&this.plugin.destroy&&this.plugin.destroy.call(this),delete this.source,delete this.target,delete this.pub,delete this.uniforms,delete this.pixels,delete this.auto,(t=Q.indexOf(this))>=0&&Q.splice(t,1),m.prototype.destroy.call(this),this===s&&(i.removeEventListener("webglcontextrestored",lt,!1),dt(),s=null)},P=function(t){var e,i=t,r=this;function n(t,e){Object.defineProperty(r,t,{configurable:!0,enumerable:!0,get:function(){return e.get.call(i)},set:function(r){!function(t,e,r){var n,s,o;n=i.inputElements[t],"string"==typeof r&&isNaN(r)&&("enum"===e.type?e.options.hasOwnProperty(r)||(r=C(r,["select"])):"number"===e.type||"boolean"===e.type?r=C(r,["input","select"]):"image"===e.type&&(r=C(r,["canvas","img","video"]))),G(r,"HTMLInputElement")||G(r,"HTMLSelectElement")?(s=r.value,n&&n.element!==r&&(n.element.removeEventListener("change",n.listener,!0),n.element.removeEventListener("input",n.listener,!0),delete i.inputElements[t],n=null),n||(n={element:r,listener:(o=r,function(){var e,n;e="checkbox"===r.type?r.checked:o.value,n=i.setInput(t,e),"color"===r.type&&(n=X(n)),n!==e&&(o.value=n)})},i.inputElements[t]=n,"range"===r.type?(r.addEventListener("input",n.listener,!0),r.addEventListener("change",n.listener,!0)):r.addEventListener("change",n.listener,!0)),n&&"checkbox"===r.type&&(s=r.checked)):(n&&(n.element.removeEventListener("change",n.listener,!0),n.element.removeEventListener("input",n.listener,!0),delete i.inputElements[t]),s=r),i.setInput(t,s)}(t,e,r)}})}function s(t){return function(){t.apply(i,arguments)&&i.setTransformDirty()}}for(e in Object.defineProperties(this,{transform:{enumerable:!0,configurable:!0,get:function(){return i.hook}},title:{enumerable:!0,configurable:!0,get:function(){return i.plugin.title||i.hook}},width:{enumerable:!0,configurable:!0,get:function(){return i.width}},height:{enumerable:!0,configurable:!0,get:function(){return i.height}},id:{enumerable:!0,configurable:!0,get:function(){return i.id}},source:{enumerable:!0,configurable:!0,get:function(){return i.source&&i.source.pub},set:function(t){i.setSource(t)}}}),i.methods)i.methods.hasOwnProperty(e)&&(this[e]=s(i.methods[e]));for(e in i.inputs)i.inputs.hasOwnProperty(e)&&n(e,i.inputs[e]);this.update=function(){i.setDirty()},this.inputs=function(t){var e,r,n,s;if(n=i.plugin.inputs,t)return!(r=n[t])||r.method?null:(e={type:r.type,defaultValue:r.defaultValue,title:r.title||t},"number"===r.type?(e.min=r.min,e.max=r.max,e.step=r.step,e.mod=r.mod):"enum"===r.type?e.options=M({},r.options):"vector"===r.type&&(e.dimensions=r.dimensions),r.description&&(e.description=r.description),e);for(s in e={},n)n.hasOwnProperty(s)&&!n[s].method&&(e[s]=this.inputs(s));return e},this.alias=function(t,e){return i.alias(t,e),this},this.on=function(t,e){i.on(t,e)},this.off=function(t,e){i.off(t,e)},this.destroy=function(){var t,e;for(t in i.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=T)},this.isDestroyed=function(){return i.isDestroyed},this.isReady=function(){return i.ready}},(R=function(t,e){var i,r,n,s,o;for(i in this.matrix=new Float32Array(16),this.cumulativeMatrix=new Float32Array(16),this.ready=!1,this.width=1,this.height=1,this.seriously=k,this.transformRef=l[t],this.hook=t,this.id=$,$++,this.options=e,this.sources=null,this.targets=[],this.inputElements={},this.inputs={},this.methods={},this.listeners={},this.texture=null,this.frameBuffer=null,this.uniforms=null,this.dirty=!0,this.transformDirty=!0,this.renderDirty=!1,this.isDestroyed=!1,this.transformed=!1,this.plugin=M({},this.transformRef),this.transformRef.definition&&M(this.plugin,this.transformRef.definition.call(this,e)),this.plugin.inputs)this.plugin.inputs.hasOwnProperty(i)&&((r=this.plugin.inputs[i]).method&&"function"==typeof r.method?this.methods[i]=r.method:"function"==typeof r.set&&"function"==typeof r.get&&(this.inputs[i]=r));for(i in Y(this.plugin),o=st[t],this.plugin.inputs)this.plugin.inputs.hasOwnProperty(i)&&"function"==typeof(r=this.plugin.inputs[i]).set&&"function"==typeof r.get&&"function"!=typeof r.method&&(n=r.get.call(this),s=void 0===r.defaultValue?n:r.defaultValue,s=r.validate.call(this,s,r,n),o&&void 0!==o[i]&&(s=r.validate.call(this,o[i],r,r.defaultValue,s),o[i]=s),s!==n&&r.set.call(this,s));j.push(this),H[this.id]=this,this.pub=new P(this),tt.push(this),g[t].push(this)}).prototype=Object.create(m.prototype),R.prototype.constructor=R,R.prototype.setDirty=function(){this.renderDirty=!0,m.prototype.setDirty.call(this)},R.prototype.setTransformDirty=function(){var t,e;for(this.transformDirty=!0,this.dirty=!0,this.renderDirty=!0,t=0;t<this.targets.length;t++)(e=this.targets[t]).setTransformDirty?e.setTransformDirty():e.setDirty()},R.prototype.resize=function(){var t;for(m.prototype.resize.call(this),this.plugin.resize&&this.plugin.resize.call(this),t=0;t<this.targets.length;t++)this.targets[t].resize();this.setTransformDirty()},R.prototype.setSource=function(t){var e;if((e=yt(t))!==this.source){if(gt(e,this))throw new Error("Attempt to make cyclical connection.");this.source&&this.source.removeTarget(this),this.source=e,e.addTarget(this),e&&e.ready?this.setReady():this.setUnready(),this.resize()}},R.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},R.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1),this.targets&&this.targets.length&&this.resize()},R.prototype.setInput=function(t,e){var i,r,n;if(this.plugin.inputs.hasOwnProperty(t))return i=this.plugin.inputs[t],r=st[this.hook]&&void 0!==st[this.hook][t]?st[this.hook][t]:i.defaultValue,n=i.get.call(this),void 0===r&&(r=n),e=i.validate.call(this,e,i,r,n),i.set.call(this,e)&&this.setTransformDirty(),i.get.call(this)},R.prototype.alias=function(t,e){var i,r,n=this;if(I.indexOf(e)>=0)throw new Error("'"+e+"' is a reserved name and cannot be used as an alias.");return this.plugin.inputs.hasOwnProperty(t)&&(e||(e=t),k.removeAlias(e),(i=this.inputs[t])?(r=n.inputs[t],Object.defineProperty(k,e,{configurable:!0,enumerable:!0,get:function(){return r.get.call(n)},set:function(t){r.set.call(n,t)&&n.setTransformDirty()}})):(i=this.methods[t])&&(r=i,k[e]=function(){r.apply(n,arguments)&&n.setTransformDirty()}),i&&(it[e]={node:this,input:t})),this},R.prototype.render=function(t){return this.source?(this.source.render(),this.transformDirty&&(this.transformed?this.source.cumulativeMatrix?O.multiply(this.cumulativeMatrix,this.matrix,this.source.cumulativeMatrix):O.copy(this.cumulativeMatrix,this.matrix):O.copy(this.cumulativeMatrix,this.source.cumulativeMatrix||n),this.transformDirty=!1),t&&r?(this.renderDirty&&(this.frameBuffer||(this.uniforms={resolution:[this.width,this.height]},this.frameBuffer=new q(r,this.width,this.height)),this.uniforms.source=this.source.texture,this.uniforms.transform=this.cumulativeMatrix||n,mt(f,h,this.uniforms,this.frameBuffer.frameBuffer,this),this.renderDirty=!1),this.texture=this.frameBuffer.texture):this.source?this.texture=this.source.texture:this.texture=null,this.dirty=!1,this.texture):(this.transformDirty&&(O.copy(this.cumulativeMatrix,this.matrix),this.transformDirty=!1),this.texture=null,void(this.dirty=!1))},R.prototype.readPixels=function(t,e,i,n,s){var o=this.gl||r;if(!r)throw new Error("Cannot read pixels until a canvas is connected");if(this.render(!0),void 0===s)s=new Uint8Array(i*n*4);else if(!G(s,"Uint8Array"))throw new Error("Incompatible array type");return o.bindFramebuffer(r.FRAMEBUFFER,this.frameBuffer.frameBuffer),o.readPixels(t,e,i,n,r.RGBA,r.UNSIGNED_BYTE,s),s},R.prototype.destroy=function(){var t,e,i,r=this.hook;for(t in this.plugin.destroy&&"function"==typeof this.plugin.destroy&&this.plugin.destroy.call(this),delete this.effect,this.frameBuffer&&(this.frameBuffer.destroy(),delete this.frameBuffer,delete this.texture),this.inputElements)this.inputElements.hasOwnProperty(t)&&((i=this.inputElements[t]).element.removeEventListener("change",i.listener,!0),i.element.removeEventListener("input",i.listener,!0));for(this.source&&this.source.removeTarget(this);this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];for(e in it)it.hasOwnProperty(e)&&(i=it[e]).node===this&&k.removeAlias(e);(t=tt.indexOf(this))>=0&&tt.splice(t,1),(t=g[r].indexOf(this))>=0&&g[r].splice(t,1),m.prototype.destroy.call(this)},R.prototype.setReady=m.prototype.setReady,R.prototype.setUnready=m.prototype.setUnready,R.prototype.on=m.prototype.on,R.prototype.off=m.prototype.off,R.prototype.emit=m.prototype.emit,(e=G(e,"HTMLCanvasElement")?{canvas:e}:e||{}).canvas,this.effect=function(t,e){if(!c[t])throw new Error("Unknown effect: "+t);return new w(t,e).pub},this.source=function(t,e,i){return yt(t,e,i).pub},this.transform=function(t,i){if("string"!=typeof t&&(i=t,t=!1),t){if(!l[t])throw new Error("Unknown transform: "+t)}else if(t=e&&e.defaultTransform||"2d",!l[t])throw new Error("No transform specified");return new R(t,i).pub},this.target=function(t,e,i){var r,n,s;for(t&&"string"==typeof t&&!p[t]&&(n=u.querySelector(t)),("string"!=typeof t||!e&&0!==e||n)&&(i&&"object"==typeof i||(i=e),e=n||t,t=null),"string"==typeof e&&isNaN(e)&&(e=u.querySelector(e)),s=0;s<Q.length;s++)if(r=Q[s],(!t||t===r.hook)&&(r.target===e||r.compare&&r.compare(e,i)))return r.pub;return(r=new D(t,e,i)).pub},this.aliases=function(){return Object.keys(it)},this.removeAlias=function(t){it[t]&&(delete this[t],delete it[t])},this.defaults=function(t,e){var i;if(t)if("object"!=typeof t)null===e?delete st[t]:"object"==typeof e&&(st[t]=M({},e));else for(i in t)t.hasOwnProperty(i)&&this.defaults(i,t[i]);else if(null===t)for(i in st)st.hasOwnProperty(i)&&delete st[i]},this.go=function(t,e){var i;for("function"==typeof t&&rt.indexOf(t)<0&&rt.push(t),"function"==typeof e&&nt.indexOf(e)<0&&nt.push(e),at=!0,i=0;i<Q.length;i++)Q[i].go();L||!rt.length&&!nt.length||pt()},this.stop=function(){rt.length=0,nt.length=0,S(L),L=0},this.render=function(){var t;for(t=0;t<Q.length;t++)Q[t].render(e)},this.destroy=function(){for(var t,e;j.length;)j[0].pub.destroy();for(t in this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=T);k=null,J=[],Q=[],et=[],j=[],rt.length=0,nt.length=0,S(L),L=0,ht=!0},this.isDestroyed=function(){return ht},this.incompatible=function(t){var e,i,r;if(r=K.incompatible(t))return r;if(!t){for(e in y)if(y.hasOwnProperty(e)&&y[e].length&&(i=c[e])&&"function"==typeof i.compatible&&!i.compatible.call(this))return"plugin-"+e;for(e in v)if(v.hasOwnProperty(e)&&v[e].length&&(i=d[e])&&"function"==typeof i.compatible&&!i.compatible.call(this))return"source-"+e}return!1},this.isNode=function(t){var e;return!(!t||!(e=H[t.id])||e.isDestroyed)},this.isSource=function(t){return this.isNode(t)&&t instanceof _},this.isEffect=function(t){return this.isNode(t)&&t instanceof A},this.isTransform=function(t){return this.isNode(t)&&t instanceof P},this.isTarget=function(t){return this.isNode(t)&&t instanceof B},Object.defineProperties(this,{id:{enumerable:!0,configurable:!0,get:function(){return z}}}),this.defaults(e.defaults)}return t.addEventListener("message",function(e){e.source===t&&"seriously-timeout-message"===e.data&&(e.stopPropagation(),m.length>0&&m.shift()())},!0),q.prototype.resize=function(t,e){var i=this.gl;this.width===t&&this.height===e||(this.width=t,this.height=e,i&&(i.bindTexture(i.TEXTURE_2D,this.texture),i.bindFramebuffer(i.FRAMEBUFFER,this.frameBuffer),i.bindRenderbuffer(i.RENDERBUFFER,this.renderBuffer),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,e,0,i.RGBA,i.UNSIGNED_BYTE,null),i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_COMPONENT16,t,e),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,this.texture,0),i.bindTexture(i.TEXTURE_2D,null),i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null)))},q.prototype.destroy=function(){var t=this.gl;t&&(t.deleteFramebuffer(this.frameBuffer),t.deleteRenderbuffer(this.renderBuffer),this.ownTexture&&t.deleteTexture(this.texture)),delete this.frameBuffer,delete this.renderBuffer,delete this.texture,delete this.gl},Z.prototype.use=function(){this.gl.useProgram(this.program)},K.incompatible=function(e){var i,n,s;if(void 0===r&&((i=u.createElement("canvas"))&&i.getContext?t.WebGLRenderingContext?(n=H())||(r="context"):r="webgl":r="canvas"),r)return r;if(e){if((s=c[e])&&"function"==typeof s.compatible&&!s.compatible(n))return"plugin-"+e;if((s=d[e])&&"function"==typeof s.compatible&&!s.compatible(n))return"source-"+e}return!1},K.plugin=function(t,e,i){var r;if(c[t])K.logger.warn("Effect ["+t+"] already loaded");else if(void 0===i&&"object"==typeof e&&(i=e),i)return r=M({},i),"function"==typeof e&&(r.definition=e),r.reserved=B,r.inputs&&Y(r),r.title||(r.title=t),c[t]=r,y[t]=[],r},K.removePlugin=function(t){var e;if(!t)return this;if(!c[t])return this;if(e=y[t]){for(;e.length;)e.shift().destroy();delete y[t]}return delete c[t],this},K.source=function(t,e,i){var r;if(d[t])K.logger.warn("Source ["+t+"] already loaded");else if(void 0===i&&"object"==typeof e&&(i=e),i||e)return r=M({},i),"function"==typeof e&&(r.definition=e),r.title||(r.title=t),d[t]=r,v[t]=[],r},K.removeSource=function(t){var e;if(!t)return this;if(!d[t])return this;if(e=v[t]){for(;e.length;)e.shift().destroy();delete v[t]}return delete d[t],this},K.transform=function(t,e,i){var r;if(l[t])K.logger.warn("Transform ["+t+"] already loaded");else if(void 0===i&&"object"==typeof e&&(i=e),i||e)return r=M({},i),"function"==typeof e&&(r.definition=e),r.reserved=L,r.inputs&&Y(r),r.title||(r.title=t),l[t]=r,g[t]=[],r},K.removeTransform=function(t){var e;if(!t)return this;if(!l[t])return this;if(e=g[t]){for(;e.length;)e.shift().destroy();delete g[t]}return delete l[t],this},K.target=function(t,e,i){var r;if(p[t])K.logger.warn("Target ["+t+"] already loaded");else if(void 0===i&&"object"==typeof e&&(i=e),i||e)return r=M({},i),"function"==typeof e&&(r.definition=e),r.title||(r.title=t),p[t]=r,x[t]=[],r},K.removeTarget=function(t){var e;if(!t)return this;if(!p[t])return this;if(e=x[t]){for(;e.length;)e.shift().destroy();delete x[t]}return delete p[t],this},K.inputValidators={color:function(t,e,r,n){var s,o,a,h;if(o=n||[],"string"==typeof t){if((a=R.exec(t))&&a.length){if(a.length<3)return o[0]=o[1]=o[2]=o[3]=0,o;for(o[3]=1,h=0;h<3;h++)o[h]=parseFloat(a[h+2])/255;return isNaN(a[6])||(o[3]=parseFloat(a[6])),"hsl"===a[1].toLowerCase()?k(o[0],o[1],o[2],o[3],o):o}if((a=D.exec(t))&&a.length)return 3===(s=a[1]).length?(o[0]=parseInt(s[0],16)/15,o[1]=parseInt(s[1],16)/15,o[2]=parseInt(s[2],16)/15,o[3]=1):4===s.length?(o[0]=parseInt(s[0],16)/15,o[1]=parseInt(s[1],16)/15,o[2]=parseInt(s[2],16)/15,o[3]=parseInt(s[3],16)/15):6===s.length?(o[0]=parseInt(s.substr(0,2),16)/255,o[1]=parseInt(s.substr(2,2),16)/255,o[2]=parseInt(s.substr(4,2),16)/255,o[3]=1):8===s.length?(o[0]=parseInt(s.substr(0,2),16)/255,o[1]=parseInt(s.substr(2,2),16)/255,o[2]=parseInt(s.substr(4,2),16)/255,o[3]=parseInt(s.substr(6,2),16)/255):o[0]=o[1]=o[2]=o[3]=0,o;if(a=w[t.toLowerCase()]){for(h=0;h<4;h++)o[h]=a[h];return o}return i||(i=u.createElement("canvas").getContext("2d")),i.fillStyle=t,(s=i.fillStyle)&&"#000000"!==s?K.inputValidators.color(s,e,r,n):(o[0]=o[1]=o[2]=o[3]=0,o)}if(j(t)){if((o=t).length<3)return o[0]=o[1]=o[2]=o[3]=0,o;for(h=0;h<3;h++)if(isNaN(o[h]))return o[0]=o[1]=o[2]=o[3]=0,o;return o.length<4&&o.push(1),o}if("number"==typeof t)return o[0]=o[1]=o[2]=t,o[3]=1,o;if("object"==typeof t){for(h=0;h<4;h++)null===t[s=_[h]]||isNaN(t[s])?o[h]=3===h?1:0:o[h]=t[s];return o}return o[0]=o[1]=o[2]=o[3]=0,o},number:function(t,e,i){return t=parseFloat(t),isNaN(t)?i||0:(e.mod&&(t-=e.mod*Math.floor(t/e.mod)),t<e.min?e.min:t>e.max?e.max:e.step?Math.round(t/e.step)*e.step:t)},enum:function(t,e,i){var r=e.options||[];return"string"==typeof t?t=t.toLowerCase():"number"==typeof t?t=t.toString():t||(t=""),r.hasOwnProperty(t)?t:i||""},vector:function(t,e,i,r){var n,s,o,a=e.dimensions||4;if(n=r||[],j(t)){for(s=0;s<a;s++)n[s]=t[s]||0;return n}if("object"==typeof t){for(s=0;s<a;s++)void 0===t[o=A[s]]&&(o=_[s]),n[s]=t[o]||0;return n}for(t=parseFloat(t)||0,s=0;s<a;s++)n[s]=t;return n},boolean:function(t){return!!t&&(!t||!t.toLowerCase||"false"!==t.toLowerCase())},string:function(t){return"string"==typeof t?t:0===t||t?t.toString?t.toString():String(t):""}},K.prototype.effects=K.effects=function(){var t,e,i,r,n,s={};for(t in c)if(c.hasOwnProperty(t)){for(n in i={title:(e=c[t]).title||t,description:e.description||"",inputs:{}},e.inputs)e.inputs.hasOwnProperty(n)&&(r=e.inputs[n],i.inputs[n]={type:r.type,defaultValue:r.defaultValue,step:r.step,min:r.min,max:r.max,mod:r.mod,minCount:r.minCount,maxCount:r.maxCount,dimensions:r.dimensions,title:r.title||n,description:r.description||"",options:r.options||[]});s[t]=i}return s},t.Float32Array&&(n=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])),t.Seriously&&"object"==typeof t.Seriously&&function(){var e;for(e in t.Seriously)t.Seriously.hasOwnProperty(e)&&"plugin"!==e&&"object"==typeof t.Seriously[e]&&K.plugin(e,t.Seriously[e])}(),K.logger={log:z("log"),info:z("info"),warn:z("warn"),error:z("error")},K.util={mat4:O,checkSource:function(e){var i,r,n,s;if(!(i=C(e,["img","canvas","video"])))return!1;if(!(r=u.createElement("canvas")))return K.logger.warn("Browser does not support canvas or Seriously.js"),!1;if(0===i.naturalWidth&&"IMG"===i.tagName)return K.logger.warn("Image not loaded"),!1;if(0===i.readyState&&0===i.videoWidth&&"VIDEO"===i.tagName)return K.logger.warn("Video not loaded"),!1;if(n=H()){(s=n.createTexture())||K.logger.error("Test WebGL context has been lost"),n.bindTexture(n.TEXTURE_2D,s);try{n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i)}catch(e){return e.code===t.DOMException.SECURITY_ERR?K.logger.log("Unable to access cross-domain image"):K.logger.error("Error storing image to texture: "+e.message),n.deleteTexture(s),!1}n.deleteTexture(s)}else{n=r.getContext("2d");try{n.drawImage(i,0,0),n.getImageData(0,0,1,1)}catch(e){return e.code===t.DOMException.SECURITY_ERR?K.logger.log("Unable to access cross-domain image"):K.logger.error("Error drawing image to canvas: "+e.message),!1}}return!0},hslToRgb:k,colors:w,setTimeoutZero:W,ShaderProgram:Z,FrameBuffer:q,requestAnimationFrame:U,shader:{makeNoise:"float makeNoise(float u, float v, float timer) {\n\tfloat x = u * v * mod(timer * 1000.0, 100.0);\n\tx = mod(x, 13.0) * mod(x, 127.0);\n\tfloat dx = mod(x, 0.01);\n\treturn clamp(0.1 + dx * 100.0, 0.0, 1.0);\n}\n",random:"#ifndef RANDOM\n#define RANDOM\nfloat random(vec2 n) {\n\treturn 0.5 + 0.5 * fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);\n}\n#endif\n"}},K.source("video",function(e,i,r){var n,o,a=this,h=!1,f=!1,c=!1,l=0;function d(){e.removeEventListener("loadedmetadata",d,!0),h||(e.videoWidth?(a.width===e.videoWidth&&a.height===e.videoHeight||(a.width=e.videoWidth,a.height=e.videoHeight,a.resize()),f&&a.setReady()):(f=!0,setTimeout(d,50)))}function p(){c=!0}function m(){c=!1,a.setDirty()}if(G(e,"HTMLVideoElement"))return e.readyState?d():(f=!0,e.addEventListener("loadedmetadata",d,!0)),e.addEventListener("seeking",p,!1),e.addEventListener("seeked",m,!1),{deferTexture:f,source:e,render:function i(r){var h;if(l=e.currentTime,!e.videoHeight||!e.videoWidth)return!1;s?(o||(o=u.createElement("canvas").getContext("2d"),(n=o.canvas).width=a.width,n.height=a.height),h=n,o.drawImage(e,0,0,a.width,a.height)):h=e,r.bindTexture(r.TEXTURE_2D,a.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,a.flip),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);try{if(r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,h),void 0===s){if(r.getError()===r.INVALID_VALUE)return s=!0,i(r);s=!1}return!0}catch(e){e.code===t.DOMException.SECURITY_ERR?(a.allowRefresh=!1,K.logger.error("Unable to access cross-domain image")):K.logger.error("Error rendering video source",e)}return!1},checkDirty:function(){return!c&&e.currentTime!==l},compare:function(t){return a.source===t},destroy:function(){h=!0,e.removeEventListener("seeking",p,!1),e.removeEventListener("seeked",m,!1),e.removeEventListener("loadedmetadata",d,!0)}}},{title:"Video"}),K.transform("2d",function(t){var e=this,i=!(t&&t.radians),r=0,n=0,s=1,o=1,a=0,h=0,u=0,f=0,c=0;function l(){var t,l,d,p,m,y,g,v,x,E,b,T=e.matrix;function w(t,e){T[12]=T[0]*t+T[4]*e+T[12],T[13]=T[1]*t+T[5]*e+T[13],T[14]=T[2]*t+T[6]*e+T[14],T[15]=T[3]*t+T[7]*e+T[15]}a||h||u||f||c||1!==s||1!==o?(O.identity(T),w(a+r,h+n),f&&(T[4]=f/e.width),c&&(T[1]=c/e.height),u&&(p=T[0],m=T[1],y=T[2],g=T[3],v=T[4],x=T[5],E=T[6],b=T[7],t=-(i?u*Math.PI/180:u),l=Math.sin(t),d=Math.cos(t),T[0]=p*d+v*l,T[1]=m*d+x*l,T[2]=y*d+E*l,T[3]=g*d+b*l,T[4]=v*d-p*l,T[5]=x*d-m*l,T[6]=E*d-y*l,T[7]=b*d-g*l),1!==s&&(T[0]*=s,T[1]*=s,T[2]*=s,T[3]*=s),1!==o&&(T[4]*=o,T[5]*=o,T[6]*=o,T[7]*=o),w(-r,-n),e.transformed=!0):e.transformed=!1}return{inputs:{reset:{method:function(){return r=0,n=0,s=1,o=1,a=0,h=0,u=0,f=0,c=0,!!e.transformed&&(e.transformed=!1,!0)}},translate:{method:function(t,e){return isNaN(t)&&(t=a),isNaN(e)&&(e=h),(t!==a||e!==h)&&(a=t,h=e,l(),!0)},type:["number","number"]},translateX:{get:function(){return a},set:function(t){return t!==a&&(a=t,l(),!0)},type:"number"},translateY:{get:function(){return h},set:function(t){return t!==h&&(h=t,l(),!0)},type:"number"},rotation:{get:function(){return u},set:function(t){return t!==u&&(u=parseFloat(t),l(),!0)},type:"number"},center:{method:function(t,e){return isNaN(t)&&(t=r),isNaN(e)&&(e=n),(t!==r||e!==n)&&(r=t,n=e,l(),!0)},type:["number","number"]},centerX:{get:function(){return r},set:function(t){return t!==r&&(r=t,l(),!0)},type:"number"},centerY:{get:function(){return n},set:function(t){return t!==n&&(n=t,l(),!0)},type:"number"},skew:{method:function(t,e){return isNaN(t)&&(t=f),isNaN(e)&&(e=c),(t!==f||e!==c)&&(f=t,c=e,l(),!0)},type:["number","number"]},skewX:{get:function(){return f},set:function(t){return t!==f&&(f=t,l(),!0)},type:"number"},skewY:{get:function(){return c},set:function(t){return t!==c&&(c=t,l(),!0)},type:"number"},scale:{method:function(t,e){var i,r;if(i=isNaN(t)?s:t,isNaN(e)){if(isNaN(t))return!1;r=i}else r=e;return(i!==s||r!==o)&&(s=i,o=r,l(),!0)},type:["number","number"]},scaleX:{get:function(){return s},set:function(t){return t!==s&&(s=t,l(),!0)},type:"number"},scaleY:{get:function(){return o},set:function(t){return t!==o&&(o=t,l(),!0)},type:"number"}}}},{title:"2D Transform",description:"Translate, Rotate, Scale, Skew"}),K.transform("flip",function(){var t=this,e=!0;function i(){var i=t.matrix;e?(i[0]=-1,i[5]=1):(i[0]=1,i[5]=-1)}return O.identity(t.matrix),i(),t.transformDirty=!0,t.transformed=!0,{inputs:{direction:{get:function(){return e?"horizontal":"vertical"},set:function(t){var r;return(r="vertical"!==t)!==e&&(e=r,i(),!0)},type:"string"}}}},{title:"Flip",description:"Flip Horizontal/Vertical"}),K.transform("reformat",function(){var t,e,i=this,r="contain";function n(){var n,s,o,a,h=i.matrix,u=t||i.width,f=e||i.height,c=i.source,l=c&&c.width||1,d=c&&c.height||1;"distort"===r||u===l&&f===d?i.transformed=!1:(o=l/d,a=u/f,"none"===r?(n=l/u,s=d/f):"width"===r||"contain"===r&&a<=o?(n=1,s=a/o):"height"===r||"contain"===r&&a>o?(n=o/a,s=1):a>o?(n=1,s=a/o):(n=o/a,s=1),1!==n||1!==s?(O.identity(h),1!==n&&(h[0]*=n,h[1]*=n,h[2]*=n,h[3]*=n),1!==s&&(h[4]*=s,h[5]*=s,h[6]*=s,h[7]*=s),i.transformed=!0):i.transformed=!1)}function s(){return t||i.source&&i.source.width||1}function o(){return e||i.source&&i.source.height||1}return this.resize=function(){var t,e=s(),i=o();if(this.width!==e||this.height!==i)for(this.width=e,this.height=i,this.uniforms&&this.uniforms.resolution&&(this.uniforms.resolution[0]=e,this.uniforms.resolution[1]=i),this.frameBuffer&&this.frameBuffer.resize&&this.frameBuffer.resize(e,i),t=0;t<this.targets.length;t++)this.targets[t].resize();this.setTransformDirty(),n()},{inputs:{width:{get:s,set:function(e){return(e=Math.floor(e))!==t&&(t=e,this.resize(),!1)},type:"number"},height:{get:o,set:function(t){return(t=Math.floor(t))!==e&&(e=t,this.resize(),!1)},type:"number"},mode:{get:function(){return r},set:function(t){return t!==r&&(r=t,n(),!0)},type:"enum",options:["cover","contain","distort","width","height","none"]}}}},{title:"Reformat",description:"Change output dimensions"}),o=["precision mediump float;","attribute vec4 position;","attribute vec2 texCoord;","uniform vec2 resolution;","uniform mat4 transform;","varying vec2 vTexCoord;","void main(void) {","\tvec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);","\tscreenPosition = transform * screenPosition;","\tgl_Position.xy = screenPosition.xy * 2.0 / resolution;","\tgl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);","\tgl_Position.w = screenPosition.w;","\tvTexCoord = texCoord;","}\n"].join("\n"),a=["precision mediump float;","varying vec2 vTexCoord;","uniform sampler2D source;","void main(void) {","\t\tgl_FragColor = texture2D(source, vTexCoord);","}"].join("\n"),K.util.shader.noiseHelpers="#ifndef NOISE_HELPERS\n#define NOISE_HELPERS\nvec2 mod289(vec2 x) {\n\treturn x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec3 mod289(vec3 x) {\n\treturn x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 mod289(vec4 x) {\n\treturn x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec3 permute(vec3 x) {\n\treturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 permute(vec4 x) {\n\treturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 taylorInvSqrt(vec4 r) {\n\treturn 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat taylorInvSqrt(float r) {\n\treturn 1.79284291400159 - 0.85373472095314 * r;\n}\n#endif\n",K.util.shader.snoise2d="#ifndef NOISE2D\n#define NOISE2D\nfloat snoise(vec2 v) {\n\tconst vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0\n\t\t0.366025403784439, // 0.5*(sqrt(3.0)-1.0)\n\t\t-0.577350269189626, // -1.0 + 2.0 * C.x\n\t\t0.024390243902439); // 1.0 / 41.0\n\tvec2 i = floor(v + dot(v, C.yy));\n\tvec2 x0 = v - i + dot(i, C.xx);\n\tvec2 i1;\n\t//i1.x = step(x0.y, x0.x); // x0.x > x0.y ? 1.0 : 0.0\n\t//i1.y = 1.0 - i1.x;\n\ti1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\t// x0 = x0 - 0.0 + 0.0 * C.xx ;\n\t// x1 = x0 - i1 + 1.0 * C.xx ;\n\t// x2 = x0 - 1.0 + 2.0 * C.xx ;\n\tvec4 x12 = x0.xyxy + C.xxzz;\n\tx12.xy -= i1;\n\ti = mod289(i); // Avoid truncation effects in permutation\n\tvec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));\n\tvec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);\n\tm = m*m ;\n\tm = m*m ;\n\tvec3 x = 2.0 * fract(p * C.www) - 1.0;\n\tvec3 h = abs(x) - 0.5;\n\tvec3 ox = floor(x + 0.5);\n\tvec3 a0 = x - ox;\n\tm *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n\tvec3 g;\n\tg.x = a0.x * x0.x + h.x * x0.y;\n\tg.yz = a0.yz * x12.xz + h.yz * x12.yw;\n\treturn 130.0 * dot(m, g);\n}\n#endif\n",K.util.shader.snoise3d="#ifndef NOISE3D\n#define NOISE3D\nfloat snoise(vec3 v) {\n\tconst vec2 C = vec2(1.0/6.0, 1.0/3.0) ;\n\tconst vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n\tvec3 i = floor(v + dot(v, C.yyy));\n\tvec3 x0 = v - i + dot(i, C.xxx) ;\n\tvec3 g = step(x0.yzx, x0.xyz);\n\tvec3 l = 1.0 - g;\n\tvec3 i1 = min(g.xyz, l.zxy);\n\tvec3 i2 = max(g.xyz, l.zxy);\n\t// x0 = x0 - 0.0 + 0.0 * C.xxx;\n\t// x1 = x0 - i1 + 1.0 * C.xxx;\n\t// x2 = x0 - i2 + 2.0 * C.xxx;\n\t// x3 = x0 - 1.0 + 3.0 * C.xxx;\n\tvec3 x1 = x0 - i1 + C.xxx;\n\tvec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n\tvec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\ti = mod289(i);\n\tvec4 p = permute(permute(permute(\n\t\t\t\t\t\ti.z + vec4(0.0, i1.z, i2.z, 1.0))\n\t\t\t\t\t\t+ i.y + vec4(0.0, i1.y, i2.y, 1.0))\n\t\t\t\t\t\t+ i.x + vec4(0.0, i1.x, i2.x, 1.0));\n\tfloat n_ = 0.142857142857; // 1.0/7.0\n\tvec3 ns = n_ * D.wyz - D.xzx;\n\tvec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p, 7 * 7)\n\tvec4 x_ = floor(j * ns.z);\n\tvec4 y_ = floor(j - 7.0 * x_); // mod(j, N)\n\tvec4 x = x_ * ns.x + ns.yyyy;\n\tvec4 y = y_ * ns.x + ns.yyyy;\n\tvec4 h = 1.0 - abs(x) - abs(y);\n\tvec4 b0 = vec4(x.xy, y.xy);\n\tvec4 b1 = vec4(x.zw, y.zw);\n\t//vec4 s0 = vec4(lessThan(b0, 0.0)) * 2.0 - 1.0;\n\t//vec4 s1 = vec4(lessThan(b1, 0.0)) * 2.0 - 1.0;\n\tvec4 s0 = floor(b0) * 2.0 + 1.0;\n\tvec4 s1 = floor(b1) * 2.0 + 1.0;\n\tvec4 sh = -step(h, vec4(0.0));\n\tvec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy ;\n\tvec4 a1 = b1.xzyw + s1.xzyw * sh.zzww ;\n\tvec3 p0 = vec3(a0.xy, h.x);\n\tvec3 p1 = vec3(a0.zw, h.y);\n\tvec3 p2 = vec3(a1.xy, h.z);\n\tvec3 p3 = vec3(a1.zw, h.w);\n\tvec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n\tp0 *= norm.x;\n\tp1 *= norm.y;\n\tp2 *= norm.z;\n\tp3 *= norm.w;\n\tvec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n\tm = m * m;\n\treturn 42.0 * dot(m*m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\n#endif\n",K.util.shader.snoise4d="#ifndef NOISE4D\n#define NOISE4D\nvec4 grad4(float j, vec4 ip)\n\t{\n\tconst vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);\n\tvec4 p, s;\n\n\tp.xyz = floor(fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;\n\tp.w = 1.5 - dot(abs(p.xyz), ones.xyz);\n\ts = vec4(lessThan(p, vec4(0.0)));\n\tp.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www;\n\n\treturn p;\n\t}\n\n#define F4 0.309016994374947451\n\nfloat snoise(vec4 v)\n\t{\n\tconst vec4 C = vec4(0.138196601125011, // (5 - sqrt(5))/20 G4\n\t\t\t\t\t\t0.276393202250021, // 2 * G4\n\t\t\t\t\t\t0.414589803375032, // 3 * G4\n\t\t\t\t\t\t-0.447213595499958); // -1 + 4 * G4\n\n\tvec4 i = floor(v + dot(v, vec4(F4)));\n\tvec4 x0 = v - i + dot(i, C.xxxx);\n\n\n\tvec4 i0;\n\tvec3 isX = step(x0.yzw, x0.xxx);\n\tvec3 isYZ = step(x0.zww, x0.yyz);\n\ti0.x = isX.x + isX.y + isX.z;\n\ti0.yzw = 1.0 - isX;\n\ti0.y += isYZ.x + isYZ.y;\n\ti0.zw += 1.0 - isYZ.xy;\n\ti0.z += isYZ.z;\n\ti0.w += 1.0 - isYZ.z;\n\n\tvec4 i3 = clamp(i0, 0.0, 1.0);\n\tvec4 i2 = clamp(i0 - 1.0, 0.0, 1.0);\n\tvec4 i1 = clamp(i0 - 2.0, 0.0, 1.0);\n\n\tvec4 x1 = x0 - i1 + C.xxxx;\n\tvec4 x2 = x0 - i2 + C.yyyy;\n\tvec4 x3 = x0 - i3 + C.zzzz;\n\tvec4 x4 = x0 + C.wwww;\n\n\ti = mod289(i);\n\tfloat j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x);\n\tvec4 j1 = permute(permute(permute(permute (\n\t\t\t\t\ti.w + vec4(i1.w, i2.w, i3.w, 1.0))\n\t\t\t\t\t+ i.z + vec4(i1.z, i2.z, i3.z, 1.0))\n\t\t\t\t\t+ i.y + vec4(i1.y, i2.y, i3.y, 1.0))\n\t\t\t\t\t+ i.x + vec4(i1.x, i2.x, i3.x, 1.0));\n\n\tvec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ;\n\n\tvec4 p0 = grad4(j0, ip);\n\tvec4 p1 = grad4(j1.x, ip);\n\tvec4 p2 = grad4(j1.y, ip);\n\tvec4 p3 = grad4(j1.z, ip);\n\tvec4 p4 = grad4(j1.w, ip);\n\n\tvec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n\tp0 *= norm.x;\n\tp1 *= norm.y;\n\tp2 *= norm.z;\n\tp3 *= norm.w;\n\tp4 *= taylorInvSqrt(dot(p4, p4));\n\n\tvec3 m0 = max(0.6 - vec3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0);\n\tvec2 m1 = max(0.6 - vec2(dot(x3, x3), dot(x4, x4)), 0.0);\n\tm0 = m0 * m0;\n\tm1 = m1 * m1;\n\treturn 49.0 * (dot(m0*m0, vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2)))\n\t\t\t\t\t\t\t+ dot(m1*m1, vec2(dot(p3, x3), dot(p4, x4)))) ;\n}\n#endif\n",K});