2022-01-13 05:24:03 +01:00
|
|
|
enum LIGHT_SHAPE_2D {
|
|
|
|
point,
|
2024-10-02 10:26:08 +02:00
|
|
|
ellipse,
|
2022-01-13 05:24:03 +01:00
|
|
|
line,
|
|
|
|
line_asym,
|
2024-10-02 10:26:08 +02:00
|
|
|
saber,
|
2024-10-01 10:15:07 +02:00
|
|
|
spot,
|
2024-10-02 10:26:08 +02:00
|
|
|
flame,
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2023-01-25 06:49:00 +01:00
|
|
|
name = "2D Light";
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Surface("Surface in", self));
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-10-03 05:00:55 +02:00
|
|
|
typeList = [
|
|
|
|
new scrollItem("Point", s_node_2d_light_shape, 0),
|
|
|
|
new scrollItem("Ellipse", s_node_2d_light_shape, 1),
|
|
|
|
new scrollItem("Line", s_node_2d_light_shape, 2),
|
|
|
|
new scrollItem("Line asymmetric", s_node_2d_light_shape, 3),
|
|
|
|
new scrollItem("Saber", s_node_2d_light_shape, 4),
|
|
|
|
new scrollItem("Spot", s_node_2d_light_shape, 5),
|
|
|
|
new scrollItem("Flame", s_node_2d_light_shape, 6),
|
|
|
|
];
|
|
|
|
typeListStr = array_create_ext(array_length(typeList), function(i) /*=>*/ {return typeList[i].name});
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
static createNewInput = function() {
|
|
|
|
var _index = array_length(inputs);
|
2024-10-03 08:09:27 +02:00
|
|
|
dynamic_input_inspecting = getInputAmount();
|
2024-10-01 13:43:37 +02:00
|
|
|
|
2024-10-02 10:26:08 +02:00
|
|
|
var _val = nodeValue_Enum_Scroll("Light shape", self, 0, typeList);
|
|
|
|
_val.options_histories = [ typeListStr,
|
|
|
|
{
|
2024-11-02 05:13:45 +01:00
|
|
|
cond: function() /*=>*/ {return LOADING_VERSION < 1_18_00_0 && !CLONING},
|
2024-10-02 10:26:08 +02:00
|
|
|
list: [ "Point", "Line", "Line asymmetric", "Spot" ]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
newInput(_index + 0, _val);
|
2024-10-01 13:43:37 +02:00
|
|
|
|
|
|
|
newInput(_index + 1, nodeValue_Vec2("Center", self, [ 16, 16 ]))
|
|
|
|
.setUnitRef(function(index) { return getDimension(index); });
|
|
|
|
|
|
|
|
newInput(_index + 2, nodeValue_Float("Range", self, 16));
|
|
|
|
|
|
|
|
newInput(_index + 3, nodeValue_Float("Intensity", self, 1))
|
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 4, 0.01 ]});
|
|
|
|
|
|
|
|
newInput(_index + 4, nodeValue_Color("Color", self, c_white));
|
|
|
|
|
|
|
|
newInput(_index + 5, nodeValue_Vec2("Start", self, [ 16, 16 ]));
|
|
|
|
|
|
|
|
newInput(_index + 6, nodeValue_Vec2("Finish", self, [ 32, 16 ]));
|
|
|
|
|
|
|
|
newInput(_index + 7, nodeValue_Int("Sweep", self, 15))
|
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [-80, 80, 0.1] });
|
|
|
|
|
|
|
|
newInput(_index + 8, nodeValue_Int("Sweep end", self, 0))
|
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [-80, 80, 0.1] });
|
|
|
|
|
|
|
|
newInput(_index + 9, nodeValue_Int("Banding", self, 0))
|
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 16, 0.1] });
|
|
|
|
|
|
|
|
newInput(_index + 10, nodeValue_Enum_Scroll("Attenuation", self, 0, [ new scrollItem("Quadratic", s_node_curve, 0),
|
|
|
|
new scrollItem("Invert quadratic", s_node_curve, 1),
|
|
|
|
new scrollItem("Linear", s_node_curve, 2), ]))
|
|
|
|
.setTooltip("Control how light fade out over distance.");
|
|
|
|
|
|
|
|
newInput(_index + 11, nodeValue_Int("Radial banding", self, 0))
|
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 16, 0.1] });
|
|
|
|
|
|
|
|
newInput(_index + 12, nodeValue_Rotation("Radial start", self, 0));
|
|
|
|
|
|
|
|
newInput(_index + 13, nodeValue_Float("Radial band ratio", self, 0.5))
|
|
|
|
.setDisplay(VALUE_DISPLAY.slider);
|
|
|
|
|
|
|
|
newInput(_index + 14, nodeValue_Bool("Active", self, true));
|
|
|
|
|
|
|
|
newInput(_index + 15, nodeValue_Float("Radius x", self, 16));
|
|
|
|
|
|
|
|
newInput(_index + 16, nodeValue_Float("Radius y", self, 16));
|
|
|
|
|
|
|
|
newInput(_index + 17, nodeValue_Rotation("Rotation", self, 0));
|
|
|
|
|
|
|
|
newInput(_index + 18, nodeValue_Float("Exponent", self, 2));
|
|
|
|
|
|
|
|
newInput(_index + 19, nodeValue_Bool("Anti aliasing", self, false));
|
|
|
|
|
|
|
|
newInput(_index + 20, nodeValue_Bool("Two sides", self, false));
|
|
|
|
|
2024-10-02 10:26:08 +02:00
|
|
|
newInput(_index + 21, nodeValue_Float("Thickness", self, 2));
|
|
|
|
|
2024-10-03 08:09:27 +02:00
|
|
|
refreshDynamicDisplay();
|
2024-10-01 13:43:37 +02:00
|
|
|
return inputs[_index];
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
|
2024-10-03 05:00:55 +02:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
newOutput(1, nodeValue_Output("Light only", self, VALUE_TYPE.surface, noone));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
lights_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
|
|
|
|
|
|
|
|
var bs = ui(24);
|
2024-10-02 10:26:08 +02:00
|
|
|
var bx = _x + ui(20);
|
|
|
|
var by = _y;
|
2024-10-01 13:43:37 +02:00
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, bs, bs, _m, _focus, _hover, "", THEME.add_16, 0, COLORS._main_value_positive) == 2) {
|
|
|
|
createNewInput();
|
|
|
|
triggerRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
var amo = getInputAmount();
|
|
|
|
var lh = ui(28);
|
2024-10-03 08:09:27 +02:00
|
|
|
var _h = ui(12) + lh * amo;
|
2024-10-01 13:43:37 +02:00
|
|
|
var yy = _y + bs + ui(4);
|
|
|
|
|
|
|
|
var del_light = -1;
|
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, yy, _w, _h, COLORS.node_composite_bg_blend, 1);
|
|
|
|
|
|
|
|
for(var i = 0; i < amo; i++) {
|
2024-10-02 10:26:08 +02:00
|
|
|
var _x0 = _x + ui(24);
|
2024-10-01 13:43:37 +02:00
|
|
|
var _x1 = _x + _w - ui(16);
|
2024-10-03 08:09:27 +02:00
|
|
|
var _yy = ui(6) + yy + i * lh + lh / 2;
|
2024-10-01 13:43:37 +02:00
|
|
|
|
|
|
|
var _ind = input_fix_len + i * data_length;
|
|
|
|
var _typ = current_data[_ind + 0];
|
2024-10-04 10:14:12 +02:00
|
|
|
var _col = current_data[_ind + 4];
|
|
|
|
|
2024-10-03 08:09:27 +02:00
|
|
|
var tc = i == dynamic_input_inspecting? COLORS._main_text_accent : COLORS._main_icon;
|
2024-10-01 13:43:37 +02:00
|
|
|
var hov = _hover && point_in_rectangle(_m[0], _m[1], _x0, _yy - lh / 2, _x1, _yy + lh / 2 - 1);
|
|
|
|
|
|
|
|
if(hov && _m[0] < _x1 - ui(32)) {
|
|
|
|
tc = COLORS._main_text;
|
|
|
|
|
|
|
|
if(mouse_press(mb_left, _focus)) {
|
2024-10-03 08:09:27 +02:00
|
|
|
dynamic_input_inspecting = i;
|
|
|
|
refreshDynamicDisplay();
|
2024-10-01 13:43:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-04 10:14:12 +02:00
|
|
|
draw_sprite_ext(s_node_2d_light_shape, _typ, _x0 + ui(8), _yy, 1, 1, 0, _col, .5 + .5 * (i == dynamic_input_inspecting));
|
2024-10-01 13:43:37 +02:00
|
|
|
|
|
|
|
draw_set_text(f_p2, fa_left, fa_center, tc);
|
2024-10-02 10:26:08 +02:00
|
|
|
draw_text_add(_x0 + ui(28), _yy, typeListStr[_typ]);
|
2024-10-01 13:43:37 +02:00
|
|
|
|
2024-10-02 10:26:08 +02:00
|
|
|
if(amo > 1) {
|
2024-10-01 13:43:37 +02:00
|
|
|
var bs = ui(24);
|
|
|
|
var bx = _x1 - bs;
|
|
|
|
var by = _yy - bs / 2;
|
2024-10-02 10:26:08 +02:00
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, bs, bs, _m, _focus, _hover, "", THEME.minus_16, 0, hov? COLORS._main_value_negative : COLORS._main_icon) == 2)
|
|
|
|
del_light = i;
|
2024-10-01 13:43:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(del_light > -1)
|
2024-10-03 08:09:27 +02:00
|
|
|
deleteDynamicInput(del_light);
|
2024-10-01 13:43:37 +02:00
|
|
|
|
|
|
|
return ui(32) + _h;
|
|
|
|
});
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-10-03 08:09:27 +02:00
|
|
|
input_display_dynamic = [ // 14,
|
2024-10-02 10:26:08 +02:00
|
|
|
["Shape", false], 0, 1, 5, 6, 7, 8, 15, 16, 17, 20, 21,
|
2024-10-01 13:43:37 +02:00
|
|
|
["Light", false], 2, 3, 4, 11, 12, 13,
|
|
|
|
["Render", false], 10, 9, 18, 19,
|
|
|
|
];
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
input_display_list = [ 0, lights_renderer ];
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2024-10-02 10:26:08 +02:00
|
|
|
setDynamicInput(22, false);
|
2024-10-01 13:43:37 +02:00
|
|
|
if(!LOADING && !APPENDING) createNewInput();
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-10-04 10:14:12 +02:00
|
|
|
attribute_surface_depth();
|
|
|
|
temp_surface = [ 0, 0, 0 ];
|
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
2024-05-10 04:01:14 +02:00
|
|
|
PROCESSOR_OVERLAY_CHECK
|
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
if(getInputAmount() == 0) return;
|
|
|
|
|
2024-10-03 08:09:27 +02:00
|
|
|
dynamic_input_inspecting = clamp(dynamic_input_inspecting, 0, getInputAmount() - 1);
|
|
|
|
var _ind = input_fix_len + dynamic_input_inspecting * data_length;
|
2024-10-01 13:43:37 +02:00
|
|
|
|
|
|
|
var _shape = current_data[_ind + 0];
|
2024-07-02 12:18:32 +02:00
|
|
|
var _hov = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-10-02 10:26:08 +02:00
|
|
|
draw_set_circle_precision(64);
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
switch(_shape) {
|
|
|
|
case LIGHT_SHAPE_2D.point :
|
2024-10-01 13:43:37 +02:00
|
|
|
var pos = current_data[_ind + 1];
|
|
|
|
var rad = current_data[_ind + 2];
|
2024-10-01 10:15:07 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
var px = _x + pos[0] * _s;
|
|
|
|
var py = _y + pos[1] * _s;
|
2024-10-01 10:15:07 +02:00
|
|
|
|
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
draw_set_alpha(0.5);
|
|
|
|
draw_circle_dash(px, py, rad * _s, 1, 8);
|
|
|
|
draw_set_alpha(1);
|
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
var hv = inputs[_ind + 1].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
|
|
|
var hv = inputs[_ind + 2].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
2022-01-13 05:24:03 +01:00
|
|
|
break;
|
2024-10-01 10:15:07 +02:00
|
|
|
|
|
|
|
case LIGHT_SHAPE_2D.ellipse :
|
2024-10-01 13:43:37 +02:00
|
|
|
var pos = current_data[_ind + 1];
|
|
|
|
var rdx = current_data[_ind + 15];
|
|
|
|
var rdy = current_data[_ind + 16];
|
|
|
|
var ang = current_data[_ind + 17];
|
2024-10-01 10:15:07 +02:00
|
|
|
|
|
|
|
var px = _x + pos[0] * _s;
|
|
|
|
var py = _y + pos[1] * _s;
|
|
|
|
|
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
draw_set_alpha(0.5);
|
|
|
|
draw_ellipse_dash(px, py, rdx * _s, rdy * _s, 1, 8, ang);
|
|
|
|
draw_set_alpha(1);
|
2024-09-19 07:36:57 +02:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
var hv = inputs[_ind + 1].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
|
|
|
var hv = inputs[_ind + 15].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny, ang); _hov |= bool(hv); hover &= !hv;
|
|
|
|
var hv = inputs[_ind + 16].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny, ang + 90); _hov |= bool(hv); hover &= !hv;
|
|
|
|
var hv = inputs[_ind + 17].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
2024-10-01 10:15:07 +02:00
|
|
|
break;
|
|
|
|
|
2024-10-02 10:26:08 +02:00
|
|
|
case LIGHT_SHAPE_2D.line :
|
2022-01-13 05:24:03 +01:00
|
|
|
case LIGHT_SHAPE_2D.line_asym :
|
2024-10-02 10:26:08 +02:00
|
|
|
case LIGHT_SHAPE_2D.spot :
|
|
|
|
case LIGHT_SHAPE_2D.flame :
|
2024-10-01 13:43:37 +02:00
|
|
|
var hv = inputs[_ind + 5].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
|
|
|
var hv = inputs[_ind + 6].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
2022-01-13 05:24:03 +01:00
|
|
|
break;
|
2024-10-02 10:26:08 +02:00
|
|
|
|
|
|
|
case LIGHT_SHAPE_2D.saber :
|
|
|
|
var hv = inputs[_ind + 5].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
|
|
|
var hv = inputs[_ind + 6].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
|
|
|
|
|
|
|
var pos = current_data[_ind + 5];
|
|
|
|
var rad = current_data[_ind + 2];
|
|
|
|
var thk = current_data[_ind + 21];
|
|
|
|
|
|
|
|
var px = _x + pos[0] * _s;
|
|
|
|
var py = _y + pos[1] * _s;
|
|
|
|
|
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
draw_set_alpha(0.5);
|
|
|
|
draw_circle(px, py, thk * _s, 1);
|
|
|
|
draw_circle_dash(px, py, rad * _s, 1, 8);
|
|
|
|
draw_set_alpha(1);
|
|
|
|
|
|
|
|
inputs[_ind + 21].overlay_text_valign = fa_bottom;
|
|
|
|
var hv = inputs[_ind + 2].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
|
|
|
var hv = inputs[_ind + 21].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
|
|
|
|
break;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2024-07-02 12:18:32 +02:00
|
|
|
|
|
|
|
return _hov;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
static applyLight = function(_data, _ind, _lightSurf) {
|
|
|
|
var _surf = _data[0];
|
|
|
|
var _dim = surface_get_dimension(_surf);
|
|
|
|
|
|
|
|
var _shape = _data[_ind + 0];
|
|
|
|
var _pos = _data[_ind + 1];
|
|
|
|
var _range = _data[_ind + 2];
|
|
|
|
var _inten = _data[_ind + 3];
|
|
|
|
var _color = _data[_ind + 4];
|
|
|
|
|
|
|
|
var _start = _data[_ind + 5];
|
|
|
|
var _finis = _data[_ind + 6];
|
|
|
|
var _sweep = _data[_ind + 7];
|
|
|
|
var _swep2 = _data[_ind + 8];
|
|
|
|
|
|
|
|
var _band = _data[_ind + 9];
|
|
|
|
var _attn = _data[_ind + 10];
|
|
|
|
var _rbnd = _data[_ind + 11];
|
|
|
|
var _rbns = _data[_ind + 12];
|
|
|
|
var _rbnr = _data[_ind + 13];
|
|
|
|
|
2024-10-21 04:42:37 +02:00
|
|
|
var _rngx = _data[_ind + 15];
|
|
|
|
var _rngy = _data[_ind + 16];
|
|
|
|
var _anng = _data[_ind + 17];
|
2024-10-01 13:43:37 +02:00
|
|
|
|
|
|
|
var _expo = _data[_ind + 18];
|
|
|
|
var _aa = _data[_ind + 19];
|
|
|
|
var _both = _data[_ind + 20];
|
2024-10-02 10:26:08 +02:00
|
|
|
var _thick = _data[_ind + 21];
|
2024-10-01 13:43:37 +02:00
|
|
|
|
|
|
|
surface_set_shader(temp_surface[0], noone);
|
|
|
|
draw_clear(c_black);
|
|
|
|
BLEND_ADD
|
|
|
|
|
|
|
|
draw_set_circle_precision(64);
|
|
|
|
|
|
|
|
switch(_shape) {
|
|
|
|
case LIGHT_SHAPE_2D.point :
|
|
|
|
if(_rbnd < 2)
|
|
|
|
draw_circle_color(_pos[0], _pos[1], _range, c_white, c_black, 0);
|
|
|
|
else {
|
|
|
|
_rbnd *= 2;
|
|
|
|
var bnd_amo = ceil(64 / _rbnd); //band radial per step
|
|
|
|
var step = bnd_amo * _rbnd;
|
|
|
|
var astp = 360 / step;
|
|
|
|
var ox, oy, nx, ny;
|
|
|
|
|
|
|
|
draw_primitive_begin(pr_trianglelist);
|
|
|
|
|
|
|
|
for( var i = 0; i <= step; i++ ) {
|
|
|
|
var dir = _rbns + i * astp;
|
|
|
|
nx = _pos[0] + lengthdir_x(_range, dir);
|
|
|
|
ny = _pos[1] + lengthdir_y(_range, dir);
|
|
|
|
|
|
|
|
if(safe_mod(i, bnd_amo) / bnd_amo < _rbnr && i) {
|
|
|
|
draw_vertex_color(_pos[0], _pos[1], c_white, 1);
|
|
|
|
draw_vertex_color(ox, oy, c_black, 1);
|
|
|
|
draw_vertex_color(nx, ny, c_black, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_primitive_end();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIGHT_SHAPE_2D.ellipse :
|
|
|
|
draw_ellipse_angle_color(_pos[0], _pos[1], _rngx, _rngy, _anng, c_white, c_black);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIGHT_SHAPE_2D.line :
|
|
|
|
case LIGHT_SHAPE_2D.line_asym :
|
|
|
|
var dir = point_direction(_start[0], _start[1], _finis[0], _finis[1]) + 90;
|
|
|
|
|
|
|
|
var _r = _range / dcos(_sweep);
|
|
|
|
var sq0 = dir + _sweep;
|
|
|
|
var sq1 = dir - ((_shape == LIGHT_SHAPE_2D.line_asym)? _swep2 : _sweep);
|
|
|
|
|
|
|
|
draw_primitive_begin(pr_trianglestrip);
|
|
|
|
draw_vertex_color(_start[0], _start[1], c_white, 1);
|
|
|
|
draw_vertex_color(_finis[0], _finis[1], c_white, 1);
|
|
|
|
draw_vertex_color(_start[0] + lengthdir_x(_r, sq0), _start[1] + lengthdir_y(_r, sq0), c_black, 1);
|
|
|
|
draw_vertex_color(_finis[0] + lengthdir_x(_r, sq1), _finis[1] + lengthdir_y(_r, sq1), c_black, 1);
|
|
|
|
draw_primitive_end();
|
|
|
|
|
|
|
|
if(_both) {
|
|
|
|
var sq0 = 180 + dir - _sweep;
|
|
|
|
var sq1 = 180 + dir + ((_shape == LIGHT_SHAPE_2D.line_asym)? _swep2 : _sweep);
|
|
|
|
|
|
|
|
draw_primitive_begin(pr_trianglestrip);
|
|
|
|
draw_vertex_color(_start[0], _start[1], c_white, 1);
|
|
|
|
draw_vertex_color(_finis[0], _finis[1], c_white, 1);
|
|
|
|
draw_vertex_color(_start[0] + lengthdir_x(_r, sq0), _start[1] + lengthdir_y(_r, sq0), c_black, 1);
|
|
|
|
draw_vertex_color(_finis[0] + lengthdir_x(_r, sq1), _finis[1] + lengthdir_y(_r, sq1), c_black, 1);
|
|
|
|
draw_primitive_end();
|
|
|
|
|
|
|
|
}
|
2024-10-02 10:26:08 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LIGHT_SHAPE_2D.saber :
|
|
|
|
draw_set_color(c_white);
|
|
|
|
draw_line_round(_start[0], _start[1], _finis[0], _finis[1], _thick * 2, true, true, 64);
|
|
|
|
|
|
|
|
var _r = _range + _thick;
|
|
|
|
var dir = point_direction(_start[0], _start[1], _finis[0], _finis[1]) + 90;
|
|
|
|
|
|
|
|
draw_primitive_begin(pr_trianglestrip);
|
|
|
|
draw_vertex_color(_start[0], _start[1], c_white, 1);
|
|
|
|
draw_vertex_color(_finis[0], _finis[1], c_white, 1);
|
|
|
|
draw_vertex_color(_start[0] + lengthdir_x(_r, dir), _start[1] + lengthdir_y(_r, dir), c_black, 1);
|
|
|
|
draw_vertex_color(_finis[0] + lengthdir_x(_r, dir), _finis[1] + lengthdir_y(_r, dir), c_black, 1);
|
|
|
|
draw_primitive_end();
|
|
|
|
|
|
|
|
draw_primitive_begin(pr_trianglelist);
|
|
|
|
var ox, oy, nx, ny;
|
|
|
|
for( var i = 0; i <= 90; i++ ) {
|
|
|
|
var _d = dir + i * 2;
|
|
|
|
nx = _start[0] + lengthdir_x(_r, _d);
|
|
|
|
ny = _start[1] + lengthdir_y(_r, _d);
|
|
|
|
|
|
|
|
if(i) {
|
|
|
|
draw_vertex_color(_start[0], _start[1], c_white, 1);
|
|
|
|
draw_vertex_color(ox, oy, c_black, 1);
|
|
|
|
draw_vertex_color(nx, ny, c_black, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
}
|
|
|
|
draw_primitive_end();
|
|
|
|
|
|
|
|
dir += 180;
|
|
|
|
draw_primitive_begin(pr_trianglestrip);
|
|
|
|
draw_vertex_color(_start[0], _start[1], c_white, 1);
|
|
|
|
draw_vertex_color(_finis[0], _finis[1], c_white, 1);
|
|
|
|
draw_vertex_color(_start[0] + lengthdir_x(_r, dir), _start[1] + lengthdir_y(_r, dir), c_black, 1);
|
|
|
|
draw_vertex_color(_finis[0] + lengthdir_x(_r, dir), _finis[1] + lengthdir_y(_r, dir), c_black, 1);
|
|
|
|
draw_primitive_end();
|
|
|
|
|
|
|
|
draw_primitive_begin(pr_trianglelist);
|
|
|
|
var ox, oy, nx, ny;
|
|
|
|
for( var i = 0; i <= 90; i++ ) {
|
|
|
|
var _d = dir + i * 2;
|
|
|
|
nx = _finis[0] + lengthdir_x(_r, _d);
|
|
|
|
ny = _finis[1] + lengthdir_y(_r, _d);
|
|
|
|
|
|
|
|
if(i) {
|
|
|
|
draw_vertex_color(_finis[0], _finis[1], c_white, 1);
|
|
|
|
draw_vertex_color(ox, oy, c_black, 1);
|
|
|
|
draw_vertex_color(nx, ny, c_black, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
}
|
|
|
|
draw_primitive_end();
|
2024-10-01 13:43:37 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIGHT_SHAPE_2D.spot :
|
2024-10-02 10:26:08 +02:00
|
|
|
case LIGHT_SHAPE_2D.flame :
|
2024-10-01 13:43:37 +02:00
|
|
|
var dir = point_direction(_start[0], _start[1], _finis[0], _finis[1]);
|
|
|
|
var astr = dir - _sweep;
|
|
|
|
var aend = dir + _sweep;
|
2024-10-02 10:26:08 +02:00
|
|
|
var stp = 2;
|
2024-10-01 13:43:37 +02:00
|
|
|
var amo = ceil(_sweep * 2 / stp);
|
|
|
|
var ran = point_distance(_start[0], _start[1], _finis[0], _finis[1]);
|
2024-10-02 10:26:08 +02:00
|
|
|
var cc;
|
2024-10-01 13:43:37 +02:00
|
|
|
|
|
|
|
draw_primitive_begin(pr_trianglelist);
|
|
|
|
for( var i = 0; i < amo; i++ ) {
|
2024-10-02 10:26:08 +02:00
|
|
|
var a0 = clamp(astr + (i ) * stp, astr, aend);
|
2024-10-01 13:43:37 +02:00
|
|
|
var a1 = clamp(astr + (i + 1) * stp, astr, aend);
|
|
|
|
|
2024-10-02 10:26:08 +02:00
|
|
|
if(_shape == LIGHT_SHAPE_2D.spot)
|
|
|
|
cc = c_white;
|
|
|
|
else {
|
|
|
|
var aa = amo > 2? 1. - abs(i / (amo - 1) - .5) * 2 : 1;
|
|
|
|
cc = _make_color_rgb(aa, aa, aa);
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_vertex_color(_start[0], _start[1], cc, 1);
|
2024-10-01 13:43:37 +02:00
|
|
|
draw_vertex_color(_start[0] + lengthdir_x(ran, a0), _start[1] + lengthdir_y(ran, a0), c_black, 1);
|
|
|
|
draw_vertex_color(_start[0] + lengthdir_x(ran, a1), _start[1] + lengthdir_y(ran, a1), c_black, 1);
|
|
|
|
}
|
|
|
|
draw_primitive_end();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface_reset_shader();
|
|
|
|
|
|
|
|
var _ls = temp_surface[0];
|
|
|
|
|
|
|
|
surface_set_shader(temp_surface[1], sh_2d_light);
|
|
|
|
draw_clear(c_black);
|
|
|
|
|
|
|
|
shader_set_color("color", _color);
|
|
|
|
shader_set_f("intensity", _inten * _color_get_alpha(_color));
|
|
|
|
shader_set_f("band", _band);
|
|
|
|
shader_set_i("atten", _attn);
|
|
|
|
shader_set_f("exponent", _expo);
|
|
|
|
|
|
|
|
BLEND_OVERRIDE draw_surface_safe(_ls);
|
|
|
|
surface_reset_shader();
|
|
|
|
|
|
|
|
_ls = temp_surface[1];
|
|
|
|
|
|
|
|
if(_aa) {
|
|
|
|
surface_set_shader(temp_surface[2], sh_FXAA);
|
|
|
|
gpu_set_texfilter(true);
|
|
|
|
shader_set_2("dimension", _dim);
|
|
|
|
shader_set_f("cornerDis", 0.5);
|
|
|
|
shader_set_f("mixAmo", 1);
|
|
|
|
|
|
|
|
BLEND_OVERRIDE draw_surface_safe(_ls);
|
|
|
|
gpu_set_texfilter(false);
|
|
|
|
surface_reset_shader();
|
|
|
|
|
|
|
|
_ls = temp_surface[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
surface_set_target(_lightSurf);
|
|
|
|
BLEND_ADD
|
|
|
|
draw_surface_safe(_ls);
|
|
|
|
BLEND_NORMAL
|
|
|
|
surface_reset_target();
|
|
|
|
}
|
|
|
|
|
|
|
|
static processData = function(_outData, _data, _output_index, _array_index) {
|
|
|
|
var _surf = _data[0];
|
|
|
|
|
|
|
|
if(getInputAmount() == 0) return;
|
|
|
|
|
2024-10-02 10:26:08 +02:00
|
|
|
#region visibility
|
2024-10-03 08:09:27 +02:00
|
|
|
dynamic_input_inspecting = clamp(dynamic_input_inspecting, 0, getInputAmount() - 1);
|
|
|
|
var _ind = input_fix_len + dynamic_input_inspecting * data_length;
|
2024-10-02 10:26:08 +02:00
|
|
|
|
|
|
|
var _shape = _data[_ind + 0];
|
|
|
|
var _attn = _data[_ind + 10];
|
|
|
|
|
|
|
|
inputs[_ind + 1].setVisible(false);
|
|
|
|
inputs[_ind + 2].setVisible(false);
|
|
|
|
inputs[_ind + 5].setVisible(false);
|
|
|
|
inputs[_ind + 6].setVisible(false);
|
|
|
|
inputs[_ind + 7].setVisible(false);
|
|
|
|
inputs[_ind + 8].setVisible(false);
|
|
|
|
inputs[_ind + 11].setVisible(false);
|
|
|
|
inputs[_ind + 12].setVisible(false);
|
|
|
|
inputs[_ind + 13].setVisible(false);
|
|
|
|
inputs[_ind + 15].setVisible(false);
|
|
|
|
inputs[_ind + 16].setVisible(false);
|
|
|
|
inputs[_ind + 17].setVisible(false);
|
|
|
|
inputs[_ind + 20].setVisible(false);
|
|
|
|
inputs[_ind + 21].setVisible(false);
|
|
|
|
|
|
|
|
switch(_shape) {
|
|
|
|
case LIGHT_SHAPE_2D.point :
|
|
|
|
inputs[_ind + 1].setVisible(true);
|
|
|
|
inputs[_ind + 2].setVisible(true);
|
|
|
|
inputs[_ind + 11].setVisible(true);
|
|
|
|
inputs[_ind + 12].setVisible(true);
|
|
|
|
inputs[_ind + 13].setVisible(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIGHT_SHAPE_2D.ellipse :
|
|
|
|
inputs[_ind + 1].setVisible(true);
|
|
|
|
inputs[_ind + 15].setVisible(true);
|
|
|
|
inputs[_ind + 16].setVisible(true);
|
|
|
|
inputs[_ind + 17].setVisible(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIGHT_SHAPE_2D.line :
|
|
|
|
case LIGHT_SHAPE_2D.line_asym :
|
|
|
|
inputs[_ind + 2].setVisible(true);
|
|
|
|
inputs[_ind + 5].setVisible(true);
|
|
|
|
inputs[_ind + 6].setVisible(true);
|
|
|
|
inputs[_ind + 7].setVisible(true);
|
|
|
|
inputs[_ind + 8].setVisible(_shape == LIGHT_SHAPE_2D.line_asym);
|
|
|
|
inputs[_ind + 20].setVisible(true);
|
|
|
|
break;
|
2024-10-01 10:15:07 +02:00
|
|
|
|
2024-10-02 10:26:08 +02:00
|
|
|
case LIGHT_SHAPE_2D.saber :
|
|
|
|
inputs[_ind + 2].setVisible(true);
|
|
|
|
inputs[_ind + 5].setVisible(true);
|
|
|
|
inputs[_ind + 6].setVisible(true);
|
|
|
|
inputs[_ind + 21].setVisible(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIGHT_SHAPE_2D.spot :
|
|
|
|
case LIGHT_SHAPE_2D.flame :
|
|
|
|
inputs[_ind + 5].setVisible(true);
|
|
|
|
inputs[_ind + 6].setVisible(true);
|
|
|
|
inputs[_ind + 7].setVisible(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs[_ind + 18].setVisible(_attn == 0 || _attn == 1);
|
|
|
|
#endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
if(!is_surface(_surf)) return _outData;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
var _dim = surface_get_dimension(_surf);
|
|
|
|
var _outSurf = surface_verify(_outData[0], _dim[0], _dim[1]);
|
|
|
|
var _lightSurf = surface_verify(_outData[1], _dim[0], _dim[1]);
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
for( var i = 0, n = array_length(temp_surface); i < n; i++ )
|
|
|
|
temp_surface[i] = surface_verify(temp_surface[i], _dim[0], _dim[1]);
|
2024-10-01 10:15:07 +02:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
surface_set_target(_lightSurf);
|
|
|
|
draw_clear(c_black);
|
|
|
|
surface_reset_target();
|
2024-10-01 10:15:07 +02:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
for( var i = 0; i < getInputAmount(); i++ ) {
|
|
|
|
var _ind = input_fix_len + i * data_length;
|
|
|
|
applyLight(_data, _ind, _lightSurf);
|
2024-10-01 10:15:07 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
surface_set_target(_outSurf);
|
|
|
|
DRAW_CLEAR
|
|
|
|
BLEND_OVERRIDE draw_surface_safe(_surf);
|
|
|
|
BLEND_ADD draw_surface_safe(_lightSurf);
|
|
|
|
BLEND_NORMAL
|
2022-12-27 04:00:50 +01:00
|
|
|
surface_reset_target();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-10-01 13:43:37 +02:00
|
|
|
return [ _outSurf, _lightSurf ];
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|