diff --git a/build/litegraph.js b/build/litegraph.js index e4e226921..0fd7b38f4 100644 --- a/build/litegraph.js +++ b/build/litegraph.js @@ -3591,10 +3591,7 @@ //allows nodes to block connection if (target_node.onConnectInput) { - if ( - target_node.onConnectInput(target_slot, output.type, output) === - false - ) { + if ( target_node.onConnectInput(target_slot, output.type, output, this, slot) === false ) { return null; } } @@ -19684,8 +19681,8 @@ void main() {\n\ }; this._uniforms = { u_texture: 0, - u_near: 0.1, - u_far: 10000 + u_camera_planes: null, //filled later + u_ires: vec2.create() }; } @@ -19717,9 +19714,6 @@ void main() {\n\ } var uniforms = this._uniforms; - - uniforms.u_near = tex.near_far_planes[0]; - uniforms.u_far = tex.near_far_planes[1]; uniforms.u_invert = this.properties.invert ? 1 : 0; gl.disable(gl.BLEND); @@ -19739,6 +19733,8 @@ void main() {\n\ planes = [0.1, 1000]; } //hardcoded uniforms.u_camera_planes = planes; + //uniforms.u_ires.set([1/tex.width, 1/tex.height]); + uniforms.u_ires.set([0,0]); this._temp_texture.drawTo(function() { tex.bind(0); @@ -19754,15 +19750,14 @@ void main() {\n\ precision highp float;\n\ varying vec2 v_coord;\n\ uniform sampler2D u_texture;\n\ - uniform float u_near;\n\ - uniform float u_far;\n\ + uniform vec2 u_camera_planes;\n\ uniform int u_invert;\n\ + uniform vec2 u_ires;\n\ \n\ void main() {\n\ - float zNear = u_near;\n\ - float zFar = u_far;\n\ - float depth = texture2D(u_texture, v_coord).x;\n\ - depth = depth * 2.0 - 1.0;\n\ + float zNear = u_camera_planes.x;\n\ + float zFar = u_camera_planes.y;\n\ + float depth = texture2D(u_texture, v_coord + u_ires*0.5).x * 2.0 - 1.0;\n\ float f = zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\ if( u_invert == 1 )\n\ f = 1.0 - f;\n\ diff --git a/build/litegraph.min.js b/build/litegraph.min.js index 92bc038e6..b0d422061 100755 --- a/build/litegraph.min.js +++ b/build/litegraph.min.js @@ -77,7 +77,7 @@ this.widgets.push(b);this.size=this.computeSize();return b};n.prototype.addCusto 0);if(this.flags&&this.flags.collapsed){if(w(a,b,this.pos[0]-d,this.pos[1]-h.NODE_TITLE_HEIGHT-d,(this._collapsed_width||h.NODE_COLLAPSED_WIDTH)+2*d,h.NODE_TITLE_HEIGHT+2*d))return!0}else if(this.pos[0]-4-da&&this.pos[1]-f-db)return!0;return!1};n.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var g=0,f=this.inputs.length;g=this.outputs.length)return h.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==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return h.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===h.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[d].link&&b.disconnectInput(d);var g=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,g.type,g))return null;var f=b.inputs[d],r=null;if(h.isValidConnection(g.type, +if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return h.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===h.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[d].link&&b.disconnectInput(d);var g=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,g.type,g,this,a))return null;var f=b.inputs[d],r=null;if(h.isValidConnection(g.type, f.type)){r=new m(++this.graph.last_link_id,f.type,this.id,a,b.id,d);this.graph.links[r.id]=r;null==g.links&&(g.links=[]);g.links.push(r.id);b.inputs[d].link=r.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!0,r,g);if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,d,!0,r,f);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(h.OUTPUT,this,a,b,d))}this.setDirtyCanvas(!1, !0);this.graph.connectionChange(this,r);return r};n.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found"; for(var g=0,f=d.links.length;gb;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512, -512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.prototype.onDropFile=function(a,b,d){if(a){var c=null;"string"==typeof a?c=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?c=GL.Texture.fromDDSInMemory(a):(a=new Blob([d]),a=URL.createObjectURL(a),c=GL.Texture.fromURL(a));this._drop_texture=c;this.properties.name=b}else this._drop_texture=null,this.properties.name=""},c.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture= -null;b.properties.name=""}}]},c.prototype.onExecute=function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=c.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);this.setOutputData(1,a.fullpath||a.filename);for(var b=2;b=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=c.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())}},c.generateLowResTexturePreview=function(a){if(!a)return null;var b=c.image_preview_size,d=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)d=this._preview_temp_tex,this._preview_temp_tex|| -(this._preview_temp_tex=d=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(d);a=this._preview_canvas;a||(this._preview_canvas=a=createCanvas(b,b));d&&d.toCanvas(a);return a},c.prototype.getResources=function(a){this.properties.name&&(a[this.properties.name]=GL.Texture);return a},c.prototype.onGetInputs=function(){return[["in","Texture"]]},c.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]},c.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g, -function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})},F.registerNodeType("texture/texture",c),m.title="Preview",m.desc="Show a texture in the graph canvas",m.allow_preview=!1,m.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||m.allow_preview)){var b=this.getInputData(0);if(b){var d=null,d=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(d,0,0,this.size[0],this.size[1]);a.restore()}}}, -F.registerNodeType("texture/preview",m),n.title="Save",n.desc="Save a texture in the repository",n.prototype.getPreviewTexture=function(){return this._texture},n.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.generate_mipmaps&&(a.bind(0),a.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR),gl.generateMipmap(a.texture_type),a.unbind(0)),this.properties.name&&(c.storeTexture?c.storeTexture(this.properties.name,a):c.getTexturesContainer()[this.properties.name]= -a),this._texture=a,this.setOutputData(0,a),this.setOutputData(1,this.properties.name))},F.registerNodeType("texture/save",n),l.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},l.title="Operation",l.desc="Texture shader operation",l.presets={},l.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]},l.prototype.onPropertyChanged= -function(){this.has_error=!1},l.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())},l.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,g=512; -a?(d=a.width,g=a.height):b&&(d=b.width,g=b.height);b||(b=GL.Texture.getWhiteTexture());var f=c.getTextureType(this.properties.precision,a);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,g,{type:f,format:gl.RGBA,filter:gl.LINEAR});f="";this.properties.uvcode&&(f="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(f=this.properties.uvcode));var e="";this.properties.pixelcode&&(e="result = "+this.properties.pixelcode, --1!=this.properties.pixelcode.indexOf(";")&&(e=this.properties.pixelcode));var k=this._shader;if(!(this.has_error||k&&this._shader_code==f+"|"+e)){var h=c.replaceCode(l.pixel_shader,{UV_CODE:f,PIXEL_CODE:e});try{k=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h),this.boxcolor="#00FF00"}catch(p){GL.Shader.dumpErrorToConsole(p,Shader.SCREEN_VERTEX_SHADER,h);this.boxcolor="#FF0000";this.has_error=!0;return}this._shader=k;this._shader_code=f+"|"+e}if(this._shader){var q=this.getInputData(2);null!=q?this.properties.value= -q:q=parseFloat(this.properties.value);var r=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 c=Mesh.getScreenQuad();k.uniforms({u_texture:0,u_textureB:1,value:q,texSize:[d,g],time:r}).draw(c)});this.setOutputData(0,this._tex)}}}},l.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec2 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t", +this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}}function f(){this.addInput("Texture","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,invert:!1};this._uniforms={u_texture:0,u_camera_planes:null,u_ires:vec2.create()}}function r(){this.addInput("Texture","Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1, +1],precision:c.DEFAULT}}function s(){this.addInput("in","Texture");this.addInput("dirt","Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:0.99,iterations:16,threshold:0,scale:1,dirt_factor:0.5,precision:c.DEFAULT};this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}}function I(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties= +{intensity:1,radius:5}}function J(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79,phi:0.017}}function H(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function E(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:c.LOW};this._uniforms={u_texture:0,u_factor:1}} +function t(){this.addInput("in","Texture");this.addOutput("out","Texture");this.properties={precision:c.LOW,split_channels:!1};this._values=new Uint8Array(1024);this._values.fill(255);this._curve_texture=null;this._uniforms={u_texture:0,u_curve:1,u_range:1};this._must_update=!0;this._points={RGB:[[0,0],[1,1]],R:[[0,0],[1,1]],G:[[0,0],[1,1]],B:[[0,0],[1,1]]};this.curve_editor=null;this.addWidget("toggle","Split Channels",!1,"split_channels");this.addWidget("combo","Channel","RGB",{values:["RGB","R", +"G","B"]});this.curve_offset=68;this.size=[240,160]}function N(){this.addInput("in","Texture");this.addInput("exp","number");this.addOutput("out","Texture");this.properties={exposition:1,precision:c.LOW};this._uniforms={u_texture:0,u_exposition:1}}function K(){this.addInput("in","Texture");this.addInput("avg","number,Texture");this.addOutput("out","Texture");this.properties={enabled:!0,scale:1,gamma:1,average_lum:1,lum_white:1,precision:c.LOW};this._uniforms={u_texture:0,u_lumwhite2:1,u_igamma:1, +u_scale:1,u_average_lum:1}}function M(){this.addOutput("out","Texture");this.properties={width:512,height:512,seed:0,persistence:0.1,octaves:8,scale:1,offset:[0,0],amplitude:1,precision:c.DEFAULT};this._key=0;this._texture=null;this._uniforms={u_persistence:0.1,u_seed:0,u_offset:vec2.create(),u_scale:1,u_viewport:vec2.create()}}function L(){this.addInput("v");this.addOutput("out","Texture");this.properties={code:L.default_code,width:512,height:512,clear:!0,precision:c.DEFAULT,use_html_canvas:!1}; +this._temp_texture=this._func=null;this.compileCode()}function O(){this.addInput("in","Texture");this.addOutput("out","Texture");this.properties={key_color:vec3.fromValues(0,1,0),threshold:0.8,slope:0.2,precision:c.DEFAULT}}function P(){this.addInput("in","texture");this.addInput("yaw","number");this.addOutput("out","texture");this.properties={yaw:0}}var F=B.LiteGraph;B.LGraphTexture=null;"undefined"!=typeof GL&&(LGraphCanvas.link_type_colors.Texture="#987",B.LGraphTexture=c,c.title="Texture",c.desc= +"Texture",c.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}},c.loadTextureCallback=null,c.image_preview_size=256,c.PASS_THROUGH=1,c.COPY=2,c.LOW=3,c.HIGH=4,c.REUSE=5,c.DEFAULT=2,c.MODE_VALUES={"pass through":c.PASS_THROUGH,copy:c.COPY,low:c.LOW,high:c.HIGH,reuse:c.REUSE,"default":c.DEFAULT},c.getTexturesContainer=function(){return gl.textures},c.loadTexture=function(a,b){b=b||{};var d=a;"http://"==d.substr(0,7)&&F.proxy&&(d=F.proxy+d.substr(7));return c.getTexturesContainer()[a]= +GL.Texture.fromURL(d,b)},c.getTexture=function(a){var b=this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found";b=b[a];return!b&&a&&":"!=a[0]?this.loadTexture(a):b},c.getTargetTexture=function(a,b,d){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var g=null;switch(d){case c.LOW:g=gl.UNSIGNED_BYTE;break;case c.HIGH:g=gl.HIGH_PRECISION_FORMAT;break;case c.REUSE:return a;default:g=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height== +a.height&&b.type==g||(b=new GL.Texture(a.width,a.height,{type:g,format:gl.RGBA,filter:gl.LINEAR}));return b},c.getTextureType=function(a,b){var d=b?b.type:gl.UNSIGNED_BYTE;switch(a){case c.HIGH:d=gl.HIGH_PRECISION_FORMAT;break;case c.LOW:d=gl.UNSIGNED_BYTE}return d},c.getWhiteTexture=function(){return this._white_texture?this._white_texture:this._white_texture=GL.Texture.fromMemory(1,1,[255,255,255,255],{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture; +for(var a=new Uint8Array(1048576),b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.prototype.onDropFile=function(a,b,d){if(a){var c=null;"string"==typeof a?c=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?c=GL.Texture.fromDDSInMemory(a):(a=new Blob([d]),a=URL.createObjectURL(a),c=GL.Texture.fromURL(a));this._drop_texture=c;this.properties.name=b}else this._drop_texture=null,this.properties.name= +""},c.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=null;b.properties.name=""}}]},c.prototype.onExecute=function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=c.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);this.setOutputData(1,a.fullpath||a.filename);for(var b=2;b= +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=c.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())}},c.generateLowResTexturePreview= +function(a){if(!a)return null;var b=c.image_preview_size,d=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)d=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=d=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(d);a=this._preview_canvas;a||(this._preview_canvas=a=createCanvas(b,b));d&&d.toCanvas(a);return a},c.prototype.getResources=function(a){this.properties.name&&(a[this.properties.name]=GL.Texture);return a},c.prototype.onGetInputs=function(){return[["in", +"Texture"]]},c.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]},c.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g,function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})},F.registerNodeType("texture/texture",c),m.title="Preview",m.desc="Show a texture in the graph canvas",m.allow_preview=!1,m.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||m.allow_preview)){var b=this.getInputData(0);if(b){var d=null, +d=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(d,0,0,this.size[0],this.size[1]);a.restore()}}},F.registerNodeType("texture/preview",m),n.title="Save",n.desc="Save a texture in the repository",n.prototype.getPreviewTexture=function(){return this._texture},n.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.generate_mipmaps&&(a.bind(0),a.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR), +gl.generateMipmap(a.texture_type),a.unbind(0)),this.properties.name&&(c.storeTexture?c.storeTexture(this.properties.name,a):c.getTexturesContainer()[this.properties.name]=a),this._texture=a,this.setOutputData(0,a),this.setOutputData(1,this.properties.name))},F.registerNodeType("texture/save",n),l.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},l.title="Operation",l.desc="Texture shader operation",l.presets={},l.prototype.getExtraMenuOptions= +function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]},l.prototype.onPropertyChanged=function(){this.has_error=!1},l.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())},l.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision=== +c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,g=512;a?(d=a.width,g=a.height):b&&(d=b.width,g=b.height);b||(b=GL.Texture.getWhiteTexture());var f=c.getTextureType(this.properties.precision,a);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,g,{type:f,format:gl.RGBA,filter:gl.LINEAR});f="";this.properties.uvcode&&(f="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&& +(f=this.properties.uvcode));var e="";this.properties.pixelcode&&(e="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(e=this.properties.pixelcode));var k=this._shader;if(!(this.has_error||k&&this._shader_code==f+"|"+e)){var h=c.replaceCode(l.pixel_shader,{UV_CODE:f,PIXEL_CODE:e});try{k=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h),this.boxcolor="#00FF00"}catch(p){GL.Shader.dumpErrorToConsole(p,Shader.SCREEN_VERTEX_SHADER,h);this.boxcolor="#FF0000";this.has_error=!0; +return}this._shader=k;this._shader_code=f+"|"+e}if(this._shader){var q=this.getInputData(2);null!=q?this.properties.value=q:q=parseFloat(this.properties.value);var r=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 c=Mesh.getScreenQuad();k.uniforms({u_texture:0,u_textureB:1,value:q,texSize:[d,g],time:r}).draw(c)});this.setOutputData(0,this._tex)}}}},l.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec2 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t", l.registerPreset=function(a,b){l.presets[a]=b},l.registerPreset("",""),l.registerPreset("bypass","color"),l.registerPreset("add","color + colorB * value"),l.registerPreset("substract","(color - colorB) * value"),l.registerPreset("mate","mix( color, colorB, color4B.a * value)"),l.registerPreset("invert","vec3(1.0) - color"),l.registerPreset("multiply","color * colorB * value"),l.registerPreset("divide","(color / colorB) / value"),l.registerPreset("difference","abs(color - colorB) * value"),l.registerPreset("max", "max(color, colorB) * value"),l.registerPreset("min","min(color, colorB) * value"),l.registerPreset("displace","texture2D(u_texture, uv + (colorB.xy - vec2(0.5)) * value).xyz"),l.registerPreset("grayscale","vec3(color.x + color.y + color.z) * value / 3.0"),l.registerPreset("saturation","mix( vec3(color.x + color.y + color.z) / 3.0, color, value )"),l.registerPreset("threshold","vec3(color.x > colorB.x * value ? 1.0 : 0.0,color.y > colorB.y * value ? 1.0 : 0.0,color.z > colorB.z * value ? 1.0 : 0.0)"), l.prototype.onInspect=function(a){var b=this;a.addCombo("Presets","",{values:Object.keys(l.presets),callback:function(d){var c=l.presets[d];c&&(b.setProperty("pixelcode",c),b.title=d,a.refresh())}})},F.registerNodeType("texture/operation",l),x.title="Shader",x.desc="Texture shader",x.widgets_info={code:{type:"code",lang:"glsl"},precision:{widget:"combo",values:c.MODE_VALUES}},x.prototype.onPropertyChanged=function(a,b){if("code"==a){var d=this.getShader();if(d){var c=d.uniformInfo;if(this.inputs)for(var g= @@ -506,8 +506,8 @@ F.registerNodeType("texture/edges",d),g.title="Depth Range",g.desc="Generates a filter:gl.LINEAR}));var d=this._uniforms,b=this.properties.distance;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.distance=b);var c=this.properties.range;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.range=c);d.u_distance=b;d.u_range=c;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad();g._shader||(g._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,g.pixel_shader),g._shader_onlydepth=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,g.pixel_shader, {ONLY_DEPTH:""}));var e=this.properties.only_depth?g._shader_onlydepth:g._shader,b=null,b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:[0.1,1E3];d.u_camera_planes=b;this._temp_texture.drawTo(function(){a.bind(0);e.uniforms(d).draw(f)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},g.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_camera_planes;\n\t\tuniform float u_distance;\n\t\tuniform float u_range;\n\t\t\n\t\tfloat LinearDepth()\n\t\t{\n\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\treturn zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t\tfloat depth = LinearDepth();\n\t\t\t#ifdef ONLY_DEPTH\n\t\t\t gl_FragColor = vec4(depth);\n\t\t\t#else\n\t\t\t\tfloat diff = abs(depth * u_camera_planes.y - u_distance);\n\t\t\t\tfloat dof = 1.0;\n\t\t\t\tif(diff <= u_range)\n\t\t\t\t\tdof = diff / u_range;\n\t\t\t gl_FragColor = vec4(dof);\n\t\t\t#endif\n\t\t}\n\t\t", F.registerNodeType("texture/depth_range",g),f.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},f.title="Linear Depth",f.desc="Creates a color texture with linear depth",f.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a&&(a.format==gl.DEPTH_COMPONENT||a.format==gl.DEPTH_STENCIL)){var b=this.properties.precision==c.HIGH?gl.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&& -this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGB,filter:gl.LINEAR}));var d=this._uniforms;d.u_near=a.near_far_planes[0];d.u_far=a.near_far_planes[1];d.u_invert=this.properties.invert?1:0;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var g=Mesh.getScreenQuad();f._shader||(f._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,f.pixel_shader));var e=f._shader,b=null,b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera? -LS.Renderer._main_camera._uniforms.u_camera_planes:[0.1,1E3];d.u_camera_planes=b;this._temp_texture.drawTo(function(){a.bind(0);e.uniforms(d).draw(g)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},f.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_near;\n\t\tuniform float u_far;\n\t\tuniform int u_invert;\n\t\t\n\t\tvoid main() {\n\t\t\tfloat zNear = u_near;\n\t\t\tfloat zFar = u_far;\n\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\tfloat f = zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\tif( u_invert == 1 )\n\t\t\t\tf = 1.0 - f;\n\t\t\tgl_FragColor = vec4(vec3(f),1.0);\n\t\t}\n\t\t", +this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGB,filter:gl.LINEAR}));var d=this._uniforms;d.u_invert=this.properties.invert?1:0;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var g=Mesh.getScreenQuad();f._shader||(f._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,f.pixel_shader));var e=f._shader,b=null,b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:[0.1, +1E3];d.u_camera_planes=b;d.u_ires.set([0,0]);this._temp_texture.drawTo(function(){a.bind(0);e.uniforms(d).draw(g)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},f.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_camera_planes;\n\t\tuniform int u_invert;\n\t\tuniform vec2 u_ires;\n\t\t\n\t\tvoid main() {\n\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\tfloat depth = texture2D(u_texture, v_coord + u_ires*0.5).x * 2.0 - 1.0;\n\t\t\tfloat f = zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\tif( u_invert == 1 )\n\t\t\t\tf = 1.0 - f;\n\t\t\tgl_FragColor = vec4(vec3(f),1.0);\n\t\t}\n\t\t", F.registerNodeType("texture/linear_depth",f),r.title="Blur",r.desc="Blur a texture",r.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},r.max_iterations=20,r.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._final_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var d=this.properties.iterations;this.isInputConnected(1)&& (d=this.getInputData(1),this.properties.iterations=d);d=Math.min(Math.floor(d),r.max_iterations);if(0==d)this.setOutputData(0,a);else{var c=this.properties.intensity;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.intensity=c);var g=F.camera_aspect;g||void 0===window.gl||(g=gl.canvas.height/gl.canvas.width);g||(g=1);var g=this.properties.preserve_aspect?g:1,f=this.properties.scale||[1,1];a.applyBlur(g*f[0],f[1],c,b);for(a=1;a