Pixel-Composer/scripts/node_gradient_points/node_gradient_points.gml

114 lines
3.9 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Gradient_Points(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2024-06-20 08:55:04 +02:00
name = "Draw 4 Points Gradient";
2022-12-13 14:11:39 +01:00
2024-08-08 06:57:51 +02:00
inputs[0] = nodeValue_Dimension(self);
2022-12-13 14:11:39 +01:00
2024-08-12 13:42:05 +02:00
inputs[1] = nodeValue_Vec2("Center 1", self, [ 0, 0 ] )
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); });
2024-08-08 06:57:51 +02:00
inputs[2] = nodeValue_Color("Color 1", self, c_white );
2022-12-13 14:11:39 +01:00
2024-08-12 13:42:05 +02:00
inputs[3] = nodeValue_Vec2("Center 2", self, [ DEF_SURF_W, 0 ] )
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); });
2024-08-08 06:57:51 +02:00
inputs[4] = nodeValue_Color("Color 2", self, c_white );
2022-12-13 14:11:39 +01:00
2024-08-12 13:42:05 +02:00
inputs[5] = nodeValue_Vec2("Center 3", self, [ 0, DEF_SURF_H ] )
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); });
2024-08-08 06:57:51 +02:00
inputs[6] = nodeValue_Color("Color 3", self, c_white );
2022-12-13 14:11:39 +01:00
2024-08-12 13:42:05 +02:00
inputs[7] = nodeValue_Vec2("Center 4", self, DEF_SURF , { useGlobal : false })
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); });
2024-08-08 06:57:51 +02:00
inputs[8] = nodeValue_Color("Color 4", self, c_white );
2022-12-13 14:11:39 +01:00
2024-08-08 06:57:51 +02:00
inputs[9] = nodeValue_Bool("Use palette", self, false );
2023-02-14 05:32:32 +01:00
2024-08-08 06:57:51 +02:00
inputs[10] = nodeValue_Palette("Palette", self, array_clone(DEF_PALETTE));
2023-02-14 05:32:32 +01:00
2024-08-08 06:57:51 +02:00
inputs[11] = nodeValue_Float("Falloff 1", self, 6 )
2024-03-24 04:58:08 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 32, 0.1 ] });
2024-08-08 06:57:51 +02:00
inputs[12] = nodeValue_Float("Falloff 2", self, 6 )
2024-03-24 04:58:08 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 32, 0.1 ] });
2024-08-08 06:57:51 +02:00
inputs[13] = nodeValue_Float("Falloff 3", self, 6 )
2024-03-24 04:58:08 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 32, 0.1 ] });
2024-08-08 06:57:51 +02:00
inputs[14] = nodeValue_Float("Falloff 4", self, 6 )
2024-03-24 04:58:08 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 32, 0.1 ] });
2024-08-08 06:57:51 +02:00
inputs[15] = nodeValue_Bool("Normalize weight", self, false )
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
2022-12-13 14:11:39 +01:00
input_display_list = [
2023-02-14 05:32:32 +01:00
["Output", true], 0,
2022-12-13 14:11:39 +01:00
["Positions", false], 1, 3, 5, 7,
["Falloff", true], 11, 12, 13, 14, 15,
2023-02-14 05:32:32 +01:00
["Colors", false], 9, 10, 2, 4, 6, 8,
2022-12-13 14:11:39 +01:00
];
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2024-07-02 12:18:32 +02:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _hov = false;
2024-08-08 06:57:51 +02:00
var hv = inputs[1].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) active &= !hv; _hov |= hv;
var hv = inputs[3].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) active &= !hv; _hov |= hv;
var hv = inputs[5].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) active &= !hv; _hov |= hv;
var hv = inputs[7].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) active &= !hv; _hov |= hv;
2024-07-02 12:18:32 +02:00
return _hov;
}
static step = function() {
var _usePal = getInputData(9);
2023-02-14 05:32:32 +01:00
2024-08-08 06:57:51 +02:00
inputs[10].setVisible(_usePal, _usePal);
2023-02-14 05:32:32 +01:00
2024-08-08 06:57:51 +02:00
inputs[ 2].setVisible(!_usePal, !_usePal);
inputs[ 4].setVisible(!_usePal, !_usePal);
inputs[ 6].setVisible(!_usePal, !_usePal);
inputs[ 8].setVisible(!_usePal, !_usePal);
2024-07-02 12:18:32 +02:00
}
2023-02-14 05:32:32 +01:00
2024-07-02 12:18:32 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2022-12-22 03:09:55 +01:00
var _dim = _data[0];
2022-12-13 14:11:39 +01:00
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
2023-02-14 05:32:32 +01:00
var _usePal = _data[9];
var _pal = _data[10];
var _1cen = _data[1], _1col = _data[2];
var _2cen = _data[3], _2col = _data[4];
var _3cen = _data[5], _3col = _data[6];
var _4cen = _data[7], _4col = _data[8];
2022-12-13 14:11:39 +01:00
var _1str = _data[11];
var _2str = _data[12];
var _3str = _data[13];
var _4str = _data[14];
var _blnd = _data[15];
2023-02-14 05:32:32 +01:00
var colArr = [];
if(_usePal) {
for( var i = 0; i < 4; i++ )
2024-06-14 12:46:25 +02:00
colArr = array_append(colArr, colorToArray(array_safe_get_fast(_pal, i, c_black)));
2023-02-14 05:32:32 +01:00
} else
2024-06-14 12:46:25 +02:00
colArr = array_merge(colorToArray(_1col), colorToArray(_2col), colorToArray(_3col), colorToArray(_4col))
2023-02-14 05:32:32 +01:00
surface_set_shader(_outSurf, sh_gradient_points);
shader_set_f("dimension", _dim);
shader_set_f("center", array_merge(_1cen, _2cen, _3cen, _4cen));
shader_set_f("color", colArr);
shader_set_f("strength", _1str, _2str, _3str, _4str);
shader_set_i("blend", _blnd);
2022-12-13 14:11:39 +01:00
draw_sprite_stretched_ext(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1], c_white, 1);
surface_reset_shader();
2022-12-22 03:09:55 +01:00
return _outSurf;
2024-07-02 12:18:32 +02:00
}
2022-12-13 14:11:39 +01:00
}