mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-24 14:06:23 +01:00
[2D light] Add Ellipse shape.
This commit is contained in:
parent
7801629f2a
commit
fa2fe00eff
9 changed files with 276 additions and 210 deletions
|
@ -79,7 +79,7 @@ function Node_VFX_effector(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
draw_set_color(COLORS._main_accent);
|
||||
draw_set_alpha(0.5);
|
||||
switch(cs) {
|
||||
case AREA_SHAPE.elipse : draw_ellipse_dash(x0, y0, x1, y1); break;
|
||||
case AREA_SHAPE.elipse : draw_ellipse_dash(cx, cy, cw + fall * 2, ch + fall * 2); break;
|
||||
case AREA_SHAPE.rectangle : draw_rectangle_dashed(x0, y0, x1, y1); break;
|
||||
}
|
||||
draw_set_alpha(1);
|
||||
|
@ -94,7 +94,7 @@ function Node_VFX_effector(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
draw_set_color(COLORS._main_accent);
|
||||
draw_set_alpha(0.5);
|
||||
switch(cs) {
|
||||
case AREA_SHAPE.elipse : draw_ellipse_dash(x0, y0, x1, y1); break;
|
||||
case AREA_SHAPE.elipse : draw_ellipse_dash(cx, cy, cw + fall * 2, ch + fall * 2); break;
|
||||
case AREA_SHAPE.rectangle : draw_rectangle_dashed(x0, y0, x1, y1); break;
|
||||
}
|
||||
draw_set_alpha(1);
|
||||
|
|
|
@ -80,17 +80,9 @@ function _Node_Strand_Affector(_x, _y, _group = noone) : Node(_x, _y, _group) co
|
|||
if(_typ == 0) {
|
||||
draw_circle_prec(px, py, _ran, true);
|
||||
|
||||
var x0 = px - (_ran + fal);
|
||||
var y0 = py - (_ran + fal);
|
||||
var x1 = px + (_ran + fal);
|
||||
var y1 = py + (_ran + fal);
|
||||
draw_ellipse_dash(x0, y0, x1, y1);
|
||||
|
||||
var x0 = px - (_ran - fal);
|
||||
var y0 = py - (_ran - fal);
|
||||
var x1 = px + (_ran - fal);
|
||||
var y1 = py + (_ran - fal);
|
||||
draw_ellipse_dash(x0, y0, x1, y1);
|
||||
draw_circle_dash(px, py, _ran + fal);
|
||||
draw_circle_dash(px, py, _ran - fal);
|
||||
|
||||
} else if(_typ == 1) {
|
||||
_dir += 90;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
function draw_circle_prec(x, y, r, border, precision = 32) { #region
|
||||
function draw_circle_prec(x, y, r, border, precision = 32) {
|
||||
draw_set_circle_precision(precision);
|
||||
draw_circle(x, y, r, border);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function draw_polygon(x, y, r, sides, a = 0) { #region
|
||||
function draw_polygon(x, y, r, sides, a = 0) {
|
||||
draw_primitive_begin(pr_trianglelist);
|
||||
for( var i = 0; i < sides; i++ ) {
|
||||
var a0 = (i + 0) / sides * 360 + a;
|
||||
|
@ -14,9 +14,9 @@ function draw_polygon(x, y, r, sides, a = 0) { #region
|
|||
draw_vertex(x + lengthdir_x(r, a1), y + lengthdir_y(r, a1));
|
||||
}
|
||||
draw_primitive_end();
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function draw_circle_color_alpha(_x, _y, _r, colI, colO, alpI, alpO) { #region
|
||||
function draw_circle_color_alpha(_x, _y, _r, colI, colO, alpI, alpO) {
|
||||
var _step = 32;
|
||||
var angle_step = 360 / _step;
|
||||
|
||||
|
@ -35,9 +35,9 @@ function draw_circle_color_alpha(_x, _y, _r, colI, colO, alpI, alpO) { #region
|
|||
draw_vertex_color(p1x, p1y, colO, alpO);
|
||||
}
|
||||
draw_primitive_end();
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function draw_circle_border(xx, yy, r, w) { #region
|
||||
function draw_circle_border(xx, yy, r, w) {
|
||||
var _step = 32;
|
||||
var angle_step = 360 / _step;
|
||||
|
||||
|
@ -52,9 +52,9 @@ function draw_circle_border(xx, yy, r, w) { #region
|
|||
draw_vertex(p1x, p1y);
|
||||
}
|
||||
draw_primitive_end();
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function draw_ellipse_border(x0, y0, x1, y1, w) { #region
|
||||
function draw_ellipse_border(x0, y0, x1, y1, w) {
|
||||
var step = 32;
|
||||
var angle_step = 360 / step;
|
||||
|
||||
|
@ -75,9 +75,89 @@ function draw_ellipse_border(x0, y0, x1, y1, w) { #region
|
|||
_px = px;
|
||||
_py = py;
|
||||
}
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function draw_circle_angle(_x, _y, _r, _angSt, _angEd, precision = 32) { #region
|
||||
function draw_ellipse_angle_color(cx, cy, rx, ry, ang, color0, color1) {
|
||||
var n = ceil(max(cx, cy));
|
||||
var step = 360 / n;
|
||||
var ox, oy, nx, ny;
|
||||
|
||||
draw_primitive_begin(pr_trianglelist);
|
||||
for (var i = 0; i <= n; i++) {
|
||||
var nx = cx + rx * dcos(i * step);
|
||||
var ny = cy + ry * dsin(i * step);
|
||||
|
||||
var p0 = point_rotate(nx, ny, cx, cy, ang);
|
||||
nx = p0[0];
|
||||
ny = p0[1];
|
||||
|
||||
if(i) {
|
||||
draw_vertex_color(cx, cy, color0, 1);
|
||||
draw_vertex_color(ox, oy, color1, 1);
|
||||
draw_vertex_color(nx, ny, color1, 1);
|
||||
}
|
||||
|
||||
ox = nx;
|
||||
oy = ny;
|
||||
}
|
||||
draw_primitive_end();
|
||||
}
|
||||
|
||||
function draw_ellipse_width(x0, y0, x1, y1, th = 1) {
|
||||
var cx = (x0 + x1) / 2;
|
||||
var cy = (y0 + y1) / 2;
|
||||
var ww = abs(x0 - x1) / 2;
|
||||
var hh = abs(y0 - y1) / 2;
|
||||
|
||||
var samp = 32;
|
||||
var ox, oy, nx, ny;
|
||||
|
||||
for( var i = 0; i < samp; i++ ) {
|
||||
nx = cx + lengthdir_x(ww, i * 360 / samp);
|
||||
ny = cy + lengthdir_y(hh, i * 360 / samp);
|
||||
|
||||
if(i)
|
||||
draw_line_width(ox, oy, nx, ny, th);
|
||||
|
||||
ox = nx;
|
||||
oy = ny;
|
||||
}
|
||||
}
|
||||
|
||||
function draw_ellipse_dash(cx, cy, ww, hh, th = 1, dash = 8, ang = 0) {
|
||||
var rd = max(ww, hh);
|
||||
|
||||
var dash_dist = 0, is_dash = true;
|
||||
var samp = dash * max(cx, cy);
|
||||
var ox, oy, nx, ny;
|
||||
|
||||
for( var i = 0; i < samp; i++ ) {
|
||||
nx = cx + lengthdir_x(ww, i * 360 / samp);
|
||||
ny = cy + lengthdir_y(hh, i * 360 / samp);
|
||||
|
||||
var p0 = point_rotate(nx, ny, cx, cy, ang);
|
||||
nx = p0[0];
|
||||
ny = p0[1];
|
||||
|
||||
if(i) {
|
||||
dash_dist += point_distance(ox, oy, nx, ny);
|
||||
if(dash_dist >= dash) {
|
||||
dash_dist -= dash;
|
||||
is_dash = !is_dash;
|
||||
}
|
||||
|
||||
if(is_dash)
|
||||
draw_line_width(ox, oy, nx, ny, th);
|
||||
}
|
||||
|
||||
ox = nx;
|
||||
oy = ny;
|
||||
}
|
||||
}
|
||||
|
||||
function draw_circle_dash(_x, _y, rad, th = 1, dash = 8, ang = 0) { draw_ellipse_dash(_x, _y, rad, rad, th, dash, ang); }
|
||||
|
||||
function draw_circle_angle(_x, _y, _r, _angSt, _angEd, precision = 32) {
|
||||
var ox, oy, nx, ny, oa, na;
|
||||
|
||||
draw_primitive_begin(pr_trianglelist);
|
||||
|
@ -99,9 +179,9 @@ function draw_circle_angle(_x, _y, _r, _angSt, _angEd, precision = 32) { #region
|
|||
}
|
||||
|
||||
draw_primitive_end();
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function draw_arc_width(_x, _y, _r, _th, _angSt, _angEd) { #region
|
||||
function draw_arc_width(_x, _y, _r, _th, _angSt, _angEd) {
|
||||
draw_primitive_begin(pr_trianglelist);
|
||||
var oxI, oyI, oxO, oyO;
|
||||
|
||||
|
@ -133,9 +213,9 @@ function draw_arc_width(_x, _y, _r, _th, _angSt, _angEd) { #region
|
|||
}
|
||||
|
||||
draw_primitive_end();
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function draw_arc_forward(_x, _y, _r, _th, _angSt, _angEd) { #region
|
||||
function draw_arc_forward(_x, _y, _r, _th, _angSt, _angEd) {
|
||||
draw_primitive_begin(pr_trianglelist);
|
||||
var oxI, oyI, oxO, oyO;
|
||||
|
||||
|
@ -167,7 +247,7 @@ function draw_arc_forward(_x, _y, _r, _th, _angSt, _angEd) { #region
|
|||
}
|
||||
|
||||
draw_primitive_end();
|
||||
} #endregion
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -13,59 +13,3 @@ function draw_rectangle_dashed(x0, y0, x1, y1, th = 1, dash = 8, shift = 0) {
|
|||
draw_line_dashed(x0, y0 - th / 2, x0, y1 + th / 2, th, dash, shift);
|
||||
draw_line_dashed(x1, y0 - th / 2, x1, y1 + th / 2, th, dash, shift);
|
||||
}
|
||||
|
||||
function draw_ellipse_width(x0, y0, x1, y1, th = 1) {
|
||||
var cx = (x0 + x1) / 2;
|
||||
var cy = (y0 + y1) / 2;
|
||||
var ww = abs(x0 - x1) / 2;
|
||||
var hh = abs(y0 - y1) / 2;
|
||||
|
||||
var samp = 32;
|
||||
var ox, oy, nx, ny;
|
||||
|
||||
for( var i = 0; i < samp; i++ ) {
|
||||
nx = cx + lengthdir_x(ww, i * 360 / samp);
|
||||
ny = cy + lengthdir_y(hh, i * 360 / samp);
|
||||
|
||||
if(i)
|
||||
draw_line_width(ox, oy, nx, ny, th);
|
||||
|
||||
ox = nx;
|
||||
oy = ny;
|
||||
}
|
||||
}
|
||||
|
||||
function draw_ellipse_dash(x0, y0, x1, y1, th = 1, dash = 8) {
|
||||
var cx = (x0 + x1) / 2;
|
||||
var cy = (y0 + y1) / 2;
|
||||
var ww = abs(x0 - x1) / 2;
|
||||
var hh = abs(y0 - y1) / 2;
|
||||
var rd = max(ww, hh);
|
||||
|
||||
var dash_dist = 0, is_dash = true;
|
||||
var samp = 64;
|
||||
var ox, oy, nx, ny;
|
||||
|
||||
for( var i = 0; i < samp; i++ ) {
|
||||
nx = cx + lengthdir_x(ww, i * 360 / samp);
|
||||
ny = cy + lengthdir_y(hh, i * 360 / samp);
|
||||
|
||||
if(i) {
|
||||
dash_dist += point_distance(ox, oy, nx, ny);
|
||||
if(dash_dist >= dash) {
|
||||
dash_dist -= dash;
|
||||
is_dash = !is_dash;
|
||||
}
|
||||
|
||||
if(is_dash)
|
||||
draw_line_width(ox, oy, nx, ny, th);
|
||||
}
|
||||
|
||||
ox = nx;
|
||||
oy = ny;
|
||||
}
|
||||
}
|
||||
|
||||
function draw_circle_dash(_x, _y, rad, th = 1, dash = 8) {
|
||||
draw_ellipse_dash(_x - rad, _y - rad, _x + rad, _y + rad, th, dash);
|
||||
}
|
|
@ -2,25 +2,21 @@ enum LIGHT_SHAPE_2D {
|
|||
point,
|
||||
line,
|
||||
line_asym,
|
||||
spot
|
||||
spot,
|
||||
ellipse,
|
||||
}
|
||||
|
||||
function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
||||
name = "2D Light";
|
||||
batch_output = false;
|
||||
|
||||
shader = sh_2d_light;
|
||||
uniform_colr = shader_get_uniform(shader, "color");
|
||||
uniform_intn = shader_get_uniform(shader, "intensity");
|
||||
uniform_band = shader_get_uniform(shader, "band");
|
||||
uniform_attn = shader_get_uniform(shader, "atten");
|
||||
|
||||
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("Spot", s_node_2d_light_shape, 3),
|
||||
new scrollItem("Ellipse", s_node_2d_light_shape, 4), ]));
|
||||
|
||||
newInput(2, nodeValue_Vec2("Center", self, [ 16, 16 ]))
|
||||
.setUnitRef(function(index) { return getDimension(index); });
|
||||
|
@ -28,7 +24,7 @@ function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
|
|||
newInput(3, nodeValue_Float("Range", self, 16));
|
||||
|
||||
newInput(4, nodeValue_Float("Intensity", self, 1))
|
||||
.setDisplay(VALUE_DISPLAY.slider);
|
||||
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 4, 0.01 ]});
|
||||
|
||||
newInput(5, nodeValue_Color("Color", self, c_white));
|
||||
|
||||
|
@ -62,13 +58,19 @@ function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
|
|||
newInput(15, nodeValue_Bool("Active", self, true));
|
||||
active_index = 15;
|
||||
|
||||
newInput(16, nodeValue_Float("Radius x", self, 16));
|
||||
|
||||
newInput(17, nodeValue_Float("Radius y", self, 16));
|
||||
|
||||
newInput(18, nodeValue_Rotation("Rotation", self, 0));
|
||||
|
||||
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,
|
||||
["Shape", false], 1, 2, 6, 7, 8, 9, 16, 17, 18,
|
||||
["Light", false], 3, 4, 5, 12, 13, 14,
|
||||
["Render", false], 11, 10
|
||||
["Render", false], 11, 10,
|
||||
];
|
||||
|
||||
attribute_surface_depth();
|
||||
|
@ -82,18 +84,45 @@ function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
|
|||
switch(_shape) {
|
||||
case LIGHT_SHAPE_2D.point :
|
||||
var pos = current_data[2];
|
||||
var rad = current_data[3];
|
||||
|
||||
var px = _x + pos[0] * _s;
|
||||
var py = _y + pos[1] * _s;
|
||||
|
||||
var hv = inputs[2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv);
|
||||
var hv = inputs[3].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); _hov |= bool(hv);
|
||||
break;
|
||||
|
||||
draw_set_color(COLORS._main_accent);
|
||||
draw_set_alpha(0.5);
|
||||
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;
|
||||
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 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);
|
||||
|
||||
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;
|
||||
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);
|
||||
var hv = inputs[7].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); _hov |= bool(hv);
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -103,43 +132,50 @@ function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
|
|||
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
||||
var _shape = _data[1];
|
||||
|
||||
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);
|
||||
|
||||
switch(_shape) {
|
||||
case LIGHT_SHAPE_2D.point :
|
||||
inputs[2].setVisible(true);
|
||||
inputs[3].setVisible(true);
|
||||
inputs[6].setVisible(false);
|
||||
inputs[7].setVisible(false);
|
||||
inputs[8].setVisible(false);
|
||||
inputs[9].setVisible(false);
|
||||
|
||||
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[2].setVisible(false);
|
||||
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);
|
||||
|
||||
inputs[12].setVisible(false);
|
||||
inputs[13].setVisible(false);
|
||||
inputs[14].setVisible(false);
|
||||
break;
|
||||
|
||||
case LIGHT_SHAPE_2D.spot :
|
||||
inputs[2].setVisible(false);
|
||||
inputs[3].setVisible(false);
|
||||
inputs[6].setVisible(true);
|
||||
inputs[7].setVisible(true);
|
||||
inputs[8].setVisible(true);
|
||||
inputs[9].setVisible(false);
|
||||
|
||||
inputs[12].setVisible(false);
|
||||
inputs[13].setVisible(false);
|
||||
inputs[14].setVisible(false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -157,100 +193,110 @@ function Node_2D_light(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
|
|||
var _attn = _data[11];
|
||||
|
||||
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(shader);
|
||||
gpu_set_colorwriteenable(1, 1, 1, 0);
|
||||
|
||||
shader_set_uniform_f(uniform_intn, _inten * _color_get_alpha(_color));
|
||||
shader_set_uniform_f(uniform_band, _band);
|
||||
shader_set_uniform_f(uniform_attn, _attn);
|
||||
shader_set_uniform_f_array_safe(uniform_colr, [ _color_get_red(_color), _color_get_green(_color), _color_get_blue(_color) ]);
|
||||
|
||||
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(_output_index == 0) {
|
||||
DRAW_CLEAR
|
||||
draw_surface_safe(_data[0]);
|
||||
} else
|
||||
draw_clear_alpha(c_black, 1);
|
||||
|
||||
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);
|
||||
|
||||
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.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;
|
||||
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]);
|
||||
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 < 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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
gpu_set_colorwriteenable(1, 1, 1, 1);
|
||||
shader_reset();
|
||||
BLEND_NORMAL;
|
||||
case LIGHT_SHAPE_2D.ellipse :
|
||||
var _rngx = _data[16];
|
||||
var _rngy = _data[17];
|
||||
var _anng = _data[18];
|
||||
|
||||
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]);
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
gpu_set_colorwriteenable(1, 1, 1, 1);
|
||||
shader_reset();
|
||||
BLEND_NORMAL;
|
||||
surface_reset_target();
|
||||
|
||||
return _outSurf;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//varying vec2 v_vTexcoord;
|
||||
varying vec4 v_vColour;
|
||||
|
||||
uniform vec3 color;
|
||||
uniform vec4 color;
|
||||
uniform float intensity;
|
||||
uniform float band;
|
||||
uniform float atten;
|
||||
|
@ -25,5 +25,5 @@ void main() {
|
|||
if(band > 0.)
|
||||
bright = ceil(bright * band) / band;
|
||||
|
||||
gl_FragColor = vec4(color, 1.) * bright;
|
||||
gl_FragColor = color * bright;
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 729 B |
Binary file not shown.
After Width: | Height: | Size: 729 B |
|
@ -2,7 +2,7 @@
|
|||
"$GMSprite":"",
|
||||
"%Name":"s_node_2d_light_shape",
|
||||
"bboxMode":0,
|
||||
"bbox_bottom":20,
|
||||
"bbox_bottom":21,
|
||||
"bbox_left":2,
|
||||
"bbox_right":21,
|
||||
"bbox_top":2,
|
||||
|
@ -16,6 +16,7 @@
|
|||
{"$GMSpriteFrame":"","%Name":"627be0c1-d02f-48eb-bad9-63437bced55a","name":"627be0c1-d02f-48eb-bad9-63437bced55a","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
|
||||
{"$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",},
|
||||
],
|
||||
"gridX":0,
|
||||
"gridY":0,
|
||||
|
@ -52,7 +53,7 @@
|
|||
},
|
||||
"eventStubScript":null,
|
||||
"eventToFunction":{},
|
||||
"length":4.0,
|
||||
"length":5.0,
|
||||
"lockOrigin":false,
|
||||
"moments":{
|
||||
"$KeyframeStore<MomentsEventKeyframe>":"",
|
||||
|
@ -83,6 +84,9 @@
|
|||
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
|
||||
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"014aa4b1-411b-42cd-bfbf-444fee6c9934","path":"sprites/s_node_2d_light_shape/s_node_2d_light_shape.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
|
||||
},"Disabled":false,"id":"38fed255-f284-4f73-8e30-9c51e8107eb5","IsCreationKey":false,"Key":3.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
|
||||
{"$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,},
|
||||
],"resourceType":"KeyframeStore<SpriteFrameKeyframe>","resourceVersion":"2.0",},"modifiers":[],"name":"frames","resourceType":"GMSpriteFramesTrack","resourceVersion":"2.0","spriteId":null,"trackColour":0,"tracks":[],"traits":0,},
|
||||
],
|
||||
"visibleRange":null,
|
||||
|
|
Loading…
Reference in a new issue