This commit is contained in:
tamat
2018-03-07 19:27:08 +01:00
parent 7b882fd027
commit ac252fa6e6
2 changed files with 9 additions and 6 deletions

View File

@@ -1815,7 +1815,7 @@ LGraphNode.prototype.trigger = function( action, param )
for(var i = 0; i < this.outputs.length; ++i)
{
var output = this.outputs[ slot ];
var output = this.outputs[ i ];
if(!output || output.type !== LiteGraph.EVENT || (action && output.name != action) )
continue;
this.triggerSlot( i, param );
@@ -11966,7 +11966,10 @@ if(typeof(LiteGraph) != "undefined")
this.properties = { aberration:1.0, distortion: 1.0, blur: 1.0, precision: LGraphTexture.DEFAULT };
if(!LGraphFXLens._shader)
{
LGraphFXLens._shader = new GL.Shader( Shader.SCREEN_VERTEX_SHADER, LGraphFXLens.pixel_shader );
LGraphFXLens._texture = new GL.Texture(3,1,{ format: gl.RGB, wrap: gl.CLAMP_TO_EDGE, magFilter: gl.LINEAR, minFilter: gl.LINEAR, pixel_data: [255,0,0, 0,255,0, 0,0,255] });
}
}
LGraphFXLens.title = "Lens";
@@ -11988,7 +11991,6 @@ if(typeof(LiteGraph) != "undefined")
this._tex = LGraphTexture.getTargetTexture( tex, this._tex, this.properties.precision );
//iterations
var aberration = this.properties.aberration;
if( this.isInputConnected(1) )
{

View File

@@ -39,7 +39,7 @@ null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[
b}};LGraphNode.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var c=this.graph.links[this.inputs[a].link];if(!c)return null;if(!b)return c.data;var h=this.graph.getNodeById(c.origin_id);if(!h)return c.data;if(h.updateOutputData)h.updateOutputData(c.origin_slot);else if(h.onExecute)h.onExecute();return c.data}};LGraphNode.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};LGraphNode.prototype.getInputInfo=
function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};LGraphNode.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};LGraphNode.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};LGraphNode.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:
null:null};LGraphNode.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:null};LGraphNode.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var h=this.graph.links[a.links[c]];h&&(h=this.graph.getNodeById(h.target_id))&&b.push(h)}return b};LGraphNode.prototype.trigger=
function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var c=0;c<this.outputs.length;++c){var h=this.outputs[slot];!h||h.type!==k.EVENT||a&&h.name!=a||this.triggerSlot(c,b)}}};LGraphNode.prototype.triggerSlot=function(a,b){if(this.outputs){var c=this.outputs[a];if(c&&(c=c.links)&&c.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var h=0;h<c.length;++h){var n=this.graph.links[c[h]];if(n){var e=this.graph.getNodeById(n.target_id);
function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var c=0;c<this.outputs.length;++c){var h=this.outputs[c];!h||h.type!==k.EVENT||a&&h.name!=a||this.triggerSlot(c,b)}}};LGraphNode.prototype.triggerSlot=function(a,b){if(this.outputs){var c=this.outputs[a];if(c&&(c=c.links)&&c.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var h=0;h<c.length;++h){var n=this.graph.links[c[h]];if(n){var e=this.graph.getNodeById(n.target_id);
if(e)if(n._last_time=k.getTime(),n=e.inputs[n.target_slot],e.onAction)e.onAction(n.name,b);else if(e.mode===k.ON_TRIGGER&&e.onExecute)e.onExecute(b)}}}}};LGraphNode.prototype.addProperty=function(a,b,c,h){c={name:a,type:c,default_value:b};if(h)for(var n in h)c[n]=h[n];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};LGraphNode.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var h in c)a[h]=
c[h];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();return a};LGraphNode.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],h={name:c[0],type:c[1],link:null};if(a[2])for(var n in c[2])h[n]=c[2][n];this.outputs||(this.outputs=[]);this.outputs.push(h);if(this.onOutputAdded)this.onOutputAdded(h)}this.size=this.computeSize()};LGraphNode.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,
1);this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a)};LGraphNode.prototype.addInput=function(a,b,c){a={name:a,type:b||0,link:null};if(c)for(var h in c)a[h]=c[h];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);return a};LGraphNode.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],h={name:c[0],type:c[1],link:null};if(a[2])for(var n in c[2])h[n]=c[2][n];this.inputs||(this.inputs=[]);
@@ -328,9 +328,10 @@ function(){if(this.isOutputConnected(0)){var d=this.getInputData(0);if(this.prop
e.u_threshold=this.properties.threshold;e.u_slope=this.properties.slope;this._tex.drawTo(function(){d.bind(0);g.uniforms(e).draw(f)});this.setOutputData(0,this._tex)}}};LGraphTextureMatte.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec3 u_key_color;\n\t\t\tuniform float u_threshold;\n\t\t\tuniform float u_slope;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec3 color = texture2D( u_texture, v_coord ).xyz;\n\t\t\t\tfloat diff = length( normalize(color) - normalize(u_key_color) );\n\t\t\t\tfloat edge = u_threshold * (1.0 - u_slope);\n\t\t\t\tfloat alpha = smoothstep( edge, u_threshold, diff);\n\t\t\t\tgl_FragColor = vec4( color, alpha );\n\t\t\t}";
LiteGraph.registerNodeType("texture/matte",LGraphTextureMatte);var LGraphCubemap=function(){this.addOutput("Cubemap","Cubemap");this.properties={name:""};this.size=[LGraphTexture.image_preview_size,LGraphTexture.image_preview_size]};LGraphCubemap.title="Cubemap";LGraphCubemap.prototype.onDropFile=function(d,e,f){d?(this._drop_texture="string"==typeof d?GL.Texture.fromURL(d):GL.Texture.fromDDSInMemory(d),this.properties.name=e):(this._drop_texture=null,this.properties.name="")};LGraphCubemap.prototype.onExecute=
function(){if(this._drop_texture)this.setOutputData(0,this._drop_texture);else if(this.properties.name){var d=LGraphTexture.getTexture(this.properties.name);d&&(this._last_tex=d,this.setOutputData(0,d))}};LGraphCubemap.prototype.onDrawBackground=function(d){this.flags.collapsed||20>=this.size[1]||d.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};LiteGraph.registerNodeType("texture/cubemap",LGraphCubemap)}
if("undefined"!=typeof LiteGraph){var LGraphFXLens=function(){this.addInput("Texture","Texture");this.addInput("Aberration","number");this.addInput("Distortion","number");this.addInput("Blur","number");this.addOutput("Texture","Texture");this.properties={aberration:1,distortion:1,blur:1,precision:LGraphTexture.DEFAULT};LGraphFXLens._shader||(LGraphFXLens._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphFXLens.pixel_shader))};LGraphFXLens.title="Lens";LGraphFXLens.desc="Camera Lens distortion";
LGraphFXLens.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphFXLens.prototype.onExecute=function(){var d=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,d);else if(d){this._tex=LGraphTexture.getTargetTexture(d,this._tex,this.properties.precision);var e=this.properties.aberration;this.isInputConnected(1)&&(e=this.getInputData(1),this.properties.aberration=e);var f=this.properties.distortion;this.isInputConnected(2)&&
(f=this.getInputData(2),this.properties.distortion=f);var g=this.properties.blur;this.isInputConnected(3)&&(g=this.getInputData(3),this.properties.blur=g);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var l=Mesh.getScreenQuad(),k=LGraphFXLens._shader;this._tex.drawTo(function(){d.bind(0);k.uniforms({u_texture:0,u_aberration:e,u_distortion:f,u_blur:g}).draw(l)});this.setOutputData(0,this._tex)}};LGraphFXLens.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t";
if("undefined"!=typeof LiteGraph){var LGraphFXLens=function(){this.addInput("Texture","Texture");this.addInput("Aberration","number");this.addInput("Distortion","number");this.addInput("Blur","number");this.addOutput("Texture","Texture");this.properties={aberration:1,distortion:1,blur:1,precision:LGraphTexture.DEFAULT};LGraphFXLens._shader||(LGraphFXLens._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphFXLens.pixel_shader),LGraphFXLens._texture=new GL.Texture(3,1,{format:gl.RGB,wrap:gl.CLAMP_TO_EDGE,
magFilter:gl.LINEAR,minFilter:gl.LINEAR,pixel_data:[255,0,0,0,255,0,0,0,255]}))};LGraphFXLens.title="Lens";LGraphFXLens.desc="Camera Lens distortion";LGraphFXLens.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphFXLens.prototype.onExecute=function(){var d=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,d);else if(d){this._tex=LGraphTexture.getTargetTexture(d,this._tex,this.properties.precision);var e=this.properties.aberration;
this.isInputConnected(1)&&(e=this.getInputData(1),this.properties.aberration=e);var f=this.properties.distortion;this.isInputConnected(2)&&(f=this.getInputData(2),this.properties.distortion=f);var g=this.properties.blur;this.isInputConnected(3)&&(g=this.getInputData(3),this.properties.blur=g);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var l=Mesh.getScreenQuad(),k=LGraphFXLens._shader;this._tex.drawTo(function(){d.bind(0);k.uniforms({u_texture:0,u_aberration:e,u_distortion:f,u_blur:g}).draw(l)});
this.setOutputData(0,this._tex)}};LGraphFXLens.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("fx/lens",LGraphFXLens);window.LGraphFXLens=LGraphFXLens;var LGraphFXBokeh=function(){this.addInput("Texture","Texture");this.addInput("Blurred","Texture");this.addInput("Mask","Texture");this.addInput("Threshold","number");this.addOutput("Texture","Texture");this.properties={shape:"",size:10,alpha:1,threshold:1,high_precision:!1}};LGraphFXBokeh.title="Bokeh";LGraphFXBokeh.desc="applies an Bokeh effect";LGraphFXBokeh.widgets_info={shape:{widget:"texture"}};LGraphFXBokeh.prototype.onExecute=
function(){var d=this.getInputData(0),e=this.getInputData(1),f=this.getInputData(2);if(d&&f&&this.properties.shape){e||(e=d);var g=LGraphTexture.getTexture(this.properties.shape);if(g){var l=this.properties.threshold;this.isInputConnected(3)&&(l=this.getInputData(3),this.properties.threshold=l);var k=gl.UNSIGNED_BYTE;this.properties.high_precision&&(k=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==k&&this._temp_texture.width==d.width&&this._temp_texture.height==
d.height||(this._temp_texture=new GL.Texture(d.width,d.height,{type:k,format:gl.RGBA,filter:gl.LINEAR}));var a=LGraphFXBokeh._first_shader;a||(a=LGraphFXBokeh._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphFXBokeh._first_pixel_shader));var b=LGraphFXBokeh._second_shader;b||(b=LGraphFXBokeh._second_shader=new GL.Shader(LGraphFXBokeh._second_vertex_shader,LGraphFXBokeh._second_pixel_shader));var c=this._points_mesh;c&&c._width==d.width&&c._height==d.height&&2==c._spacing||(c=this.createPointsMesh(d.width,