2023-02-28 09:43:01 +01:00
|
|
|
function Node_Flood_Fill(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
|
|
|
name = "Flood Fill";
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Surface("Surface in", self));
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(1, nodeValue_Surface("Mask", self));
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(2, nodeValue_Float("Mix", self, 1))
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider);
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(3, nodeValue_Bool("Active", self, true));
|
2023-02-28 09:43:01 +01:00
|
|
|
active_index = 3;
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(4, nodeValue_Vec2("Position", self, [ 1, 1 ]));
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(5, nodeValue_Color("Colors", self, cola(c_black) ));
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(6, nodeValue_Float("Threshold", self, 0.1))
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider);
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(7, nodeValue_Bool("Diagonal", self, false));
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2023-11-24 10:41:53 +01:00
|
|
|
__init_mask_modifier(1); // inputs 8, 9
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(10, nodeValue_Enum_Scroll("Blend", self, 0, [ "Override", "Multiply" ]));
|
2024-05-02 14:36:59 +02:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
|
2023-02-28 09:43:01 +01:00
|
|
|
|
|
|
|
input_display_list = [ 3,
|
2023-11-24 10:41:53 +01:00
|
|
|
["Surfaces", false], 0, 1, 2, 8, 9,
|
2024-05-02 14:36:59 +02:00
|
|
|
["Fill", false], 4, 6, 5, 7, 10,
|
2023-02-28 09:43:01 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
temp_surface = [ surface_create(1, 1), surface_create(1, 1) ];
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
attributes.fill_iteration = -1;
|
2023-03-24 09:32:08 +01:00
|
|
|
array_push(attributeEditors, "Algorithm");
|
2023-07-14 20:34:35 +02:00
|
|
|
array_push(attributeEditors, ["Fill iteration", function() { return attributes.fill_iteration; },
|
2023-04-11 20:29:20 +02:00
|
|
|
new textBox(TEXTBOX_INPUT.number, function(val) {
|
2023-06-13 14:42:06 +02:00
|
|
|
attributes.fill_iteration = val;
|
2023-04-11 20:29:20 +02:00
|
|
|
triggerRender();
|
|
|
|
})]);
|
2023-03-24 09:32:08 +01:00
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
2024-07-02 12:18:32 +02:00
|
|
|
var _hov = false;
|
2024-08-08 06:57:51 +02:00
|
|
|
var hv = inputs[4].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= hv;
|
2024-07-02 12:18:32 +02:00
|
|
|
|
|
|
|
return _hov;
|
2023-02-28 09:43:01 +01:00
|
|
|
}
|
|
|
|
|
2023-11-24 10:41:53 +01:00
|
|
|
static step = function() { #region
|
|
|
|
__step_mask_modifier();
|
|
|
|
} #endregion
|
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2023-02-28 09:43:01 +01:00
|
|
|
var inSurf = _data[0];
|
|
|
|
if(!is_surface(inSurf)) return _outSurf;
|
|
|
|
|
2024-05-02 14:36:59 +02:00
|
|
|
var _pos = _data[ 4];
|
|
|
|
var _col = _data[ 5];
|
|
|
|
var _thr = _data[ 6];
|
|
|
|
var _dia = _data[ 7];
|
|
|
|
var _bnd = _data[10];
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2023-03-31 06:59:08 +02:00
|
|
|
var _filC = surface_get_pixel_ext(inSurf, _pos[0], _pos[1]);
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2023-09-08 21:37:36 +02:00
|
|
|
var sw = surface_get_width_safe(inSurf);
|
|
|
|
var sh = surface_get_height_safe(inSurf);
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(temp_surface); i < n; i++ )
|
2023-03-19 09:17:39 +01:00
|
|
|
temp_surface[i] = surface_verify(temp_surface[i], sw, sh, attrDepth());
|
2023-02-28 09:43:01 +01:00
|
|
|
|
|
|
|
surface_set_target(temp_surface[0]);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
2023-02-28 09:43:01 +01:00
|
|
|
|
|
|
|
shader_set(sh_flood_fill_thres);
|
2023-03-25 12:27:04 +01:00
|
|
|
shader_set_f("color", colaToVec4(_filC));
|
|
|
|
shader_set_f("thres", _thr);
|
2023-02-28 09:43:01 +01:00
|
|
|
BLEND_OVERRIDE
|
2024-07-10 03:45:25 +02:00
|
|
|
draw_surface_safe(inSurf);
|
2023-02-28 09:43:01 +01:00
|
|
|
BLEND_NORMAL
|
|
|
|
shader_reset();
|
|
|
|
|
|
|
|
BLEND_OVERRIDE
|
|
|
|
draw_set_color(c_red);
|
|
|
|
draw_point(_pos[0] - 1, _pos[1] - 1);
|
|
|
|
BLEND_NORMAL
|
|
|
|
surface_reset_target();
|
|
|
|
|
|
|
|
var ind = 0;
|
2024-05-02 14:36:59 +02:00
|
|
|
var it = attributes.fill_iteration == -1? 8 : attributes.fill_iteration;
|
2023-02-28 09:43:01 +01:00
|
|
|
repeat(it) {
|
|
|
|
ind = !ind;
|
|
|
|
|
2024-01-08 08:10:50 +01:00
|
|
|
surface_set_shader(temp_surface[ind], sh_flood_fill_it);
|
|
|
|
shader_set_f("dimension", [ sw, sh ]);
|
|
|
|
shader_set_i("diagonal", _dia);
|
2024-07-10 03:45:25 +02:00
|
|
|
draw_surface_safe(temp_surface[!ind]);
|
2024-01-08 08:10:50 +01:00
|
|
|
surface_reset_shader();
|
2023-02-28 09:43:01 +01:00
|
|
|
}
|
|
|
|
|
2024-01-08 08:10:50 +01:00
|
|
|
surface_set_shader(_outSurf, sh_flood_fill_replace);
|
2024-05-02 14:36:59 +02:00
|
|
|
shader_set_color("color", _col);
|
2024-01-08 08:10:50 +01:00
|
|
|
shader_set_surface("mask", temp_surface[ind]);
|
2024-05-02 14:36:59 +02:00
|
|
|
shader_set_i("blend", _bnd);
|
|
|
|
|
2024-07-10 03:45:25 +02:00
|
|
|
draw_surface_safe(inSurf);
|
2024-01-08 08:10:50 +01:00
|
|
|
surface_reset_shader();
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2023-11-24 10:41:53 +01:00
|
|
|
__process_mask_modifier(_data);
|
2023-02-28 09:43:01 +01:00
|
|
|
_outSurf = mask_apply(_data[0], _outSurf, _data[1], _data[2]);
|
|
|
|
return _outSurf;
|
|
|
|
}
|
|
|
|
}
|