Pixel-Composer/scripts/node_particle/node_particle.gml

70 lines
2.2 KiB
Plaintext
Raw Normal View History

2022-12-13 09:20:36 +01:00
function Node_Particle(_x, _y, _group = -1) : Node_VFX_Spawner(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Particle";
auto_update = false;
use_cache = true;
2022-12-13 09:20:36 +01:00
input_len = ds_list_size(inputs);
inputs[| input_len + 0] = nodeValue(input_len + 0, "Output dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2022-01-13 05:24:03 +01:00
2022-12-13 09:20:36 +01:00
inputs[| input_len + 1] = nodeValue(input_len + 1, "Round position", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true );
2022-01-13 05:24:03 +01:00
2022-12-13 09:20:36 +01:00
inputs[| input_len + 2] = nodeValue(input_len + 2, "Blend mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Normal", "Additive" ]);
2022-01-13 05:24:03 +01:00
2022-09-21 06:09:40 +02:00
outputs[| 0] = nodeValue(0, "Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, PIXEL_SURFACE);
2022-01-13 05:24:03 +01:00
2022-12-13 09:20:36 +01:00
array_insert(input_display_list, 0, ["Output", true], input_len + 0);
array_push(input_display_list, input_len + 1, input_len + 2);
2022-01-13 05:24:03 +01:00
2022-12-13 09:20:36 +01:00
def_surface = -1;
2022-12-10 05:06:01 +01:00
2022-12-13 09:20:36 +01:00
static onStep = function() {
if(!ANIMATOR.frame_progress) return;
2022-01-13 05:24:03 +01:00
2022-12-13 09:20:36 +01:00
if(recoverCache()) {
triggerRender();
return;
2022-01-13 05:24:03 +01:00
}
2022-12-13 09:20:36 +01:00
if(!ANIMATOR.is_playing) return;
2022-01-13 05:24:03 +01:00
2022-12-13 09:20:36 +01:00
if(ANIMATOR.current_frame == 0) {
reset();
runFrame(ANIMATOR.current_frame);
} else if(cached_output[ANIMATOR.current_frame - 1] != 0) {
runFrame(ANIMATOR.current_frame);
2022-01-13 05:24:03 +01:00
}
}
2022-12-10 05:06:01 +01:00
function render(_time = ANIMATOR.current_frame) {
2022-12-13 09:20:36 +01:00
var _dim = inputs[| input_len + 0].getValue(_time);
var _exact = inputs[| input_len + 1].getValue(_time);
var _blend = inputs[| input_len + 2].getValue(_time);
2022-01-13 05:24:03 +01:00
var _outSurf = outputs[| 0].getValue();
if(is_surface(_outSurf))
2022-11-01 03:06:03 +01:00
surface_size_to(_outSurf, _dim[0], _dim[1]);
2022-01-13 05:24:03 +01:00
else {
2022-11-01 03:06:03 +01:00
_outSurf = surface_create_valid(_dim[0], _dim[1]);
2022-01-13 05:24:03 +01:00
outputs[| 0].setValue(_outSurf);
}
surface_set_target(_outSurf);
2022-09-27 06:37:28 +02:00
draw_clear_alpha(c_white, 0);
2022-01-13 05:24:03 +01:00
switch(_blend) {
2022-09-27 06:37:28 +02:00
case PARTICLE_BLEND_MODE.normal : gpu_set_blendmode(bm_normal); break;
case PARTICLE_BLEND_MODE.additive : gpu_set_blendmode(bm_add); break;
2022-01-13 05:24:03 +01:00
}
for(var i = 0; i < PREF_MAP[? "part_max_amount"]; i++)
parts[| i].draw(_exact);
gpu_set_blendmode(bm_normal);
surface_reset_target();
cacheCurrentFrame(_outSurf);
}
}