From 20666b9a700879901cc3d59866db8d76743fbf30 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Thu, 2 May 2024 19:36:59 +0700 Subject: [PATCH] floodfill perf --- .../node_array_rearrange.gml | 11 ++++++++++ scripts/node_flood_fill/node_flood_fill.gml | 20 ++++++++++++------- .../node_graph_preview/node_graph_preview.gml | 2 +- shaders/sh_flood_fill_it/sh_flood_fill_it.fsh | 11 +++++++--- .../sh_flood_fill_replace.fsh | 11 ++++++---- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/scripts/node_array_rearrange/node_array_rearrange.gml b/scripts/node_array_rearrange/node_array_rearrange.gml index e6412bdd5..35c89a81c 100644 --- a/scripts/node_array_rearrange/node_array_rearrange.gml +++ b/scripts/node_array_rearrange/node_array_rearrange.gml @@ -1,6 +1,9 @@ function Node_Array_Rearrange(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { name = "Array Rearrange"; + draw_pad_w = 10; + setDimension(96, 48); + inputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0) .setArrayDepth(1) .setVisible(true, true); @@ -140,4 +143,12 @@ function Node_Array_Rearrange(_x, _y, _group = noone) : Node(_x, _y, _group) con outputs[| 0].setValue(res); } #endregion + + static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region + draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text); + var str = outputs[| 0].getValue(); + var bbox = drawGetBbox(xx, yy, _s); + draw_text_bbox(bbox, str); + } #endregion + } \ No newline at end of file diff --git a/scripts/node_flood_fill/node_flood_fill.gml b/scripts/node_flood_fill/node_flood_fill.gml index 8b2f03041..93ef7e921 100644 --- a/scripts/node_flood_fill/node_flood_fill.gml +++ b/scripts/node_flood_fill/node_flood_fill.gml @@ -24,11 +24,14 @@ function Node_Flood_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _group __init_mask_modifier(1); // inputs 8, 9 + inputs[| 10] = nodeValue("Blend", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Override", "Multiply" ]); + outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); input_display_list = [ 3, ["Surfaces", false], 0, 1, 2, 8, 9, - ["Fill", false], 4, 6, 5, 7, + ["Fill", false], 4, 6, 5, 7, 10, ] temp_surface = [ surface_create(1, 1), surface_create(1, 1) ]; @@ -55,10 +58,11 @@ function Node_Flood_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _group var inSurf = _data[0]; if(!is_surface(inSurf)) return _outSurf; - var _pos = _data[4]; - var _col = _data[5]; - var _thr = _data[6]; - var _dia = _data[7]; + var _pos = _data[ 4]; + var _col = _data[ 5]; + var _thr = _data[ 6]; + var _dia = _data[ 7]; + var _bnd = _data[10]; var _filC = surface_get_pixel_ext(inSurf, _pos[0], _pos[1]); @@ -86,7 +90,7 @@ function Node_Flood_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _group surface_reset_target(); var ind = 0; - var it = attributes.fill_iteration == -1? sw + sh : attributes.fill_iteration; + var it = attributes.fill_iteration == -1? 8 : attributes.fill_iteration; repeat(it) { ind = !ind; @@ -98,8 +102,10 @@ function Node_Flood_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _group } surface_set_shader(_outSurf, sh_flood_fill_replace); - shader_set_color("color", _col); + shader_set_color("color", _col); shader_set_surface("mask", temp_surface[ind]); + shader_set_i("blend", _bnd); + draw_surface_safe(inSurf, 0, 0); surface_reset_shader(); diff --git a/scripts/node_graph_preview/node_graph_preview.gml b/scripts/node_graph_preview/node_graph_preview.gml index e15ab5051..079c435f3 100644 --- a/scripts/node_graph_preview/node_graph_preview.gml +++ b/scripts/node_graph_preview/node_graph_preview.gml @@ -85,7 +85,7 @@ function Node_Graph_Preview(_x, _y, _group = noone) : Node(_x, _y, _group) const var _hov = false; - if(PANEL_INSPECTOR.inspecting == self) { + if(PANEL_INSPECTOR.inspecting == self && PANEL_GRAPH.node_hovering == noone && PANEL_GRAPH.junction_hovering == noone) { var _sw = surface_get_width_safe(surf); var _sh = surface_get_height_safe(surf); diff --git a/shaders/sh_flood_fill_it/sh_flood_fill_it.fsh b/shaders/sh_flood_fill_it/sh_flood_fill_it.fsh index 9ab3ff7b6..57b5bd9b5 100644 --- a/shaders/sh_flood_fill_it/sh_flood_fill_it.fsh +++ b/shaders/sh_flood_fill_it/sh_flood_fill_it.fsh @@ -17,10 +17,12 @@ void main() { if(c.rgb == vec3(0.)) return; if(c == red) return; - float ite = diagonal == 1? 8. : 4.; - + float ite = diagonal == 1? 8. : 4.; float base = 1.; float top = 0.; + vec2 shf = vec2(0.); + vec2 tx = 1. / dimension; + for(float i = 0.; i < ite; i++) { float ang = top / base * TAU; top += 2.; @@ -29,8 +31,11 @@ void main() { base *= 2.; } + shf.x = cos(ang); + shf.y = sin(ang); + for(float j = 0.; j < dimension.x; j++) { - vec2 _pos = v_vTexcoord + vec2(cos(ang), sin(ang)) * j / dimension; + vec2 _pos = v_vTexcoord + shf * j * tx; if(_pos.x < 0. || _pos.y < 0. || _pos.x > 1. || _pos.y > 1.) break; diff --git a/shaders/sh_flood_fill_replace/sh_flood_fill_replace.fsh b/shaders/sh_flood_fill_replace/sh_flood_fill_replace.fsh index 7db20f3be..d5aa10201 100644 --- a/shaders/sh_flood_fill_replace/sh_flood_fill_replace.fsh +++ b/shaders/sh_flood_fill_replace/sh_flood_fill_replace.fsh @@ -1,15 +1,18 @@ -// -// Simple passthrough fragment shader -// varying vec2 v_vTexcoord; varying vec4 v_vColour; +uniform int blend; uniform vec4 color; uniform sampler2D mask; void main() { + vec4 red = vec4(1., 0., 0., 1.); vec4 col = texture2D( gm_BaseTexture, v_vTexcoord ); vec4 msk = texture2D( mask, v_vTexcoord ); - gl_FragColor = msk.rgb == vec3(1., 0., 0.)? color : col; + gl_FragColor = col; + if(msk != red) return; + + if(blend == 0) gl_FragColor = color; + else if(blend == 1) gl_FragColor = color * col; }