Pixel-Composer/scripts/node_time_remap/node_time_remap.gml

57 lines
1.5 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
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-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
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();
2024-11-12 03:39:57 +01:00
static update = function(frame = CURRENT_FRAME) {
var _inSurf = getInputData(0);
var _map = getInputData(1);
var _life = getInputData(2);
var _loop = getInputData(3);
2024-11-12 03:39:57 +01:00
cacheCurrentFrame(_inSurf);
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;
2024-11-12 03:39:57 +01:00
surface_set_shader(_surf, sh_time_remap);
shader_set_surface("map", _map);
2022-01-13 05:24:03 +01:00
for(var i = 0; i <= _life; i++) {
2023-10-09 16:07:33 +02:00
var _frame = CURRENT_FRAME - i;
2024-11-12 03:39:57 +01:00
if(_loop) _frame = _frame < 0? TOTAL_FRAMES - 1 + _frame : _frame;
else _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
2024-11-12 03:39:57 +01:00
shader_set_f("vMin", i * ste);
shader_set_f("vMax", 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();
2024-11-12 03:39:57 +01:00
}
2022-01-13 05:24:03 +01:00
}