2023-02-28 09:43:01 +01:00
|
|
|
function Node_Dither(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2024-01-09 03:39:40 +01:00
|
|
|
static dither2 = [ 0, 2,
|
|
|
|
3, 1 ];
|
|
|
|
static dither4 = [ 0, 8, 2, 10,
|
|
|
|
12, 4, 14, 6,
|
|
|
|
3, 11, 1, 9,
|
|
|
|
15, 7, 13, 5];
|
|
|
|
static dither8 = [ 0, 32, 8, 40, 2, 34, 10, 42,
|
|
|
|
48, 16, 56, 24, 50, 18, 58, 26,
|
|
|
|
12, 44, 4, 36, 14, 46, 6, 38,
|
|
|
|
60, 28, 52, 20, 62, 30, 54, 22,
|
|
|
|
3, 35, 11, 43, 1, 33, 9, 41,
|
|
|
|
51, 19, 59, 27, 49, 17, 57, 25,
|
|
|
|
15, 47, 7, 39, 13, 45, 5, 37,
|
|
|
|
63, 31, 55, 23, 61, 29, 53, 21];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
name = "Dither";
|
|
|
|
|
2024-08-07 11:48:39 +02:00
|
|
|
inputs[| 0] = nodeValue_Surface("Surface in", self);
|
2024-01-09 03:39:40 +01:00
|
|
|
|
2024-08-07 13:20:45 +02:00
|
|
|
inputs[| 1] = nodeValue_Palette("Palette", self, array_clone(DEF_PALETTE));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-07 11:48:39 +02:00
|
|
|
inputs[| 2] = nodeValue_Enum_Scroll("Pattern", self, 0, [ "2 x 2 Bayer", "4 x 4 Bayer", "8 x 8 Bayer", "White Noise", "Custom" ]);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-07 11:48:39 +02:00
|
|
|
inputs[| 3] = nodeValue_Surface("Dither map", self)
|
2023-01-01 02:06:02 +01:00
|
|
|
.setVisible(false);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-07 13:20:45 +02:00
|
|
|
inputs[| 4] = nodeValue_Float("Contrast", self, 1)
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [1, 5, 0.1] });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-07 11:48:39 +02:00
|
|
|
inputs[| 5] = nodeValue_Surface("Contrast map", self);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-07 11:48:39 +02:00
|
|
|
inputs[| 6] = nodeValue_Enum_Button("Mode", self, 0, [ "Color", "Alpha" ]);
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2024-08-07 11:48:39 +02:00
|
|
|
inputs[| 7] = nodeValue_Surface("Mask", self);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-07 13:20:45 +02:00
|
|
|
inputs[| 8] = 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-07 13:20:45 +02:00
|
|
|
inputs[| 9] = nodeValue_Bool("Active", self, true);
|
2023-02-14 05:32:32 +01:00
|
|
|
active_index = 9;
|
|
|
|
|
2024-08-07 13:20:45 +02:00
|
|
|
inputs[| 10] = 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(7); // inputs 11, 12,
|
|
|
|
|
2024-08-07 13:20:45 +02:00
|
|
|
inputs[| 13] = nodeValue_Int("Seed", self, seed_random(6))
|
2024-06-08 06:31:21 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY._default, { side_button : button(function() { randomize(); inputs[| 13].setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) });
|
2024-05-18 13:46:01 +02:00
|
|
|
|
2024-08-07 13:20:45 +02:00
|
|
|
inputs[| 14] = nodeValue_Bool("Use palette", self, true);
|
2024-05-19 07:55:09 +02:00
|
|
|
|
2024-08-07 13:20:45 +02:00
|
|
|
inputs[| 15] = nodeValue_Int("Steps", self, 4)
|
2024-05-19 07:55:09 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [2, 16, 0.1] });
|
|
|
|
|
2024-08-07 13:20:45 +02:00
|
|
|
outputs[| 0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2024-05-18 13:46:01 +02:00
|
|
|
input_display_list = [ 9, 10, 13,
|
2023-11-24 10:41:53 +01:00
|
|
|
["Surfaces", true], 0, 7, 8, 11, 12,
|
2023-01-01 02:06:02 +01:00
|
|
|
["Pattern", false], 2, 3,
|
2024-05-19 07:55:09 +02:00
|
|
|
["Dither", false], 6, 4, 5,
|
|
|
|
["Palette", false, 14], 1, 15,
|
2023-01-01 02:06:02 +01:00
|
|
|
]
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2023-11-24 10:41:53 +01:00
|
|
|
static step = function() { #region
|
|
|
|
__step_mask_modifier();
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-05-19 07:55:09 +02:00
|
|
|
var _type = getInputData(2);
|
|
|
|
var _mode = getInputData(6);
|
|
|
|
var _use_pal = getInputData(14);
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-05-18 13:46:01 +02:00
|
|
|
inputs[| 3].setVisible(_type == 4, _type == 4);
|
2024-05-19 07:55:09 +02:00
|
|
|
inputs[| 1].setVisible(_mode == 0 && _use_pal);
|
2024-01-29 14:33:55 +01:00
|
|
|
inputs[| 4].setVisible(_mode == 0);
|
|
|
|
inputs[| 5].setVisible(_mode == 0);
|
2024-05-19 07:55:09 +02:00
|
|
|
|
|
|
|
inputs[| 15].setVisible(!_use_pal);
|
2023-11-24 10:41:53 +01:00
|
|
|
} #endregion
|
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2024-01-09 03:39:40 +01:00
|
|
|
var _pal = _data[1];
|
|
|
|
var _typ = _data[2];
|
|
|
|
var _map = _data[3];
|
|
|
|
var _con = _data[4];
|
2022-01-13 05:24:03 +01:00
|
|
|
var _conMap = _data[5];
|
2024-01-09 03:39:40 +01:00
|
|
|
var _mode = _data[6];
|
2024-05-18 13:46:01 +02:00
|
|
|
var _seed = _data[13];
|
2024-05-19 07:55:09 +02:00
|
|
|
var _usepal = _data[14];
|
|
|
|
var _step = _data[15];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
surface_set_shader(_outSurf, _mode? sh_alpha_hash : sh_dither);
|
|
|
|
shader_set_f("dimension", surface_get_dimension(_data[0]));
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
switch(_typ) {
|
|
|
|
case 0 :
|
2024-01-29 14:33:55 +01:00
|
|
|
shader_set_i("useMap", 0);
|
|
|
|
shader_set_f("ditherSize", 2);
|
|
|
|
shader_set_f("dither", dither2);
|
2022-01-13 05:24:03 +01:00
|
|
|
break;
|
2024-05-18 13:46:01 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
case 1 :
|
2024-01-29 14:33:55 +01:00
|
|
|
shader_set_i("useMap", 0);
|
|
|
|
shader_set_f("ditherSize", 4);
|
|
|
|
shader_set_f("dither", dither4);
|
2022-01-13 05:24:03 +01:00
|
|
|
break;
|
2024-05-18 13:46:01 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
case 2 :
|
2024-01-29 14:33:55 +01:00
|
|
|
shader_set_i("useMap", 0);
|
|
|
|
shader_set_f("ditherSize", 8);
|
|
|
|
shader_set_f("dither", dither8);
|
2022-01-13 05:24:03 +01:00
|
|
|
break;
|
2024-05-18 13:46:01 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
case 3 :
|
2024-05-18 13:46:01 +02:00
|
|
|
shader_set_i("useMap", 2);
|
|
|
|
shader_set_f("seed", _seed);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4 :
|
2022-01-13 05:24:03 +01:00
|
|
|
if(is_surface(_map)) {
|
2024-01-29 14:33:55 +01:00
|
|
|
shader_set_i("useMap", 1);
|
|
|
|
shader_set_f("mapDimension", surface_get_dimension(_map));
|
|
|
|
shader_set_surface("map", _map);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-03-14 14:35:19 +01:00
|
|
|
|
2023-01-01 02:06:02 +01:00
|
|
|
if(_mode == 0) {
|
2024-01-29 14:33:55 +01:00
|
|
|
shader_set_f("contrast", _con);
|
2024-03-14 14:35:19 +01:00
|
|
|
shader_set_i("useConMap", is_surface(_conMap));
|
|
|
|
shader_set_surface("conMap", _conMap);
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-05-19 07:55:09 +02:00
|
|
|
shader_set_i("usePalette", _usepal);
|
2024-01-29 14:33:55 +01:00
|
|
|
shader_set_f("palette", paletteToArray(_pal));
|
2024-05-19 07:55:09 +02:00
|
|
|
shader_set_f("colors", _step);
|
2024-01-29 14:33:55 +01:00
|
|
|
shader_set_i("keys", array_length(_pal));
|
2023-01-01 02:06:02 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-09 03:39:40 +01:00
|
|
|
draw_surface_safe(_data[0]);
|
|
|
|
surface_reset_shader();
|
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, _data[7], _data[8]);
|
2023-11-09 04:02:41 +01:00
|
|
|
_outSurf = channel_apply(_data[0], _outSurf, _data[10]);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2022-12-27 04:00:50 +01:00
|
|
|
return _outSurf;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|