Pixel-Composer/scripts/node_time_remap/node_time_remap.gml

65 lines
1.8 KiB
Text
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-12-05 04:28:49 +01:00
name = "Time Remap";
2023-10-02 14:41:44 +02:00
use_cache = CACHE_USE.manual;
2023-12-05 04:28:49 +01:00
update_on_frame = 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
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_Surface("Surface in", self))
2023-02-14 05:32:32 +01:00
.rejectArray();
2023-01-25 06:49:00 +01:00
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_Surface("Map", self))
2023-02-14 05:32:32 +01:00
.rejectArray();
2023-01-25 06:49:00 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Int("Max life", self, 3))
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Bool("Loop", self, false))
2023-03-05 07:16:44 +01:00
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
input_display_list = [
["Surfaces", 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-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) { #region
var _inSurf = getInputData(0);
var _map = getInputData(1);
var _life = getInputData(2);
var _loop = getInputData(3);
2022-01-13 05:24:03 +01:00
2024-08-08 06:57:51 +02: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());
2024-08-08 06:57:51 +02: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-10-09 16:07:33 +02:00
var _frame = CURRENT_FRAME - i;
2023-03-05 07:16:44 +01:00
if(_loop)
2023-10-09 16:07:33 +02:00
_frame = _frame < 0? TOTAL_FRAMES - 1 + _frame : _frame;
2023-03-05 07:16:44 +01:00
else
2023-10-09 16:07:33 +02:00
_frame = clamp(_frame, 0, TOTAL_FRAMES - 1);
2023-03-05 07:16:44 +01:00
2024-03-31 05:36:11 +02:00
var s = array_safe_get_fast(cached_output, _frame);
2023-03-05 07:16:44 +01:00
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);
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
}