Pixel-Composer/scripts/node_interpret_number/node_interpret_number.gml

78 lines
2.3 KiB
Text
Raw Normal View History

function Node_Interpret_Number(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Interpret Number";
dimension_index = -1;
2024-08-08 06:57:51 +02:00
inputs[0] = nodeValue_Float("Number", self, [] )
.setVisible(true, true)
.setArrayDepth(1);
2024-08-08 06:57:51 +02:00
inputs[1] = nodeValue_Enum_Button("Mode", self, 0, [ "Greyscale", "Gradient" ]);
2024-08-08 06:57:51 +02:00
inputs[2] = nodeValue_Range("Range", self, [ 0, 1 ] );
2024-08-08 06:57:51 +02:00
inputs[3] = nodeValue_Gradient("Gradient", self, new gradientObject(cola(c_white)))
2024-01-22 10:26:25 +01:00
.setMappable(4);
//////////////////////////////////////////////////////////////////////////////////////////////////
2024-08-08 06:57:51 +02:00
inputs[4] = nodeValueMap("Gradient map", self);
2024-01-22 10:26:25 +01:00
2024-08-08 06:57:51 +02:00
inputs[5] = nodeValueGradientRange("Gradient map range", self, inputs[3]);
2024-01-22 10:26:25 +01:00
//////////////////////////////////////////////////////////////////////////////////////////////////
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
input_display_list = [ 0,
2024-01-22 10:26:25 +01:00
["Interpret", false], 1, 2, 3, 4,
];
attribute_surface_depth();
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
2024-07-02 12:18:32 +02:00
var _hov = false;
2024-08-08 06:57:51 +02:00
var hv = inputs[5].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny, getDimension()); active &= !hv; _hov |= hv;
2024-07-02 12:18:32 +02:00
return _hov;
2024-01-22 10:26:25 +01:00
}
static step = function() {
var _mode = getInputData(1);
2024-08-08 06:57:51 +02:00
inputs[3].setVisible(_mode == 1);
inputs[3].mappableStep();
}
static processData = function(_outSurf, _data, _output_index, _array_index) {
2023-12-13 11:09:06 +01:00
static BATCH_SIZE = 128;
2023-11-24 10:41:53 +01:00
var _val = _data[0];
var _mod = _data[1];
var _ran = _data[2];
2023-11-24 10:41:53 +01:00
if(is_array(_val) && array_empty(_val)) return _outSurf;
if(!is_array(_val)) _val = [ _val ];
var _num = array_spread(_val);
var _amo = array_length(_num);
_outSurf = surface_verify(_outSurf, _amo, 1, attrDepth());
2023-11-24 10:41:53 +01:00
if(_amo == 0) return _outSurf;
surface_set_shader(_outSurf, sh_interpret_number);
shader_set_i("mode", _mod);
shader_set_f("range", _ran);
2024-01-22 10:26:25 +01:00
2024-08-08 06:57:51 +02:00
shader_set_gradient(_data[3], _data[4], _data[5], inputs[3]);
for(var i = 0; i < _amo; i += BATCH_SIZE) {
var _arr = [];
array_copy(_arr, 0, _num, i, BATCH_SIZE);
shader_set_f("number", _arr);
draw_sprite_stretched(s_fx_pixel, 0, i, 0, BATCH_SIZE, 1);
}
surface_reset_shader();
return _outSurf;
}
}