2023-02-28 09:43:01 +01:00
|
|
|
function Node_VFX_Renderer(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-12-22 08:42:02 +01:00
|
|
|
name = "Renderer";
|
2023-02-14 05:32:32 +01:00
|
|
|
color = COLORS.node_blend_vfx;
|
|
|
|
icon = THEME.vfx;
|
2023-10-02 14:41:44 +02:00
|
|
|
use_cache = CACHE_USE.auto;
|
2023-02-23 07:02:19 +01:00
|
|
|
|
2023-12-22 08:42:02 +01:00
|
|
|
manual_ungroupable = false;
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Vec2("Output dimension", self, DEF_SURF ));
|
2022-12-13 09:20:36 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(1, nodeValue_Bool("Round position", self, true, "Round position to the closest integer value to avoid jittering."))
|
2023-02-14 05:32:32 +01:00
|
|
|
.rejectArray();
|
2022-12-13 09:20:36 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(2, nodeValue_Enum_Button("Render Type", self, PARTICLE_RENDER_TYPE.surface , [ "Surface", "Line" ]))
|
2024-01-29 14:33:55 +01:00
|
|
|
.rejectArray();
|
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(3, nodeValue_Int("Line life", self, 4 ))
|
2024-01-29 14:33:55 +01:00
|
|
|
.rejectArray();
|
|
|
|
|
2024-11-30 12:02:41 +01:00
|
|
|
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
|
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
input_display_list = [
|
|
|
|
["Output", false], 0,
|
|
|
|
["Rendering", false], 1, 2, 3,
|
|
|
|
];
|
2022-12-13 09:20:36 +01:00
|
|
|
|
2024-11-30 12:02:41 +01:00
|
|
|
temp_surface = [ 0 ];
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
2023-04-03 11:55:45 +02:00
|
|
|
attribute_interpolation();
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-05-23 10:59:39 +02:00
|
|
|
static createNewInput = function() {
|
2024-08-08 06:57:51 +02:00
|
|
|
var index = array_length(inputs);
|
2023-11-17 12:33:25 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(index + 0, nodeValue_Enum_Scroll("Blend mode", self, 0 , [ "Normal", "Alpha", "Additive" ]))
|
2023-11-17 12:33:25 +01:00
|
|
|
.rejectArray();
|
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(index + 1, nodeValue_Particle("Particles", self, noone ))
|
2022-12-16 09:18:09 +01:00
|
|
|
.setVisible(true, true);
|
2023-11-17 12:33:25 +01:00
|
|
|
|
|
|
|
array_push(input_display_list, ["Particle", false], index + 0, index + 1);
|
2024-05-23 10:59:39 +02:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
return inputs[index + 1];
|
2024-05-24 07:44:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setDynamicInput(2, true, VALUE_TYPE.particle);
|
2024-05-23 10:59:39 +02:00
|
|
|
dyna_input_check_shift = 1;
|
2022-12-13 09:20:36 +01:00
|
|
|
|
2024-11-26 05:52:57 +01:00
|
|
|
setTrigger(2, "Clear cache", [ THEME.cache, 0, COLORS._main_icon ]);
|
2023-02-23 07:02:19 +01:00
|
|
|
|
|
|
|
static onInspector2Update = function() { clearCache(); }
|
|
|
|
|
2024-11-30 12:02:41 +01:00
|
|
|
static step = function() {
|
2024-01-29 14:33:55 +01:00
|
|
|
var _typ = getInputData(2);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[3].setVisible(_typ == PARTICLE_RENDER_TYPE.line);
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
if(previewing && is_instanceof(group, Node_VFX_Group))
|
|
|
|
group.preview_node = self;
|
2024-11-30 12:02:41 +01:00
|
|
|
}
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2024-11-30 12:02:41 +01:00
|
|
|
static update = function(_time = CURRENT_FRAME) {
|
|
|
|
var _dim = inputs[0].getValue(_time);
|
|
|
|
temp_surface[0] = surface_verify(temp_surface[0], _dim[0], _dim[1]);
|
|
|
|
|
2023-10-31 13:33:36 +01:00
|
|
|
if(!IS_PLAYING) {
|
2023-02-23 07:02:19 +01:00
|
|
|
recoverCache();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _exact = inputs[1].getValue(_time);
|
|
|
|
var _type = inputs[2].getValue(_time);
|
|
|
|
var _llife = inputs[3].getValue(_time);
|
2022-12-13 09:20:36 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _outSurf = outputs[0].getValue();
|
2024-01-29 14:33:55 +01:00
|
|
|
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(_outSurf);
|
2022-12-13 09:20:36 +01:00
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
var surf_w = surface_get_width_safe(_outSurf);
|
|
|
|
var surf_h = surface_get_height_safe(_outSurf);
|
2024-05-02 09:48:48 +02:00
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
surface_set_shader(_outSurf, _type == PARTICLE_RENDER_TYPE.surface? sh_sample : noone);
|
|
|
|
if(_type == PARTICLE_RENDER_TYPE.surface)
|
|
|
|
shader_set_interpolation(_outSurf);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
for( var i = input_fix_len; i < array_length(inputs); i += data_length ) {
|
|
|
|
var blend = inputs[i + 0].getValue(_time);
|
|
|
|
var parts = inputs[i + 1].getValue(_time);
|
2023-11-17 12:33:25 +01:00
|
|
|
|
|
|
|
switch(blend) {
|
|
|
|
case PARTICLE_BLEND_MODE.normal: BLEND_NORMAL; break;
|
|
|
|
case PARTICLE_BLEND_MODE.alpha: BLEND_ALPHA; break;
|
|
|
|
case PARTICLE_BLEND_MODE.additive: BLEND_ADD; break;
|
|
|
|
}
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(!is_array(parts) || array_length(parts) == 0) continue;
|
2023-01-25 06:49:00 +01:00
|
|
|
if(!is_array(parts[0])) parts = [ parts ];
|
|
|
|
|
2024-05-02 09:48:48 +02:00
|
|
|
for(var j = 0; j < array_length(parts); j++) {
|
|
|
|
var part = parts[j];
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-05-02 09:48:48 +02:00
|
|
|
for(var k = 0; k < array_length(part); k++) {
|
|
|
|
var _part = part[k];
|
|
|
|
|
|
|
|
_part.render_type = _type;
|
|
|
|
_part.line_draw = _llife;
|
|
|
|
|
|
|
|
if(_part.active || _type) _part.draw(_exact, surf_w, surf_h);
|
|
|
|
}
|
2022-12-18 03:20:38 +01:00
|
|
|
}
|
2022-12-16 09:18:09 +01:00
|
|
|
}
|
2022-12-13 09:20:36 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_NORMAL;
|
2023-04-03 11:55:45 +02:00
|
|
|
surface_reset_shader();
|
2022-12-13 09:20:36 +01:00
|
|
|
|
|
|
|
cacheCurrentFrame(_outSurf);
|
2024-11-30 12:02:41 +01:00
|
|
|
}
|
2024-12-02 02:45:17 +01:00
|
|
|
|
|
|
|
static getPreviewValues = function() {
|
|
|
|
var val = outputs[preview_channel].getValue();
|
|
|
|
return is_surface(val)? val : temp_surface[0];
|
|
|
|
}
|
2022-12-13 09:20:36 +01:00
|
|
|
}
|