This commit is contained in:
tamat
2019-05-08 15:15:57 +02:00
parent cc2e26ac74
commit b6ca97f2b1
2 changed files with 5006 additions and 2392 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -67,7 +67,7 @@ function(a){for(var b=0;b<a.length;++b){var d=a[b],c={name:d[0],type:d[1],link:n
if(this.onInputRemoved)this.onInputRemoved(a);this.setDirtyCanvas(!0,!0)};r.prototype.addConnection=function(a,b,d,c){a={name:a,type:b,pos:d,direction:c,links:null};this.connections.push(a);return a};r.prototype.computeSize=function(a,b){function d(a){return a?g*a.length*0.6:0}if(this.constructor.size)return this.constructor.size.concat();var u=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),k=b||new Float32Array([0,0]),u=Math.max(u,1),g=c.NODE_TEXT_SIZE;k[1]=(this.constructor.slot_start_y||
0)+u*c.NODE_SLOT_HEIGHT;u=0;this.widgets&&this.widgets.length&&(u=this.widgets.length*(c.NODE_WIDGET_HEIGHT+4)+8);k[1]=this.widgets_up?Math.max(k[1],u):k[1]+u;var u=d(this.title),e=0,f=0;if(this.inputs)for(var p=0,n=this.inputs.length;p<n;++p){var q=this.inputs[p],q=q.label||q.name||"",q=d(q);e<q&&(e=q)}if(this.outputs)for(p=0,n=this.outputs.length;p<n;++p)q=this.outputs[p],q=q.label||q.name||"",q=d(q),f<q&&(f=q);k[0]=Math.max(e+f+10,u);k[0]=Math.max(k[0],c.NODE_WIDTH);this.widgets&&this.widgets.length&&
(k[0]=Math.max(k[0],1.5*c.NODE_WIDTH));if(this.onResize)this.onResize(k);this.constructor.min_height&&k[1]<this.constructor.min_height&&(k[1]=this.constructor.min_height);k[1]+=6;return k};r.prototype.addWidget=function(a,b,d,c,k){this.widgets||(this.widgets=[]);b={type:a.toLowerCase(),name:b,value:d,callback:c,options:k||{}};void 0!==b.options.y&&(b.y=b.options.y);c||console.warn("LiteGraph addWidget(...) without a callback");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";
this.widgets.push(b);return b};r.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};r.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-c.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+c.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};r.prototype.isPointInside=function(a,b,d,u){d=d||0;var k=this.graph&&this.graph.isLive()?0:20;u&&(k=0);if(this.flags&&this.flags.collapsed){if(B(a,
this.widgets.push(b);return b};r.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};r.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-c.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+c.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};r.prototype.isPointInside=function(a,b,d,u){d=d||0;var k=this.graph&&this.graph.isLive()?0:c.NODE_TITLE_HEIGHT;u&&(k=0);if(this.flags&&this.flags.collapsed){if(B(a,
b,this.pos[0]-d,this.pos[1]-c.NODE_TITLE_HEIGHT-d,(this._collapsed_width||c.NODE_COLLAPSED_WIDTH)+2*d,c.NODE_TITLE_HEIGHT+2*d))return!0}else if(this.pos[0]-4-d<a&&this.pos[0]+this.size[0]+4+d>a&&this.pos[1]-k-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};r.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var c=0,k=this.inputs.length;c<k;++c){var g=this.inputs[c];this.getConnectionPos(!0,c,d);if(B(a,b,d[0]-10,d[1]-5,20,10))return{input:g,slot:c,link_pos:d}}if(this.outputs)for(c=
0,k=this.outputs.length;c<k;++c)if(g=this.outputs[c],this.getConnectionPos(!1,c,d),B(a,b,d[0]-10,d[1]-5,20,10))return{output:g,slot:c,link_pos:d};return null};r.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,d=this.inputs.length;b<d;++b)if(a==this.inputs[b].name)return b;return-1};r.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,d=this.outputs.length;b<d;++b)if(a==this.outputs[b].name)return b;return-1};r.prototype.connect=function(a,b,d){d=d||
0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return c.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return c.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==
@@ -384,15 +384,15 @@ h.prototype.onDropFile=function(a,b,c){if(a){var d=null;"string"==typeof a?d=GL.
function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=h.getTexture(this.properties.name));if(a){this._last_tex=a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0,a);for(var b=1;b<this.outputs.length;b++){var c=this.outputs[b];if(c){var d=null;"width"==c.name?d=a.width:"height"==c.name?d=a.height:"aspect"==c.name&&
(d=a.width/a.height);this.setOutputData(b,d)}}}};h.prototype.onResourceRenamed=function(a,b){this.properties.name==a&&(this.properties.name=b)};h.prototype.onDrawBackground=function(a){if(!(this.flags.collapsed||20>=this.size[1]))if(this._drop_texture&&a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=h.generateLowResTexturePreview(this._last_tex);if(!b)return;this._last_preview_tex=
this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],this.size[1]),a.restore())}};h.generateLowResTexturePreview=function(a){if(!a)return null;var b=h.image_preview_size,c=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)c=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=c=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(c);a=this._preview_canvas;
a||(this._preview_canvas=a=createCanvas(b,b));c&&c.toCanvas(a);return a};h.prototype.getResources=function(a){a[this.properties.name]=GL.Texture;return a};h.prototype.onGetInputs=function(){return[["in","Texture"]]};h.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]};e.registerNodeType("texture/texture",h);var r=function(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[h.image_preview_size,h.image_preview_size]};r.title=
"Preview";r.desc="Show a texture in the graph canvas";r.allow_preview=!1;r.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||r.allow_preview)){var b=this.getInputData(0);if(b){var c=null,c=!b.handle&&a.webgl?b:h.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(c,0,0,this.size[0],this.size[1]);a.restore()}}};e.registerNodeType("texture/preview",r);var m=function(){this.addInput("Texture","Texture");this.addOutput("",
"Texture");this.properties={name:""}};m.title="Save";m.desc="Save a texture in the repository";m.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(h.storeTexture?h.storeTexture(this.properties.name,a):h.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};e.registerNodeType("texture/save",m);var s=function(){this.addInput("Texture","Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");
this.help="<p>pixelcode must be vec3</p>\t\t\t<p>uvcode must be vec2, is optional</p>\t\t\t<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture</p><p><strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time</p><p><strong>value:</strong> input value</p>";this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value",precision:h.DEFAULT}};s.widgets_info={uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},precision:{widget:"combo",
values:h.MODE_VALUES}};s.title="Operation";s.desc="Texture shader operation";s.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};s.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())};s.prototype.onExecute=function(){var a=
this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===h.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var c=512,d=512;a?(c=a.width,d=a.height):b&&(c=b.width,d=b.height);var e=h.getTextureType(this.properties.precision,a);this._tex=a||this._tex?h.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(c,d,{type:e,format:gl.RGBA,filter:gl.LINEAR});e="";this.properties.uvcode&&
(e="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(e=this.properties.uvcode));var g="";this.properties.pixelcode&&(g="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(g=this.properties.pixelcode));var f=this._shader;if(!f||this._shader_code!=e+"|"+g){try{this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.pixel_shader,{UV_CODE:e,PIXEL_CODE:g}),this.boxcolor="#00FF00"}catch(k){console.log("Error compiling shader: ",k);this.boxcolor="#FF0000";
return}this.boxcolor="#FF0000";this._shader_code=e+"|"+g;f=this._shader}if(f){this.boxcolor="green";var q=this.getInputData(2);null!=q?this.properties.value=q:q=parseFloat(this.properties.value);var l=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var e=Mesh.getScreenQuad();f.uniforms({u_texture:0,u_textureB:1,value:q,texSize:[c,d],time:l}).draw(e)});this.setOutputData(0,this._tex)}else this.boxcolor=
"red"}}};s.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 texSize;\n\t\t\tuniform float time;\n\t\t\tuniform float value;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tUV_CODE;\n\t\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\t\tvec3 color = color4.rgb;\n\t\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\t\tvec3 colorB = color4B.rgb;\n\t\t\t\tvec3 result = color;\n\t\t\t\tfloat alpha = 1.0;\n\t\t\t\tPIXEL_CODE;\n\t\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t\t}\n\t\t\t";
a||(this._preview_canvas=a=createCanvas(b,b));c&&c.toCanvas(a);return a};h.prototype.getResources=function(a){a[this.properties.name]=GL.Texture;return a};h.prototype.onGetInputs=function(){return[["in","Texture"]]};h.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]};h.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g,function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})};e.registerNodeType("texture/texture",h);var r=function(){this.addInput("Texture",
"Texture");this.properties={flipY:!1};this.size=[h.image_preview_size,h.image_preview_size]};r.title="Preview";r.desc="Show a texture in the graph canvas";r.allow_preview=!1;r.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||r.allow_preview)){var b=this.getInputData(0);if(b){var c=null,c=!b.handle&&a.webgl?b:h.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(c,0,0,this.size[0],this.size[1]);a.restore()}}};
e.registerNodeType("texture/preview",r);var m=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={name:""}};m.title="Save";m.desc="Save a texture in the repository";m.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(h.storeTexture?h.storeTexture(this.properties.name,a):h.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};e.registerNodeType("texture/save",m);var s=function(){this.addInput("Texture","Texture");
this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="<p>pixelcode must be vec3</p>\t\t\t<p>uvcode must be vec2, is optional</p>\t\t\t<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture</p><p><strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time</p><p><strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value",
precision:h.DEFAULT};this.has_error=!1};s.widgets_info={uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},precision:{widget:"combo",values:h.MODE_VALUES}};s.title="Operation";s.desc="Texture shader operation";s.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};s.prototype.onPropertyChanged=function(){this.has_error=!1};s.prototype.onDrawBackground=
function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())};s.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===h.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var c=512,d=512;a?(c=a.width,d=a.height):b&&(c=b.width,d=b.height);var e=h.getTextureType(this.properties.precision,
a);this._tex=a||this._tex?h.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(c,d,{type:e,format:gl.RGBA,filter:gl.LINEAR});e="";this.properties.uvcode&&(e="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(e=this.properties.uvcode));var g="";this.properties.pixelcode&&(g="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(g=this.properties.pixelcode));var f=this._shader;if(!(this.has_error||f&&this._shader_code==
e+"|"+g)){var k=h.replaceCode(s.pixel_shader,{UV_CODE:e,PIXEL_CODE:g});try{f=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,k),this.boxcolor="#00FF00"}catch(q){console.log("Error compiling shader: ",q,k);this.boxcolor="#FF0000";this.has_error=!0;return}this._shader=f;this._shader_code=e+"|"+g}var l=this.getInputData(2);null!=l?this.properties.value=l:l=parseFloat(this.properties.value);var m=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);
a&&a.bind(0);b&&b.bind(1);var e=Mesh.getScreenQuad();f.uniforms({u_texture:0,u_textureB:1,value:l,texSize:[c,d],time:m}).draw(e)});this.setOutputData(0,this._tex)}}};s.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 texSize;\n\t\t\tuniform float time;\n\t\t\tuniform float value;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\t{{UV_CODE}};\n\t\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\t\tvec3 color = color4.rgb;\n\t\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\t\tvec3 colorB = color4B.rgb;\n\t\t\t\tvec3 result = color;\n\t\t\t\tfloat alpha = 1.0;\n\t\t\t\t{{PIXEL_CODE}};\n\t\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t\t}\n\t\t\t";
e.registerNodeType("texture/operation",s);var f=function(){this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,precision:h.DEFAULT};this.properties.code="\nvoid main() {\n vec2 uv = v_coord;\n vec3 color = vec3(0.0);\n//your code here\n\ngl_FragColor = vec4(color, 1.0);\n}\n";this._uniforms={in_texture:0,texSize:vec2.create(),time:0}};f.title="Shader";f.desc="Texture shader";f.widgets_info={code:{type:"code"},precision:{widget:"combo",values:h.MODE_VALUES}};f.prototype.onPropertyChanged=
function(a,b){if("code"==a){var c=this.getShader();if(c){var d=c.uniformInfo;if(this.inputs)for(var e={},g=0;g<this.inputs.length;++g){var f=this.getInputInfo(g);f&&(d[f.name]&&!e[f.name]?e[f.name]=!0:(this.removeInput(g),g--))}for(g in d)if(f=c.uniformInfo[g],null!==f.loc&&"time"!=g){d="number";if(this._shader.samplers[g])d="texture";else switch(f.size){case 1:d="number";break;case 2:d="vec2";break;case 3:d="vec3";break;case 4:d="vec4";break;case 9:d="mat3";break;case 16:d="mat4";break;default:continue}f=
this.findInputSlot(g);-1==f?this.addInput(g,d):(e=this.getInputInfo(f),e)?e.type!=d&&(this.removeInput(f,d),this.addInput(g,d)):this.addInput(g,d)}}}};f.prototype.getShader=function(){if(this._shader&&this._shader_code==this.properties.code)return this._shader;this._shader_code=this.properties.code;if(this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader+this.properties.code))this.boxcolor="green";else return this.boxcolor="red",null;return this._shader};f.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=
@@ -415,8 +415,8 @@ a);else{var b=z._shader;b||(z._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SH
d,a);q.push(k);f.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);f.copyTo(k,b,l);if(1==c&&1==d)break;f=k}this._texture=q.pop();for(m=0;m<q.length;++m)GL.Texture.releaseTemporary(q[m]);this.properties.generate_mipmaps&&(this._texture.bind(0),gl.generateMipmap(this._texture.texture_type),this._texture.unbind(0));this.setOutputData(0,this._texture)}};z.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord );\n\t\t\t\tcolor += texture2D(u_texture, v_coord + vec2( u_offset.x, 0.0 ) );\n\t\t\t\tcolor += texture2D(u_texture, v_coord + vec2( 0.0, u_offset.y ) );\n\t\t\t\tcolor += texture2D(u_texture, v_coord + vec2( u_offset.x, u_offset.y ) );\n\t\t\t gl_FragColor = color * 0.25;\n\t\t\t}\n\t\t\t";
e.registerNodeType("texture/downsample",z);var c=function(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg","vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,mipmap_offset:0,low_precision:!1};this._uniforms={u_texture:0,u_mipmap_offset:this.properties.mipmap_offset};this._luminance=new Float32Array(4)};c.title="Average";c.desc="Compute a partial average (32 random samples) of a texture and stores it as a 1x1 pixel texture";c.prototype.onExecute=
function(){this.properties.use_previous_frame||this.updateAverage();var a=this._luminance;this.setOutputData(0,this._temp_texture);this.setOutputData(1,a);this.setOutputData(2,(a[0]+a[1]+a[2])/3)};c.prototype.onPreRenderExecute=function(){this.updateAverage()};c.prototype.updateAverage=function(){var a=this.getInputData(0);if(a&&(this.isOutputConnected(0)||this.isOutputConnected(1)||this.isOutputConnected(2))){if(!c._shader){c._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,c.pixel_shader);for(var b=
new Float32Array(32),d=0;32>d;++d)b[d]=Math.random();c._shader.uniforms({u_samples_a:b.subarray(0,16),u_samples_b:b.subarray(16,32)})}d=this._temp_texture;b=gl.UNSIGNED_BYTE;a.type!=b&&(b=gl.FLOAT);d&&d.type==b||(this._temp_texture=new GL.Texture(1,1,{type:b,format:gl.RGBA,filter:gl.NEAREST}));var e=c._shader,g=this._uniforms;g.u_mipmap_offset=this.properties.mipmap_offset;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){a.toViewport(e,g)});if(this.isOutputConnected(1)||
this.isOutputConnected(2))if(d=this._temp_texture.getPixels()){var f=this._luminance,b=this._temp_texture.type;f.set(d);b==gl.UNSIGNED_BYTE&&vec4.scale(f,f,1/255)}}};c.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_mipmap_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t";
new Float32Array(16),d=0;d<b.length;++d)b[d]=Math.random();c._shader.uniforms({u_samples_a:b.subarray(0,16),u_samples_b:b.subarray(16,32)})}d=this._temp_texture;b=gl.UNSIGNED_BYTE;a.type!=b&&(b=gl.FLOAT);d&&d.type==b||(this._temp_texture=new GL.Texture(1,1,{type:b,format:gl.RGBA,filter:gl.NEAREST}));var e=c._shader,g=this._uniforms;g.u_mipmap_offset=this.properties.mipmap_offset;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){a.toViewport(e,g)});if(this.isOutputConnected(1)||
this.isOutputConnected(2))if(d=this._temp_texture.getPixels()){var f=this._luminance,b=this._temp_texture.type;f.set(d);b==gl.UNSIGNED_BYTE&&vec4.scale(f,f,1/255)}}};c.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_mipmap_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\t//random average\n\t\t\t\tfor(int i = 0; i <= 4; ++i)\n\t\t\t\t\tfor(int j = 0; j <= 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t";
e.registerNodeType("texture/average",c);var x=function(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:0.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}};x.title="Smooth";x.desc="Smooth texture over time";x.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){x._shader||(x._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,x.pixel_shader));var b=this._temp_texture;
b&&b.type==a.type&&b.width==a.width&&b.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.NEAREST}),this._temp_texture2=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.NEAREST}),a.copyTo(this._temp_texture2));var b=this._temp_texture,c=this._temp_texture2,d=x._shader,e=this._uniforms;e.u_factor=1-this.getInputOrProperty("factor");gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);b.drawTo(function(){c.bind(1);a.toViewport(d,
e)});this.setOutputData(0,b);this._temp_texture=c;this._temp_texture2=b}};x.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform float u_factor;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tgl_FragColor = mix( texture2D( u_texture, v_coord ), texture2D( u_textureB, v_coord ), u_factor );\n\t\t\t}\n\t\t\t";e.registerNodeType("texture/temporal_smooth",x);m=function(){this.addInput("Image",