Pixel-Composer/scripts/node_VFX_renderer/node_VFX_renderer.gml

119 lines
3.5 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_VFX_Renderer(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2022-12-13 09:20:36 +01:00
name = "Renderer";
2023-02-14 05:32:32 +01:00
color = COLORS.node_blend_vfx;
icon = THEME.vfx;
2022-12-13 09:20:36 +01:00
2023-10-02 14:41:44 +02:00
use_cache = CACHE_USE.auto;
2023-02-23 07:02:19 +01:00
2023-07-21 12:40:20 +02:00
inputs[| 0] = nodeValue("Output dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
2022-12-13 09:20:36 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Round position", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true, "Round position to the closest integer value to avoid jittering.")
.rejectArray();
2022-12-13 09:20:36 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("Blend mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2023-02-28 09:43:01 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Normal", "Alpha", "Additive" ])
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-12-13 09:20:36 +01:00
2023-08-05 14:00:33 +02:00
setIsDynamicInput(1);
2023-01-25 06:49:00 +01:00
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
attribute_interpolation();
2023-03-19 09:17:39 +01:00
2022-12-16 09:18:09 +01:00
static createNewInput = function() {
var index = ds_list_size(inputs);
2023-02-14 05:32:32 +01:00
inputs[| index] = nodeValue("Particles", self, JUNCTION_CONNECT.input, VALUE_TYPE.particle, noone )
2022-12-16 09:18:09 +01:00
.setVisible(true, true);
}
2022-12-21 02:30:23 +01:00
if(!LOADING && !APPENDING) createNewInput();
2022-12-16 09:18:09 +01:00
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2022-12-13 09:20:36 +01:00
2023-02-23 07:02:19 +01:00
insp2UpdateTooltip = "Clear cache";
insp2UpdateIcon = [ THEME.cache, 0, COLORS._main_icon ];
static onInspector2Update = function() { clearCache(); }
2023-10-09 16:07:33 +02:00
static refreshDynamicInput = function() { #region
2022-12-16 09:18:09 +01:00
var _l = ds_list_create();
for( var i = 0; i < ds_list_size(inputs); i++ ) {
2023-01-09 03:14:20 +01:00
if(i < input_fix_len || inputs[| i].value_from)
2022-12-16 09:18:09 +01:00
ds_list_add(_l, inputs[| i]);
else
delete inputs[| i];
}
2022-12-27 04:00:50 +01:00
for( var i = 0; i < ds_list_size(_l); i++ )
_l[| i].index = i;
2022-12-16 09:18:09 +01:00
ds_list_destroy(inputs);
inputs = _l;
createNewInput();
2023-10-09 16:07:33 +02:00
} #endregion
2022-12-16 09:18:09 +01:00
2023-10-09 16:07:33 +02:00
static onValueFromUpdate = function(index) { #region
2023-01-09 03:14:20 +01:00
if(index < input_fix_len) return;
if(LOADING || APPENDING) return;
refreshDynamicInput();
2023-10-09 16:07:33 +02:00
} #endregion
2023-01-09 03:14:20 +01:00
2023-10-09 16:07:33 +02:00
static step = function() { #region
var _dim = getInputData(0);
2023-03-07 14:29:47 +01:00
var _outSurf = outputs[| 0].getValue();
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
2023-03-07 14:29:47 +01:00
outputs[| 0].setValue(_outSurf);
2023-10-09 16:07:33 +02:00
if(previewing && is_instanceof(group, Node_VFX_Group))
group.preview_node = self;
} #endregion
2023-03-07 14:29:47 +01:00
2023-10-09 16:07:33 +02:00
static update = function(_time = CURRENT_FRAME) { #region
if(!IS_PLAYING) {
2023-02-23 07:02:19 +01:00
recoverCache();
return;
}
2022-12-16 09:18:09 +01:00
var _dim = inputs[| 0].getValue(_time);
var _exact = inputs[| 1].getValue(_time);
var _blend = inputs[| 2].getValue(_time);
2022-12-13 09:20:36 +01:00
var _outSurf = outputs[| 0].getValue();
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
2022-12-27 04:00:50 +01:00
outputs[| 0].setValue(_outSurf);
2022-12-13 09:20:36 +01:00
surface_set_shader(_outSurf);
shader_set_interpolation(_outSurf);
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;
}
2022-12-13 09:20:36 +01:00
2023-09-08 21:37:36 +02:00
var surf_w = surface_get_width_safe(_outSurf);
var surf_h = surface_get_height_safe(_outSurf);
2023-01-17 08:11:55 +01:00
2023-01-09 03:14:20 +01:00
for( var i = input_fix_len; i < ds_list_size(inputs) - 1; i++ ) {
2022-12-16 09:18:09 +01:00
var parts = inputs[| i].getValue(_time);
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 ];
for(var j = 0; j < array_length(parts); j++)
for(var k = 0; k < array_length(parts[j]); k++) {
2023-09-26 14:35:25 +02:00
if(!parts[j][k].active) continue;
2023-01-25 06:49:00 +01:00
parts[j][k].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;
surface_reset_shader();
2022-12-13 09:20:36 +01:00
cacheCurrentFrame(_outSurf);
2023-10-09 16:07:33 +02:00
} #endregion
getPreviewingNode = VFX_PREVIEW_NODE;
2022-12-13 09:20:36 +01:00
}