text: var PX={version:"0.1.0"};PX.readPixels=!1,PX.broadcast=!1,PX.speed=.02,PX.useTransforms=!1,PX.usePodPosUniforms=!1,PX.pointCloud={},PX.pointGeometry={},PX.pointMaterial={},PX.pointSprite,PX.pointSize=25,PX.BLEND={},PX.BLEND.OFF=0,PX.BLEND.Add=1,PX.BLEND.Subtract=2,PX.BLEND.Darkest=3,PX.BLEND.Lightest=4,PX.BLEND.Difference=5,PX.BLEND.Exclusion=6,PX.BLEND.Multiply=7,PX.BLEND.Screen=8,PX.BLEND.Overlay=9,PX.BLEND.HardLight=10,PX.BLEND.SoftLight=11,PX.BLEND.Dodge=12,PX.BLEND.Burn=13,PX.BLEND.LinearBurn=14,PX.BLEND.LinearLight=15,PX.BLEND.VividLight=16,PX.BLEND.PinLight=17,PX.BLEND.Replace=18,PX.BLEND.Ignore=19,PX.BLENDS=["Add","Substract","Darkest","Lightest","Difference","Exclusion","Multiply","Screen","Overlay","HardLight","SoftLight","Dodge","Burn","LinearBurn","LinearLight","VividLight","PinLight"],PX.PORT_TYPE_OFF=0,PX.PORT_TYPE_KINET_1=1,PX.PORT_TYPE_KINET_2=2,PX.PORT_TYPE_KINET_3=3,PX.PORT_TYPE_KINET_4=4,PX.PORT_TYPE_DMX_1=5,PX.PORT_TYPE_DMX_2=6,PX.PORT_TYPE_DMX_3=7,PX.PORT_TYPE_LASER_1=8,PX.CHANNEL_TYPE_OFF=0,PX.CHANNEL_TYPE_ADD=1,PX.CHANNEL_TYPE_FX=2,PX.CHANNEL_TYPE_SCENE=3,PX.HARDWAREGROUP_OFF=0,PX.HARDWAREGROUP_SOLO=1,PX.HARDWAREGROUP_EXCLUDE=2,PX.MAP_NORMAL=0,PX.MAP_ALT1=1,PX.MAP_ALT2=2,PX.shaderCount=-1,PX.init=function(e,t,i){PX.broadcast=i.broadcast||PX.broadcast,PX.readPixels=i.readPixels||PX.readPixels,PX.pointSize=i.pointSize||PX.pointSize,PX.pointSprite=i.pointSprite||PX.pointSprite,PX.useTransforms=i.useTransforms||PX.useTransforms,PX.shaderCount=0;for(var r in PX.clips)PX.clips.hasOwnProperty(r)&&(PX.shaderCount++,PX.clips[r].id=PX.shaderCount);for(i.maxNodeCount=i.maxNodeCount||Math.pow(128,2),PX.simSize=4;Math.pow(PX.simSize,2)<i.maxNodeCount;)PX.simSize*=2;PX.ports=new PX.PortManager,PX.hardware=new PX.HardwareManager,PX.channels=new PX.ChannelManager,PX.app=new PX.AppManager(e,t),PX.ports.init(),PX.hardware.init(),PX.channels.init(),PX.app.init(),PX.appSize||PX.setSize(600,400)},PX.dataSetLength=null,PX.shaderNeedsUpdate=!1,PX.updateFresh=!1,PX.updateShaderLimiter=0,PX.update=function(){PX.ready&&(PX.app?PX.ready&&((!PX.shaderNeedsUpdate||PX.updateShaderLimiter<2)&&PX.updateShaderLimiter>0?(PX.app.update(),PX.ports.update(),PX.hardware.update(),PX.channels.update()):(PX.app.updateMainSourceShader(),PX.app.update(),PX.ports.update(),PX.updateShaderLimiter=0,PX.shaderNeedsUpdate=!1,PX.updateFresh=!1),PX.updateShaderLimiter++):console.log("AP Error: Need to call PX.init before PX.update."))},PX.updateShader=function(){PX.shaderNeedsUpdate=!0},PX.pointPosition=[0,0,0],PX.setPointPosition=function(e,t,i){PX.pointPosition=[e,t,i],PX.pointCloud.position&&(PX.pointCloud.position={x:e,y:t,z:i})},PX.appSize,PX.setSize=function(e,t){PX.appSize=[e,t],PX.app&&(PX.app.glWidth=e,PX.app.glHeight=t,PX.app.readPixels&&(PX.app.pixels=new Uint8Array(4*PX.app.glWidth*PX.app.glHeight)),PX.app.renderer.setSize(PX.app.glWidth,PX.app.glHeight),PX.setPointSize(PX.pointSize),PX.pointMaterial&&(PX.pointMaterial.uniforms.u_res.value=PX.app.glWidth/PX.app.glHeight))},PX.setPointSize=function(e){PX.pointSize<=0&&(PX.pointSize=e)},PX.mouseX=0,PX.mouseY=0,PX.setMouse=function(e,t){PX.mouseX=e,PX.mouseY=t,PX.material.uniforms.mouse.value=new THREE.Vector2(e,t)},PX.importShader=function(e,t){PX.app.importShader(e,t)},PX.generateShader=function(){PX.app.updateMainSourceShader()},PX.simpleSetup=function(e){e.mix=e.mix||1,e.channel=e.channel||1;for(var t=[],i=0;i<e.ids.length;i++)t[i]=new PX.Clip({id:e.ids[i]});var r=[];r[0]=new PX.Pod({clips:t});var s=new PX.Channel({mix:e.mix,pods:r});PX.channels.setChannel(e.channel,s)},PX.updateNodePoints=function(){PX.app.updateGeometry(),PX.app.generateCoordsMap(),PX.app.createNodePointCloud()},PX.get=function(e,t,i,r){return t?PX.getUniform(e,t,i,r).value:PX.material.uniforms[e].value},PX.set=function(e,t,i,r,s){if(i){if(PX.material.uniforms)PX.getUniform(e,i,r,s).value=t;else{var n="_"+i+"_"+r+"_"+s+"_"+e;PX.app.initialUniforms[n]||(PX.app.initialUniforms[n]={}),PX.app.initialUniforms[n].value=t}PX.setObjProperty(e,t,i,r,s)}else PX.material.uniforms[e].value=t},PX.getUniform=function(e,t,i,r){var s="_"+t;return i&&(s+="_"+i,r&&(s+="_"+r)),PX.material.uniforms[s+"_"+e]},PX.getObj=function(e,t,i){var r=PX.channels.channels[e-1];return r&&t&&(r=r.pods[t-1],i&&(r=r.clips[i-1])),r},PX.setObj=function(e,t,i,r){i?r?PX.channels.channels[t-1].pods[i-1].clips[r-1]=e:PX.channels.channels[t-1].pods[i-1]=e:PX.channels.channels[t-1]=e},PX.getObjProperty=function(e,t,i,r){var s=PX.getObj(t,i,r);return s[e]},PX.setObjProperty=function(e,t,i,r,s){var n=PX.getObj(i,r,s);n&&(n[e]=t)},PX.load=function(e){PX.channels.channels=e,PX.shaderNeedsUpdate=!0,PX.updateFresh=!0},PX.stringifyChannels=function(){return JSON.stringify(PX.channels.channels)},PX.stringifyNodes=function(){return JSON.stringify(PX.ports.ports)},PX.material=!1,PX.ready=!1,PX.simSize,PX.shaders={},PX.clips={},PX.imported={},PX.techs={},PX.pixels,PX.demoClipNames=["TestFrame","SolidColor","ColorSineBar","ColorSwirls","LineCosSin","SimpleSwirl","SinSpiral","SineParticles","DiSinSwirl","HexifyRadial","SinCosTan"],PX.demoHardware=["ApHardwareTest","Grid+zLayer","RanZGrid"],PX.getVariableTypeFromShorthand=function(e){var t;switch(e){case"i":t="int";break;case"f":t="float";break;case"t":t="sampler2D";break;case"v2":t="vec2";break;case"v3":t="vec3";break;case"v4":t="vec4"}return t},PX.AppManager=function(e,t){this.glWidth=0,this.glHeight=0,this.sceneMain=e,this.renderer=t,this.initialUniforms={},this.cameraRTT,this.sceneRTT,this.rtTextureA,this.rtTextureB,this.rtToggle=!0,this.controls,this.camera,this.pointSizes=[],this.pointTypes=[],this.geoX=[],this.geoY=[],this.render=!0,this.fragmentShader,this.time=0,this.coordsMap,this.portsMap,this.altMap1,this.altMap2,this.gl,this.plane=new THREE.PlaneBufferGeometry(PX.simSize,PX.simSize),PX.pointGeometry=new THREE.Geometry},PX.AppManager.prototype={init:function(){this.rtTextureA=new THREE.WebGLRenderTarget(PX.simSize,PX.simSize,{minFilter:THREE.NearestMipMapNearestFilter,magFilter:THREE.NearestFilter,format:THREE.RGBFormat}),this.rtTextureB=this.rtTextureA.clone(),this.cameraRTT=new THREE.OrthographicCamera(PX.simSize/-2,PX.simSize/2,PX.simSize/2,PX.simSize/-2,-1e4,1e4),this.sceneRTT=new THREE.Scene,PX.pointGeometry=new THREE.Geometry,PX.updateNodePoints(),PX.readPixels&&(PX.pixels=new Uint8Array(4*Math.pow(PX.simSize,2)),this.gl=this.renderer.getContext())},update:function(){this.time+=PX.speed,this.render&&PX.ready&&(PX.material.uniforms.time.value=this.time,PX.material.uniforms._random.value=Math.random(),this.rtToggle?(PX.material.uniforms.u_prevCMap.value=this.rtTextureB,this.renderer.render(this.sceneRTT,this.cameraRTT,this.rtTextureA,!0),PX.pointMaterial.uniforms.u_colorMap.value=this.rtTextureA):(PX.material.uniforms.u_prevCMap.value=this.rtTextureA,this.renderer.render(this.sceneRTT,this.cameraRTT,this.rtTextureB,!0),PX.pointMaterial.uniforms.u_colorMap.value=this.rtTextureB),this.rtToggle=!this.rtToggle,this.updateClips(),PX.readPixels&&this.gl.readPixels(0,0,PX.simSize,PX.simSize,this.gl.RGBA,this.gl.UNSIGNED_BYTE,PX.pixels))},setSize:function(e,t){this.glWidth=e,this.glHeight=t},importShader:function(e,t){function i(e){return e=e.trim(),e=e.replace(/ +(?= )/g,""),e.indexOf("#ifdef GL_")>-1?!0:e.indexOf("#else")>-1?!0:e.indexOf("#endif")>-1?!0:e.indexOf("uniform float time")>-1?!0:e.indexOf("uniform float random")>-1?!0:e.indexOf("uniform vec2 mouse")>-1?!0:e.indexOf("uniform vec2 resolution")>-1?!0:e.indexOf("precision highp float")>-1?!0:e.indexOf("precision mediump float")>-1?!0:e.indexOf("precision lowp float")>-1?!0:e.indexOf("varying vec2 surfacePosition")>-1?!0:e.indexOf("void main(")>-1?!0:e.indexOf("define time")>-1?!0:!1}var r=0,s=!1,n="",o="",a=0,p=0,l={};l.constants=[],l.fragmentFunctions=[];var c=t.split("\n");for(P=0;P<c.length;P++)if(n=c[P].trim(),n=n.replace(/ +(?= )/g,""),n.indexOf("//")>-1&&(n=n.substring(0,n.indexOf("//"))),n.length>0){n=n.replace("main (","main("),n=n.replace(";",";\n"),n=n.replace("}","}\n"),n=n.replace("{","{\n");var d="";n.indexOf("#")>-1&&(d="\n"),o+=n+d}c=o.split("\n"),o="",n="";for(var P=0;P<c.length;P++)if(n=c[P].trim(),n=n.replace(/ +(?= )/g,""),n.length>0){var h=n.replace(/[^{]/g,"").length,u=n.replace(/[^}]/g,"").length;r+=h,r-=u,r>0&&(s=!0),s?(n=n.replace("surfacePosition","(gl_FragCoord.xy/resolution.xy-.5)"),o+=n+"\n",0===r&&(s=!1,o.localeCompare("void main(")>-1?l.fragmentMain=o.slice(o.indexOf("{")+1,o.lastIndexOf("}")):(l.fragmentFunctions[a]=o,a++),o="")):i(n)||(l.constants[p]=n,p++)}PX.shaderCount>-1&&(PX.clips[e]?l.id=PX.clips[e].id:(PX.shaderCount++,l.id=PX.shaderCount)),PX.clips[e]=l},clipUpdateTime:function(e,t){t.value+=e.speed*PX.speed},updateClips:function(){for(var e=0;e<PX.channels.channels.length;e++){var t=PX.channels.channels[e];if(t&&t.pods)for(var i=0;i<t.pods.length;i++){var r=t.pods[i];if(r&&r.clips)for(var s=0;s<r.clips.length;s++){var n=r.clips[s];if(n&&PX.clips[n.id]){this.clipUpdateTime(n,PX.material.uniforms["_"+(e+1)+"_"+(i+1)+"_"+(s+1)+"_time"],e+1,i+1,s+1);var o=PX.clips[n.id];o&&o.update&&PX.material&&o.update("_"+(e+1)+"_"+(i+1)+"_"+(s+1),PX.material.uniforms)}}}}},updateGeometry:function(){this.pointSizes=[],this.pointTypes=[],this.geoX=[],this.geoY=[],PX.pointGeometry=new THREE.Geometry;var t=new Float32Array(4*Math.pow(PX.simSize,2)),r=0,s=0;for(e=0;e<PX.ports.getPorts().length;e++){var n=PX.ports.getPort(e+1);if(n&&n.nodes)for(i=0;i<n.nodes.length;i++){var o=new THREE.Vector3;o.x=n.nodes[i].x||0,o.y=n.nodes[i].y||0,o.z=n.nodes[i].z||0,PX.pointGeometry.vertices.push(o),n.nodes[i].indexId=r;var a=PX.simSize,p=(r+1)%a;0===p&&(p=a);var l=(r+2-p)/a;this.pointSizes.push(PX.hardware.getCustomPointSize(n.nodesType));var c=n.nodesType;PX.pointSprite||0!==c||(c=-1),PX.hardware.getCustomPointSprite(c)&&(c=2*(c+2),this.pointTypes.push(c)),this.geoX.push(p/a-.5/a),this.geoY.push(l/a+.5/a),r++,t[s]=e+1,t[s+1]=i+1,t[s+2]=n.nodesType,t[s+3]=1,s+=4}}this.portsMap=new THREE.DataTexture(t,PX.simSize,PX.simSize,THREE.RGBAFormat,THREE.FloatType),this.portsMap.minFilter=THREE.NearestFilter,this.portsMap.magFilter=THREE.NearestFilter,this.portsMap.needsUpdate=!0,this.portsMap.flipY=!1},generateCoordsMap:function(){for(var e=new Float32Array(4*Math.pow(PX.simSize,2)),t=0,i=1e11,r=i,s=-i,n=i,o=-i,a=i,p=-i,l=0,c=e.length;c>l;l+=4){var d=0,P=0,h=0;PX.pointGeometry.vertices[t]?(d=PX.pointGeometry.vertices[t].x,P=PX.pointGeometry.vertices[t].y,h=PX.pointGeometry.vertices[t].z,r=Math.min(r,d),s=Math.max(s,d),n=Math.min(n,P),o=Math.max(o,P),a=Math.min(a,h),p=Math.max(p,h),e[l+3]=1,t++):e[l+3]=0,e[l+0]=d,e[l+1]=P,e[l+2]=h}PX.channels.setPodPos(1,new PX.PodPosition({x:r,y:n,z:a,w:s-r,h:o-n,d:p-a})),this.coordsMap=new THREE.DataTexture(e,PX.simSize,PX.simSize,THREE.RGBAFormat,THREE.FloatType),this.coordsMap.minFilter=THREE.NearestFilter,this.coordsMap.magFilter=THREE.NearestFilter,this.coordsMap.needsUpdate=!0,this.coordsMap.flipY=!1,this.altMap1=new THREE.DataTexture(e,PX.simSize,PX.simSize,THREE.RGBAFormat,THREE.FloatType),this.altMap1.minFilter=THREE.NearestFilter,this.altMap1.magFilter=THREE.NearestFilter,this.altMap1.needsUpdate=!0,this.altMap1.flipY=!1},merge:function(e,t){var i={};for(var r in e)e[r]&&(i[r]=e[r]);for(var s in t)t[s]&&(i[s]=t[s]);return i},createNodePointCloud:function(){var e={a_pointSizes:{type:"f",value:this.pointSizes},a_texId:{type:"f",value:this.pointTypes},a_geoX:{type:"f",value:this.geoX},a_geoY:{type:"f",value:this.geoY}},t=0;PX.pointSprite&&(t=1);for(var i={u_res:{type:"f",value:PX.app.glWidth/PX.app.glHeight},u_colorMap:{type:"t",value:this.rtTextureA},u_useTexture:{type:"i",value:t}},r=[THREE.ImageUtils.loadTexture(PX.pointSprite)],s=0;2>s;s++)PX.hardware.getCustomPointSprite(s+1)&&(r[s+1]=THREE.ImageUtils.loadTexture(PX.hardware.getCustomPointSprite(s+1)));i.u_texArray={type:"tv",value:r},PX.pointMaterial=new THREE.ShaderMaterial({uniforms:this.merge(i,PX.shaders.PointCloudShader.uniforms),attributes:this.merge(e,PX.shaders.PointCloudShader.attributes),vertexShader:PX.shaders.PointCloudShader.vertexShader,fragmentShader:PX.shaders.PointCloudShader.fragmentShader,depthTest:!1,transparent:!0});var n="PixelMixer Nodes";this.sceneMain.getObjectByName(n)&&this.sceneMain.remove(PX.pointCloud),PX.pointCloud=new THREE.PointCloud(PX.pointGeometry,PX.pointMaterial),PX.pointCloud.sortParticles=!0,PX.pointCloud.name=n,PX.pointPosition&&(PX.pointCloud.position.x=PX.pointPosition[0],PX.pointCloud.position.y=PX.pointPosition[1],PX.pointCloud.position.z=PX.pointPosition[2]),this.sceneMain.add(PX.pointCloud),PX.pointGeometry.vertices.length>0&&(PX.ready||console.log("PixelMixer v"+PX.version+", SimSize: "+PX.simSize+"x"+PX.simSize+", Nodes: "+PX.pointGeometry.vertices.length),PX.ready=!0)},updateMainSourceShader:function(){var e={time:{type:"f",value:this.time},_random:{type:"f",value:Math.random()},u_coordsMap:{type:"t",value:this.coordsMap},u_portsMap:{type:"t",value:this.portsMap},u_prevCMap:{type:"t",value:this.rtTextureB},u_mapSize:{type:"f",value:PX.simSize},mouse:{type:"v2",value:new THREE.Vector2(0,0)}},t=PX.channels.generateSourceShader(),i="";PX.usePodPosUniforms&&(e.u_pos_id={type:"i",value:0},e.u_pos_x={type:"f",value:0},e.u_pos_y={type:"f",value:0},e.u_pos_z={type:"f",value:0},e.u_pos_w={type:"f",value:0},e.u_pos_h={type:"f",value:0},e.u_pos_d={type:"f",value:0},i+="uniform int u_pos_id;\n",i+="uniform float u_pos_x;\n",i+="uniform float u_pos_y;\n",i+="uniform float u_pos_z;\n",i+="uniform float u_pos_w;\n",i+="uniform float u_pos_h;\n",i+="uniform float u_pos_d;\n");for(var r in t.uniforms){var s=PX.getVariableTypeFromShorthand(t.uniforms[r].type);i+="uniform "+s+" "+r+";\n",e[r]=t.uniforms[r]}for(r in this.initialUniforms)e[r]&&(e[r].value=this.initialUniforms[r].value,delete this.initialUniforms[r]);if(this.altMap1&&(i+="uniform sampler2D u_altMap1; vec4 px_alt1; \n",e.u_altMap1={type:"t",value:this.altMap1}),this.altMap2&&(i+="uniform sampler2D u_altMap2; vec4 px_alt2; \n",e.u_altMap2={type:"t",value:this.altMap2}),!PX.updateFresh&&PX.material)for(r in e)PX.material.uniforms[r]&&(e[r].value=PX.material.uniforms[r].value);this.fragmentShader=PX.MainShader.fragmentShader,this.fragmentShader=this.fragmentShader.replace("#INCLUDESHADERS",t.fragmentMain),this.fragmentShader=this.fragmentShader.replace("#INCLUDESHADERFUNCTIONS",t.fragmentFunctions),this.fragmentShader=this.fragmentShader.replace("#INCLUDESHADERUTILS",PX.shaders.ShaderUtils+i),this.fragmentShader=this.minFragmentShader(this.fragmentShader),PX.material=new THREE.ShaderMaterial({uniforms:e,vertexShader:PX.shaders.SimpleTextureShader.vertexShader,fragmentShader:this.fragmentShader}),PX.material.uniforms.u_coordsMap.value=this.coordsMap,PX.material.uniforms.u_portsMap.value=this.portsMap,PX.material.uniforms.u_prevCMap.value=this.rtTextureB,this.altMap1&&(PX.material.uniforms.u_altMap1.value=this.altMap1),this.altMap2&&(PX.material.uniforms.u_altMap2.value=this.altMap2);var n="SourceQuad",o=this.sceneRTT.getObjectByName(n);o&&this.sceneRTT.remove(o);var a=new THREE.Mesh(this.plane,PX.material);a.position.z=-100,a.name=n,this.sceneRTT.add(a)},minFragmentShader:function(e){return e=e.replace(/px_alt/g,"_0"),e=e.replace(/px_/g,"_"),e=e.replace(/_xyz/g,"_1"),e=e.replace(/hsv2rgb/g,"_2"),e=e.replace(/rgb2hsv/g,"_3"),e=e.replace(/offsetPos/g,"_4"),e=e.replace(/_rgb/g,"_5"),e=e.replace(/_hsv/g,"_6"),e=e.replace(/resolution/g,"_7"),e=e.replace(/superFunction/g,"_8"),e=e.replace(/checkBounds/g,"_9"),e=e.replace(/returnColor/g,"_91"),e=e.replace(/getPodSize/g,"_92"),e=e.replace(/getPodPos/g,"_93"),e=e.replace(/_lastRgb/g,"_94"),e=e.replace(/getPodScale/g,"_95"),e=e.replace(/getPodOffset/g,"_96"),e.trim()}},PX.ChannelManager=function(){this.channels=[],this.podpositions=[]},PX.ChannelManager.prototype={init:function(){},update:function(){},generateSourceShader:function(){function e(e,t){var i=e.match(new RegExp("^(?:\\w+\\W+){"+--t+"}(\\w+)"));return i&&i[1]}function t(e){return e.indexOf("rgb2hsv")>-1?!0:e.indexOf("hsv2rgb")>-1?!0:e.indexOf("blend")>-1?!0:!1}for(var i={},r={},s={},n={},o=this.generateSizingFunctions(),a="",p="",l="",c={},d="",P=0;P<this.channels.length;P++){var h=this.channels[P];h.address="_"+(P+1);var f=!1;if(h.type===PX.CHANNEL_TYPE_FX&&(f=!0),p+="if(_channel_mix>0.){ \n",i[h.address+"_mix"]={type:"f",value:h.mix},h&&h.pods)for(var g=0;g<h.pods.length;g++){var X=h.pods[g];if(X){X.address=h.address+"_"+(g+1),i[X.address+"_mix"]={type:"f",value:X.mix},i[X.address+"_blend"]={type:"f",value:X.blend};var m=!1;if(X.clips&&X.clips.length)for(var _=0;_<X.positionIds.length;_++){p+="//-- \n";var v=this.getPodPos(X.positionIds[_]);if(c!==v){c=v;var x="vec2("+v.w+", "+v.h+");";PX.usePodPosUniforms&&(x="vec2(getPodSize("+X.positionIds[_]+").x, getPodSize("+X.positionIds[_]+").y);"),d!==x&&(d=x,p+="resolution = "+x+" \n"),p+="px_xyz = offsetPos(px_xyz2, "+X.positionIds[_]+", px_xyz.w);\n"}for(p+="if(_pod_mix > 0. && checkBounds(px_xyz2, "+X.positionIds[_]+") > 0.){ \n",m=!0,u=0;u<X.clips.length;u++){var y=X.clips[u];if(y){var S=PX.clips[y.id];if(S){if(!s[X.clips[u].id]){s[X.clips[u].id]=!0;for(var z in S.constants)r[z]||(r[z]=1,o+=S.constants[z]+"\n");if(o+="\n",S.fragmentFunctions)for(var b=0;b<S.fragmentFunctions.length;b++){var T=S.fragmentFunctions[b].trim();t(T)||(T=e(T,1)+e(T,2)+e(T,3)+e(T,4)+e(T,5),n[T]||(n[T]=!0,o+=S.fragmentFunctions[b]+"\n"))}a+="else if(id == "+S.id+"){\n",a+=S.fragmentMain.replace("gl_FragColor","returnColor"),a+="\n",a=a.replace(/gl_FragCoord/g,"px_xyz"),a+="\n}\n"}if(y.address=X.address+"_"+(u+1),y.id.length>0&&S){for(var M in S.params)PX.setObjProperty(M,S.params[M].value,P+1,g+1,u+1),i[y.address+"_"+M]={type:"f",value:S.params[M].value};for(var E in S.properties)i[y.address+"_"+E]=S.properties[E];S.init&&S.init(y.address,i),i[y.address+"_mix"]={type:"f",value:y.mix},i[y.address+"_blend"]={type:"f",value:y.blend},i[y.address+"_time"]={type:"f",value:PX.app.time};for(var C=["0.","0.","0.","0.","0.","0.","0.","0.","0."],w=0;w<C.length;w++)S.params&&S.params["p"+(w+1)]&&(C[w]=y.address+"_p"+(w+1));l="",y.posMap==PX.MAP_ALT1&&PX.app.altMap1&&(l+="px_xyz = offsetPos(px_alt1, "+X.positionIds[_]+", px_xyz.w);\n"),l+="px_rgb2 = superFunction(_clip_mix, "+S.id+", _fxIn, _clip_time, "+C[0]+","+C[1]+","+C[2]+","+C[3]+","+C[4]+","+C[5]+","+C[6]+","+C[7]+","+C[8]+");",l=l.replace(/gl_FragCoord/g,"px_xyz");var N=PX.clips[y.id].fx;0===u?(l+="px_rgb = px_rgb2; \n",N||f?l+="px_rgb = mix(px_p, px_rgb2, _clip_mix); \n":(m=f,l+="px_rgb = px_rgb * (_clip_mix); \n")):N||f?l+="px_rgb = mix(px_rgb, px_rgb2, _clip_mix); \n":(l+="px_rgb2 = px_rgb2 * (_clip_mix); \n",l+="px_rgb = blend(px_rgb2, px_rgb, _clip_blend); \n",m=f),l=l.replace(/_clip_/g,y.address+"_"),l=l.replace(/__/g,y.address+"_"),l=0===u?l.replace(/_fxIn/g,"px_p"):l.replace(/_fxIn/g,"px_rgb"),p+=l}}else console.log("AP Error - shader not found: "+y.id)}}m?p+="px_p = mix(px_p, px_rgb, _pod_mix); \n":0===g?p+="px_p = (px_rgb * _pod_mix) + px_p; \n":(p+="px_rgb = px_rgb * (_pod_mix); \n",p+="px_p = blend(px_p, px_rgb, _pod_blend); \n"),p+="}"}p=p.replace(/_pod_/g,X.address+"_")+"\n"}}0===P?p+="px_c = px_p = px_p * (_channel_mix); \n":f?p+="px_c = mix(px_c, px_p, _channel_mix); \n":(p+="px_p = px_p * (_channel_mix); \n",p+="px_c = blend(px_c, px_p, 1.); \n"),p+="}",p=p.replace(/_channel_/g,h.address+"_")+"\n"}return a=a.slice(5,a.length),a="vec4 returnColor = vec4(0.,0.,0.,0.); if(_mi == 0.){return vec3(0.,0.,0.);} \n"+a,a+="return max(min(vec3(returnColor.x, returnColor.y, returnColor.z), vec3(1.0)), vec3(0.0)); \n",a="vec3 superFunction(float _mi, int id, vec3 _fxIn, float time, float _p1, float _p2, float _p3, float _p4, float _p5, float _p6, float _p7, float _p8, float _p9) { \n"+a+"}\n",o+=a,PX.app.altMap1&&(p="px_alt1 = texture2D( u_altMap1, v_vUv);"+p),PX.app.altMap2&&(p="px_alt2 = texture2D( u_altMap2, v_vUv);"+p),PX.dataSetLength&&PX.dataSetLength>0&&(o="uniform float data[ "+PX.dataSetLength+" ]; \n"+o),{uniforms:i,fragmentFunctions:o,fragmentMain:p+"\n"}},generateSizingFunctions:function(){function e(e){for(var t=0;t<PX.channels.channels.length;t++){var i=PX.channels.channels[t];if(i&&i.pods)for(var r=0;r<i.pods.length;r++){var s=i.pods[r];if(s)for(var n=0;n<s.positionIds.length;n++){var o=s.positionIds[n];if(o===e)return!0}}}return!1}var t="",i={},r=!1,s=0,n="";PX.usePodPosUniforms&&(t+="if(d==u_pos_id){\n",t+="p=vec3(u_pos_x, u_pos_y, u_pos_z);\n",t+="}");for(var o=0;o<this.podpositions.length;o++)e(o+1)&&(t+="else if(d=="+(o+1)+"){\n",t+="p=vec3("+this.podpositions[o].x+","+this.podpositions[o].y+","+this.podpositions[o].z+");\n",t+="}\n");PX.usePodPosUniforms||(t=t.slice(5,t.length)),t="vec3 p=vec3(0.,0.,0.); \n"+t,t+="return p; \n",t="vec3 getPodPos(int d) { \n"+t+"}\n";var a=t;t="",PX.usePodPosUniforms&&(t+="if(d==u_pos_id){\n",t+="p=vec3(u_pos_w, u_pos_h, u_pos_d);\n",t+="}");var p=[];for(o=0;o<this.podpositions.length;o++)if(e(o+1)){for(i={},i.w=this.podpositions[o].w,i.h=this.podpositions[o].h,i.d=this.podpositions[o].d,i.s=[],r=!1,s=0;s<p.length;s++)if(p[s].w===i.w&&p[s].h===i.h&&p[s].d===i.d){r=!0,p[s].s[p[s].s.length]=o+1;break}r||(i.s[0]=o+1,p[p.length]=i)}for(o=0;o<p.length;o++){t+="else if(",n="";for(var l=0;l<p[o].s.length;l++)n+="||d=="+p[o].s[l];n=n.slice(2,n.length),t+=n+"){\n",t+="p=vec3("+p[o].w+","+p[o].h+","+p[o].d+");\n",t+="}\n"}if(PX.usePodPosUniforms||(t=t.slice(5,t.length)),t="vec3 p = vec3(0.,0.,0.); \n"+t,t+="return p; \n",t="vec3 getPodSize(int d) { \n"+t+"}\n",a+=t,PX.useTransforms){for(t="",p=[],o=0;o<this.podpositions.length;o++)if(e(o+1)){for(i={},i.xt=this.podpositions[o].xt,i.yt=this.podpositions[o].yt,i.zt=this.podpositions[o].zt,i.s=[],r=!1,s=0;s<p.length;s++)if(p[s].xt===i.xt&&p[s].yt===i.yt&&p[s].zt===i.zt){r=!0,p[s].s[p[s].s.length]=o+1;break}r||(i.s[0]=o+1,p[p.length]=i)}for(o=0;o<p.length;o++){for(t+="else if(",n="",s=0;s<p[o].s.length;s++)n+="||d=="+p[o].s[s];n=n.slice(2,n.length),t+=n+"){\n",t+="p=vec3("+p[o].xt+","+p[o].yt+","+p[o].zt+");\n",t+="}\n"}for(PX.usePodPosUniforms||(t=t.slice(5,t.length)),t="vec3 p = vec3(0.,0.,0.); \n"+t,t+="return p; \n",t="vec3 getPodOffset(int d) { \n"+t+"}\n",a+=t,t="",p=[],o=0;o<this.podpositions.length;o++)if(e(o+1)){for(i={},i.xs=this.podpositions[o].xs,i.ys=this.podpositions[o].ys,i.zs=this.podpositions[o].zs,i.swapaxis=this.podpositions[o].swapaxis,i.s=[],r=!1,s=0;s<p.length;s++)if(p[s].xs===i.xs&&p[s].ys===i.ys&&p[s].zs===i.zs&&p[s].swapaxis===i.swapaxis){r=!0,p[s].s[p[s].s.length]=o+1;break}r||(i.s[0]=o+1,p[p.length]=i)}for(o=0;o<p.length;o++){for(t+="else if(",n="",s=0;s<p[o].s.length;s++)n+="||d=="+p[o].s[s];n=n.slice(2,n.length),t+=n+"){\n",t+="p=vec4("+p[o].xs+","+p[o].ys+","+p[o].zs+","+p[o].swapaxis+");\n",t+="}\n"}PX.usePodPosUniforms||(t=t.slice(5,t.length)),t="vec4 p = vec4(0.,0.,0.,0.); \n"+t,t+="return p; \n",t="vec4 getPodScale(int d) { \n"+t+"}\n",a+=t}return a+=["float checkBounds(vec4 b, int p)","{","vec3 s = getPodPos(p);","if(b.x >= s.x && b.y >= s.y && b.z >= s.z){ ","vec3 e = getPodSize(p);","if(b.x <= (e.x + s.x) && b.y <= (e.y + s.y) && b.z <= (e.z + s.z)) {","	return 1.;","}}","	return 0.;","}"].join("\n"),a+="vec4 offsetPos(vec4 b, int p, float w){\n",a+="vec3 c = getPodPos(p);\n",a+="float x = b.x - c.x;\n",a+="float y = b.y - c.y;\n",a+="float z = b.z - c.z;\n",PX.useTransforms&&(a+="vec3 d = getPodOffset(p);\n",a+="vec3 e = getPodSize(p);\n",a+="vec4 s = getPodScale(p);\n",a+="x += (b.x - (e.x * .5 + c.x)) * (1.-(s.x * 2.))*8.;\n",a+="y += (b.y - (e.y * .5 + c.y)) * (1.-(s.y * 2.))*8.;\n",a+="z += (b.z - (e.z * .5 + c.z)) * (1.-(s.z * 2.))*8.;\n",a+="x += (e.x * 8. * (d.x - .5));\n",a+="y += (e.y * 8. * (d.y - .5));\n",a+="z += (e.z * 8. * (d.z - .5));\n",a+="float t = x;\n",a+="if(s.w == 1.){",a+="x=y;y=t;\n",a+="}else if(s.w == 2.){",a+="x=z;z=t;\n",a+="}else if(s.w == 3.){",a+="t=y;y=z;z=t;\n",a+="}\n"),a+="return vec4(x, y, z, w);\n",a+="}\n"},setChannel:function(e,t){this.channels[e-1]=t},getChannel:function(e){return this.channels[e-1]},getChannels:function(){return this.channels},clearChannel:function(e){delete this.channels[e-1]},clearAllChannels:function(){this.channels=[]},clearAllPodsInChannel:function(e){delete this.channels[e-1].pods},getPod:function(e,t){return this.channels[e-1].pods[t-1]},podPosFromPorts:function(t,r){var s=1e11,n=s,o=-s,a=s,p=-s,l=s,c=-s,d=!1;for(e=0;e<r.length;e++){var P=PX.ports.getPort(r[e]);if(P&&P.nodes)for(i=0;i<P.nodes.length;i++){var h=P.nodes[i];n=Math.min(n,h.x),o=Math.max(o,h.x),a=Math.min(a,h.y),p=Math.max(p,h.y),l=Math.min(l,h.z),c=Math.max(c,h.z),d=!0}}d&&(this.podpositions[t-1]=new PX.PodPosition({x:n,y:a,z:l,w:o-n+1,h:p-a,d:c-l}))},setPodPos:function(e,t){this.podpositions[e-1]=t},getPodPos:function(e){return this.podpositions[e-1]?this.podpositions[e-1]:this.podpositions[0]},clearPodPos:function(e){delete this.podpositions[e-1]},clearAllPodPos:function(){this.podpositions=[]},setPodPosTransforms:function(e){var t=this.getPodPos(e.id);(e.xt||e.xt<1)&&(t.xt=e.xt),(e.yt||e.yt<1)&&(t.yt=e.yt),(e.zt||e.zt<1)&&(t.zt=e.zt),(e.xs||e.xs<1)&&(t.xs=e.xs),(e.ys||e.ys<1)&&(t.ys=e.ys),(e.zs||e.zs<1)&&(t.zs=e.zs),(e.swapaxis||e.swapaxis<1)&&(t.swapaxis=e.swapaxis)},resetPodPosTransforms:function(e){this.setPodPosTransforms({id:e,xt:.5,yt:.5,zt:.5,xs:.5,ys:.5,zs:.5,swapaxis:0})},setClip:function(e,t,i,r){return this.channels[e-1]?void(this.channels[e-1].pods[t-1]?this.channels[e-1].pods[t-1].clips[i-1]=r:this.channels[e-1].pods[t-1]=new Pod(1,1,PX.BLEND.Add,[r])):!1},clearClip:function(e,t,i){delete this.channels[e-1].pods[t-1].clips[i-1]},clearAllClipsInPod:function(e,t){delete this.channels[e-1].pods[t-1].clips}},PX.HardwareManager=function(){this.pointSizes=[PX.pointSize,50,15],this.pointSprites=[PX.pointSprite]},PX.HardwareManager.prototype={init:function(){},update:function(){},importNodes:function(e,t,i,r,s,n){t=t||0,i=i||0,r=r||0,s=s||0,e.scale=e.scale||1;var o=n||e.scale;for(var a in e.hardwareunit){var p=e.hardwareunit[a];for(var l in p.ports){var c=p.ports[l];PX.ports[c.portid-1]||PX.ports.setPort(c.portid+t,new PX.Port);for(var d in c.nodes){var P=c.nodes[d];P.x=P.x||0,P.y=P.y||0,P.z=P.z||0,P.x*=o,P.y*=o,P.z*=o,P.x+=i,P.y+=r,P.z+=s}PX.ports.setNodes(c.portid+t,c.nodes)}}},importNodeArray:function(e){e.portOffset=e.portOffset||0,e.x=e.x||0,e.y=e.y||0,e.z=e.z||0,e.scale=e.scale||1;for(var t,i=[],r=0;r<e.nodes.length;r+=4)t={},t.x=e.nodes[r+1]*e.scale+e.x,t.y=e.nodes[r+2]*e.scale+e.y,t.z=e.nodes[r+3]*e.scale+e.z,i.push[t],2===e.nodes[r],PX.ports.addNode(e.nodes[r]+1,t)},importVertices:function(e){PX.ports[e.port-1]||PX.ports.setPort(e.port,new PX.Port),PX.ports.setNodes(e.port,e.vertices)},addSimpleNodeGrid:function(t){t.port||(t.port=PX.ports.ports.length+1);var r=1e11,s=r,n=-r,o=r,a=-r,p=[],l={};for(e=0;e<t.width;e++)for(i=0;i<t.height;i++)l={},l.x=e*t.pitch+t.x,l.y=i*t.pitch+t.y,l.z=t.z,p.push(l),s=Math.min(s,l.x),n=Math.max(n,l.x),o=Math.min(o,l.y),a=Math.max(a,l.y);var c=new PX.Port({name:"Port "+c,nodes:p});PX.ports.setPort(t.port,c),t.positionId>1&&PX.channels.setPodPos(t.port,new PX.PodPosition({x:s,y:o,z:l.z,w:n-s,h:a-o,d:l.z+1}))},addTestGrid:function(t,r,s){var n=[];for(e=0;e<24;e++)for(i=0;i<14;i++){var o={};o.x=30*e+r,o.y=30*i+s,o.z=0,n.push(o)}PX.ports.setNodes(t,n)},addTestPortsGrid:function(t,r,s){var n=830,o=1100,a=0,p=0;for(u=0;u<15;u++){var l=[];for(e=0;e<18;e++)for(i=0;i<24;i++){var c={};c.x=.26*(40*e+a-650+r),c.y=.26*(40*i+p+s),c.z=300*Math.random()-150,l.push(c)}var d=new PX.Port({name:"Port "+d,nodes:l});PX.ports.setPort(u+t,d),a+=n,(u+2)%5==1&&(a=0,p+=o)}},addTestPortsGrid2:function(t,r,s){var n=[];for(e=0;e<70;e++)for(i=0;i<38;i++){var o={};o.x=20*e-340+r,o.y=20*i+30+s,n.push(o)}var a=new PX.Port({name:"Port "+a,nodes:n});PX.ports.setPort(t,a)},addTestPortsGrid3:function(t,r,s){var n=[],o={};for(e=0;e<70;e++)for(i=0;i<38;i++)o={},o.x=20*e-340+r,o.y=20*i+30+s-1,n.push(o);var a=new PX.Port({name:"Port "+a,nodes:n});for(PX.ports.setPort(t,a),n=[],e=0;e<70;e++)for(i=0;i<38;i++)(i+2)%2==1&&(o={},o.x=20*e-340+r,o.y=20*i+30+s,o.z=110,n.push(o));for(a=new PX.Port({name:"Port "+a,nodes:n}),PX.ports.setPort(t+1,a),n=[],e=0;e<70;e++)for(i=0;i<38;i++)(i-1)%3==1&&(e-1)%2==1&&(o={},o.x=20*e-340+r-1,o.y=20*i+30+s-1,o.z=210,n.push(o));a=new PX.Port({name:"Port "+a,nodes:n}),PX.ports.setPort(t+2,a)},setCustomPointSprite:function(e,t){this.pointSprites[e]=t},getCustomPointSprite:function(e){return 0===e?PX.pointSprite:this.pointSprites[e]},setCustomPointSize:function(e,t){this.pointSizes[e]=t},getCustomPointSize:function(e){return 0===e?PX.pointSize:this.pointSizes[e]}},PX.PortManager=function(){this.ports=[],this.tests=0},PX.PortManager.prototype={init:function(){for(var e in PX.techs)PX.techs[e].init&&PX.techs[e].init()},update:function(){this.updateTechs()},updateTechs:function(){if(PX.broadcast&&PX.readPixels){var t=0;for(e=0;e<PX.ports.getPorts().length;e++){var r=PX.ports.getPort(e+1);if(r&&r.broadcast&&r.type&&r.nodes){var s=PX.techs[r.type];if(s&&s.broadcast){var n=[];for(i=0;i<r.nodes.length;i++)n.push(PX.pixels[4*t]),n.push(PX.pixels[4*t+1]),n.push(PX.pixels[4*t+2]),t++;s.broadcastPort(r,n)}}}}},getNodes:function(e){return this.ports[e-1].nodes},getNodeCount:function(e){return this.ports[e-1].nodes.length},setNodes:function(e,t){this.ports[e-1]||this.setPort(e,new PX.Port({name:"Port "+e})),this.ports[e-1].nodes=t},addNode:function(e,t){this.ports[e-1]||this.setPort(e,new PX.Port({name:"Port "+e})),this.ports[e-1].nodes[this.ports[e-1].nodes.length]=t},clearNodes:function(e){delete this.ports[e-1].nodes},setPort:function(e,t){t.id=e,this.ports[e-1]=t},getPort:function(e){return this.ports[e-1]},getPorts:function(){return this.ports},getPortCount:function(){return this.ports.length},addPortDetails:function(e,t){if(!this.ports[e-1])return void console.log("Error: Cannot add details to unexisting Port "+e);var i=this.ports[e-1].nodes,r={};for(var s in this.ports[e-1])this.ports[e-1][s]&&(r[s]=this.ports[e-1][s]);for(var n in t)t[n]&&(r[n]=t[n]);this.ports[e-1]=r,this.ports[e-1].nodes=i},clearPort:function(e){delete this.ports[e-1]},clearAllPorts:function(){delete this.ports,this.ports=[]}},PX.Channel=function(e){e=e||{},this.name=e.name,this.type=e.type||PX.CHANNEL_TYPE_ADD,this.mix=e.mix||0,this.blend=e.blend||PX.BLEND.Add,this.pods=e.pods||[]},PX.Clip=function(e){e=e||{},this.id=e.id,this.mix=e.mix||1,this.blend=e.blend||PX.BLEND.Add,this.posMap=e.posMap||PX.MAP_NORMAL,this.speed=e.speed||1,this.p1=e.p1||0,this.p2=e.p2||0,this.p3=e.p3||0,this.p4=e.p4||0,this.p5=e.p5||0,this.p6=e.p6||0,this.p7=e.p7||0,this.p8=e.p8||0,this.p9=e.p9||0},PX.Clip.prototype={setParams:function(e,t,i,r,s,n,o,a,p){this.p1=e,this.p2=t,this.p3=i,this.p4=r,this.p5=s,this.p6=n,this.p7=o,this.p8=a,this.p9=p}},PX.Pod=function(e){e=e||{},this.positionIds=e.positionIds||[1],this.mix=e.mix||1,this.blend=e.blend||PX.BLEND.Add,this.clips=e.clips||[]},PX.PodPosition=function(e){this.x=e.x||0,this.y=e.y||0,this.z=e.z||0,this.w=Math.max(.1,e.w)||1,this.h=Math.max(.1,e.h)||1,this.d=Math.max(.1,e.d)||1,this.xt=e.xt||.5,this.yt=e.yt||.5,this.zt=e.zt||.5,this.xs=e.xs||.5,this.ys=e.ys||.5,this.zs=e.zs||.5,this.swapaxis=e.swapaxis||0},PX.Port=function(e){e=e||{},this.name=e.name||"",this.type=e.type||"test",this.broadcast=e.broadcast||!1,this.address=e.address||"",this.nodes=e.nodes||[],this.nodesType=e.nodesType||0,this.hardwarePort=e.hardwarePort||1,this.id=e.id||-1},PX.MainShader={fragmentShader:["#INCLUDESHADERUTILS","precision mediump float;","float px_index;","vec4 px_xyz;","vec4 px_xyz2;","vec3 px_lastRgb;","vec3 px_rgb = vec3(0.);","vec3 px_hsv;","vec3 px_rgb2;","vec4 px_rgbV4;","vec3 px_c = vec3(0.);","vec3 px_p = vec3(0.);","vec2 resolution;","vec2 surfacePosition = vec2(0.);","float random;","float px_port;","float px_id;","float px_type;","varying vec2 v_vUv;","uniform float time;","uniform float _random;","uniform float u_mapSize;","uniform vec2 mouse;","uniform sampler2D u_coordsMap;","uniform sampler2D u_prevCMap;","uniform sampler2D u_portsMap;","#INCLUDESHADERFUNCTIONS","void main() {","random = rand(vec2(gl_FragCoord[0] * (gl_FragCoord[2] + 1.), gl_FragCoord[1] * _random) * (time * 0.0001));","px_xyz2 = px_xyz = texture2D( u_coordsMap, v_vUv);","if(px_xyz[3] == 0.0){ discard; }","px_index = ((1.0 - v_vUv.y) * u_mapSize * u_mapSize + v_vUv.x * u_mapSize);","px_lastRgb = vec3(texture2D( u_prevCMap, v_vUv));","px_p = vec3(texture2D( u_portsMap, v_vUv));","px_port = px_p.r;","px_id = px_p.g;","px_type = px_p.b;","px_p = vec3(0.);","#INCLUDESHADERS","gl_FragColor = vec4(px_c, 1.0);","}"].join("\n")},PX.shaders.PointCloudShader={vertexShader:["uniform float u_res;","attribute float a_pointSizes;","attribute float a_geoX;","attribute float a_geoY;","attribute float a_texId;","varying float v_geoX;","varying float v_geoY;","varying float v_texId;","void main() {","v_geoX = a_geoX;","v_geoY = a_geoY;","v_texId = a_texId;","vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );","gl_PointSize = (a_pointSizes * ( 4000. /  length( mvPosition.xyz )  )) / u_res;","gl_Position = projectionMatrix * mvPosition;","}"].join("\n"),fragmentShader:["uniform int u_useTexture;","uniform sampler2D u_colorMap;","uniform sampler2D u_texArray[ 3 ];","varying float v_geoX;","varying float v_geoY;","varying float v_texId;","void main() {","if(v_texId > 7.) {","gl_FragColor = texture2D( u_colorMap, vec2( v_geoX, v_geoY )) * texture2D( u_texArray[2], gl_PointCoord);","}else if(v_texId > 5.) {","gl_FragColor = texture2D( u_colorMap, vec2( v_geoX, v_geoY )) * texture2D( u_texArray[1], gl_PointCoord);","}else if(v_texId > 3.) {","gl_FragColor = texture2D( u_colorMap, vec2( v_geoX, v_geoY )) * texture2D( u_texArray[0], gl_PointCoord);","}else{","gl_FragColor = texture2D( u_colorMap, vec2( v_geoX, v_geoY )) * vec4(1.);","}","}"].join("\n")},PX.shaders.ShaderUtils=["vec3 rgb2hsv(vec3 c){","vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);"," vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));","vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));","float d = q.x - min(q.w, q.y);","float e = 1.0e-10;","return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);","}","vec3 hsv2rgb(vec3 c) {","	vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);","	vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);","	return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);","}","vec3 blend(vec3 c1, vec3 c2, float type)","{","if(type == 1.){ return c1 + c2; }else					","if(type == 2.){ return c1 - c2; }else					","if(type == 3.){ return min(c1, c2); }else				","if(type == 4.){ return max(c1, c2); }else				","if(type == 5.){ return abs(c2 - c1); }else			","if(type == 6.){ return c1 + c2 - 2.0 * c1 * c2; }else	","if(type == 7.){ return c1 * c2; }else					","if(type == 8.){ return (c1 + c2) - (c1 * c2); }else	","if(type == 9.){ return vec3((c2.r <= 0.5) ? (2.0 * c1.r * c2.r) : (1.0 - 2.0 * (1.0 - c2.r) * (1.0 - c1.r)),(c2.g <= 0.5) ? (2.0 * c1.g * c2.g) : (1.0 - 2.0 * (1.0 - c2.g) * (1.0 - c1.g)),(c2.b <= 0.5) ? (2.0 * c1.b * c2.b) : (1.0 - 2.0 * (1.0 - c2.b) * (1.0 - c1.b))); }else","if(type == 10.){ return vec3((c1.r <= 0.5) ? (2.0 * c1.r * c2.r) : (1.0 - 2.0 * (1.0 - c1.r) * (1.0 - c2.r)),(c1.g <= 0.5) ? (2.0 * c1.g * c2.g) : (1.0 - 2.0 * (1.0 - c1.g) * (1.0 - c2.g)),(c1.b <= 0.5) ? (2.0 * c1.b * c2.b) : (1.0 - 2.0 * (1.0 - c1.b) * (1.0 - c2.b))); }else","if(type == 11.){ return vec3((c1.r <= 0.5) ? (c2.r - (1.0 - 2.0 * c1.r) * c2.r * (1.0 - c2.r)) : (((c1.r > 0.5) && (c2.r <= 0.25)) ? (c2.r + (2.0 * c1.r - 1.0) * (4.0 * c2.r * (4.0 * c2.r + 1.0) * (c2.r - 1.0) + 7.0 * c2.r)) : (c2.r + (2.0 * c1.r - 1.0) * (sqrt(c2.r) - c2.r))),(c1.g <= 0.5) ? (c2.g - (1.0 - 2.0 * c1.g) * c2.g * (1.0 - c2.g)) : (((c1.g > 0.5) && (c2.g <= 0.25)) ? (c2.g + (2.0 * c1.g - 1.0) * (4.0 * c2.g * (4.0 * c2.g + 1.0) * (c2.g - 1.0) + 7.0 * c2.g)) : (c2.g + (2.0 * c1.g - 1.0) * (sqrt(c2.g) - c2.g))),(c1.b <= 0.5) ? (c2.b - (1.0 - 2.0 * c1.b) * c2.b * (1.0 - c2.b)) : (((c1.b > 0.5) && (c2.b <= 0.25)) ? (c2.b + (2.0 * c1.b - 1.0) * (4.0 * c2.b * (4.0 * c2.b + 1.0) * (c2.b - 1.0) + 7.0 * c2.b)) : (c2.b + (2.0 * c1.b - 1.0) * (sqrt(c2.b) - c2.b)))); }else","if(type == 12.){ return vec3((c1.r == 1.0) ? 1.0 : min(1.0, c2.r / (1.0 - c1.r)),(c1.g == 1.0) ? 1.0 : min(1.0, c2.g / (1.0 - c1.g)),(c1.b == 1.0) ? 1.0 : min(1.0, c2.b / (1.0 - c1.b))); }else","if(type == 13.){ return vec3((c1.r == 0.0) ? 0.0 : (1.0 - ((1.0 - c2.r) / c1.r)),(c1.g == 0.0) ? 0.0 : (1.0 - ((1.0 - c2.g) / c1.g)), (c1.b == 0.0) ? 0.0 : (1.0 - ((1.0 - c2.b) / c1.b))); }else","if(type == 14.){ return (c1 + c2) - 1.0; }else","if(type == 15.){ return 2.0 * c1 + c2 - 1.0; }else","if(type == 16.){ return vec3((c1.r <= 0.5) ? (1.0 - (1.0 - c2.r) / (2.0 * c1.r)) : (c2.r / (2.0 * (1.0 - c1.r))),(c1.g <= 0.5) ? (1.0 - (1.0 - c2.g) / (2.0 * c1.g)) : (c2.g / (2.0 * (1.0 - c1.g))),(c1.b <= 0.5) ? (1.0 - (1.0 - c2.b) / (2.0 * c1.b)) : (c2.b / (2.0 * (1.0 - c1.b)))); }else","if(type == 17.){ return vec3((c1.r > 0.5) ? max(c2.r, 2.0 * (c1.r - 0.5)) : min(c2.r, 2.0 * c1.r), (c1.r > 0.5) ? max(c2.g, 2.0 * (c1.g - 0.5)) : min(c2.g, 2.0 * c1.g),(c1.b > 0.5) ? max(c2.b, 2.0 * (c1.b - 0.5)) : min(c2.b, 2.0 * c1.b)); }else","if(type == 18.){return c1; }else						","if(type == 19.){return c2; }else","{ return c1 + c2; }								","}","float rand(vec2 co)","{","  highp float a = 12.9898;","  highp float b = 78.233;","  highp float c = 43758.5453;","  highp float dt= dot(co.xy ,vec2(a,b));","  highp float sn= mod(dt,3.14);","  return fract(sin(sn) * c);","}"].join("\n"),PX.shaders.SimpleTextureShader={uniforms:{u_texture:{type:"t",value:null}},vertexShader:["varying vec2 v_vUv;","void main() {","v_vUv = uv;","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["varying vec2 v_vUv;","uniform sampler2D u_texture;","void main() {","	gl_FragColor = texture2D( u_texture, v_vUv );","}"].join("\n")};
  