2023-02-28 09:43:01 +01:00
|
|
|
function Node_Time_Remap(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-01-25 06:49:00 +01:00
|
|
|
name = "Time Remap";
|
2023-10-02 14:41:44 +02:00
|
|
|
use_cache = CACHE_USE.manual;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-21 02:30:23 +01:00
|
|
|
shader = sh_time_remap;
|
|
|
|
uniform_map = shader_get_sampler_index(shader, "map");
|
|
|
|
uniform_min = shader_get_uniform(shader, "vMin");
|
|
|
|
uniform_max = shader_get_uniform(shader, "vMax");
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0)
|
|
|
|
.rejectArray();
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 1] = nodeValue("Map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0)
|
|
|
|
.rejectArray();
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 2] = nodeValue("Max life", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 3)
|
|
|
|
.rejectArray();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
inputs[| 3] = nodeValue("Loop", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false)
|
|
|
|
|
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-14 05:32:32 +01:00
|
|
|
input_display_list = [
|
2023-05-03 21:42:17 +02:00
|
|
|
["Output", false], 0, 1,
|
2023-03-05 07:16:44 +01:00
|
|
|
["Remap", false], 2, 3,
|
2023-02-14 05:32:32 +01:00
|
|
|
]
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2023-09-14 16:29:39 +02:00
|
|
|
static update = function(frame = PROJECT.animator.current_frame) { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _inSurf = getInputData(0);
|
|
|
|
var _map = getInputData(1);
|
|
|
|
var _life = getInputData(2);
|
|
|
|
var _loop = getInputData(3);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var _surf = outputs[| 0].getValue();
|
2023-09-08 21:37:36 +02:00
|
|
|
_surf = surface_verify(_surf, surface_get_width_safe(_inSurf), surface_get_height_safe(_inSurf), attrDepth());
|
2022-12-27 04:00:50 +01:00
|
|
|
outputs[| 0].setValue(_surf);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var ste = 1 / _life;
|
|
|
|
|
2023-09-19 12:53:24 +02:00
|
|
|
surface_set_shader(_surf, shader);
|
2022-01-13 05:24:03 +01:00
|
|
|
texture_set_stage(uniform_map, surface_get_texture(_map));
|
|
|
|
|
|
|
|
for(var i = 0; i <= _life; i++) {
|
2023-07-06 19:49:16 +02:00
|
|
|
var _frame = PROJECT.animator.current_frame - i;
|
2023-03-05 07:16:44 +01:00
|
|
|
if(_loop)
|
2023-07-06 19:49:16 +02:00
|
|
|
_frame = _frame < 0? PROJECT.animator.frames_total - 1 + _frame : _frame;
|
2023-03-05 07:16:44 +01:00
|
|
|
else
|
2023-07-06 19:49:16 +02:00
|
|
|
_frame = clamp(_frame, 0, PROJECT.animator.frames_total - 1);
|
2023-03-05 07:16:44 +01:00
|
|
|
|
|
|
|
var s = array_safe_get(cached_output, _frame)
|
|
|
|
if(!is_surface(s)) continue;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
shader_set_uniform_f(uniform_min, i * ste);
|
|
|
|
shader_set_uniform_f(uniform_max, i * ste + ste);
|
|
|
|
draw_surface_safe(s, 0, 0);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-09-19 12:53:24 +02:00
|
|
|
surface_reset_shader();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
cacheCurrentFrame(_inSurf);
|
2023-09-14 16:29:39 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|