2023-02-28 09:43:01 +01:00
|
|
|
function Node_Trail(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Trail";
|
2023-10-02 14:41:44 +02:00
|
|
|
use_cache = CACHE_USE.manual;
|
2023-08-05 14:00:33 +02:00
|
|
|
clearCacheOnChange = false;
|
2023-02-20 10:16:31 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Surface("Surface in", self));
|
2023-02-20 10:16:31 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(1, nodeValue_Int("Max life", self, 5));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(2, nodeValue_Bool("Loop", self, false));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(3, nodeValue_Int("Max distance", self, -1, "Maximum distance to search for movement, set to -1 to search the entire image."));
|
2023-02-23 07:02:19 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(4, nodeValue_Bool("Match color", self, true, "Make trail track pixels of the same color, instead of the closet pixels."));
|
2023-02-23 07:02:19 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(5, nodeValue_Bool("Blend color", self, true, "Blend color between two pixel smoothly."));
|
2023-02-23 07:02:19 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(6, nodeValue("Alpha over life", self, CONNECT_TYPE.input, VALUE_TYPE.curve, CURVE_DEF_11));
|
2023-02-21 04:48:50 +01:00
|
|
|
|
2024-09-04 03:57:11 +02:00
|
|
|
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-09-04 03:57:11 +02:00
|
|
|
newOutput(1, nodeValue_Output("Trail UV", self, VALUE_TYPE.surface, noone));
|
2023-02-21 04:48:50 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
input_display_list = [
|
2023-11-08 14:37:51 +01:00
|
|
|
["Surfaces", true], 0,
|
2023-02-23 07:02:19 +01:00
|
|
|
["Trail settings", false], 1, 2,
|
|
|
|
["Tracking", false], 3, 4, 5,
|
|
|
|
["Modification", false], 6,
|
2022-01-13 05:24:03 +01:00
|
|
|
];
|
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
temp_surface = [ surface_create(1, 1), surface_create(1, 1), surface_create(1, 1) ];
|
|
|
|
|
2023-12-29 14:30:54 +01:00
|
|
|
cached_trail = [];
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2023-12-29 14:30:54 +01:00
|
|
|
insp2UpdateTooltip = "Clear cache";
|
|
|
|
insp2UpdateIcon = [ THEME.cache, 0, COLORS._main_icon ];
|
|
|
|
|
|
|
|
static onInspector2Update = function() {
|
|
|
|
clearCache(true);
|
|
|
|
for( var i = 0, n = array_length(cached_trail); i < n; i++ )
|
|
|
|
surface_free_safe(cached_trail[i]);
|
|
|
|
cached_trail = [];
|
|
|
|
}
|
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
static step = function() {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _colr = getInputData(4);
|
2023-02-23 07:02:19 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[5].setVisible(!_colr);
|
2023-02-23 07:02:19 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-19 13:49:20 +01:00
|
|
|
static update = function() {
|
2024-08-08 06:57:51 +02:00
|
|
|
if(!inputs[0].value_from) return;
|
2023-02-19 13:49:20 +01:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var _surf = getInputData(0);
|
|
|
|
var _life = getInputData(1);
|
|
|
|
var _loop = getInputData(2);
|
2023-06-17 18:59:20 +02:00
|
|
|
if(!is_real(_loop)) _loop = false;
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var _rang = getInputData(3);
|
|
|
|
var _colr = getInputData(4);
|
|
|
|
var _blend = getInputData(5);
|
|
|
|
var _alpha = getInputData(6);
|
2023-03-19 09:17:39 +01:00
|
|
|
var cDep = attrDepth();
|
2023-02-19 13:49:20 +01:00
|
|
|
if(!is_surface(_surf)) return;
|
|
|
|
cacheCurrentFrame(_surf);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(temp_surface); i < n; i++ ) {
|
2023-09-08 21:37:36 +02:00
|
|
|
temp_surface[i] = surface_verify(temp_surface[i], surface_get_width_safe(_surf), surface_get_height_safe(_surf), cDep);
|
2023-02-23 07:02:19 +01:00
|
|
|
surface_set_target(temp_surface[i]);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
2023-02-21 04:48:50 +01:00
|
|
|
surface_reset_target();
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _outSurf = outputs[0].getValue();
|
2023-09-08 21:37:36 +02:00
|
|
|
_outSurf = surface_verify(_outSurf, surface_get_width_safe(_surf), surface_get_height_safe(_surf), cDep);
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(_outSurf);
|
2023-02-21 04:48:50 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _outUV = outputs[1].getValue();
|
2023-09-08 21:37:36 +02:00
|
|
|
_outUV = surface_verify(_outUV, surface_get_width_safe(_surf), surface_get_height_safe(_surf), cDep);
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[1].setValue(_outUV);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
var curf = CURRENT_FRAME;
|
2023-02-20 10:16:31 +01:00
|
|
|
var frame_amo = _loop? _life : min(_life, curf);
|
2023-02-19 13:49:20 +01:00
|
|
|
var st_frame = curf - frame_amo;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-19 13:49:20 +01:00
|
|
|
for(var i = 0; i <= frame_amo; i++) {
|
|
|
|
var frame_idx = st_frame + i;
|
2023-08-05 14:00:33 +02:00
|
|
|
var prog = (frame_idx - (curf - _life)) / _life;
|
|
|
|
|
|
|
|
var a0 = eval_curve_x(_alpha, 1 - i / (frame_amo + 1));
|
|
|
|
var a1 = eval_curve_x(_alpha, 1 - (i + 1) / (frame_amo + 1));
|
2023-02-19 13:49:20 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
if(_loop && frame_idx < 0) frame_idx = TOTAL_FRAMES + frame_idx;
|
2023-02-20 10:16:31 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
var prev = _loop? safe_mod(frame_idx - 1 + TOTAL_FRAMES, TOTAL_FRAMES) : frame_idx - 1;
|
2023-02-23 07:02:19 +01:00
|
|
|
var _prevFrame = getCacheFrame(prev);
|
|
|
|
var _currFrame = getCacheFrame(frame_idx);
|
2023-02-20 10:16:31 +01:00
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
if(!is_surface(_currFrame)) continue;
|
|
|
|
|
|
|
|
if(!is_surface(_prevFrame)) {
|
|
|
|
surface_set_target(temp_surface[0]);
|
2023-08-05 14:00:33 +02:00
|
|
|
draw_surface_ext_safe(_currFrame, 0, 0, 1, 1, 0, c_white, a0);
|
2023-02-21 04:48:50 +01:00
|
|
|
surface_reset_target();
|
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
surface_set_target(temp_surface[2]);
|
2023-08-05 14:00:33 +02:00
|
|
|
draw_surface_ext_safe(_currFrame, 0, 0, 1, 1, 0, c_white, a1);
|
2023-02-20 10:16:31 +01:00
|
|
|
surface_reset_target();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
shader_set(sh_trail_filler_pass1);
|
|
|
|
shader_set_dim("dimension", _surf);
|
2023-09-08 21:37:36 +02:00
|
|
|
shader_set_f("range", _rang? _rang : surface_get_width_safe(_surf) / 2);
|
2023-08-05 14:00:33 +02:00
|
|
|
shader_set_i("matchColor", _colr);
|
|
|
|
shader_set_i("blendColor", _blend);
|
|
|
|
shader_set_f("segmentStart", (frame_amo - i) / frame_amo);
|
|
|
|
shader_set_f("segmentSize", 1 / frame_amo);
|
|
|
|
shader_set_surface("prevFrame", _prevFrame);
|
|
|
|
shader_set_f("alphaPrev", a0);
|
|
|
|
shader_set_f("alphaCurr", a1);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
surface_set_target(temp_surface[0]);
|
2024-01-09 03:39:40 +01:00
|
|
|
shader_set_i("mode", 1);
|
|
|
|
draw_surface_safe(_currFrame);
|
2023-02-21 04:48:50 +01:00
|
|
|
surface_reset_target();
|
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
surface_set_target(temp_surface[2]);
|
2024-01-09 03:39:40 +01:00
|
|
|
shader_set_i("mode", 0);
|
|
|
|
draw_surface_safe(_currFrame);
|
2023-02-21 04:48:50 +01:00
|
|
|
surface_reset_target();
|
|
|
|
|
2023-02-20 10:16:31 +01:00
|
|
|
shader_reset();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
surface_set_target(temp_surface[1]);
|
2023-08-05 14:00:33 +02:00
|
|
|
shader_set(sh_trail_filler_pass2);
|
|
|
|
shader_set_dim("dimension", _surf);
|
2024-01-09 03:39:40 +01:00
|
|
|
draw_surface_safe(temp_surface[0]);
|
2023-08-05 14:00:33 +02:00
|
|
|
shader_reset();
|
2023-02-21 04:48:50 +01:00
|
|
|
surface_reset_target();
|
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
surface_set_shader(_outUV);
|
2024-01-09 03:39:40 +01:00
|
|
|
draw_surface_safe(temp_surface[1]);
|
2023-08-05 14:00:33 +02:00
|
|
|
surface_reset_shader();
|
2023-02-21 04:48:50 +01:00
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
surface_set_shader(_outSurf);
|
2024-01-09 03:39:40 +01:00
|
|
|
draw_surface_safe(temp_surface[2]);
|
2023-08-05 14:00:33 +02:00
|
|
|
surface_reset_shader();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-02-23 07:02:19 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|