Pixel-Composer/scripts/node_trail/node_trail.gml

153 lines
5.3 KiB
Plaintext
Raw Normal View History

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";
use_cache = true;
2023-02-21 04:48:50 +01:00
shader1 = sh_trail_filler_pass1;
uni_dimension = shader_get_uniform(shader1, "dimension");
uni_mode = shader_get_uniform(shader1, "mode");
uni_range = shader_get_uniform(shader1, "range");
2023-02-23 07:02:19 +01:00
uni_colr = shader_get_uniform(shader1, "matchColor");
uni_blend = shader_get_uniform(shader1, "blendColor");
2023-02-21 04:48:50 +01:00
uni_seg_st = shader_get_uniform(shader1, "segmentStart");
2023-02-23 07:02:19 +01:00
uni_seg_sz = shader_get_uniform(shader1, "segmentSize");
2023-02-21 04:48:50 +01:00
uni_sam_prev = shader_get_sampler_index(shader1, "prevFrame");
shader2 = sh_trail_filler_pass2;
uni2_dimension = shader_get_uniform(shader2, "dimension");
2023-02-20 10:16:31 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
2023-02-20 10:16:31 +01:00
2023-02-23 07:02:19 +01:00
inputs[| 1] = nodeValue("Max life", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 5);
2022-01-13 05:24:03 +01:00
2023-02-23 07:02:19 +01:00
inputs[| 2] = nodeValue("Loop", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
2022-01-13 05:24:03 +01:00
2023-02-23 07:02:19 +01:00
inputs[| 3] = nodeValue("Max distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, -1, "Maximum distance to search for movement, set to -1 to search the entire image.");
inputs[| 4] = nodeValue("Match color", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true, "Make trail track pixels of the same color, instead of the closet pixels.");
inputs[| 5] = nodeValue("Blend color", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true, "Blend color between two pixel smoothly.");
inputs[| 6] = nodeValue("Alpha over life", self, JUNCTION_CONNECT.input, VALUE_TYPE.curve, CURVE_DEF_11);
2023-02-21 04:48:50 +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
2023-02-21 04:48:50 +01:00
outputs[| 1] = nodeValue("Trail UV", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2022-01-13 05:24:03 +01:00
input_display_list = [
2023-02-19 13:49:20 +01:00
["Surface", 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-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-02-23 07:02:19 +01:00
static step = function() {
var _colr = inputs[| 4].getValue();
inputs[| 5].setVisible(!_colr);
}
2022-01-13 05:24:03 +01:00
2023-02-19 13:49:20 +01:00
static update = function() {
if(!inputs[| 0].value_from) return;
var _surf = inputs[| 0].getValue();
var _life = inputs[| 1].getValue();
2023-02-20 10:16:31 +01:00
var _loop = inputs[| 2].getValue();
2023-02-21 04:48:50 +01:00
var _rang = inputs[| 3].getValue();
2023-02-23 07:02:19 +01:00
var _colr = inputs[| 4].getValue();
var _blend = inputs[| 5].getValue();
var _alpha = inputs[| 6].getValue();
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-02-23 07:02:19 +01:00
for( var i = 0; i < array_length(temp_surface); i++ ) {
2023-03-19 09:17:39 +01:00
temp_surface[i] = surface_verify(temp_surface[i], surface_get_width(_surf), surface_get_height(_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
2023-02-19 13:49:20 +01:00
var _outSurf = outputs[| 0].getValue();
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, surface_get_width(_surf), surface_get_height(_surf), cDep);
2023-02-19 13:49:20 +01:00
outputs[| 0].setValue(_outSurf);
2023-02-21 04:48:50 +01:00
var _outUV = outputs[| 1].getValue();
2023-03-19 09:17:39 +01:00
_outUV = surface_verify(_outUV, surface_get_width(_surf), surface_get_height(_surf), cDep);
2023-02-21 04:48:50 +01:00
outputs[| 1].setValue(_outUV);
2022-01-13 05:24:03 +01:00
2023-02-19 13:49:20 +01:00
var curf = ANIMATOR.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;
var prog = (frame_idx - (curf - _life)) / _life;
2023-02-20 10:16:31 +01:00
if(_loop && frame_idx < 0) frame_idx = ANIMATOR.frames_total + frame_idx;
var prev = _loop? safe_mod(frame_idx - 1 + ANIMATOR.frames_total, ANIMATOR.frames_total) : 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-03-19 09:17:39 +01:00
draw_surface_safe(_currFrame, 0, 0);
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-03-19 09:17:39 +01:00
draw_surface_safe(_currFrame, 0, 0);
2023-02-20 10:16:31 +01:00
surface_reset_target();
continue;
}
2023-02-21 04:48:50 +01:00
shader_set(shader1);
2023-02-20 10:16:31 +01:00
shader_set_uniform_f(uni_dimension, surface_get_width(_surf), surface_get_height(_surf));
2023-02-28 09:43:01 +01:00
shader_set_uniform_f(uni_range, _rang? _rang : surface_get_width(_surf) / 2);
2023-02-23 07:02:19 +01:00
shader_set_uniform_i(uni_colr, _colr);
shader_set_uniform_i(uni_blend, _blend);
2023-02-21 04:48:50 +01:00
shader_set_uniform_f(uni_seg_st, (frame_amo - i) / frame_amo);
shader_set_uniform_f(uni_seg_sz, 1 / frame_amo);
2023-02-23 07:02:19 +01:00
texture_set_stage(uni_sam_prev, surface_get_texture(_prevFrame));
2022-01-13 05:24:03 +01:00
2023-02-21 04:48:50 +01:00
shader_set_uniform_i(uni_mode, 1);
2023-02-23 07:02:19 +01:00
surface_set_target(temp_surface[0]);
2023-03-19 09:17:39 +01:00
draw_surface_safe(_currFrame, 0, 0);
2023-02-21 04:48:50 +01:00
surface_reset_target();
shader_set_uniform_i(uni_mode, 0);
2023-02-23 07:02:19 +01:00
surface_set_target(temp_surface[2]);
2023-03-19 09:17:39 +01:00
draw_surface_safe(_currFrame, 0, 0);
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-02-21 04:48:50 +01:00
shader_set(shader2);
shader_set_uniform_f(uni2_dimension, surface_get_width(_surf), surface_get_height(_surf));
2023-03-19 09:17:39 +01:00
draw_surface_safe(temp_surface[0], 0, 0);
2023-02-21 04:48:50 +01:00
shader_reset();
surface_reset_target();
surface_set_target(_outUV);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
2023-02-21 04:48:50 +01:00
BLEND_ALPHA;
2023-02-23 07:02:19 +01:00
draw_surface_safe(temp_surface[1], 0, 0);
2023-02-21 04:48:50 +01:00
BLEND_NORMAL;
surface_reset_target();
2022-01-13 05:24:03 +01:00
surface_set_target(_outSurf);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
2023-02-21 04:48:50 +01:00
BLEND_ALPHA;
2023-02-23 07:02:19 +01:00
draw_surface_safe(temp_surface[2], 0, 0);
2023-02-14 05:32:32 +01:00
BLEND_NORMAL;
2022-01-13 05:24:03 +01:00
surface_reset_target();
}
2023-02-23 07:02:19 +01:00
2022-01-13 05:24:03 +01:00
}