linear curves

This commit is contained in:
Tanasart 2025-02-22 09:48:11 +07:00
parent ab92a6c32a
commit a75e5c120e
12 changed files with 260 additions and 209 deletions

Binary file not shown.

View file

@ -1,47 +1,49 @@
function curveBox(_onModify) : widget() constructor {
h = 200;
onModify = _onModify;
curr_data = [];
anc_mirror = [];
h = 200;
linear_mode = false;
curve_surface = surface_create(1, 1);
node_dragging = -1;
node_drag_typ = -1;
curve_surface = surface_create(1, 1);
node_dragging = -1;
node_drag_typ = -1;
node_drag_break = false;
height_drag = false;
height_my = 0;
height_ss = 0;
show_coord = false;
height_drag = false;
height_my = 0;
height_ss = 0;
show_coord = false;
minx = 0; maxx = 1;
miny = 0; maxy = 1;
dragging = 0;
drag_m = 0;
drag_s = 0;
drag_h = 0;
progress_draw = -1;
dragging = 0;
drag_m = 0;
drag_s = 0;
drag_h = 0;
progress_draw = -1;
display_pos_x = 0;
display_pos_y = 0;
display_sel = 0;
display_pos_x = 0;
display_pos_y = 0;
display_sel = 0;
grid_snap = false;
grid_step = 0.10;
grid_show = true;
grid_snap = false;
grid_step = 0.10;
grid_show = true;
scale_control = true;
control_zoom = 64;
scale_control = true;
control_zoom = 64;
selecting = noone;
select_type = 0;
selecting = noone;
select_type = 0;
cw = 0;
ch = 0;
tb_shift = new textBox(TEXTBOX_INPUT.number, function(val) { var _data = array_clone(curr_data); _data[0] = val; onModify(_data); });
tb_scale = new textBox(TEXTBOX_INPUT.number, function(val) { var _data = array_clone(curr_data); _data[1] = val; onModify(_data); });
tb_shift = new textBox(TEXTBOX_INPUT.number, function(v) /*=>*/ { var _data = array_clone(curr_data); _data[0] = v; onModify(_data); });
tb_scale = new textBox(TEXTBOX_INPUT.number, function(v) /*=>*/ { var _data = array_clone(curr_data); _data[1] = v; onModify(_data); });
tb_shift.label = "Shift";
tb_scale.label = "Scale";
@ -108,6 +110,8 @@ function curveBox(_onModify) : widget() constructor {
if(_shf == 1) { _shift = _data[0]; }
else if(_shf == 2) { _shift = _data[0]; _scale = _data[1]; }
linear_mode = curr_data[2 + 0] == 0 && curr_data[2 + 4] == 0;
display_pos_x = lerp(minx, maxx, (_m[0] - _x) / cw);
display_pos_y = lerp(miny, maxy, 1 - (_m[1] - _y) / ch);
display_sel = false;
@ -209,6 +213,8 @@ function curveBox(_onModify) : widget() constructor {
var msx = _m[0] - _x;
var msy = _m[1] - _y;
right_click_block = !point_in_rectangle(_m[0], _m[1], _x, _y, _x + w, _y + h);
#region ==== draw curve ====
surface_set_target(curve_surface);
DRAW_CLEAR
@ -232,8 +238,8 @@ function curveBox(_onModify) : widget() constructor {
var y1 = ch - ch * (1 - miny) / (maxy - miny);
draw_set_alpha(0.9);
draw_line(0, y0, cw, y0);
draw_line(0, y1, cw, y1);
draw_line(0, y0, cw, y0);
draw_line(0, y1, cw, y1);
draw_set_alpha(1);
if(progress_draw > -1) {
@ -333,6 +339,8 @@ function curveBox(_onModify) : widget() constructor {
var hov = 0;
var bs = zoom_size;
////- Height
var zminy = 0 - 1;
var zmaxy = 1 + 1;
@ -346,19 +354,24 @@ function curveBox(_onModify) : widget() constructor {
if(dragging) {
var _mdy = (drag_m[1] - _m[1]) / (byH - bs) * 2;
if(dragging == 1 || dragging == 3) miny = clamp(drag_s[0] + _mdy, zminy, min(maxy - 0.1, zmaxy));
if(dragging == 2 || dragging == 3) maxy = clamp(drag_s[1] + _mdy, max(miny + 0.1, zminy), zmaxy);
if(dragging == 1 || dragging == 3) {
miny = clamp(drag_s[0] + _mdy, zminy, min(maxy - 0.1, zmaxy));
if(mouse_release(mb_left))
dragging = false;
if(dragging == 1 && key_mod_press(CTRL))
maxy = clamp(drag_s[1] - _mdy, max(miny + 0.1, zminy), zmaxy);
}
if(dragging == 2 || dragging == 3) {
maxy = clamp(drag_s[1] + _mdy, max(miny + 0.1, zminy), zmaxy);
if(dragging == 2 && key_mod_press(CTRL))
miny = clamp(drag_s[0] - _mdy, zminy, min(maxy - 0.1, zmaxy));
}
}
if(point_in_rectangle(_m[0], _m[1], bx, zy0 - bs / 2, bx + bs, zy0 + bs / 2))
hov = 1;
else if(point_in_rectangle(_m[0], _m[1], bx, zy1 - bs / 2, bx + bs, zy1 + bs / 2))
hov = 2;
else if(point_in_rectangle(_m[0], _m[1], bx, zy1 - bs / 2, bx + bs, zy0 + bs / 2))
hov = 3;
if(point_in_rectangle(_m[0], _m[1], bx, zy0 - bs / 2, bx + bs, zy0 + bs / 2)) hov = 1;
else if(point_in_rectangle(_m[0], _m[1], bx, zy1 - bs / 2, bx + bs, zy1 + bs / 2)) hov = 2;
else if(point_in_rectangle(_m[0], _m[1], bx, zy1 - bs / 2, bx + bs, zy0 + bs / 2)) hov = 3;
draw_sprite_stretched_ext(THEME.box_r2, 0, bx, by, bs, byH, CDEF.main_black, 1);
draw_sprite_stretched_ext(THEME.box_r2, 0, bx, zy1, bs, zy0 - zy1, drag_h == 3? merge_color(CDEF.main_dkgrey, CDEF.main_grey, 0.4) : CDEF.main_dkgrey, 1);
@ -366,6 +379,8 @@ function curveBox(_onModify) : widget() constructor {
draw_sprite_stretched_ext(THEME.box_r2, 0, bx, zy0 - bs / 2, bs, bs, drag_h == 1? COLORS._main_icon_light : COLORS._main_icon, 1);
draw_sprite_stretched_ext(THEME.box_r2, 0, bx, zy1 - bs / 2, bs, bs, drag_h == 2? COLORS._main_icon_light : COLORS._main_icon, 1);
////- Width
var zminx = 0;
var zmaxx = 1;
@ -379,19 +394,24 @@ function curveBox(_onModify) : widget() constructor {
if(dragging) {
var _mdx = (_m[0] - drag_m[0]) / (bxW - bs);
if(dragging == 4 || dragging == 6) minx = clamp(drag_s[2] + _mdx, zminx, min(maxx - 0.1, zmaxx));
if(dragging == 5 || dragging == 6) maxx = clamp(drag_s[3] + _mdx, max(minx + 0.1, zminx), zmaxx);
if(dragging == 4 || dragging == 6) {
minx = clamp(drag_s[2] + _mdx, zminx, min(maxx - 0.1, zmaxx));
if(mouse_release(mb_left))
dragging = false;
if(dragging == 4 && key_mod_press(CTRL))
maxx = clamp(drag_s[3] - _mdx, max(minx + 0.1, zminx), zmaxx);
}
if(dragging == 5 || dragging == 6) {
maxx = clamp(drag_s[3] + _mdx, max(minx + 0.1, zminx), zmaxx);
if(dragging == 5 && key_mod_press(CTRL))
minx = clamp(drag_s[2] - _mdx, zminx, min(maxx - 0.1, zmaxx));
}
}
if(point_in_rectangle(_m[0], _m[1], zx0 - bs / 2, by, zx0 + bs / 2, by + bs))
hov = 4;
else if(point_in_rectangle(_m[0], _m[1], zx1 - bs / 2, by, zx1 + bs / 2, by + bs))
hov = 5;
else if(point_in_rectangle(_m[0], _m[1], zx0 - bs / 2, by, zx1 + bs / 2, by + bs))
hov = 6;
if(point_in_rectangle(_m[0], _m[1], zx0 - bs / 2, by, zx0 + bs / 2, by + bs)) hov = 4;
else if(point_in_rectangle(_m[0], _m[1], zx1 - bs / 2, by, zx1 + bs / 2, by + bs)) hov = 5;
else if(point_in_rectangle(_m[0], _m[1], zx0 - bs / 2, by, zx1 + bs / 2, by + bs)) hov = 6;
draw_sprite_stretched_ext(THEME.box_r2, 0, bx, by, bxW, bs, CDEF.main_black, 1);
draw_sprite_stretched_ext(THEME.box_r2, 0, zx0, by, zx1 - zx0, bs, drag_h == 6? merge_color(CDEF.main_dkgrey, CDEF.main_grey, 0.4) : CDEF.main_dkgrey, 1);
@ -399,11 +419,21 @@ function curveBox(_onModify) : widget() constructor {
draw_sprite_stretched_ext(THEME.box_r2, 0, zx0 - bs / 2, by, bs, bs, drag_h == 4? COLORS._main_icon_light : COLORS._main_icon, 1);
draw_sprite_stretched_ext(THEME.box_r2, 0, zx1 - bs / 2, by, bs, bs, drag_h == 5? COLORS._main_icon_light : COLORS._main_icon, 1);
////- Pan
drag_h = hov;
if(mouse_press(mb_left, hov && active)) {
dragging = hov;
drag_m = [ _m[0], _m[1] ];
drag_s = [ miny, maxy, minx, maxx ];
if(hov) {
if(DOUBLE_CLICK && active) {
if(hov <= 3) { miny = 0; maxy = 1; }
else if(hov <= 6) { minx = 0; maxx = 1; }
}
if(mouse_press(mb_left, active)) {
dragging = hov;
drag_m = [ _m[0], _m[1] ];
drag_s = [ miny, maxy, minx, maxx ];
}
}
if(dragging == 10) {
@ -421,9 +451,6 @@ function curveBox(_onModify) : widget() constructor {
miny = cy - zh / 2;
maxy = cy + zh / 2;
if(mouse_release(mb_middle))
dragging = false;
}
if(point_in_rectangle(_m[0], _m[1], _x, _y, _x + cw, _y + ch) && mouse_press(mb_middle, active)) {
@ -432,6 +459,11 @@ function curveBox(_onModify) : widget() constructor {
drag_s = [ miny, maxy, minx, maxx ];
}
if(mouse_release(mb_left) || mouse_release(mb_middle))
dragging = false;
////- Height drag
var _bhx = _x + _w - bs;
var _bhy = _y + _h - bs - (tbh + ui(4)) * bool(_shf);
var _hov = false;
@ -468,11 +500,11 @@ function curveBox(_onModify) : widget() constructor {
var _px = (_m[0] - _x) / cw;
var _py = 1 - (_m[1] - _y) / ch;
array_insert(_data, _ind + 0, -1 / 3);
array_insert(_data, _ind + 0, linear_mode? 0 : -1/3);
array_insert(_data, _ind + 1, 0);
array_insert(_data, _ind + 2, _px);
array_insert(_data, _ind + 3, _py);
array_insert(_data, _ind + 4, 1 / 3);
array_insert(_data, _ind + 4, linear_mode? 0 : 1/3);
array_insert(_data, _ind + 5, 0);
if(onModify(_data))
@ -498,12 +530,6 @@ function curveBox(_onModify) : widget() constructor {
}
}
} else if(mouse_press(mb_right, active)) {
// var node_point = (node_hovering - _shf - 2) / 6;
// if(node_hover_typ == 0 && node_point > 0 && node_point < points - 1) {
// array_delete(_data, _shf + node_point * 6, 6);
// if(onModify(_data)) UNDO_HOLDING = true;
// }
}
if(mouse_press(mb_right, active)) {
@ -513,18 +539,29 @@ function curveBox(_onModify) : widget() constructor {
if(node_hovering == -1 || node_hover_typ != 0) {
menuCall("widget_curve", [
menuItemGroup(__txt("Presets"), [
[ [THEME.curve_presets, 0], function() /*=>*/ { onModify(CURVE_DEF_00); } ],
[ [THEME.curve_presets, 1], function() /*=>*/ { onModify(CURVE_DEF_11); } ],
[ [THEME.curve_presets, 2], function() /*=>*/ { onModify(CURVE_DEF_01); } ],
[ [THEME.curve_presets, 3], function() /*=>*/ { onModify(CURVE_DEF_10); } ],
[ [THEME.curve_presets, 0], function() /*=>*/ {return onModify(CURVE_DEF_00)} ],
[ [THEME.curve_presets, 1], function() /*=>*/ {return onModify(CURVE_DEF_11)} ],
[ [THEME.curve_presets, 2], function() /*=>*/ {return onModify(CURVE_DEF_01)} ],
[ [THEME.curve_presets, 3], function() /*=>*/ {return onModify(CURVE_DEF_10)} ],
]),
-1,
menuItem(__txt("Reset View"), function() /*=>*/ {
minx = 0; maxx = 1;
miny = 0; maxy = 1;
}),
menuItem(__txt("Grid"), function() /*=>*/ { grid_show = !grid_show; }, noone, noone, function() /*=>*/ {return grid_show}),
menuItem(__txt("Snap to grid"), function() /*=>*/ { grid_snap = !grid_snap; }, noone, noone, function() /*=>*/ {return grid_snap}),
menuItem(__txt("Linear Curve"), function() /*=>*/ {
var _lin = linear_mode;
for( var i = 2, n = array_length(curr_data); i < n; i += 6 ) {
curr_data[@ i + 0] = _lin? -1/3 : 0;
curr_data[@ i + 1] = _lin? 0 : 0;
curr_data[@ i + 4] = _lin? 1/3 : 0;
curr_data[@ i + 5] = _lin? 0 : 0;
}
onModify(curr_data);
}, noone, noone, function() /*=>*/ {return linear_mode}),
menuItem(__txt("Reset View"), function() /*=>*/ { minx = 0; maxx = 1; miny = 0; maxy = 1; } ),
menuItem(__txt("Grid"), function() /*=>*/ { grid_show = !grid_show; }, noone, noone, function() /*=>*/ {return grid_show} ),
menuItem(__txt("Snap to grid"), function() /*=>*/ { grid_snap = !grid_snap; }, noone, noone, function() /*=>*/ {return grid_snap} ),
menuItemGroup(__txt("Grid size"), [
[ "1%", function() /*=>*/ { grid_step = 0.01; } ],
[ "5%", function() /*=>*/ { grid_step = 0.05; } ],
@ -539,27 +576,21 @@ function curveBox(_onModify) : widget() constructor {
select_type = node_hover_typ;
select_data = _data;
var node_point = (selecting - _shf - 2) / 6;
var _pnt = (selecting - _shf - 2) / 6;
var _menu = [];
array_push(_menu, menuItem(__txt("Reset Controls"), function() /*=>*/ {
var node_point = (selecting - _shf - 2) / 6;
var _ind = _shf + node_point * 6;
var _ind = selecting - 2;
select_data[@ _ind + 0] = -1 / 3;
select_data[@ _ind + 0] = -1/3;
select_data[@ _ind + 1] = 0;
select_data[@ _ind + 4] = 1 / 3;
select_data[@ _ind + 4] = 1/3;
select_data[@ _ind + 5] = 0;
onModify(select_data);
}));
if(node_point > 0 && node_point < points - 1) {
array_push(_menu, menuItem(__txt("Delete Anchor"), function() /*=>*/ {
var node_point = (selecting - _shf - 2) / 6;
array_delete(select_data, _shf + node_point * 6, 6);
onModify(select_data);
}, THEME.cross));
}
if(_pnt > 0 && _pnt < points - 1)
array_push(_menu, menuItem(__txt("Delete Anchor"), function() /*=>*/ { array_delete(select_data, selecting - 2, 6); onModify(select_data); }, THEME.cross));
menuCall("widget_curve", _menu, rmx, rmy);
}
@ -580,9 +611,9 @@ function curveBox(_onModify) : widget() constructor {
ty -= line_get_height();
draw_text_add(tx, ty, $"{display_sel == 2? "dx" : "x"}: {string_format(display_pos_x * 100, -1, 2)}%");
}
show_coord = false;
show_coord = false;
}
if(_shf) {
var tby = _y + h - tbh;
@ -606,12 +637,7 @@ function curveBox(_onModify) : widget() constructor {
return h;
}
static clone = function() {
var cln = new curveBox(onModify);
return cln;
}
static clone = function() /*=>*/ {return new curveBox(onModify)};
static free = function() {
surface_free_safe(curve_surface);
}
static free = function() { surface_free_safe(curve_surface); }
}

View file

@ -9,6 +9,7 @@
//////////////////////////////////////////////////////////////////////////////////////////// DRAW ////////////////////////////////////////////////////////////////////////////////////////////
function eval_curve_segment_t_position(_t, bbz) {
var _t2 = _t * _t;
var _t3 = _t * _t * _t;
var _T = 1 - _t;
@ -77,17 +78,23 @@ function draw_curve(x0, y0, _w, _h, _bz, minx = 0, maxx = 1, miny = 0, maxy = 1,
draw_line(x0 + _w, _ny, _nx, _ny);
}
var ax0 = _bz[ind + 4] + _x0;
var ay0 = _bz[ind + 5] + _y0;
if(_bz[ind + 4] == 0 && _bz[ind + 5] == 0 && _bz[ind + 6 + 0] == 0 && _bz[ind + 6 + 1] == 0) {
draw_line(x0 + _x0 * _w, y0 + (1 - _y0) * _h,
x0 + _x1 * _w, y0 + (1 - _y1) * _h);
continue;
}
var bx1 = _bz[ind + 6 + 0] + _x1;
var by1 = _bz[ind + 6 + 1] + _y1;
var ax0 = _x0 + _bz[ind + 4];
var ay0 = _y0 + _bz[ind + 5];
var bx1 = _x1 + _bz[ind + 6 + 0];
var by1 = _y1 + _bz[ind + 6 + 1];
var bbz = [ _y0, ax0, ay0, bx1, by1, _y1 ];
// print($"{i}, {bbz}")
for(var j = 0; j <= smp; j++) {
var t = j / smp;
var _r = eval_curve_segment_t_position(t, bbz);
var _t = j / smp;
var _r = eval_curve_segment_t_position(_t, bbz);
var _rx = _r[0] * _xr + _x0;
var _ry = _r[1];
@ -113,8 +120,8 @@ function draw_curve(x0, y0, _w, _h, _bz, minx = 0, maxx = 1, miny = 0, maxy = 1,
//////////////////////////////////////////////////////////////////////////////////////////// EVAL ////////////////////////////////////////////////////////////////////////////////////////////
function eval_curve_segment_t(_bz, t) {
// if(_bz[1] == 0 && _bz[2] == 0 && _bz[3] == 0 && _bz[4] == 0)
// return lerp(_bz[0], _bz[5], t);
if(_bz[1] == 0 && _bz[2] == 0 && _bz[3] == 0 && _bz[4] == 0)
return lerp(_bz[0], _bz[5], t);
return power(1 - t, 3) * _bz[0]
+ 3 * power(1 - t, 2) * t * _bz[2]

View file

@ -43,8 +43,8 @@
LATEST_VERSION = 1_18_00_0;
VERSION = 1_18_08_0;
SAVE_VERSION = 1_18_09_0;
VERSION_STRING = MAC? "1.18.003m" : "1.18.9.010";
BUILD_NUMBER = 118080.010;
VERSION_STRING = MAC? "1.18.003m" : "1.18.9.011";
BUILD_NUMBER = 118080.011;
PREF_VERSION = 1_17_1;
var _vsp = string_split(VERSION_STRING, ".");

View file

@ -411,10 +411,6 @@ function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover = false, _foc
param.h = widExtend? ui(96) : ui(48);
break;
case VALUE_TYPE.curve :
if(point_in_rectangle(_m[0], _m[1], ui(32), _hsy, ui(32) + ww - ui(16), _hsy + wid.h))
mbRight = false;
break;
}
var _widH = wid.drawParam(param) ?? 0;

View file

@ -52,15 +52,16 @@ function Node_Anim_Loop(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
var _loop_a = _loop_infin? infinity : _loop_amoun;
loop_amount = _loop_a;
loop_start = _loop_start;
loop_range = _loop_range;
loop_start = _loop_start - 1;
loop_range = _loop_range - 1;
var _sw = surface_get_width_safe(_surf);
var _sw = surface_get_width_safe(_surf);
var _sh = surface_get_height_safe(_surf);
_output = surface_verify(_output, _sw, _sh);
curr_frame = _time;
if(_time < _loop_start) {
if(_time < loop_start) {
_output = surface_verify(_output, _sw, _sh);
if(_loop_pre == 0) {
surface_set_shader(_output, sh_sample, true, BLEND.over);
draw_surface_safe(_surf);
@ -70,18 +71,23 @@ function Node_Anim_Loop(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
return _output;
}
var _loop_time = (_time - _loop_start) % _loop_range;
var _loop_perd = floor((_time - _loop_start) / _loop_range);
var _loop_time = (_time - loop_start) % _loop_range;
var _loop_perd = floor((_time - loop_start) / _loop_range);
if(_loop_perd > _loop_a) {
if(_loop_pos == 0) return _surf;
if(_loop_pos == 1) surface_clear(_output);
_output = surface_verify(_output, _sw, _sh);
if(_loop_pos == 0) {
surface_set_shader(_output, sh_sample, true, BLEND.over);
draw_surface_safe(_surf);
surface_reset_target();
} if(_loop_pos == 1) surface_clear(_output);
return _output;
}
var _surfA = surf_indexes[_array_index];
if(_time < _loop_start + _loop_range) {
if(_time < loop_start + _loop_range) {
_surfA[_loop_time] = surface_verify(_surfA[_loop_time], _sw, _sh);
surface_set_shader(_surfA[_loop_time], sh_sample, true, BLEND.over);
@ -89,18 +95,23 @@ function Node_Anim_Loop(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
surface_reset_target();
}
var _sw = surface_get_width_safe(_surfA[_loop_time]);
var _sh = surface_get_height_safe(_surfA[_loop_time]);
_output = surface_verify(_output, _sw, _sh);
surface_set_shader(_output, sh_sample, true, BLEND.over);
draw_surface_safe(_surfA[_loop_time]);
surface_reset_target();
curr_frame = _loop_start + _loop_time;
curr_frame = loop_start + _loop_time;
return _output;
}
static drawAnimationTimeline = function(_shf, _w, _h, _s) {
var _x0 = _shf + (loop_start + 1) * _s;
var _ww = (loop_range - 1) * _s;
var _ww = (loop_range) * _s;
BLEND_ADD
draw_sprite_stretched_ext(THEME.ui_selection, 0, _x0, ui(13), _ww, ui(15), COLORS._main_value_positive, .5);
BLEND_NORMAL

View file

@ -42,10 +42,13 @@ vec4 sample(vec2 pos) { #region
} #endregion
float eval_curve_segment_t(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float prog) {
return _y0 * pow(1. - prog, 3.) +
ay0 * 3. * pow(1. - prog, 2.) * prog +
by1 * 3. * (1. - prog) * pow(prog, 2.) +
_y1 * pow(prog, 3.);
float p = prog;
float i = 1. - p;
return _y0 * i*i*i +
ay0 * 3. * i*i*p +
by1 * 3. * i*p*p +
_y1 * p*p*p;
}
float eval_curve_segment_x(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float _x) {
@ -109,8 +112,6 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
int ind = _shf + i * 6;
float _x0 = curve[ind + 2];
float _y0 = curve[ind + 3];
//float bx0 = _x0 + curve[ind + 0];
//float by0 = _y0 + curve[ind + 1];
float ax0 = _x0 + curve[ind + 4];
float ay0 = _y0 + curve[ind + 5];
@ -118,13 +119,15 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
float _y1 = curve[ind + 6 + 3];
float bx1 = _x1 + curve[ind + 6 + 0];
float by1 = _y1 + curve[ind + 6 + 1];
//float ax1 = _x1 + curve[ind + 6 + 4];
//float ay1 = _y1 + curve[ind + 6 + 5];
if(_x < _x0) continue;
if(_x > _x1) continue;
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, (_x - _x0) / (_x1 - _x0));
float t = (_x - _x0) / (_x1 - _x0);
if(curve[ind + 4] == 0. && curve[ind + 5] == 0. && curve[ind + 6 + 0] == 0. && curve[ind + 6 + 1] == 0.)
return mix(_y0, _y1, t);
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, t);
}
return curve[0];

View file

@ -1,4 +1,3 @@
#ifdef _YY_HLSL11_
#define CURVE_MAX 256
#else
@ -24,10 +23,13 @@ uniform float a_curve[CURVE_MAX];
uniform int a_amount;
float eval_curve_segment_t(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float prog) {
return _y0 * pow(1. - prog, 3.) +
ay0 * 3. * pow(1. - prog, 2.) * prog +
by1 * 3. * (1. - prog) * pow(prog, 2.) +
_y1 * pow(prog, 3.);
float p = prog;
float i = 1. - p;
return _y0 * i*i*i +
ay0 * 3. * i*i*p +
by1 * 3. * i*p*p +
_y1 * p*p*p;
}
float eval_curve_segment_x(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float _x) {
@ -91,8 +93,6 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
int ind = _shf + i * 6;
float _x0 = curve[ind + 2];
float _y0 = curve[ind + 3];
//float bx0 = _x0 + curve[ind + 0];
//float by0 = _y0 + curve[ind + 1];
float ax0 = _x0 + curve[ind + 4];
float ay0 = _y0 + curve[ind + 5];
@ -100,13 +100,15 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
float _y1 = curve[ind + 6 + 3];
float bx1 = _x1 + curve[ind + 6 + 0];
float by1 = _y1 + curve[ind + 6 + 1];
//float ax1 = _x1 + curve[ind + 6 + 4];
//float ay1 = _y1 + curve[ind + 6 + 5];
if(_x < _x0) continue;
if(_x > _x1) continue;
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, (_x - _x0) / (_x1 - _x0));
float t = (_x - _x0) / (_x1 - _x0);
if(curve[ind + 4] == 0. && curve[ind + 5] == 0. && curve[ind + 6 + 0] == 0. && curve[ind + 6 + 1] == 0.)
return mix(_y0, _y1, t);
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, t);
}
return curve[0];

View file

@ -18,10 +18,13 @@ uniform float v_curve[CURVE_MAX];
uniform int v_amount;
float eval_curve_segment_t(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float prog) {
return _y0 * pow(1. - prog, 3.) +
ay0 * 3. * pow(1. - prog, 2.) * prog +
by1 * 3. * (1. - prog) * pow(prog, 2.) +
_y1 * pow(prog, 3.);
float p = prog;
float i = 1. - p;
return _y0 * i*i*i +
ay0 * 3. * i*i*p +
by1 * 3. * i*p*p +
_y1 * p*p*p;
}
float eval_curve_segment_x(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float _x) {
@ -85,8 +88,6 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
int ind = _shf + i * 6;
float _x0 = curve[ind + 2];
float _y0 = curve[ind + 3];
//float bx0 = _x0 + curve[ind + 0];
//float by0 = _y0 + curve[ind + 1];
float ax0 = _x0 + curve[ind + 4];
float ay0 = _y0 + curve[ind + 5];
@ -94,13 +95,15 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
float _y1 = curve[ind + 6 + 3];
float bx1 = _x1 + curve[ind + 6 + 0];
float by1 = _y1 + curve[ind + 6 + 1];
//float ax1 = _x1 + curve[ind + 6 + 4];
//float ay1 = _y1 + curve[ind + 6 + 5];
if(_x < _x0) continue;
if(_x > _x1) continue;
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, (_x - _x0) / (_x1 - _x0));
float t = (_x - _x0) / (_x1 - _x0);
if(curve[ind + 4] == 0. && curve[ind + 5] == 0. && curve[ind + 6 + 0] == 0. && curve[ind + 6 + 1] == 0.)
return mix(_y0, _y1, t);
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, t);
}
return curve[0];

View file

@ -23,10 +23,13 @@ uniform vec2 point2[1024];
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float eval_curve_segment_t(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float prog) {
return _y0 * pow(1. - prog, 3.) +
ay0 * 3. * pow(1. - prog, 2.) * prog +
by1 * 3. * (1. - prog) * pow(prog, 2.) +
_y1 * pow(prog, 3.);
float p = prog;
float i = 1. - p;
return _y0 * i*i*i +
ay0 * 3. * i*i*p +
by1 * 3. * i*p*p +
_y1 * p*p*p;
}
float eval_curve_segment_x(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float _x) {
@ -90,8 +93,6 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
int ind = _shf + i * 6;
float _x0 = curve[ind + 2];
float _y0 = curve[ind + 3];
//float bx0 = _x0 + curve[ind + 0];
//float by0 = _y0 + curve[ind + 1];
float ax0 = _x0 + curve[ind + 4];
float ay0 = _y0 + curve[ind + 5];
@ -99,13 +100,15 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
float _y1 = curve[ind + 6 + 3];
float bx1 = _x1 + curve[ind + 6 + 0];
float by1 = _y1 + curve[ind + 6 + 1];
//float ax1 = _x1 + curve[ind + 6 + 4];
//float ay1 = _y1 + curve[ind + 6 + 5];
if(_x < _x0) continue;
if(_x > _x1) continue;
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, (_x - _x0) / (_x1 - _x0));
float t = (_x - _x0) / (_x1 - _x0);
if(curve[ind + 4] == 0. && curve[ind + 5] == 0. && curve[ind + 6 + 0] == 0. && curve[ind + 6 + 1] == 0.)
return mix(_y0, _y1, t);
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, t);
}
return curve[0];

View file

@ -13,14 +13,17 @@ uniform float alpha_curve[CURVE_MAX];
uniform int curve_amount;
uniform float randomAmount;
float eval_curve_segment_t(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float prog) { #region
return _y0 * pow(1. - prog, 3.) +
ay0 * 3. * pow(1. - prog, 2.) * prog +
by1 * 3. * (1. - prog) * pow(prog, 2.) +
_y1 * pow(prog, 3.);
} #endregion
float eval_curve_segment_t(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float prog) {
float p = prog;
float i = 1. - p;
float eval_curve_segment_x(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float _x) { #region
return _y0 * i*i*i +
ay0 * 3. * i*i*p +
by1 * 3. * i*p*p +
_y1 * p*p*p;
}
float eval_curve_segment_x(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float _x) {
float st = 0.;
float ed = 1.;
float _prec = 0.0001;
@ -46,12 +49,12 @@ float eval_curve_segment_x(in float _y0, in float ax0, in float ay0, in float bx
_xt = (st + ed) / 2.;
}
int _newRep = 8;
int _newRep = 16;
for(int i = 0; i < _newRep; i++) {
float slope = (9. * ax0 - 9. * bx1 + 3.) * _xt * _xt
float slope = ( 9. * ax0 - 9. * bx1 + 3.) * _xt * _xt
+ (-12. * ax0 + 6. * bx1) * _xt
+ 3. * ax0;
+ 3. * ax0;
float _ftx = 3. * pow(1. - _xt, 2.) * _xt * ax0
+ 3. * (1. - _xt) * pow(_xt, 2.) * bx1
+ pow(_xt, 3.)
@ -65,48 +68,42 @@ float eval_curve_segment_x(in float _y0, in float ax0, in float ay0, in float bx
_xt = clamp(_xt, 0., 1.);
return eval_curve_segment_t(_y0, ax0, ay0, bx1, by1, _y1, _xt);
} #endregion
}
float curveEval(in float _x) { #region
float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
int _shf = int(mod(float(curve_amount), 6.));
float shift = 0.;
float scale = 1.;
int _shf = amo - int(floor(float(amo) / 6.) * 6.);
int _segs = (amo - _shf) / 6 - 1;
float _shift = _shf > 0? curve[0] : 0.;
float _scale = _shf > 1? curve[1] : 1.;
if(_shf > 0) {
shift = alpha_curve[0];
scale = alpha_curve[1];
}
_x = _x / scale - shift;
_x = _x / _scale - _shift;
_x = clamp(_x, 0., 1.);
int segments = (curve_amount - _shf) / 6 - 1;
for( int i = 0; i < _segs; i++ ) {
int ind = _shf + i * 6;
float _x0 = curve[ind + 2];
float _y0 = curve[ind + 3];
float ax0 = _x0 + curve[ind + 4];
float ay0 = _y0 + curve[ind + 5];
for( int i = 0; i < segments; i++ ) {
int ind = _shf + i * 6;
float _x0 = alpha_curve[ind + 2];
float _y0 = alpha_curve[ind + 3];
//float bx0 = _x0 + alpha_curve[ind + 0];
//float by0 = _y0 + alpha_curve[ind + 1];
float ax0 = _x0 + alpha_curve[ind + 4];
float ay0 = _y0 + alpha_curve[ind + 5];
float _x1 = alpha_curve[ind + 6 + 2];
float _y1 = alpha_curve[ind + 6 + 3];
float bx1 = _x1 + alpha_curve[ind + 6 + 0];
float by1 = _y1 + alpha_curve[ind + 6 + 1];
//float ax1 = _x1 + alpha_curve[ind + 6 + 4];
//float ay1 = _y1 + alpha_curve[ind + 6 + 5];
float _x1 = curve[ind + 6 + 2];
float _y1 = curve[ind + 6 + 3];
float bx1 = _x1 + curve[ind + 6 + 0];
float by1 = _y1 + curve[ind + 6 + 1];
if(_x < _x0) continue;
if(_x > _x1) continue;
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, (_x - _x0) / (_x1 - _x0));
float t = (_x - _x0) / (_x1 - _x0);
if(curve[ind + 4] == 0. && curve[ind + 5] == 0. && curve[ind + 6 + 0] == 0. && curve[ind + 6 + 1] == 0.)
return mix(_y0, _y1, t);
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, t);
}
return alpha_curve[0];
} #endregion
return curve[0];
}
#region //////////////////////////////////// GRADIENT ////////////////////////////////////
#define GRADIENT_LIMIT 128
@ -274,7 +271,7 @@ void main() {
_col = texture2D( gm_BaseTexture, _new_pos );
vec4 cc = gradientEval(str + frandom(_pos, 1.235) * randomAmount);
_col.rgb *= cc.rgb;
_col.a *= cc.a * curveEval(str + frandom(_pos, 2.984) * randomAmount);
_col.a *= cc.a * curveEval(alpha_curve, curve_amount, str + frandom(_pos, 2.984) * randomAmount);
}
gl_FragColor = _col;

View file

@ -73,10 +73,13 @@ float smin( float a, float b, float k ) {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float eval_curve_segment_t(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float prog) {
return _y0 * pow(1. - prog, 3.) +
ay0 * 3. * pow(1. - prog, 2.) * prog +
by1 * 3. * (1. - prog) * pow(prog, 2.) +
_y1 * pow(prog, 3.);
float p = prog;
float i = 1. - p;
return _y0 * i*i*i +
ay0 * 3. * i*i*p +
by1 * 3. * i*p*p +
_y1 * p*p*p;
}
float eval_curve_segment_x(in float _y0, in float ax0, in float ay0, in float bx1, in float by1, in float _y1, in float _x) {
@ -140,8 +143,6 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
int ind = _shf + i * 6;
float _x0 = curve[ind + 2];
float _y0 = curve[ind + 3];
//float bx0 = _x0 + curve[ind + 0];
//float by0 = _y0 + curve[ind + 1];
float ax0 = _x0 + curve[ind + 4];
float ay0 = _y0 + curve[ind + 5];
@ -149,13 +150,15 @@ float curveEval(in float[CURVE_MAX] curve, in int amo, in float _x) {
float _y1 = curve[ind + 6 + 3];
float bx1 = _x1 + curve[ind + 6 + 0];
float by1 = _y1 + curve[ind + 6 + 1];
//float ax1 = _x1 + curve[ind + 6 + 4];
//float ay1 = _y1 + curve[ind + 6 + 5];
if(_x < _x0) continue;
if(_x > _x1) continue;
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, (_x - _x0) / (_x1 - _x0));
float t = (_x - _x0) / (_x1 - _x0);
if(curve[ind + 4] == 0. && curve[ind + 5] == 0. && curve[ind + 6 + 0] == 0. && curve[ind + 6 + 1] == 0.)
return mix(_y0, _y1, t);
return eval_curve_segment_x(_y0, ax0, ay0, bx1, by1, _y1, t);
}
return curve[0];