2023-02-28 09:43:01 +01:00
|
|
|
function Node_Average(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2023-01-17 08:11:55 +01:00
|
|
|
name = "Average";
|
|
|
|
|
|
|
|
shader = sh_average;
|
|
|
|
uniform_dim = shader_get_uniform(shader, "dimension");
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 1] = nodeValue("Mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
|
|
|
|
|
|
|
|
inputs[| 2] = nodeValue("Mix", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
inputs[| 3] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
|
|
|
|
active_index = 3;
|
|
|
|
|
|
|
|
input_display_list = [ 3,
|
2023-05-03 21:42:17 +02:00
|
|
|
["Output", false], 0, 1, 2,
|
2023-02-14 05:32:32 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
outputs[| 1] = nodeValue("Color", self, JUNCTION_CONNECT.output, VALUE_TYPE.color, c_black);
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
colors = [];
|
|
|
|
|
2023-09-14 16:29:39 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
|
2023-01-17 08:11:55 +01:00
|
|
|
var inSurf = _data[0];
|
|
|
|
if(!is_surface(inSurf)) return _outSurf;
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
if(_output_index == 1)
|
|
|
|
return array_safe_get(colors, _array_index);
|
|
|
|
|
2023-09-08 21:37:36 +02:00
|
|
|
var side = max(surface_get_width_safe(inSurf), surface_get_height_safe(inSurf));
|
2023-03-19 09:17:39 +01:00
|
|
|
var lop = ceil(log2(side));
|
2023-01-17 08:11:55 +01:00
|
|
|
var cc;
|
|
|
|
side = power(2, lop);
|
|
|
|
|
|
|
|
if(side / 2 >= 1) {
|
2023-02-28 09:43:01 +01:00
|
|
|
var _Surf = [ surface_create_valid(side, side), surface_create_valid(side, side) ];
|
2023-01-17 08:11:55 +01:00
|
|
|
var _ind = 1;
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
surface_set_target(_Surf[0]);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_OVERRIDE;
|
2023-03-19 09:17:39 +01:00
|
|
|
draw_surface_stretched_safe(inSurf, 0, 0, side, side);
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_NORMAL;
|
2023-01-17 08:11:55 +01:00
|
|
|
surface_reset_target();
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
shader_set(sh_average);
|
|
|
|
for( var i = 0; i <= lop; i++ ) {
|
|
|
|
shader_set_uniform_f(uniform_dim, side);
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
surface_set_target(_Surf[_ind]);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
|
|
|
draw_surface_safe(_Surf[!_ind], 0, 0);
|
2023-01-17 08:11:55 +01:00
|
|
|
surface_reset_target();
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
_ind = !_ind;
|
|
|
|
side /= 2;
|
|
|
|
}
|
2023-02-28 09:43:01 +01:00
|
|
|
shader_reset();
|
|
|
|
|
2023-03-31 06:59:08 +02:00
|
|
|
cc = surface_get_pixel(_Surf[!_ind], 0, 0);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
surface_free(_Surf[0]);
|
|
|
|
surface_free(_Surf[1]);
|
2023-01-17 08:11:55 +01:00
|
|
|
} else
|
2023-03-31 06:59:08 +02:00
|
|
|
cc = surface_get_pixel(inSurf, 0, 0);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
surface_set_target(_outSurf);
|
|
|
|
draw_clear(cc);
|
|
|
|
surface_reset_target();
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
_outSurf = mask_apply(_data[0], _outSurf, _data[1], _data[2]);
|
2023-02-28 09:43:01 +01:00
|
|
|
colors[_array_index] = cc;
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
return _outSurf;
|
2023-09-14 16:29:39 +02:00
|
|
|
} #endregion
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|