Pixel-Composer/scripts/node_VFX_renderer/node_VFX_renderer.gml

85 lines
2.4 KiB
Plaintext
Raw Normal View History

2022-12-13 09:20:36 +01:00
function Node_VFX_Renderer(_x, _y, _group = -1) : Node(_x, _y, _group) constructor {
name = "Renderer";
2022-12-16 09:18:09 +01:00
inputs[| 0] = nodeValue(0, "Output dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2)
2022-12-13 09:20:36 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2022-12-16 09:18:09 +01:00
inputs[| 1] = nodeValue(1, "Round position", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true );
2022-12-13 09:20:36 +01:00
2022-12-16 09:18:09 +01:00
inputs[| 2] = nodeValue(2, "Blend mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2022-12-13 09:20:36 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Normal", "Additive" ]);
2022-12-16 09:18:09 +01:00
input_index = ds_list_size(inputs);
static createNewInput = function() {
var index = ds_list_size(inputs);
inputs[| index] = nodeValue( index, "Particles", self, JUNCTION_CONNECT.input, VALUE_TYPE.object, noone )
.setVisible(true, true);
}
createNewInput();
2022-12-13 09:20:36 +01:00
outputs[| 0] = nodeValue(0, "Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, PIXEL_SURFACE);
2022-12-16 09:18:09 +01:00
static updateValueFrom = function(index) {
if(index < input_index) return;
var _l = ds_list_create();
for( var i = 0; i < ds_list_size(inputs); i++ ) {
if(i < input_index || inputs[| i].value_from)
ds_list_add(_l, inputs[| i]);
else
delete inputs[| i];
}
for( var i = 0; i < ds_list_size(_l); i++ ) {
_l[| i].index = i;
}
ds_list_destroy(inputs);
inputs = _l;
createNewInput();
}
2022-12-13 09:20:36 +01:00
function update(_time = ANIMATOR.current_frame) {
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();
if(is_surface(_outSurf))
surface_size_to(_outSurf, _dim[0], _dim[1]);
else {
_outSurf = surface_create_valid(_dim[0], _dim[1]);
outputs[| 0].setValue(_outSurf);
}
surface_set_target(_outSurf);
draw_clear_alpha(c_white, 0);
switch(_blend) {
case PARTICLE_BLEND_MODE.normal : gpu_set_blendmode(bm_normal); break;
case PARTICLE_BLEND_MODE.additive : gpu_set_blendmode(bm_add); break;
}
2022-12-16 09:18:09 +01:00
for( var i = input_index; i < ds_list_size(inputs) - 1; i++ ) {
var parts = inputs[| i].getValue(_time);
for(var j = 0; j < PREF_MAP[? "part_max_amount"]; j++)
parts[| j].draw(_exact);
}
2022-12-13 09:20:36 +01:00
gpu_set_blendmode(bm_normal);
surface_reset_target();
cacheCurrentFrame(_outSurf);
}
2022-12-16 09:18:09 +01:00
static postDeserialize = function() {
var _inputs = load_map[? "inputs"];
for(var i = input_index; i < ds_list_size(_inputs); i++)
createNewInput();
}
2022-12-13 09:20:36 +01:00
}