2023-11-30 13:07:08 +01:00
|
|
|
function Node_MK_Rain(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
|
|
|
name = "MK Rain";
|
|
|
|
update_on_frame = true;
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Surface("Surface in", self));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(1, nodeValue_Rotation("Direction", self, 45));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(2, nodeValue_Float("Density", self, 5));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(3, nodeValue_Range("Raindrop width", self, [ 1, 1 ]));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(4, nodeValue_Range("Raindrop length", self, [ 5, 10 ]));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(5, nodeValue_Gradient("Color", self, new gradientObject(cola(c_white))));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(6, nodeValue_Slider_Range("Alpha", self, [ 0.5, 1 ]));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(7, nodeValue_Range("Velocity", self, [ 1, 2 ]));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(8, nodeValue_Int("Seed", self, seed_random(6)))
|
2024-08-08 06:57:51 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY._default, { side_button : button(function() { randomize(); inputs[8].setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) });
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(9, nodeValue_Enum_Scroll("Shape", self, 0, [ new scrollItem("Rain", s_node_mk_rain_type, 0),
|
|
|
|
new scrollItem("Snow", s_node_mk_rain_type, 1),
|
|
|
|
new scrollItem("Texture", s_node_mk_rain_type, 2) ]));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(10, nodeValue_Range("Snow size", self, [ 3, 4 ]));
|
2023-12-01 05:49:44 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(11, nodeValue_Surface("Texture", self));
|
2023-12-15 12:56:36 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(12, nodeValue_Slider_Range("Track extension", self, [ 0, 0 ], { range: [ 0, 10, 0.01 ] }));
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(13, nodeValue("Size over lifetime", self, CONNECT_TYPE.input, VALUE_TYPE.curve, CURVE_DEF_11));
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(14, nodeValue_Bool("Limited lifespan", self, false));
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(15, nodeValue_Slider_Range("Lifespan", self, [ 0, 1 ]))
|
2024-08-07 13:20:45 +02:00
|
|
|
.setTooltip("Lifespan of a droplet as a ratio of the entire animation.");
|
2024-01-29 14:33:55 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(16, nodeValue("Alpha over lifetime", self, CONNECT_TYPE.input, VALUE_TYPE.curve, CURVE_DEF_11));
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(17, nodeValue_Bool("Fade alpha", self, false));
|
2024-01-31 11:34:12 +01:00
|
|
|
|
2023-12-11 09:59:58 +01:00
|
|
|
input_display_list = [ new Inspector_Sprite(s_MKFX), 0, 8,
|
2024-01-29 14:33:55 +01:00
|
|
|
["Shape", false], 9, 3, 4, 10, 11,
|
|
|
|
["Lifespan", false, 14], 15, 13, 16,
|
|
|
|
["Effect", false], 2, 1, 7,
|
2024-01-31 11:34:12 +01:00
|
|
|
["Render", false], 5, 6, 17,
|
2023-11-30 13:07:08 +01:00
|
|
|
];
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2023-12-01 05:49:44 +01:00
|
|
|
static step = function() { #region
|
2023-11-30 13:07:08 +01:00
|
|
|
var _shap = getSingleValue(9);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[ 3].setVisible(_shap == 0);
|
|
|
|
inputs[ 4].setVisible(_shap == 0);
|
|
|
|
inputs[10].setVisible(_shap == 1);
|
|
|
|
inputs[11].setVisible(_shap == 2);
|
|
|
|
inputs[17].setVisible(_shap == 0);
|
2023-12-01 05:49:44 +01:00
|
|
|
} #endregion
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2023-12-01 05:49:44 +01:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
|
2023-11-30 13:07:08 +01:00
|
|
|
var _surf = _data[0];
|
|
|
|
var _dirr = _data[1];
|
|
|
|
var _dens = _data[2];
|
|
|
|
var _rwid = _data[3];
|
|
|
|
var _rhei = _data[4];
|
|
|
|
var _colr = _data[5];
|
|
|
|
var _alph = _data[6];
|
|
|
|
var _velo = _data[7];
|
|
|
|
var _seed = _data[8];
|
|
|
|
var _shap = _data[9];
|
|
|
|
var _snws = _data[10];
|
2023-12-01 05:49:44 +01:00
|
|
|
var _text = _data[11];
|
2023-12-15 12:56:36 +01:00
|
|
|
var _trex = _data[12];
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
var _llif = _data[13];
|
|
|
|
var _liml = _data[14];
|
|
|
|
var _life = _data[15];
|
|
|
|
var _alif = _data[16];
|
|
|
|
|
2024-01-31 11:34:12 +01:00
|
|
|
var _afad = _data[17];
|
|
|
|
|
2023-11-30 13:07:08 +01:00
|
|
|
if(!is_surface(_surf)) return _outSurf;
|
2023-12-01 05:49:44 +01:00
|
|
|
if(_shap == 2 && !is_surface(_text)) return _outSurf;
|
2023-11-30 13:07:08 +01:00
|
|
|
|
|
|
|
var _sw = surface_get_width_safe(_surf);
|
|
|
|
var _sh = surface_get_height_safe(_surf);
|
2023-12-01 05:49:44 +01:00
|
|
|
var _tw = surface_get_width_safe(_text);
|
|
|
|
var _th = surface_get_height_safe(_text);
|
|
|
|
|
2023-11-30 13:07:08 +01:00
|
|
|
var _rad = sqrt(_sw * _sw + _sh * _sh) / 2;
|
|
|
|
var _rx = _sw / 2;
|
|
|
|
var _ry = _sh / 2;
|
|
|
|
|
|
|
|
var _tr_span_x = lengthdir_x(1, _dirr);
|
|
|
|
var _tr_span_y = lengthdir_y(1, _dirr);
|
|
|
|
|
2023-12-01 05:49:44 +01:00
|
|
|
var _in_span_x = lengthdir_x(1, _dirr + 90);
|
|
|
|
var _in_span_y = lengthdir_y(1, _dirr + 90);
|
|
|
|
|
|
|
|
var prg = CURRENT_FRAME / TOTAL_FRAMES;
|
|
|
|
|
|
|
|
var _1c = array_length(_colr.keys) == 1;
|
|
|
|
var _cc = _1c? _colr.eval(0) : _colr;
|
|
|
|
|
|
|
|
draw_set_circle_precision(32);
|
2023-11-30 13:07:08 +01:00
|
|
|
surface_set_target(_outSurf);
|
|
|
|
DRAW_CLEAR
|
|
|
|
|
2024-07-10 03:45:25 +02:00
|
|
|
draw_surface_safe(_surf);
|
2024-01-31 11:34:12 +01:00
|
|
|
var _lcc = _cc;
|
|
|
|
|
|
|
|
if(_afad) BLEND_ADD
|
|
|
|
else BLEND_ALPHA_MULP
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2023-12-01 05:49:44 +01:00
|
|
|
repeat(_dens) {
|
2023-12-15 12:56:36 +01:00
|
|
|
random_set_seed(_seed); _seed += 100;
|
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
var _velRaw = random_range(_velo[0], _velo[1]);
|
|
|
|
_velRaw = max(1, _velRaw);
|
|
|
|
|
2024-01-16 09:56:20 +01:00
|
|
|
var _vel = _velRaw < 1? _velRaw : floor(_velRaw);
|
|
|
|
var _vex = _velRaw < 1? 0 : frac(_velRaw);
|
|
|
|
|
|
|
|
var _rrad = _rad * (1 + _vex);
|
|
|
|
var _r_shf = random_range( -_rad, _rad);
|
2023-12-15 12:56:36 +01:00
|
|
|
var _y_shf = random(1);
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2023-12-01 05:49:44 +01:00
|
|
|
var _drpW, _drpH, _drpS;
|
2023-11-30 13:07:08 +01:00
|
|
|
switch(_shap) {
|
|
|
|
case 0 :
|
|
|
|
_drpW = irandom_range(_rwid[0], _rwid[1]);
|
|
|
|
_drpH = irandom_range(_rhei[0], _rhei[1]);
|
|
|
|
break;
|
|
|
|
case 1 :
|
|
|
|
_drpW = random_range(_snws[0], _snws[1]);
|
|
|
|
_drpH = _drpW;
|
|
|
|
break;
|
2023-12-01 05:49:44 +01:00
|
|
|
case 2 :
|
|
|
|
_drpW = _tw;
|
|
|
|
_drpH = _th;
|
|
|
|
break;
|
2023-11-30 13:07:08 +01:00
|
|
|
}
|
|
|
|
|
2023-12-01 05:49:44 +01:00
|
|
|
var _rmx = _rx + _in_span_x * _r_shf;
|
|
|
|
var _rmy = _ry + _in_span_y * _r_shf;
|
|
|
|
|
2023-12-15 12:56:36 +01:00
|
|
|
var _radH = _rrad + _drpH;
|
2023-12-01 05:49:44 +01:00
|
|
|
var _radHx = _radH * _tr_span_x;
|
|
|
|
var _radHy = _radH * _tr_span_y;
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2023-12-01 05:49:44 +01:00
|
|
|
var _prg = _y_shf + _vel * prg;
|
2024-01-29 14:33:55 +01:00
|
|
|
_prg = frac(_prg) - 0.5; // -0.5 - 0.5
|
2023-12-01 05:49:44 +01:00
|
|
|
|
2024-01-31 11:34:12 +01:00
|
|
|
if(!_1c) _lcc = _colr.eval(random(1));
|
2024-01-29 14:33:55 +01:00
|
|
|
var _aa = random_range(_alph[0], _alph[1]);
|
2023-11-30 13:07:08 +01:00
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
var _clife = clamp((_prg + 0.5) / random_range(_life[0], _life[1]), 0, 1);
|
|
|
|
var _scaL = 1;
|
|
|
|
var _aaL = 1;
|
2024-01-16 09:56:20 +01:00
|
|
|
|
2024-01-29 14:33:55 +01:00
|
|
|
if(_liml) {
|
|
|
|
_scaL = eval_curve_x(_llif, _clife);
|
|
|
|
_aaL = eval_curve_x(_alif, _clife);
|
|
|
|
}
|
|
|
|
|
2024-01-31 11:34:12 +01:00
|
|
|
draw_set_color(_lcc);
|
2024-01-29 14:33:55 +01:00
|
|
|
draw_set_alpha(_aa * _aaL);
|
|
|
|
|
|
|
|
var _drpX = _rmx - _prg * _radHx * 2;
|
|
|
|
var _drpY = _rmy - _prg * _radHy * 2;
|
|
|
|
|
|
|
|
switch(_shap) {
|
|
|
|
case 0 :
|
|
|
|
var _tr_span_w = _tr_span_x * _drpH; // rain drop x span
|
|
|
|
var _tr_span_h = _tr_span_y * _drpH; // rain drop y span
|
|
|
|
|
|
|
|
var _x0 = _drpX - _tr_span_w;
|
|
|
|
var _x1 = _x0 + _tr_span_w * 2 * _scaL;
|
|
|
|
|
|
|
|
var _y0 = _drpY - _tr_span_h;
|
|
|
|
var _y1 = _y0 + _tr_span_h * 2 * _scaL;
|
2023-12-01 05:49:44 +01:00
|
|
|
|
2024-01-31 11:34:12 +01:00
|
|
|
if(_afad) {
|
|
|
|
if(_drpW == 1) draw_line_color( _x0, _y0, _x1, _y1, _lcc, c_black );
|
|
|
|
else draw_line_width_color( _x0, _y0, _x1, _y1, _drpW, _lcc, c_black );
|
|
|
|
} else {
|
|
|
|
if(_drpW == 1) draw_line( _x0, _y0, _x1, _y1 );
|
|
|
|
else draw_line_width( _x0, _y0, _x1, _y1, _drpW );
|
|
|
|
}
|
2024-01-29 14:33:55 +01:00
|
|
|
break;
|
|
|
|
case 1 :
|
|
|
|
draw_circle(_drpX, _drpY, _drpW * _scaL, false);
|
|
|
|
break;
|
|
|
|
case 2 :
|
|
|
|
draw_surface_ext(_text, _drpX, _drpY, _scaL, _scaL, 0, draw_get_color(), draw_get_alpha());
|
|
|
|
break;
|
2023-11-30 13:07:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_set_alpha(1);
|
|
|
|
BLEND_NORMAL
|
|
|
|
surface_reset_target();
|
|
|
|
|
|
|
|
return _outSurf;
|
2023-12-01 05:49:44 +01:00
|
|
|
} #endregion
|
2023-11-30 13:07:08 +01:00
|
|
|
}
|