Pixel-Composer/scripts/node_time_remap/node_time_remap.gml

59 lines
1.8 KiB
Plaintext
Raw Normal View History

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";
2022-12-21 02:30:23 +01:00
use_cache = true;
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-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 = [
["Surface", false], 0, 1, 2,
]
static update = function(frame = ANIMATOR.current_frame) {
2022-01-13 05:24:03 +01:00
if(array_length(cached_output) != ANIMATOR.frames_total + 1)
return;
var _inSurf = inputs[| 0].getValue();
var _map = inputs[| 1].getValue();
var _life = inputs[| 2].getValue();
var _surf = outputs[| 0].getValue();
2022-12-27 04:00:50 +01:00
_surf = surface_verify(_surf, surface_get_width(_inSurf), surface_get_height(_inSurf));
outputs[| 0].setValue(_surf);
2022-01-13 05:24:03 +01:00
var ste = 1 / _life;
surface_set_target(_surf);
draw_clear_alpha(0, 0);
2022-12-21 02:30:23 +01:00
shader_set(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-02-14 05:32:32 +01:00
var _frame = clamp(ANIMATOR.current_frame - i, 0, ANIMATOR.frames_total - 1);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
if(is_surface(cached_output[_frame])) {
2022-01-13 05:24:03 +01:00
shader_set_uniform_f(uniform_min, i * ste);
shader_set_uniform_f(uniform_max, i * ste + ste);
2023-02-14 05:32:32 +01:00
draw_surface_safe(cached_output[_frame], 0, 0);
2022-01-13 05:24:03 +01:00
}
}
shader_reset();
surface_reset_target();
cacheCurrentFrame(_inSurf);
}
}