Pixel-Composer/scripts/node_mk_blinker/node_mk_blinker.gml

130 lines
3.7 KiB
Text
Raw Normal View History

2024-01-12 13:11:26 +01:00
function Node_MK_Blinker(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "MK Blinker";
batch_output = false;
2024-01-12 13:11:26 +01:00
2024-08-08 06:57:51 +02:00
inputs[0] = nodeValue_Surface("Surface in", self);
2024-01-12 13:11:26 +01:00
2024-08-08 06:57:51 +02:00
inputs[1] = nodeValue_Surface("Mask", self);
2024-01-12 13:11:26 +01:00
2024-08-08 06:57:51 +02:00
inputs[2] = nodeValue_Int("Seed", self, seed_random(6))
.setDisplay(VALUE_DISPLAY._default, { side_button : button(function() { randomize(); inputs[2].setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) });
2024-01-12 13:11:26 +01:00
2024-08-08 06:57:51 +02:00
inputs[3] = nodeValue_Float("Amount", self, 0.5)
2024-01-12 13:11:26 +01:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-08 06:57:51 +02:00
inputs[4] = nodeValue_Palette("Target Colors", self, [ c_black ] );
2024-01-12 13:11:26 +01:00
2024-08-08 06:57:51 +02:00
inputs[5] = nodeValue_Palette("Light Colors", self, [ c_white ] );
2024-01-12 13:11:26 +01:00
2024-08-08 06:57:51 +02:00
inputs[6] = nodeValue_Bool("Active", self, true);
2024-01-12 13:11:26 +01:00
active_index = 6;
2024-08-08 06:57:51 +02:00
inputs[7] = nodeValue_Float("Tolerance", self, 0.1 )
2024-01-12 13:11:26 +01:00
.setDisplay(VALUE_DISPLAY.slider);
2024-01-13 08:06:44 +01:00
2024-08-08 06:57:51 +02:00
inputs[8] = nodeValue_Bool("Glow", self, false);
2024-01-13 08:06:44 +01:00
2024-08-08 06:57:51 +02:00
inputs[9] = nodeValue_Float("Size", self, 4 )
2024-03-24 04:58:08 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range : [ 1, 8, 0.1 ] });
2024-01-13 08:06:44 +01:00
2024-08-08 06:57:51 +02:00
inputs[10] = nodeValue_Float("Strength", self, 0.5 )
2024-01-13 08:06:44 +01:00
.setDisplay(VALUE_DISPLAY.slider);
2024-01-12 13:11:26 +01:00
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
2024-01-12 14:02:49 +01:00
2024-08-08 06:57:51 +02:00
outputs[1] = nodeValue_Output("Light only", self, VALUE_TYPE.surface, noone);
2024-01-12 13:11:26 +01:00
input_display_list = [ new Inspector_Sprite(s_MKFX), 6,
2024-01-13 08:06:44 +01:00
["Surfaces", false], 0, 1,
["Blink", false], 2, 3, 4, 5, 7,
["Glow", true, 8], 9, 10,
2024-01-12 13:11:26 +01:00
]
temp_surface = [ surface_create( 1, 1 ), surface_create( 1, 1 ), surface_create( 1, 1 ) ];
2024-03-17 14:24:24 +01:00
light_only = [];
2024-01-12 14:02:49 +01:00
2024-01-13 08:06:44 +01:00
surface_blur_init();
2024-01-12 13:11:26 +01:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2024-01-12 14:02:49 +01:00
if(_output_index == 1) return light_only[_array_index];
2024-01-12 13:11:26 +01:00
var _surf = _data[0];
var _mask = _data[1];
var _seed = _data[2];
var _amou = _data[3];
var _trgC = _data[4];
var _ligC = _data[5];
var _tolr = _data[7];
2024-01-13 08:06:44 +01:00
var _glow = _data[8];
var _glsz = _data[9];
var _glop = _data[10];
2024-01-12 13:11:26 +01:00
if(!is_surface(_surf)) return _outSurf;
var _sw = surface_get_width_safe(_outSurf);
var _sh = surface_get_height_safe(_outSurf);
for( var i = 0, n = array_length(temp_surface); i < n; i++ )
temp_surface[i] = surface_verify(temp_surface[i], _sw, _sh);
2024-03-31 05:36:11 +02:00
light_only[_array_index] = surface_verify(array_safe_get_fast(light_only, _array_index), _sw, _sh);
2024-01-12 13:11:26 +01:00
surface_set_shader(temp_surface[0], sh_blink_extract);
shader_set_palette(_trgC, "colorTarget", "colorTargetAmount");
shader_set_f("tolerance", _tolr);
draw_surface_safe(_surf);
surface_reset_shader();
var rp = sqrt(_sw * _sw + _sh * _sh);
var ind = 0;
var _umask = is_surface(_mask);
repeat(rp) {
surface_set_shader(temp_surface[!ind], sh_blink_expand);
shader_set_f("dimension", _sw, _sh);
shader_set_i("useMask", _umask);
shader_set_surface("mask", _mask);
draw_surface_safe(temp_surface[ind]);
2024-01-12 13:11:26 +01:00
surface_reset_shader();
ind = !ind;
}
surface_set_shader(temp_surface[2], sh_blink_replace);
shader_set_f("seed", _seed);
shader_set_f("ratio", _amou);
shader_set_palette(_ligC);
draw_surface_safe(temp_surface[ind]);
surface_reset_shader();
2024-01-12 14:02:49 +01:00
surface_set_target(light_only[_array_index]);
DRAW_CLEAR
BLEND_OVERRIDE
draw_surface_safe(temp_surface[2]);
2024-01-12 14:02:49 +01:00
BLEND_NORMAL
surface_reset_target();
2024-01-13 08:06:44 +01:00
if(_glow) var lightBlur = surface_apply_gaussian(light_only[_array_index], _glsz, true, c_black, 1);
2024-01-12 13:11:26 +01:00
surface_set_target(_outSurf);
DRAW_CLEAR
2024-01-13 08:06:44 +01:00
2024-01-12 13:11:26 +01:00
BLEND_OVERRIDE
draw_surface_safe(_surf);
2024-01-13 08:06:44 +01:00
if(_glow) {
BLEND_ADD
draw_surface_ext(lightBlur, 0, 0, 1, 1, 0, c_white, _glop);
}
2024-01-12 13:11:26 +01:00
BLEND_ALPHA_MULP
draw_surface_safe(temp_surface[2]);
2024-01-13 08:06:44 +01:00
2024-01-12 13:11:26 +01:00
BLEND_NORMAL
surface_reset_target();
return _outSurf;
}
}