Pixel-Composer/scripts/node_posterize/node_posterize.gml

79 lines
2.6 KiB
Text
Raw Normal View History

2023-02-28 15:43:01 +07:00
function Node_Posterize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-01-13 11:24:03 +07:00
name = "Posterize";
2024-03-14 20:35:19 +07:00
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
2023-01-25 12:49:00 +07:00
2024-04-20 10:00:28 +07:00
inputs[| 1] = nodeValue("Palette", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, array_clone(DEF_PALETTE))
2022-01-13 11:24:03 +07:00
.setDisplay(VALUE_DISPLAY.palette);
2023-02-14 11:32:32 +07:00
inputs[| 2] = nodeValue("Use palette", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
2022-01-13 11:24:03 +07:00
2023-02-14 11:32:32 +07:00
inputs[| 3] = nodeValue("Colors", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4)
2024-03-24 10:58:08 +07:00
.setDisplay(VALUE_DISPLAY.slider, { range: [2, 16, 0.1] });
2022-01-13 11:24:03 +07:00
2023-02-14 11:32:32 +07:00
inputs[| 4] = nodeValue("Gamma", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.6)
2023-12-23 15:39:55 +07:00
.setDisplay(VALUE_DISPLAY.slider)
.setMappable(7);
2022-01-13 11:24:03 +07:00
2023-02-14 11:32:32 +07:00
inputs[| 5] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
active_index = 5;
2023-08-01 19:21:51 +02:00
inputs[| 6] = nodeValue("Posterize alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
2023-02-14 11:32:32 +07:00
2023-12-23 15:39:55 +07:00
//////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 7] = nodeValueMap("Gamma map", self);
//////////////////////////////////////////////////////////////////////////////////////////////////
2024-05-03 18:40:46 +07:00
inputs[| 8] = nodeValue("Space", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ "RGB", "LAB" ]);
2024-01-09 09:39:40 +07:00
input_display_list = [ 5, 0,
2024-05-03 18:40:46 +07:00
["Palette", false, 2], 1, 3, 4, 7, 8,
2024-01-09 09:39:40 +07:00
["Alpha", false, 6],
2022-01-13 11:24:03 +07:00
];
2023-02-14 11:32:32 +07:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2022-01-13 11:24:03 +07:00
2023-03-19 15:17:39 +07:00
attribute_surface_depth();
2022-01-18 11:31:19 +07:00
static step = function() {
var _use_pal = getInputData(2);
2022-01-13 11:24:03 +07:00
2022-01-19 12:11:17 +07:00
inputs[| 1].setVisible(_use_pal);
inputs[| 3].setVisible(!_use_pal);
inputs[| 4].setVisible(!_use_pal);
2023-12-23 15:39:55 +07:00
inputs[| 4].mappableStep();
2024-05-03 18:40:46 +07:00
inputs[| 8].setVisible(_use_pal);
2022-01-13 11:24:03 +07:00
}
2023-08-17 16:56:54 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2024-05-03 18:40:46 +07:00
var _pal = _data[1];
var _use_pal = _data[2];
2023-08-01 19:21:51 +02:00
var _alp = _data[6];
2024-05-03 18:40:46 +07:00
var _spce = _data[8];
2022-01-13 11:24:03 +07:00
2024-05-03 18:40:46 +07:00
if(_use_pal) {
2023-08-01 19:21:51 +02:00
surface_set_shader(_outSurf, sh_posterize_palette);
2024-05-03 18:40:46 +07:00
shader_set_f("palette", paletteToArray(_pal));
shader_set_i("keys", array_length(_pal));
2023-08-01 19:21:51 +02:00
shader_set_i("alpha", _alp);
2024-05-03 18:40:46 +07:00
shader_set_i("space", _spce);
2023-02-14 11:32:32 +07:00
draw_surface_safe(_data[0]);
2023-08-01 19:21:51 +02:00
surface_reset_shader();
2022-01-13 11:24:03 +07:00
} else {
2023-08-01 19:21:51 +02:00
surface_set_shader(_outSurf, sh_posterize);
2023-12-23 15:39:55 +07:00
shader_set_i("colors", _data[3]);
shader_set_f_map("gamma", _data[4], _data[7], inputs[| 4]);
shader_set_i("alpha", _alp);
2022-01-13 11:24:03 +07:00
draw_surface_safe(_data[0]);
2023-08-01 19:21:51 +02:00
surface_reset_shader();
2022-01-13 11:24:03 +07:00
}
return _outSurf;
}
}