Pixel-Composer/scripts/node_gradient/node_gradient.gml

119 lines
4.3 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Gradient(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-01-25 06:49:00 +01:00
name = "Draw Gradient";
2022-01-13 05:24:03 +01:00
2022-12-21 02:30:23 +01:00
shader = sh_gradient;
2022-12-23 04:45:52 +01:00
uniform_grad_blend = shader_get_uniform(shader, "gradient_blend");
uniform_grad = shader_get_uniform(shader, "gradient_color");
uniform_grad_time = shader_get_uniform(shader, "gradient_time");
uniform_grad_key = shader_get_uniform(shader, "gradient_keys");
uniform_grad_loop = shader_get_uniform(shader, "gradient_loop");
2022-01-14 02:44:58 +01:00
2022-12-23 04:45:52 +01:00
uniform_type = shader_get_uniform(shader, "type");
uniform_center = shader_get_uniform(shader, "center");
2022-01-13 05:24:03 +01:00
2022-12-23 04:45:52 +01:00
uniform_angle = shader_get_uniform(shader, "angle");
uniform_radius = shader_get_uniform(shader, "radius");
uniform_radius_shf = shader_get_uniform(shader, "shift");
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2 )
2022-01-13 05:24:03 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-03-02 07:59:14 +01:00
inputs[| 1] = nodeValue("Gradient", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, new gradientObject(c_white) )
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.gradient);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Linear", "Circular", "Radial" ]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Angle", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.rotation);
2022-01-18 05:31:19 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 4] = nodeValue("Radius", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, .5);
2022-01-18 05:31:19 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 5] = nodeValue("Shift", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.slider, [-2, 2, 0.01]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 6] = nodeValue("Center", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [def_surf_size / 2, def_surf_size / 2])
2022-12-27 04:00:50 +01:00
.setDisplay(VALUE_DISPLAY.vector)
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); });
2022-01-18 05:31:19 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 7] = nodeValue("Loop", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 8] = nodeValue("Mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
2022-09-21 06:09:40 +02:00
2023-03-08 12:14:01 +01:00
inputs[| 9] = nodeValue("Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider, [0, 2, 0.01]);
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
input_display_list = [
2022-09-21 06:09:40 +02:00
["Output", true], 0, 8,
2023-03-08 12:14:01 +01:00
["Gradient", false], 1, 5, 9, 7,
2022-01-18 05:31:19 +01:00
["Shape", false], 2, 3, 4, 6
2022-01-13 05:24:03 +01:00
];
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2022-12-19 13:35:30 +01:00
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
inputs[| 6].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
2022-01-13 05:24:03 +01:00
}
2023-01-01 02:06:02 +01:00
static process_data = function(_outSurf, _data, _output_index, _array_index) {
2022-12-22 03:09:55 +01:00
var _dim = _data[0];
2022-01-13 05:24:03 +01:00
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
2022-01-13 05:24:03 +01:00
2022-12-22 03:09:55 +01:00
var _gra = _data[1];
2023-03-13 10:45:56 +01:00
//print("Draw gradient " + string(_gra))
2022-01-13 05:24:03 +01:00
2022-12-22 03:09:55 +01:00
var _typ = _data[2];
var _ang = _data[3];
var _rad = _data[4];
var _shf = _data[5];
var _cnt = _data[6];
var _lop = _data[7];
var _msk = _data[8];
2023-03-08 12:14:01 +01:00
var _sca = _data[9];
2022-01-13 05:24:03 +01:00
2023-03-02 07:59:14 +01:00
var _grad = _gra.toArray();
2023-02-14 05:32:32 +01:00
var _grad_color = _grad[0];
var _grad_time = _grad[1];
2022-01-13 05:24:03 +01:00
2023-03-08 12:14:01 +01:00
for( var i = 0; i < array_length(_grad_time); i++ )
_grad_time[i] = 0.5 + (_grad_time[i] - 0.5) * _sca;
2022-01-13 05:24:03 +01:00
if(_typ == 0 || _typ == 2) {
2022-01-19 06:11:17 +01:00
inputs[| 3].setVisible(true);
inputs[| 4].setVisible(false);
2022-01-13 05:24:03 +01:00
} else if(_typ == 1) {
2022-01-19 06:11:17 +01:00
inputs[| 3].setVisible(false);
inputs[| 4].setVisible(true);
2022-09-21 06:09:40 +02:00
}
2022-01-13 05:24:03 +01:00
surface_set_target(_outSurf);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
2022-12-21 02:30:23 +01:00
shader_set(shader);
2023-03-02 07:59:14 +01:00
shader_set_uniform_i(uniform_grad_blend, _gra.type);
2023-02-14 05:32:32 +01:00
shader_set_uniform_f_array_safe(uniform_grad, _grad_color);
shader_set_uniform_f_array_safe(uniform_grad_time, _grad_time);
2023-03-02 07:59:14 +01:00
shader_set_uniform_i(uniform_grad_key, array_length(_gra.keys));
2022-01-18 05:31:19 +01:00
shader_set_uniform_i(uniform_grad_loop, _lop);
2022-01-14 02:44:58 +01:00
2023-02-14 05:32:32 +01:00
shader_set_uniform_f_array_safe(uniform_center, [_cnt[0] / _dim[0], _cnt[1] / _dim[1]]);
2022-01-13 05:24:03 +01:00
shader_set_uniform_i(uniform_type, _typ);
shader_set_uniform_f(uniform_angle, degtorad(_ang));
shader_set_uniform_f(uniform_radius, _rad * sqrt(2));
shader_set_uniform_f(uniform_radius_shf, _shf);
2023-02-14 05:32:32 +01:00
BLEND_OVERRIDE;
2022-09-21 06:09:40 +02:00
if(is_surface(_msk))
draw_surface_stretched_ext(_msk, 0, 0, _dim[0], _dim[1], c_white, 1);
else
draw_sprite_stretched_ext(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1], c_white, 1);
2023-02-14 05:32:32 +01:00
BLEND_NORMAL;
2022-01-13 05:24:03 +01:00
shader_reset();
surface_reset_target();
2022-12-22 03:09:55 +01:00
return _outSurf;
2022-01-13 05:24:03 +01:00
}
}