2023-02-28 09:43:01 +01:00
function Node_Blur(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Blur";
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Surface("Surface in", self));
2024-10-21 05:35:29 +02:00
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_Int("Size", self, 3))
2024-10-21 05:35:29 +02:00
.setValidator(VV_min(0))
.setUnitRef(function(index) /*=>*/ {return getDimension(index)});
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Enum_Scroll("Oversample mode", self, 0, [ "Empty", "Clamp", "Repeat" ]))
2024-08-07 11:48:39 +02:00
.setTooltip("How to deal with pixel outside the surface.\n - Empty: Use empty pixel\n - Clamp: Repeat edge pixel\n - Repeat: Repeat texture.");
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(3, nodeValue_Bool("Override color", self, false, "Replace all color while keeping the alpha. Used to\nfix grey outline when bluring transparent pixel."));
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(4, nodeValue_Color("Color", self, c_black));
2022-12-27 04:00:50 +01:00
2024-08-18 06:16:20 +02:00
newInput(5, nodeValue_Surface("Mask", self));
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(6, nodeValue_Float("Mix", self, 1))
2023-10-02 08:57:44 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 05:32:32 +01:00
2024-08-18 06:16:20 +02:00
newInput(7, nodeValue_Bool("Active", self, true));
2023-02-14 05:32:32 +01:00
active_index = 7;
2024-08-18 06:16:20 +02:00
newInput(8, nodeValue_Toggle("Channel", self, 0b1111, { data: array_create(4, THEME.inspector_channel) }));
2023-11-09 04:02:41 +01:00
2023-11-24 10:41:53 +01:00
__init_mask_modifier(5); // inputs 9, 10
2024-08-18 06:16:20 +02:00
newInput(11, nodeValue_Bool("Gamma Correction", self, false));
2024-06-13 09:21:07 +02:00
2024-08-18 09:13:41 +02:00
newInput(12, nodeValue_Float("Aspect Ratio", self, 1))
2024-06-22 12:09:44 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-18 06:16:20 +02:00
newInput(13, nodeValue_Rotation("Direction", self, 0));
2024-06-22 12:09:44 +02:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
2023-02-14 05:32:32 +01:00
2023-11-09 04:02:41 +01:00
input_display_list = [ 7, 8,
2024-06-22 12:09:44 +02:00
["Surfaces", true], 0, 5, 6, 9, 10,
["Blur", false], 1, 3, 4, 11,
["Directional", true], 12, 13,
2023-01-17 08:11:55 +01:00
];
2024-06-22 12:09:44 +02:00
temp_surface = [ 0, 0 ];
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-03-21 03:01:53 +01:00
attribute_oversample();
2023-02-14 05:32:32 +01:00
surface_blur_init();
2024-10-21 05:35:29 +02:00
static step = function() {
2023-11-24 10:41:53 +01:00
__step_mask_modifier();
2024-10-21 05:35:29 +02:00
}
2023-11-24 10:41:53 +01:00
2024-10-21 05:35:29 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2024-06-22 12:09:44 +02:00
var _surf = _data[0];
var _size = min(128, _data[1]);
2024-11-07 07:59:04 +01:00
var _clamp = getAttribute("oversample");
2023-01-17 08:11:55 +01:00
var _isovr = _data[3];
2023-02-14 05:32:32 +01:00
var _mask = _data[5];
var _mix = _data[6];
2023-01-17 08:11:55 +01:00
var _overc = _isovr? _data[4] : noone;
2024-06-13 09:21:07 +02:00
var _gam = _data[11];
2024-06-22 12:09:44 +02:00
var _aspc = _data[12];
var _dirr = _data[13];
2023-01-17 08:11:55 +01:00
2024-08-08 06:57:51 +02:00
inputs[4].setVisible(_isovr);
2022-01-13 05:24:03 +01:00
2024-07-06 10:37:29 +02:00
if(!is_surface(_surf)) return _outSurf;
2024-06-22 12:09:44 +02:00
var format = surface_get_format(_surf);
var _sw = surface_get_width_safe(_surf);
var _sh = surface_get_height_safe(_surf);
for(var i = 0; i < 2; i++)
temp_surface[i] = surface_verify(temp_surface[i], _sw, _sh, format);
BLEND_OVERRIDE
gpu_set_tex_filter(true);
surface_set_target(temp_surface[0]);
draw_clear_alpha(c_white, false);
shader_set(sh_blur_gaussian);
shader_set_f("dimension", [ _sw, _sh ]);
shader_set_f("weight", __gaussian_get_kernel(_size));
shader_set_i("sampleMode", _clamp);
shader_set_i("size", _size);
shader_set_i("horizontal", 1);
shader_set_i("gamma", _gam);
shader_set_i("overrideColor", _overc != noone);
shader_set_f("overColor", colToVec4(_overc));
shader_set_f("angle", degtorad(_dirr));
2024-07-10 03:45:25 +02:00
draw_surface_safe(_surf);
2024-06-22 12:09:44 +02:00
shader_reset();
surface_reset_target();
surface_set_target(temp_surface[1]);
draw_clear_alpha(c_white, false);
var _size_v = round(_size * _aspc);
shader_set(sh_blur_gaussian);
shader_set_f("weight", __gaussian_get_kernel(_size_v));
shader_set_i("size", _size_v);
shader_set_i("horizontal", 0);
2024-07-10 03:45:25 +02:00
draw_surface_safe(temp_surface[0]);
2024-06-22 12:09:44 +02:00
shader_reset();
surface_reset_target();
gpu_set_tex_filter(false);
2022-01-13 05:24:03 +01:00
surface_set_target(_outSurf);
2023-08-12 12:35:35 +02:00
draw_clear_alpha(_isovr? _overc : 0, 0);
2024-07-10 03:45:25 +02:00
draw_surface_safe(temp_surface[1]);
2022-01-13 05:24:03 +01:00
surface_reset_target();
2024-06-22 12:09:44 +02:00
BLEND_NORMAL;
2022-01-13 05:24:03 +01:00
2023-11-24 10:41:53 +01:00
__process_mask_modifier(_data);
2023-02-14 05:32:32 +01:00
_outSurf = mask_apply(_data[0], _outSurf, _mask, _mix);
2023-11-09 04:02:41 +01:00
_outSurf = channel_apply(_data[0], _outSurf, _data[8]);
2023-02-14 05:32:32 +01:00
2022-01-13 05:24:03 +01:00
return _outSurf;
2024-10-21 05:35:29 +02:00
}
2022-01-13 05:24:03 +01:00
}