fix horizontal nodes

This commit is contained in:
tamat
2019-05-08 15:15:44 +02:00
parent 57147e88fb
commit cc2e26ac74
2 changed files with 36 additions and 27 deletions

View File

@@ -3168,7 +3168,7 @@
LGraphNode.prototype.isPointInside = function(x, y, margin, skip_title) { LGraphNode.prototype.isPointInside = function(x, y, margin, skip_title) {
margin = margin || 0; margin = margin || 0;
var margin_top = this.graph && this.graph.isLive() ? 0 : 20; var margin_top = this.graph && this.graph.isLive() ? 0 : LiteGraph.NODE_TITLE_HEIGHT;
if (skip_title) { if (skip_title) {
margin_top = 0; margin_top = 0;
} }

View File

@@ -366,6 +366,15 @@
]; ];
}; };
//used to replace shader code
LGraphTexture.replaceCode = function( code, context )
{
return code.replace(/\{\{[a-zA-Z0-9_]*\}\}/g, function(v){
v = v.replace( /[\{\}]/g, "" );
return context[v] || "";
});
}
LiteGraph.registerNodeType("texture/texture", LGraphTexture); LiteGraph.registerNodeType("texture/texture", LGraphTexture);
//************************** //**************************
@@ -458,7 +467,7 @@
this.help = this.help =
"<p>pixelcode must be vec3</p>\ "<p>pixelcode must be vec3</p>\
<p>uvcode must be vec2, is optional</p>\ <p>uvcode must be vec2, is optional</p>\
<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><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 = { this.properties = {
value: 1, value: 1,
@@ -466,6 +475,8 @@
pixelcode: "color + colorB * value", pixelcode: "color + colorB * value",
precision: LGraphTexture.DEFAULT precision: LGraphTexture.DEFAULT
}; };
this.has_error = false;
} }
LGraphTextureOperation.widgets_info = { LGraphTextureOperation.widgets_info = {
@@ -492,6 +503,11 @@
]; ];
}; };
LGraphTextureOperation.prototype.onPropertyChanged = function()
{
this.has_error = false;
}
LGraphTextureOperation.prototype.onDrawBackground = function(ctx) { LGraphTextureOperation.prototype.onDrawBackground = function(ctx) {
if ( if (
this.flags.collapsed || this.flags.collapsed ||
@@ -583,30 +599,21 @@
var shader = this._shader; var shader = this._shader;
if (!shader || this._shader_code != uvcode + "|" + pixelcode) { if ( !this.has_error && (!shader || this._shader_code != uvcode + "|" + pixelcode) ) {
var final_pixel_code = LGraphTexture.replaceCode( LGraphTextureOperation.pixel_shader, { UV_CODE:uvcode, PIXEL_CODE:pixelcode });
try { try {
this._shader = new GL.Shader( shader = new GL.Shader( Shader.SCREEN_VERTEX_SHADER, final_pixel_code );
Shader.SCREEN_VERTEX_SHADER,
LGraphTextureOperation.pixel_shader,
{ UV_CODE: uvcode, PIXEL_CODE: pixelcode }
);
this.boxcolor = "#00FF00"; this.boxcolor = "#00FF00";
} catch (err) { } catch (err) {
console.log("Error compiling shader: ", err); console.log("Error compiling shader: ", err, final_pixel_code );
this.boxcolor = "#FF0000"; this.boxcolor = "#FF0000";
this.has_error = true;
return; return;
} }
this.boxcolor = "#FF0000"; this._shader = shader;
this._shader_code = uvcode + "|" + pixelcode; this._shader_code = uvcode + "|" + pixelcode;
shader = this._shader;
}
if (!shader) {
this.boxcolor = "red";
return;
} else {
this.boxcolor = "green";
} }
var value = this.getInputData(2); var value = this.getInputData(2);
@@ -655,14 +662,14 @@
\n\ \n\
void main() {\n\ void main() {\n\
vec2 uv = v_coord;\n\ vec2 uv = v_coord;\n\
UV_CODE;\n\ {{UV_CODE}};\n\
vec4 color4 = texture2D(u_texture, uv);\n\ vec4 color4 = texture2D(u_texture, uv);\n\
vec3 color = color4.rgb;\n\ vec3 color = color4.rgb;\n\
vec4 color4B = texture2D(u_textureB, uv);\n\ vec4 color4B = texture2D(u_textureB, uv);\n\
vec3 colorB = color4B.rgb;\n\ vec3 colorB = color4B.rgb;\n\
vec3 result = color;\n\ vec3 result = color;\n\
float alpha = 1.0;\n\ float alpha = 1.0;\n\
PIXEL_CODE;\n\ {{PIXEL_CODE}};\n\
gl_FragColor = vec4(result, alpha);\n\ gl_FragColor = vec4(result, alpha);\n\
}\n\ }\n\
"; ";
@@ -1556,11 +1563,12 @@
GL.Shader.SCREEN_VERTEX_SHADER, GL.Shader.SCREEN_VERTEX_SHADER,
LGraphTextureAverage.pixel_shader LGraphTextureAverage.pixel_shader
); );
//creates 32 random numbers and stores the, in two mat4 //creates 256 random numbers and stores them in two mat4
var samples = new Float32Array(32); var samples = new Float32Array(16);
for (var i = 0; i < 32; ++i) { for (var i = 0; i < samples.length; ++i) {
samples[i] = Math.random(); samples[i] = Math.random(); //poorly distributed samples
} }
//upload only once
LGraphTextureAverage._shader.uniforms({ LGraphTextureAverage._shader.uniforms({
u_samples_a: samples.subarray(0, 16), u_samples_a: samples.subarray(0, 16),
u_samples_b: samples.subarray(16, 32) u_samples_b: samples.subarray(16, 32)
@@ -1620,8 +1628,9 @@
\n\ \n\
void main() {\n\ void main() {\n\
vec4 color = vec4(0.0);\n\ vec4 color = vec4(0.0);\n\
for(int i = 0; i < 4; ++i)\n\ //random average\n\
for(int j = 0; j < 4; ++j)\n\ for(int i = 0; i <= 4; ++i)\n\
for(int j = 0; j <= 4; ++j)\n\
{\n\ {\n\
color += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\ color += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\
color += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\ color += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\