Pixel-Composer/scripts/node_blur_path/node_blur_path.gml

117 lines
3.2 KiB
Plaintext
Raw Normal View History

2024-06-22 12:09:44 +02:00
function Node_Blur_Path(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Path Blur";
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Surface("Surface in", self));
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_PathNode("Blur Path", self, noone))
2024-06-22 12:09:44 +02:00
.setVisible(true, true);
2024-08-18 06:16:20 +02:00
newInput(2, nodeValue_Int("Resolution", self, 32));
2024-06-22 12:09:44 +02:00
2024-08-18 06:16:20 +02:00
newInput(3, nodeValue_Surface("Mask", self));
2024-06-22 12:09:44 +02:00
2024-08-18 09:13:41 +02:00
newInput(4, nodeValue_Float("Mix", self, 1))
2024-06-22 12:09:44 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-18 06:16:20 +02:00
newInput(5, nodeValue_Bool("Active", self, true));
2024-06-22 12:09:44 +02:00
active_index = 5;
2024-08-18 06:16:20 +02:00
newInput(6, nodeValue_Toggle("Channel", self, 0b1111, { data: array_create(4, THEME.inspector_channel) }));
2024-06-22 12:09:44 +02:00
__init_mask_modifier(3); // inputs 7, 8
2024-08-18 06:16:20 +02:00
newInput(9, nodeValue_Float("Intensity", self, 1));
2024-06-22 12:09:44 +02:00
newInput(10, nodeValue_Curve("Intensity Along Path", self, CURVE_DEF_11));
2024-06-22 12:09:44 +02:00
2024-08-18 06:16:20 +02:00
newInput(11, nodeValue_Slider_Range("Range", self, [ 0, 1 ]));
2024-06-22 12:09:44 +02:00
2024-08-18 09:13:41 +02:00
newInput(12, nodeValue_Float("Path Origin", self, 0))
2024-07-22 07:10:46 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2024-06-22 12:09:44 +02:00
input_display_list = [ 5, 6,
["Surfaces", true], 0, 3, 4, 7, 8,
2024-07-22 07:10:46 +02:00
["Path", false], 1, 12, 11,
2024-06-22 12:09:44 +02:00
["Blur", false], 2, 9, 10,
];
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
2024-06-22 12:09:44 +02:00
attribute_surface_depth();
attribute_oversample();
static step = function() {
__step_mask_modifier();
}
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _hov = false;
var hv = inputs[1].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv);
return _hov;
}
static getTool = function() {
var _path = getInputData(1);
return is_instanceof(_path, Node)? _path : self;
}
2024-06-22 12:09:44 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
if(!is_surface(_data[0])) return _outSurf;
2024-11-07 07:59:04 +01:00
var _samp = getAttribute("oversample");
2024-06-22 12:09:44 +02:00
var _surf = _data[0];
var _path = _data[1];
var _reso = _data[2];
var _intn = _data[9];
var _curv = _data[10];
var _rang = _data[11];
2024-07-22 07:10:46 +02:00
var _orig = _data[12];
2024-06-22 12:09:44 +02:00
var _pntc = clamp(_reso, 2, 128);
if(!is_struct(_path)) return _outSurf;
var _dim = surface_get_dimension(_surf)
var _points_x = array_create(_pntc);
var _points_y = array_create(_pntc);
var _p = new __vec2();
var _rst = _rang[0];
var _red = _rang[1];
var _rrr = _red - _rst;
var ox = 0, oy = 0;
2024-07-22 07:10:46 +02:00
_p = _path.getPointRatio(_orig, 0, _p);
2024-06-22 12:09:44 +02:00
ox = _p.x;
oy = _p.y;
for(var i = 0; i < _pntc; i++) {
var _pg = clamp(_rst + _rrr * i / (_pntc - 1), 0., 0.99);
_p = _path.getPointRatio(_pg, 0, _p);
_points_x[i] = (_p.x - ox) / _dim[0];
_points_y[i] = (_p.y - oy) / _dim[1];
}
surface_set_shader(_outSurf, sh_blur_path);
shader_set_f("dimension", _dim);
shader_set_i("sampleMode", _samp);
shader_set_i("resolution", _pntc);
shader_set_i("pointAmount", _pntc);
shader_set_f("points_x", _points_x);
shader_set_f("points_y", _points_y);
shader_set_f("intensity", _intn);
shader_set_f("i_curve", _curv);
shader_set_i("i_amount", array_length(_curv));
draw_surface_safe(_surf);
surface_reset_shader();
__process_mask_modifier(_data);
_outSurf = mask_apply(_surf, _outSurf, _data[3], _data[4]);
_outSurf = channel_apply(_surf, _outSurf, _data[6]);
return _outSurf;
}
}