floodfill perf

This commit is contained in:
Tanasart 2024-05-02 19:36:59 +07:00
parent 1e8f1dc6d3
commit 20666b9a70
5 changed files with 40 additions and 15 deletions

View file

@ -1,6 +1,9 @@
function Node_Array_Rearrange(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { function Node_Array_Rearrange(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Array Rearrange"; name = "Array Rearrange";
draw_pad_w = 10;
setDimension(96, 48);
inputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0) inputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0)
.setArrayDepth(1) .setArrayDepth(1)
.setVisible(true, true); .setVisible(true, true);
@ -140,4 +143,12 @@ function Node_Array_Rearrange(_x, _y, _group = noone) : Node(_x, _y, _group) con
outputs[| 0].setValue(res); outputs[| 0].setValue(res);
} #endregion } #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
} }

View file

@ -24,11 +24,14 @@ function Node_Flood_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _group
__init_mask_modifier(1); // inputs 8, 9 __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); outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
input_display_list = [ 3, input_display_list = [ 3,
["Surfaces", false], 0, 1, 2, 8, 9, ["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) ]; 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]; var inSurf = _data[0];
if(!is_surface(inSurf)) return _outSurf; if(!is_surface(inSurf)) return _outSurf;
var _pos = _data[4]; var _pos = _data[ 4];
var _col = _data[5]; var _col = _data[ 5];
var _thr = _data[6]; var _thr = _data[ 6];
var _dia = _data[7]; var _dia = _data[ 7];
var _bnd = _data[10];
var _filC = surface_get_pixel_ext(inSurf, _pos[0], _pos[1]); 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(); surface_reset_target();
var ind = 0; 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) { repeat(it) {
ind = !ind; 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); 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_surface("mask", temp_surface[ind]);
shader_set_i("blend", _bnd);
draw_surface_safe(inSurf, 0, 0); draw_surface_safe(inSurf, 0, 0);
surface_reset_shader(); surface_reset_shader();

View file

@ -85,7 +85,7 @@ function Node_Graph_Preview(_x, _y, _group = noone) : Node(_x, _y, _group) const
var _hov = false; 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 _sw = surface_get_width_safe(surf);
var _sh = surface_get_height_safe(surf); var _sh = surface_get_height_safe(surf);

View file

@ -17,10 +17,12 @@ void main() {
if(c.rgb == vec3(0.)) return; if(c.rgb == vec3(0.)) return;
if(c == red) return; if(c == red) return;
float ite = diagonal == 1? 8. : 4.; float ite = diagonal == 1? 8. : 4.;
float base = 1.; float base = 1.;
float top = 0.; float top = 0.;
vec2 shf = vec2(0.);
vec2 tx = 1. / dimension;
for(float i = 0.; i < ite; i++) { for(float i = 0.; i < ite; i++) {
float ang = top / base * TAU; float ang = top / base * TAU;
top += 2.; top += 2.;
@ -29,8 +31,11 @@ void main() {
base *= 2.; base *= 2.;
} }
shf.x = cos(ang);
shf.y = sin(ang);
for(float j = 0.; j < dimension.x; j++) { 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.) if(_pos.x < 0. || _pos.y < 0. || _pos.x > 1. || _pos.y > 1.)
break; break;

View file

@ -1,15 +1,18 @@
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord; varying vec2 v_vTexcoord;
varying vec4 v_vColour; varying vec4 v_vColour;
uniform int blend;
uniform vec4 color; uniform vec4 color;
uniform sampler2D mask; uniform sampler2D mask;
void main() { void main() {
vec4 red = vec4(1., 0., 0., 1.);
vec4 col = texture2D( gm_BaseTexture, v_vTexcoord ); vec4 col = texture2D( gm_BaseTexture, v_vTexcoord );
vec4 msk = texture2D( mask, 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;
} }