2023-09-27 14:55:21 +02:00
|
|
|
function Node_Interpret_Number(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
|
|
|
name = "Interpret Number";
|
|
|
|
dimension_index = -1;
|
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(0, nodeValue_Float("Number", self, [] ))
|
2023-09-27 14:55:21 +02:00
|
|
|
.setVisible(true, true)
|
|
|
|
.setArrayDepth(1);
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(1, nodeValue_Enum_Button("Mode", self, 0, [ "Greyscale", "Gradient" ]));
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(2, nodeValue_Range("Range", self, [ 0, 1 ] ));
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(3, nodeValue_Gradient("Gradient", self, new gradientObject(cola(c_white))))
|
2024-01-22 10:26:25 +01:00
|
|
|
.setMappable(4);
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(4, nodeValueMap("Gradient map", self));
|
2024-01-22 10:26:25 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(5, nodeValueGradientRange("Gradient map range", self, inputs[3]));
|
2024-01-22 10:26:25 +01:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2024-09-04 03:57:11 +02:00
|
|
|
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
|
2023-09-27 14:55:21 +02:00
|
|
|
|
|
|
|
input_display_list = [ 0,
|
2024-01-22 10:26:25 +01:00
|
|
|
["Interpret", false], 1, 2, 3, 4,
|
2023-09-27 14:55:21 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
static step = function() {
|
|
|
|
var _mode = getInputData(1);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[3].setVisible(_mode == 1);
|
|
|
|
inputs[3].mappableStep();
|
2023-09-27 14:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2023-12-13 11:09:06 +01:00
|
|
|
static BATCH_SIZE = 128;
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2023-11-24 10:41:53 +01:00
|
|
|
var _val = _data[0];
|
2023-09-27 14:55:21 +02:00
|
|
|
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);
|
2023-09-27 14:55:21 +02:00
|
|
|
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;
|
2023-09-27 14:55:21 +02:00
|
|
|
|
|
|
|
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]);
|
2023-09-27 14:55:21 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|