2022-12-13 09:20:36 +01:00
|
|
|
function Node_Trail(_x, _y, _group = -1) : Node_Processor(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Trail";
|
|
|
|
use_cache = true;
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
|
|
|
|
inputs[| 1] = nodeValue("Max life", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 3);
|
|
|
|
inputs[| 2] = nodeValue("Step", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1);
|
|
|
|
inputs[| 3] = nodeValue("Alpha decrease", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
|
2022-11-22 14:25:39 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 4] = nodeValue("Blend mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
2022-01-19 03:05:13 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, BLEND_TYPES );
|
2022-01-13 05:24:03 +01:00
|
|
|
|
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 = [
|
|
|
|
["Trail settings", false], 0, 1, 2, 4, 3
|
|
|
|
];
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
temp_surf = [ surface_create(1, 1), surface_create(1, 1) ];
|
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-01-13 05:24:03 +01:00
|
|
|
if(!inputs[| 0].value_from)
|
|
|
|
return _outSurf;
|
|
|
|
if(array_length(cached_output) != ANIMATOR.frames_total + 1)
|
|
|
|
return _outSurf
|
|
|
|
|
|
|
|
for(var i = 0; i < 2; i++) {
|
2022-12-27 04:00:50 +01:00
|
|
|
temp_surf[i] = surface_verify(temp_surf[i], surface_get_width(_outSurf), surface_get_height(_outSurf));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
surface_set_target(temp_surf[i]);
|
|
|
|
draw_clear_alpha(0, 0);
|
|
|
|
surface_reset_target();
|
|
|
|
}
|
|
|
|
|
|
|
|
var _life = _data[1];
|
|
|
|
var _step = _data[2];
|
|
|
|
var _alpha = _data[3];
|
|
|
|
var _blend = _data[4];
|
|
|
|
|
|
|
|
var aa = 1;
|
|
|
|
var res_index = 0;
|
2022-11-22 14:25:39 +01:00
|
|
|
var frame_amo = min(_life, floor(ANIMATOR.current_frame / _step));
|
|
|
|
var st_frame = ANIMATOR.current_frame - frame_amo * _step;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-22 14:25:39 +01:00
|
|
|
for(var i = 0; i <= _life; i++) {
|
|
|
|
var frame_idx = clamp(st_frame + i * _step, 0, ANIMATOR.frames_total - 1);
|
2022-01-13 05:24:03 +01:00
|
|
|
var bg = i % 2;
|
2022-11-22 14:25:39 +01:00
|
|
|
var fg = !bg;
|
|
|
|
var aa = 1 - _alpha * (_life - i);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
surface_set_target(temp_surf[bg]);
|
|
|
|
if(i == _life)
|
|
|
|
draw_surface_safe(_data[0], 0, 0);
|
2022-11-22 14:25:39 +01:00
|
|
|
else if(is_surface(cached_output[frame_idx]))
|
|
|
|
draw_surface_blend(temp_surf[fg], cached_output[frame_idx], _blend, aa);
|
2022-01-13 05:24:03 +01:00
|
|
|
surface_reset_target();
|
|
|
|
|
|
|
|
res_index = bg;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface_set_target(_outSurf);
|
|
|
|
draw_clear_alpha(0, 0);
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_OVERRIDE;
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_surface_safe(temp_surf[res_index], 0, 0);
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_NORMAL;
|
2022-01-13 05:24:03 +01:00
|
|
|
surface_reset_target();
|
|
|
|
|
|
|
|
cacheCurrentFrame(_data[0]);
|
|
|
|
|
|
|
|
return _outSurf;
|
|
|
|
}
|
|
|
|
}
|