Pixel-Composer/scripts/node_pixel_cloud/node_pixel_cloud.gml

95 lines
3.2 KiB
Plaintext
Raw Normal View History

2022-12-13 09:20:36 +01:00
function Node_Pixel_Cloud(_x, _y, _group = -1) : Node_Processor(_x, _y, _group) constructor {
2022-01-14 02:44:58 +01:00
name = "Pixel Cloud";
2022-12-21 02:30:23 +01:00
shader = sh_pixel_cloud;
uniform_sed = shader_get_uniform(shader, "seed");
uniform_str = shader_get_uniform(shader, "strength");
uniform_dis = shader_get_uniform(shader, "dist");
2022-01-14 02:44:58 +01:00
2022-12-21 02:30:23 +01:00
uniform_map_use = shader_get_uniform(shader, "useMap");
uniform_map = shader_get_sampler_index(shader, "strengthMap");
2022-01-14 02:44:58 +01:00
2022-12-21 02:30:23 +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");
2022-01-14 02:44:58 +01:00
2022-12-21 02:30:23 +01:00
uniform_alpha = shader_get_uniform(shader, "alpha_curve");
2022-01-14 02:44:58 +01:00
inputs[| 0] = nodeValue(0, "Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
2022-01-19 03:05:13 +01:00
inputs[| 1] = nodeValue(1, "Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, irandom(100000));
2022-01-14 02:44:58 +01:00
inputs[| 2] = nodeValue(2, "Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.1)
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.slider, [ 0, 2, 0.01]);
2022-01-14 02:44:58 +01:00
inputs[| 3] = nodeValue(3, "Strength map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
inputs[| 4] = nodeValue(4, "Gradient", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white)
.setDisplay(VALUE_DISPLAY.gradient);
inputs[| 5] = nodeValue(5, "Size", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1);
2023-01-09 03:14:20 +01:00
inputs[| 6] = nodeValue(6, "Alpha over lifetime", self, JUNCTION_CONNECT.input, VALUE_TYPE.curve, CURVE_DEF_11)
2022-01-14 02:44:58 +01:00
.setDisplay(VALUE_DISPLAY.curve);
input_display_list = [
["Input", true], 0, 1,
["Movement", false], 5, 2, 3,
["Color", true], 4, 6
]
2022-09-21 06:09:40 +02:00
outputs[| 0] = nodeValue(0, "Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, PIXEL_SURFACE);
2022-01-14 02:44:58 +01:00
2023-01-01 02:06:02 +01:00
static process_data = function(_outSurf, _data, _output_index, _array_index) {
2022-01-14 02:44:58 +01:00
var _sed = _data[1];
var _str = _data[2];
var _map = _data[3];
var _gra = _data[4];
var _gra_data = inputs[| 4].getExtraData();
var _grad_color = [];
var _grad_time = [];
var _dis = _data[5];
var _alp = _data[6];
for(var i = 0; i < ds_list_size(_gra); i++) {
_grad_color[i * 4 + 0] = color_get_red(_gra[| i].value) / 255;
_grad_color[i * 4 + 1] = color_get_green(_gra[| i].value) / 255;
_grad_color[i * 4 + 2] = color_get_blue(_gra[| i].value) / 255;
_grad_color[i * 4 + 3] = 1;
_grad_time[i] = _gra[| i].time;
}
surface_set_target(_outSurf);
draw_clear_alpha(0, 0);
2022-12-27 04:00:50 +01:00
BLEND_OVER
2022-01-14 02:44:58 +01:00
2022-12-21 02:30:23 +01:00
shader_set(shader);
2022-01-14 02:44:58 +01:00
shader_set_uniform_f(uniform_sed, _sed);
shader_set_uniform_f(uniform_str, _str);
shader_set_uniform_f(uniform_dis, _dis);
if(is_surface(_map)) {
shader_set_uniform_i(uniform_map_use, 1);
texture_set_stage(uniform_map, surface_get_texture(_map));
} else {
shader_set_uniform_i(uniform_map_use, 0);
}
shader_set_uniform_i(uniform_grad_blend, ds_list_get(_gra_data, 0));
shader_set_uniform_f_array(uniform_grad, _grad_color);
shader_set_uniform_f_array(uniform_grad_time, _grad_time);
shader_set_uniform_i(uniform_grad_key, ds_list_size(_gra));
shader_set_uniform_f_array(uniform_alpha, _alp);
draw_surface_safe(_data[0], 0, 0);
shader_reset();
BLEND_NORMAL
surface_reset_target();
return _outSurf;
}
}