Pixel-Composer/scripts/node_combine_rgb/node_combine_rgb.gml

86 lines
2.7 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Combine_RGB(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-12-27 04:00:50 +01:00
name = "RGB Combine";
2023-11-28 09:42:22 +01:00
dimension_index = -1;
2022-12-27 04:00:50 +01:00
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Surface("Red", self));
newInput(1, nodeValue_Surface("Green", self));
newInput(2, nodeValue_Surface("Blue", self));
newInput(3, nodeValue_Surface("Alpha", self));
2023-01-01 02:06:02 +01:00
2024-08-18 06:16:20 +02:00
newInput(4, nodeValue_Enum_Scroll("Sampling type", self, 0, ["Channel value", "Greyscale"]));
2022-12-27 04:00:50 +01:00
2024-08-18 09:13:41 +02:00
newInput(5, nodeValue_Float("Base value", self, 0, "Set value to the unconnected color channels."))
2023-12-23 09:39:55 +01:00
.setDisplay(VALUE_DISPLAY.slider)
.setMappable(6);
//////////////////////////////////////////////////////////////////////////////////////////////////
2024-08-18 06:16:20 +02:00
newInput(6, nodeValueMap("Base value", self));
2023-12-23 09:39:55 +01:00
//////////////////////////////////////////////////////////////////////////////////////////////////
2023-11-27 11:40:28 +01:00
2024-08-18 06:16:20 +02:00
newInput(7, nodeValue_Bool("Array Input", self, false));
2024-03-17 14:24:24 +01:00
2024-08-18 09:13:41 +02:00
newInput(8, nodeValue_Surface("RGBA Array", self, []))
2024-03-17 14:24:24 +01:00
.setArrayDepth(1);
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
2022-12-27 04:00:50 +01:00
2023-01-01 02:06:02 +01:00
input_display_list = [
2023-12-23 09:39:55 +01:00
["Sampling", false], 4, 5, 6,
2024-03-17 14:24:24 +01:00
["Surfaces", true], 7, 0, 1, 2, 3, 8,
2023-01-01 02:06:02 +01:00
]
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-12-23 09:39:55 +01:00
static step = function() { #region
2024-08-08 06:57:51 +02:00
inputs[5].mappableStep();
2024-03-17 14:24:24 +01:00
var _arr = getInputData(7);
2024-08-08 06:57:51 +02:00
inputs[0].setVisible(!_arr, !_arr);
inputs[1].setVisible(!_arr, !_arr);
inputs[2].setVisible(!_arr, !_arr);
inputs[3].setVisible(!_arr, !_arr);
2024-03-17 14:24:24 +01:00
2024-08-08 06:57:51 +02:00
inputs[8].setVisible(_arr, _arr);
2023-12-23 09:39:55 +01:00
} #endregion
2023-09-14 16:29:39 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
2024-03-17 14:24:24 +01:00
var _arr = _data[7];
2024-03-31 05:36:11 +02:00
var _r = _arr? array_safe_get_fast(_data[8], 0) : _data[0];
var _g = _arr? array_safe_get_fast(_data[8], 1) : _data[1];
var _b = _arr? array_safe_get_fast(_data[8], 2) : _data[2];
var _a = _arr? array_safe_get_fast(_data[8], 3) : _data[3];
2022-12-27 04:00:50 +01:00
2024-03-19 09:49:29 +01:00
var _baseS = is_surface(_r)? _r : (is_surface(_g)? _g : _b);
2023-11-28 09:42:22 +01:00
if(!is_surface(_baseS)) return _outSurf;
2024-03-19 09:49:29 +01:00
var _ww = surface_get_width_safe(_baseS);
var _hh = surface_get_height_safe(_baseS);
_outSurf = surface_verify(_outSurf, _ww, _hh);
2023-11-28 09:42:22 +01:00
surface_set_shader(_outSurf, sh_combine_rgb);
2024-03-17 14:24:24 +01:00
shader_set_surface("samplerR", _r);
shader_set_surface("samplerG", _g);
shader_set_surface("samplerB", _b);
shader_set_surface("samplerA", _a);
2024-03-17 14:24:24 +01:00
2023-11-27 11:40:28 +01:00
shader_set_i("useR", is_surface(_r));
shader_set_i("useG", is_surface(_g));
shader_set_i("useB", is_surface(_b));
shader_set_i("useA", is_surface(_a));
2023-11-27 11:40:28 +01:00
shader_set_i("mode", !_data[4]);
2024-08-08 06:57:51 +02:00
shader_set_f_map("base", _data[5], _data[6], inputs[5]);
2023-01-01 02:06:02 +01:00
2024-03-19 09:49:29 +01:00
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _ww, _hh);
surface_reset_shader();
2022-12-27 04:00:50 +01:00
return _outSurf;
2023-09-14 16:29:39 +02:00
} #endregion
2022-12-27 04:00:50 +01:00
}