[2D light] Add supports for multiple lights.

This commit is contained in:
Tanasart 2024-10-01 18:43:37 +07:00
parent fa2fe00eff
commit bcdf5d8786
11 changed files with 450 additions and 255 deletions

View File

@ -39,11 +39,11 @@
globalvar VERSION, SAVE_VERSION, VERSION_STRING, BUILD_NUMBER, LATEST_VERSION;
globalvar HOTKEYS, HOTKEY_CONTEXT;
LATEST_VERSION = 1_17_00;
VERSION = 1_17_12_0;
SAVE_VERSION = 1_17_10_0;
VERSION_STRING = MAC? "1.18.003m" : "1.18.1";
BUILD_NUMBER = 1_18_00_0;
LATEST_VERSION = 1_18_00;
VERSION = 1_18_00_0;
SAVE_VERSION = 1_18_00_0;
VERSION_STRING = MAC? "1.18.003m" : "1.18.1.001";
BUILD_NUMBER = 1_18_00_1;
HOTKEYS = ds_map_create();
HOTKEY_CONTEXT = ds_list_create();

View File

@ -8,83 +8,197 @@ enum LIGHT_SHAPE_2D {
function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "2D Light";
batch_output = false;
newInput(0, nodeValue_Surface("Surface in", self));
newInput(1, nodeValue_Enum_Scroll("Light shape", self, 0, [ new scrollItem("Point", s_node_2d_light_shape, 0),
new scrollItem("Line", s_node_2d_light_shape, 1),
new scrollItem("Line asymmetric", s_node_2d_light_shape, 2),
new scrollItem("Spot", s_node_2d_light_shape, 3),
new scrollItem("Ellipse", s_node_2d_light_shape, 4), ]));
light_inspecting = 0;
newInput(2, nodeValue_Vec2("Center", self, [ 16, 16 ]))
.setUnitRef(function(index) { return getDimension(index); });
newInput(3, nodeValue_Float("Range", self, 16));
newInput(4, nodeValue_Float("Intensity", self, 1))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 4, 0.01 ]});
newInput(5, nodeValue_Color("Color", self, c_white));
newInput(6, nodeValue_Vec2("Start", self, [ 16, 16 ]));
newInput(7, nodeValue_Vec2("Finish", self, [ 32, 16 ]));
newInput(8, nodeValue_Int("Sweep", self, 15))
.setDisplay(VALUE_DISPLAY.slider, { range: [-80, 80, 0.1] });
newInput(9, nodeValue_Int("Sweep end", self, 0))
.setDisplay(VALUE_DISPLAY.slider, { range: [-80, 80, 0.1] });
newInput(10, nodeValue_Int("Banding", self, 0))
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 16, 0.1] });
newInput(11, 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(12, nodeValue_Int("Radial banding", self, 0))
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 16, 0.1] });
newInput(13, nodeValue_Rotation("Radial start", self, 0));
newInput(14, nodeValue_Float("Radial band ratio", self, 0.5))
.setDisplay(VALUE_DISPLAY.slider);
newInput(15, nodeValue_Bool("Active", self, true));
active_index = 15;
static createNewInput = function() {
var _index = array_length(inputs);
light_inspecting = getInputAmount();
newInput(16, nodeValue_Float("Radius x", self, 16));
newInput(17, nodeValue_Float("Radius y", self, 16));
newInput(18, nodeValue_Rotation("Rotation", self, 0));
newInput(_index + 0, nodeValue_Enum_Scroll("Light shape", self, 0, [ new scrollItem("Point", s_node_2d_light_shape, 0),
new scrollItem("Line", s_node_2d_light_shape, 1),
new scrollItem("Line asymmetric", s_node_2d_light_shape, 2),
new scrollItem("Spot", s_node_2d_light_shape, 3),
new scrollItem("Ellipse", s_node_2d_light_shape, 4), ]));
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));
resetDisplay();
return inputs[_index];
}
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
newOutput(1, nodeValue_Output("Light only", self, VALUE_TYPE.surface, noone));
input_display_list = [ 15, 0,
["Shape", false], 1, 2, 6, 7, 8, 9, 16, 17, 18,
["Light", false], 3, 4, 5, 12, 13, 14,
["Render", false], 11, 10,
light_type_names = [
"Point light",
"Line light",
"Asymmetric line light",
"Spot light",
"Ellipse light",
];
attribute_surface_depth();
lights_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
var bx = _x;
var by = _y;
var bs = ui(24);
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);
var _h = ui(8) + lh * amo;
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++) {
var _x0 = ui(24);
var _x1 = _x + _w - ui(16);
var _yy = ui(4) + yy + i * lh + lh / 2;
var _ind = input_fix_len + i * data_length;
var _typ = current_data[_ind + 0];
var cc = i == light_inspecting? COLORS._main_text_accent : COLORS._main_icon;
var tc = i == light_inspecting? COLORS._main_text_accent : COLORS._main_icon;
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)) {
light_inspecting = i;
resetDisplay();
}
}
draw_sprite_ext(s_node_2d_light_shape, _typ, _x0 + ui(8), _yy, 1, 1, 0, cc);
draw_set_text(f_p2, fa_left, fa_center, tc);
draw_text_add(_x0 + ui(28), _yy, light_type_names[_typ]);
if(amo > 1 && hov) {
var bs = ui(24);
var bx = _x1 - bs;
var by = _yy - bs / 2;
if(buttonInstant(THEME.button_hide, bx, by, bs, bs, _m, _focus, _hover, "", THEME.minus_16, 0, COLORS._main_value_negative) == 2)
del_light = i;
}
}
if(del_light > -1)
deleteLight(del_light);
return ui(32) + _h;
});
input_display_light = [ // 14,
["Shape", false], 0, 1, 5, 6, 7, 8, 15, 16, 17, 20,
["Light", false], 2, 3, 4, 11, 12, 13,
["Render", false], 10, 9, 18, 19,
];
input_display_list = [ 0, lights_renderer ];
attribute_surface_depth();
temp_surface = [ 0, 0, 0 ];
static resetDisplay = function() {
input_display_list = array_clone(input_display_list_raw);
if(getInputAmount()) light_inspecting = clamp(light_inspecting, 0, getInputAmount() - 1);
var _ind = input_fix_len + light_inspecting * data_length;
for( var i = 0, n = array_length(input_display_light); i < n; i++ ) {
var v = input_display_light[i];
if(is_real(v)) v += _ind;
array_push(input_display_list, v);
}
}
setDynamicInput(21, false);
if(!LOADING && !APPENDING) createNewInput();
static deleteLight = function(index) {
var _ind = input_fix_len + index * data_length;
array_delete(inputs, _ind, data_length);
light_inspecting = clamp(light_inspecting, 0, getInputAmount() - 1);
resetDisplay();
triggerRender();
}
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
PROCESSOR_OVERLAY_CHECK
var _shape = current_data[1];
if(getInputAmount() == 0) return;
light_inspecting = clamp(light_inspecting, 0, getInputAmount() - 1);
var _ind = input_fix_len + light_inspecting * data_length;
var _shape = current_data[_ind + 0];
var _hov = false;
switch(_shape) {
case LIGHT_SHAPE_2D.point :
var pos = current_data[2];
var rad = current_data[3];
var pos = current_data[_ind + 1];
var rad = current_data[_ind + 2];
var px = _x + pos[0] * _s;
var py = _y + pos[1] * _s;
@ -94,15 +208,15 @@ function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
draw_circle_dash(px, py, rad * _s, 1, 8);
draw_set_alpha(1);
var hv = inputs[2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
var hv = inputs[3].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
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;
break;
case LIGHT_SHAPE_2D.ellipse :
var pos = current_data[ 2];
var rdx = current_data[16];
var rdy = current_data[17];
var ang = current_data[18];
var pos = current_data[_ind + 1];
var rdx = current_data[_ind + 15];
var rdy = current_data[_ind + 16];
var ang = current_data[_ind + 17];
var px = _x + pos[0] * _s;
var py = _y + pos[1] * _s;
@ -112,193 +226,276 @@ function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
draw_ellipse_dash(px, py, rdx * _s, rdy * _s, 1, 8, ang);
draw_set_alpha(1);
var hv = inputs[ 2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
var hv = inputs[16].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny, ang); _hov |= bool(hv); hover &= !hv;
var hv = inputs[17].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny, ang + 90); _hov |= bool(hv); hover &= !hv;
var hv = inputs[18].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
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;
break;
case LIGHT_SHAPE_2D.line :
case LIGHT_SHAPE_2D.line_asym :
case LIGHT_SHAPE_2D.spot :
var hv = inputs[6].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
var hv = inputs[7].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv); hover &= !hv;
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;
break;
}
return _hov;
}
static processData = function(_outSurf, _data, _output_index, _array_index) {
var _shape = _data[1];
static applyLight = function(_data, _ind, _lightSurf) {
var _surf = _data[0];
var _dim = surface_get_dimension(_surf);
inputs[ 2].setVisible(false);
inputs[ 3].setVisible(false);
inputs[ 6].setVisible(false);
inputs[ 7].setVisible(false);
inputs[ 8].setVisible(false);
inputs[ 9].setVisible(false);
inputs[12].setVisible(false);
inputs[13].setVisible(false);
inputs[14].setVisible(false);
inputs[16].setVisible(false);
inputs[17].setVisible(false);
inputs[18].setVisible(false);
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];
switch(_shape) {
case LIGHT_SHAPE_2D.point :
inputs[2].setVisible(true);
inputs[3].setVisible(true);
inputs[12].setVisible(true);
inputs[13].setVisible(true);
inputs[14].setVisible(true);
break;
case LIGHT_SHAPE_2D.ellipse :
inputs[2].setVisible(true);
inputs[16].setVisible(true);
inputs[17].setVisible(true);
inputs[18].setVisible(true);
break;
case LIGHT_SHAPE_2D.line :
case LIGHT_SHAPE_2D.line_asym :
inputs[3].setVisible(true);
inputs[6].setVisible(true);
inputs[7].setVisible(true);
inputs[8].setVisible(true);
inputs[9].setVisible(_shape == LIGHT_SHAPE_2D.line_asym);
break;
case LIGHT_SHAPE_2D.spot :
inputs[6].setVisible(true);
inputs[7].setVisible(true);
inputs[8].setVisible(true);
break;
}
var _start = _data[_ind + 5];
var _finis = _data[_ind + 6];
var _sweep = _data[_ind + 7];
var _swep2 = _data[_ind + 8];
var _range = _data[3];
var _inten = _data[4];
var _color = _data[5];
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];
var _pos = _data[2];
var _start = _data[6];
var _finis = _data[7];
var _sweep = _data[8];
var _swep2 = _data[9];
var _rngx = _data[_ind + 14];
var _rngy = _data[_ind + 15];
var _anng = _data[_ind + 16];
var _band = _data[10];
var _attn = _data[11];
var _expo = _data[_ind + 18];
var _aa = _data[_ind + 19];
var _both = _data[_ind + 20];
surface_set_target(_outSurf);
if(_output_index == 0) {
DRAW_CLEAR
draw_surface_safe(_data[0]);
} else
draw_clear_alpha(c_black, 1);
BLEND_ADD;
shader_set(sh_2d_light);
gpu_set_colorwriteenable(1, 1, 1, 0);
shader_set_color("color", _color);
shader_set_f("intensity", _inten * _color_get_alpha(_color));
shader_set_f("band", _band);
shader_set_f("atten", _attn);
draw_set_circle_precision(64);
switch(_shape) {
case LIGHT_SHAPE_2D.point :
var _rbnd = _data[12];
var _rbns = _data[13];
var _rbnr = _data[14];
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;
var banding = false;
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);
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;
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);
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;
}
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();
}
break;
case LIGHT_SHAPE_2D.spot :
var dir = point_direction(_start[0], _start[1], _finis[0], _finis[1]);
var astr = dir - _sweep;
var aend = dir + _sweep;
var stp = 3;
var amo = ceil(_sweep * 2 / stp);
var ran = point_distance(_start[0], _start[1], _finis[0], _finis[1]);
draw_primitive_begin(pr_trianglelist);
for( var i = 0; i < amo; i++ ) {
var a0 = clamp(astr + (i) * stp, astr, aend);
var a1 = clamp(astr + (i + 1) * stp, astr, aend);
draw_vertex_color(_start[0], _start[1], c_white, 1);
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;
break;
}
case LIGHT_SHAPE_2D.ellipse :
var _rngx = _data[16];
var _rngy = _data[17];
var _anng = _data[18];
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;
light_inspecting = clamp(light_inspecting, 0, getInputAmount() - 1);
var _ind = input_fix_len + light_inspecting * data_length;
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);
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;
draw_ellipse_angle_color(_pos[0], _pos[1], _rngx, _rngy, _anng, c_white, c_black);
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 :
var dir = point_direction(_start[0], _start[1], _finis[0], _finis[1]);
var sq0 = dir + 90 + _sweep;
var sq1 = dir + 90 - ((_shape == LIGHT_SHAPE_2D.line_asym)? _swep2 : _sweep);
var _r = _range / cos(degtorad(_sweep));
var st_sw = [ _start[0] + lengthdir_x(_r, sq0), _start[1] + lengthdir_y(_r, sq0) ];
var fn_sw = [ _finis[0] + lengthdir_x(_r, sq1), _finis[1] + lengthdir_y(_r, sq1) ];
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(st_sw[0], st_sw[1], c_black, 1);
draw_vertex_color(fn_sw[0], fn_sw[1], c_black, 1);
draw_primitive_end();
break;
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;
case LIGHT_SHAPE_2D.spot :
var dir = point_direction(_start[0], _start[1], _finis[0], _finis[1]);
var astr = dir - _sweep;
var aend = dir + _sweep;
var stp = 3;
var amo = ceil(_sweep * 2 / stp);
var ran = point_distance(_start[0], _start[1], _finis[0], _finis[1]);
draw_primitive_begin(pr_trianglelist);
for( var i = 0; i < amo; i++ ) {
var a0 = clamp(astr + (i) * stp, astr, aend);
var a1 = clamp(astr + (i + 1) * stp, astr, aend);
draw_vertex_color(_start[0], _start[1], c_white, 1);
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;
inputs[_ind + 5].setVisible(true);
inputs[_ind + 6].setVisible(true);
inputs[_ind + 7].setVisible(true);
break;
}
gpu_set_colorwriteenable(1, 1, 1, 1);
shader_reset();
BLEND_NORMAL;
inputs[_ind + 18].setVisible(_attn == 0 || _attn == 1);
/////////////////////////////////////////
if(!is_surface(_surf)) return _outData;
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]);
for( var i = 0, n = array_length(temp_surface); i < n; i++ )
temp_surface[i] = surface_verify(temp_surface[i], _dim[0], _dim[1]);
surface_set_target(_lightSurf);
draw_clear(c_black);
surface_reset_target();
for( var i = 0; i < getInputAmount(); i++ ) {
var _ind = input_fix_len + i * data_length;
applyLight(_data, _ind, _lightSurf);
}
surface_set_target(_outSurf);
DRAW_CLEAR
BLEND_OVERRIDE draw_surface_safe(_surf);
BLEND_ADD draw_surface_safe(_lightSurf);
BLEND_NORMAL
surface_reset_target();
return _outSurf;
return [ _outSurf, _lightSurf ];
}
static preDeserialize = function() {
// if(LOADING_VERSION < 1_18_00_0)
// load_map.data_length = 1;
}
}

View File

@ -2209,10 +2209,13 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
/////========== DESERIALIZE ==========
static deserialize = function(_map, scale = false, preset = false) {
load_map = _map;
load_scale = scale;
renamed = struct_try_get(load_map, "renamed", false);
preDeserialize();
if(!preset) {
if(APPENDING) APPEND_MAP[? load_map.id] = node_id;
else node_id = load_map.id;
@ -2305,7 +2308,7 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
if(createNewInput == noone)
return;
var _dynamic_inputs = (array_length(load_map.inputs) - input_fix_len) / data_length;
var _dynamic_inputs = ceil((array_length(load_map.inputs) - input_fix_len) / data_length);
repeat(_dynamic_inputs)
createNewInput();
}
@ -2315,6 +2318,7 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
}
static processDeserialize = function() {}
static preDeserialize = function() {}
static postDeserialize = function() {}
static applyDeserialize = function(preset = false) {

View File

@ -1,29 +1,23 @@
//
// Simple passthrough fragment shader
//
//varying vec2 v_vTexcoord;
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec4 color;
uniform float intensity;
uniform float band;
uniform float atten;
uniform int atten;
uniform float exponent;
void main() {
float bright = (v_vColour.r + v_vColour.b + v_vColour.g) / 3.;
bright = clamp(bright, 0., 1.);
if(atten == 0.)
bright = bright * bright;
else if(atten == 1.)
bright = 1. - (bright - 1.) * (bright - 1.);
else if(atten == 2.)
bright = bright;
vec4 samp = texture2D( gm_BaseTexture, v_vTexcoord);
float bright = (samp.r + samp.b + samp.g) / 3.;
if(atten == 0) bright = pow(bright, exponent);
else if(atten == 1) bright = 1. - pow(1. - bright, exponent);
else if(atten == 2) bright = bright;
bright *= intensity;
if(band > 0.)
bright = ceil(bright * band) / band;
if(band > 0.) bright = ceil(bright * band) / band;
gl_FragColor = color * bright;
gl_FragColor = vec4(color.rgb * bright, 1.);
}

View File

@ -4,9 +4,9 @@
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
//attribute vec2 in_TextureCoord; // (u,v)
attribute vec2 in_TextureCoord; // (u,v)
//varying vec2 v_vTexcoord;
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
@ -15,5 +15,5 @@ void main()
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
//v_vTexcoord = in_TextureCoord;
v_vTexcoord = in_TextureCoord;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

View File

@ -17,6 +17,7 @@
{"$GMSpriteFrame":"","%Name":"fe76a977-1573-4abb-94d3-9571afbd00e9","name":"fe76a977-1573-4abb-94d3-9571afbd00e9","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"014aa4b1-411b-42cd-bfbf-444fee6c9934","name":"014aa4b1-411b-42cd-bfbf-444fee6c9934","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"909e1d1a-83ba-4b6a-abb2-139b2769b8a5","name":"909e1d1a-83ba-4b6a-abb2-139b2769b8a5","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"0d97f314-4177-4118-9acc-b414e17b45b8","name":"0d97f314-4177-4118-9acc-b414e17b45b8","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
],
"gridX":0,
"gridY":0,
@ -53,7 +54,7 @@
},
"eventStubScript":null,
"eventToFunction":{},
"length":5.0,
"length":6.0,
"lockOrigin":false,
"moments":{
"$KeyframeStore<MomentsEventKeyframe>":"",
@ -87,6 +88,9 @@
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"909e1d1a-83ba-4b6a-abb2-139b2769b8a5","path":"sprites/s_node_2d_light_shape/s_node_2d_light_shape.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"2eaa440e-b483-4950-925b-c80a1c956a46","IsCreationKey":false,"Key":4.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"0d97f314-4177-4118-9acc-b414e17b45b8","path":"sprites/s_node_2d_light_shape/s_node_2d_light_shape.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"1977edc2-395d-46d2-b1bf-4a9451a8427f","IsCreationKey":false,"Key":5.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
],"resourceType":"KeyframeStore<SpriteFrameKeyframe>","resourceVersion":"2.0",},"modifiers":[],"name":"frames","resourceType":"GMSpriteFramesTrack","resourceVersion":"2.0","spriteId":null,"trackColour":0,"tracks":[],"traits":0,},
],
"visibleRange":null,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 B

View File

@ -2,9 +2,9 @@
"$GMSprite":"",
"%Name":"s_node_curve",
"bboxMode":0,
"bbox_bottom":165,
"bbox_left":0,
"bbox_right":23,
"bbox_bottom":20,
"bbox_left":3,
"bbox_right":21,
"bbox_top":3,
"collisionKind":1,
"collisionTolerance":0,
@ -13,11 +13,10 @@
"For3D":false,
"frames":[
{"$GMSpriteFrame":"","%Name":"bd7ad13c-f64a-4d4c-867f-ec4773fd2490","name":"bd7ad13c-f64a-4d4c-867f-ec4773fd2490","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"1a6ebc69-d2fa-4270-bbb4-fcf7fceeccae","name":"1a6ebc69-d2fa-4270-bbb4-fcf7fceeccae","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"dc773099-05a9-410a-8dd1-a5c1f68469a2","name":"dc773099-05a9-410a-8dd1-a5c1f68469a2","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"7a86ca18-ce47-423d-88e1-859c3cb27230","name":"7a86ca18-ce47-423d-88e1-859c3cb27230","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"b7e0036b-e78a-4d2d-9f3b-ee90c7a4f0d0","name":"b7e0036b-e78a-4d2d-9f3b-ee90c7a4f0d0","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"2bfc1360-c72a-4b3e-a79f-deb793c62bf8","name":"2bfc1360-c72a-4b3e-a79f-deb793c62bf8","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
{"$GMSpriteFrame":"","%Name":"dc773099-05a9-410a-8dd1-a5c1f68469a2","name":"dc773099-05a9-410a-8dd1-a5c1f68469a2","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
],
"gridX":0,
"gridY":0,
@ -54,7 +53,7 @@
},
"eventStubScript":null,
"eventToFunction":{},
"length":6.0,
"length":5.0,
"lockOrigin":false,
"moments":{
"$KeyframeStore<MomentsEventKeyframe>":"",
@ -77,8 +76,8 @@
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"bd7ad13c-f64a-4d4c-867f-ec4773fd2490","path":"sprites/s_node_curve/s_node_curve.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"b2fdd3cd-8ef1-48e3-af34-e969b677d89e","IsCreationKey":false,"Key":0.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"1a6ebc69-d2fa-4270-bbb4-fcf7fceeccae","path":"sprites/s_node_curve/s_node_curve.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"a9c9c603-b455-4bc5-8d3f-13aca3ffb07f","IsCreationKey":false,"Key":1.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"dc773099-05a9-410a-8dd1-a5c1f68469a2","path":"sprites/s_node_curve/s_node_curve.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"a456d519-e09d-4a31-98dd-09cfbdabb3c9","IsCreationKey":false,"Key":1.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"7a86ca18-ce47-423d-88e1-859c3cb27230","path":"sprites/s_node_curve/s_node_curve.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"de85f870-f7c3-4f0d-85cc-de7030e0252b","IsCreationKey":false,"Key":2.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
@ -88,9 +87,6 @@
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"2bfc1360-c72a-4b3e-a79f-deb793c62bf8","path":"sprites/s_node_curve/s_node_curve.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"e147b60a-04c9-419c-9626-539a72e93226","IsCreationKey":false,"Key":4.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"dc773099-05a9-410a-8dd1-a5c1f68469a2","path":"sprites/s_node_curve/s_node_curve.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"a456d519-e09d-4a31-98dd-09cfbdabb3c9","IsCreationKey":false,"Key":5.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
],"resourceType":"KeyframeStore<SpriteFrameKeyframe>","resourceVersion":"2.0",},"modifiers":[],"name":"frames","resourceType":"GMSpriteFramesTrack","resourceVersion":"2.0","spriteId":null,"trackColour":0,"tracks":[],"traits":0,},
],
"visibleRange":null,