2023-02-28 09:43:01 +01:00
|
|
|
function Node_Posterize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Posterize";
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
inputs[| 1] = nodeValue("Palette", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE )
|
2022-01-13 05:24:03 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.palette);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 2] = nodeValue("Use palette", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 3] = nodeValue("Colors", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4)
|
2022-01-13 05:24:03 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, [2, 16, 1]);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 4] = nodeValue("Gamma", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.6)
|
2022-01-13 05:24:03 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
|
|
|
|
2023-02-14 05:32:32 +01: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 05:32:32 +01:00
|
|
|
|
|
|
|
input_display_list = [ 5,
|
2023-08-01 19:21:51 +02:00
|
|
|
["Effect settings", false], 0, 2, 1, 6,
|
2022-01-13 05:24:03 +01:00
|
|
|
["Auto color", false], 3, 4
|
|
|
|
];
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2022-01-18 05:31:19 +01:00
|
|
|
static step = function() {
|
2022-01-13 05:24:03 +01:00
|
|
|
var _use_pal = inputs[| 2].getValue();
|
|
|
|
|
2022-01-19 06:11:17 +01:00
|
|
|
inputs[| 1].setVisible(_use_pal);
|
|
|
|
inputs[| 3].setVisible(!_use_pal);
|
|
|
|
inputs[| 4].setVisible(!_use_pal);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var _gra = _data[1];
|
|
|
|
var _use_gra = _data[2];
|
2023-08-01 19:21:51 +02:00
|
|
|
var _alp = _data[6];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(_use_gra) {
|
|
|
|
var _colors = array_create(array_length(_gra) * 4);
|
|
|
|
for(var i = 0; i < array_length(_gra); i++) {
|
|
|
|
_colors[i * 4 + 0] = color_get_red(_gra[i]) / 255;
|
|
|
|
_colors[i * 4 + 1] = color_get_green(_gra[i]) / 255;
|
|
|
|
_colors[i * 4 + 2] = color_get_blue(_gra[i]) / 255;
|
|
|
|
_colors[i * 4 + 3] = 1;
|
|
|
|
}
|
|
|
|
|
2023-08-01 19:21:51 +02:00
|
|
|
surface_set_shader(_outSurf, sh_posterize_palette);
|
|
|
|
shader_set_f("palette", _colors);
|
|
|
|
shader_set_i("keys", array_length(_gra));
|
|
|
|
shader_set_i("alpha", _alp);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_surface_safe(_data[0], 0, 0);
|
2023-08-01 19:21:51 +02:00
|
|
|
surface_reset_shader();
|
2022-01-13 05:24:03 +01:00
|
|
|
} else {
|
|
|
|
var _colors = _data[3];
|
|
|
|
var _gamma = _data[4];
|
|
|
|
|
2023-08-01 19:21:51 +02:00
|
|
|
surface_set_shader(_outSurf, sh_posterize);
|
|
|
|
shader_set_i("colors", _colors);
|
|
|
|
shader_set_f("gamma", _gamma);
|
|
|
|
shader_set_i("alpha", _alp);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
draw_surface_safe(_data[0], 0, 0);
|
2023-08-01 19:21:51 +02:00
|
|
|
surface_reset_shader();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return _outSurf;
|
|
|
|
}
|
|
|
|
}
|