oklch color node

This commit is contained in:
Tanasart 2024-12-01 18:42:45 +07:00
parent 04457621aa
commit fe66f66a30
25 changed files with 888 additions and 100 deletions

View file

@ -736,6 +736,7 @@
{"name":"node_color_data","order":6,"path":"scripts/node_color_data/node_color_data.yy",},
{"name":"node_color_hsv","order":8,"path":"scripts/node_color_hsv/node_color_hsv.yy",},
{"name":"node_color_mix","order":14,"path":"scripts/node_color_mix/node_color_mix.yy",},
{"name":"node_color_oklch","order":17,"path":"scripts/node_color_oklch/node_color_oklch.yy",},
{"name":"node_color_remove","order":2,"path":"scripts/node_color_remove/node_color_remove.yy",},
{"name":"node_color_replace","order":14,"path":"scripts/node_color_replace/node_color_replace.yy",},
{"name":"node_color_rgb","order":7,"path":"scripts/node_color_rgb/node_color_rgb.yy",},
@ -1212,6 +1213,7 @@
{"name":"notification_system","order":7,"path":"scripts/notification_system/notification_system.yy",},
{"name":"number_function","order":14,"path":"scripts/number_function/number_function.yy",},
{"name":"obj_reader","order":2,"path":"scripts/obj_reader/obj_reader.yy",},
{"name":"okhsl_function","order":18,"path":"scripts/okhsl_function/okhsl_function.yy",},
{"name":"outputBox","order":15,"path":"scripts/outputBox/outputBox.yy",},
{"name":"pack_bottom_left","order":2,"path":"scripts/pack_bottom_left/pack_bottom_left.yy",},
{"name":"pack_corner","order":3,"path":"scripts/pack_corner/pack_corner.yy",},
@ -2127,6 +2129,7 @@
{"name":"s_node_color_data_label","order":25,"path":"sprites/s_node_color_data_label/s_node_color_data_label.yy",},
{"name":"s_node_color_data","order":2,"path":"sprites/s_node_color_data/s_node_color_data.yy",},
{"name":"s_node_color_from_hsv","order":3,"path":"sprites/s_node_color_from_hsv/s_node_color_from_hsv.yy",},
{"name":"s_node_color_from_oklch","order":23,"path":"sprites/s_node_color_from_oklch/s_node_color_from_oklch.yy",},
{"name":"s_node_color_from_rgb","order":4,"path":"sprites/s_node_color_from_rgb/s_node_color_from_rgb.yy",},
{"name":"s_node_color_mix","order":5,"path":"sprites/s_node_color_mix/s_node_color_mix.yy",},
{"name":"s_node_color_out","order":6,"path":"sprites/s_node_color_out/s_node_color_out.yy",},

View file

@ -1282,6 +1282,7 @@
{"id":{"name":"node_color_data","path":"scripts/node_color_data/node_color_data.yy",},},
{"id":{"name":"node_color_hsv","path":"scripts/node_color_hsv/node_color_hsv.yy",},},
{"id":{"name":"node_color_mix","path":"scripts/node_color_mix/node_color_mix.yy",},},
{"id":{"name":"node_color_oklch","path":"scripts/node_color_oklch/node_color_oklch.yy",},},
{"id":{"name":"node_color_remove","path":"scripts/node_color_remove/node_color_remove.yy",},},
{"id":{"name":"node_color_replace","path":"scripts/node_color_replace/node_color_replace.yy",},},
{"id":{"name":"node_color_rgb","path":"scripts/node_color_rgb/node_color_rgb.yy",},},
@ -1815,6 +1816,7 @@
{"id":{"name":"notification_system","path":"scripts/notification_system/notification_system.yy",},},
{"id":{"name":"number_function","path":"scripts/number_function/number_function.yy",},},
{"id":{"name":"obj_reader","path":"scripts/obj_reader/obj_reader.yy",},},
{"id":{"name":"okhsl_function","path":"scripts/okhsl_function/okhsl_function.yy",},},
{"id":{"name":"outputBox","path":"scripts/outputBox/outputBox.yy",},},
{"id":{"name":"pack_best_fit","path":"scripts/pack_best_fit/pack_best_fit.yy",},},
{"id":{"name":"pack_bottom_left","path":"scripts/pack_bottom_left/pack_bottom_left.yy",},},
@ -2846,6 +2848,7 @@
{"id":{"name":"s_node_color_data_label","path":"sprites/s_node_color_data_label/s_node_color_data_label.yy",},},
{"id":{"name":"s_node_color_data","path":"sprites/s_node_color_data/s_node_color_data.yy",},},
{"id":{"name":"s_node_color_from_hsv","path":"sprites/s_node_color_from_hsv/s_node_color_from_hsv.yy",},},
{"id":{"name":"s_node_color_from_oklch","path":"sprites/s_node_color_from_oklch/s_node_color_from_oklch.yy",},},
{"id":{"name":"s_node_color_from_rgb","path":"sprites/s_node_color_from_rgb/s_node_color_from_rgb.yy",},},
{"id":{"name":"s_node_color_mix","path":"sprites/s_node_color_mix/s_node_color_mix.yy",},},
{"id":{"name":"s_node_color_out","path":"sprites/s_node_color_out/s_node_color_out.yy",},},

View file

@ -102,7 +102,6 @@ if !ready exit;
menuCall("gradient_window_blend_menu", [
menuItem(__txtx("gradient_editor_blend_hard", "Solid"), function() { gradient.type = 1; onApply(gradient); }),
menuItem(__txtx("gradient_editor_blend_RGB", "RGB"), function() { gradient.type = 0; onApply(gradient); }),
menuItem(__txtx("gradient_editor_blend_sRGB", "sRGB"), function() { gradient.type = 4; onApply(gradient); }),
menuItem(__txtx("gradient_editor_blend_HSV", "HSV"), function() { gradient.type = 2; onApply(gradient); }),
menuItem(__txtx("gradient_editor_blend_OKLAB", "OKLAB"), function() { gradient.type = 3; onApply(gradient); }),
], bx + ui(32), by, fa_left, gradient);

View file

@ -23,7 +23,7 @@
function _color_get_light(color) { INLINE return 0.299 * _color_get_red(color) + 0.587 * _color_get_green(color) + 0.114 * _color_get_blue(color); }
#endregion
#region conversions
#region creation
function _make_color_rgb(r, g, b) { INLINE return make_color_rgb(r * 255, g * 255, b * 255); }
function make_color_rgba(r, g, b, a) { INLINE return int64(round(r) + (round(g) << 8) + (round(b) << 16) + (round(a) << 24)); }
@ -80,21 +80,10 @@
}
#endregion
#region color spaces
function color_rgb(col) {
INLINE
return [ color_get_red(col) / 255, color_get_green(col) / 255, color_get_blue(col) / 255 ];
}
function color_srgb(col) {
INLINE
return [ power(color_get_red(col) / 255, 2.2), power(color_get_green(col) / 255, 2.2), power(color_get_blue(col) / 255, 2.2) ];
}
function color_hsv(col) {
INLINE
return [ color_get_hue(col) / 255, color_get_saturation(col) / 255, color_get_value(col) / 255 ];
}
#region conversion
function color_rgb(col) { return [ color_get_red(col) / 255, color_get_green(col) / 255, color_get_blue(col) / 255 ]; }
function color_srgb(col) { return [ power(color_get_red(col) / 255, 2.2), power(color_get_green(col) / 255, 2.2), power(color_get_blue(col) / 255, 2.2) ]; }
function color_hsv(col) { return [ color_get_hue(col) / 255, color_get_saturation(col) / 255, color_get_value(col) / 255 ]; }
global.CVTMAT_RGB_OKLAB = new __mat3([ 0.4121656120, 0.2118591070, 0.0883097947,
0.5362752080, 0.6807189584, 0.2818474174,

View file

@ -46,7 +46,7 @@
LATEST_VERSION = 1_18_00_0;
VERSION = 1_18_04_0;
SAVE_VERSION = 1_18_04_0;
VERSION_STRING = MAC? "1.18.003m" : "1.18.5.009";
VERSION_STRING = MAC? "1.18.003m" : "1.18.5.010";
BUILD_NUMBER = 1_18_04_1;
HOTKEYS = ds_map_create();

View file

@ -93,9 +93,9 @@ function gradientObject(color = c_black) constructor {
switch(type) {
case GRADIENT_INTER.smooth : return merge_color_rgba (_pkey.value, _key.value, rat);
case GRADIENT_INTER.srgb : return merge_color_srgb (_pkey.value, _key.value, rat);
case GRADIENT_INTER.hue : return merge_color_hsva (_pkey.value, _key.value, rat);
case GRADIENT_INTER.oklab : return merge_color_oklab(_pkey.value, _key.value, rat);
case GRADIENT_INTER.srgb : return merge_color_srgb (_pkey.value, _key.value, rat);
case GRADIENT_INTER.none : return _pkey.value;
}
}

View file

@ -0,0 +1,12 @@
{
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "variable",
"path": "folders/nodes/data/variable.yy",
},
"resourceVersion": "1.0",
"name": "node_array",
"tags": [],
"resourceType": "GMScript",
}

View file

@ -0,0 +1,102 @@
function Node_Color_OKLCH(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "OKLCH Color";
setDimension(96, 48);
newInput(0, nodeValue_Float("Lightness", self, .5))
.setVisible(true, true);
newInput(1, nodeValue_Float("Chroma", self, .2))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, .37, .01] })
.setVisible(true, true);
newInput(2, nodeValue_Float("Hue", self, 0))
.setDisplay(VALUE_DISPLAY.rotation)
.setVisible(true, true);
newInput(3, nodeValue_Float("Alpha", self, 1))
.setDisplay(VALUE_DISPLAY.slider);
newInput(4, nodeValue_Enum_Scroll("Gamut clipping", self, 0, [ "Chroma", "50% grey", "Adaptive grey", "RGB (Naive)" ]))
newOutput(0, nodeValue_Output("Color", self, VALUE_TYPE.color, c_white));
newOutput(1, nodeValue_Output("Raw RGB", self, VALUE_TYPE.float, [ 0, 0, 0 ]))
.setDisplay(VALUE_DISPLAY.vector);
inspector_info = new Inspector_Label();
input_display_list = [
0, 1, 2, 3,
["Gamut clipping", false], inspector_info, 4,
];
static processData = function(_outSurf, _data, _output_index, _array_index) {
var l = _data[0];
var c = _data[1];
var h = _data[2];
var alp = _data[3];
var clp = _data[4];
// var k1 = 0.206;
// var k2 = 0.03;
// var k3 = (1 + k1) / (1 + k2);
// l = (k3 * l - k1 * sqrt(sqr(k3 * l - k1) + 4 * k2 * k3 * l)) / 2;
// l = (l * (l + k1)) / (k3 * (l + k2));
var rgb = oklch2rgb([ l, c, h ]);
var _inrange = rgb[0] >= 0 && rgb[0] <= 1 &&
rgb[1] >= 0 && rgb[1] <= 1 &&
rgb[2] >= 0 && rgb[2] <= 1;
if(_inrange) {
var col = make_color_rgba(
clamp(round(rgb[0] * 255), 0, 255),
clamp(round(rgb[1] * 255), 0, 255),
clamp(round(rgb[2] * 255), 0, 255),
clamp( alp * 255, 0, 255),
);
} else {
switch(clp) {
case 0 : rgb = gamut_clip_preserve_chroma(rgb); break;
case 1 : rgb = gamut_clip_project_to_0_5(rgb); break;
case 2 : rgb = gamut_clip_adaptive_L0_0_5(rgb); break;
case 3 :
rgb[0] = clamp(rgb[0], 0, 1);
rgb[1] = clamp(rgb[1], 0, 1);
rgb[2] = clamp(rgb[2], 0, 1);
break;
}
rgb[0] = is_nan(rgb[0])? 0 : rgb[0];
rgb[1] = is_nan(rgb[1])? 0 : rgb[1];
rgb[2] = is_nan(rgb[2])? 0 : rgb[2];
var col = make_color_rgba(
clamp(round(rgb[0] * 255), 0, 255),
clamp(round(rgb[1] * 255), 0, 255),
clamp(round(rgb[2] * 255), 0, 255),
clamp( alp * 255, 0, 255),
);
}
inspector_info.text = _inrange? "" : "Color(s) outside 8-bit rgb range\nOutput will not be accurate.";
return [ col, rgb ];
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
if(bbox.h < 1) return;
var col = outputs[0].getValue();
if(is_array(col)) {
drawPalette(col, bbox.x0, bbox.y0, bbox.w, bbox.h);
return;
}
drawColor(col, bbox.x0, bbox.y0, bbox.w, bbox.h);
}
}

View file

@ -0,0 +1,13 @@
{
"$GMScript":"v1",
"%Name":"node_color_oklch",
"isCompatibility":false,
"isDnD":false,
"name":"node_color_oklch",
"parent":{
"name":"color",
"path":"folders/nodes/data/value/color.yy",
},
"resourceType":"GMScript",
"resourceVersion":"2.0",
}

View file

@ -0,0 +1,12 @@
{
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "variable",
"path": "folders/nodes/data/variable.yy",
},
"resourceVersion": "1.0",
"name": "node_counter",
"tags": [],
"resourceType": "GMScript",
}

View file

@ -18,6 +18,7 @@ function Node_Number(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
rotator_s = 0;
rotator_p = 0;
rotator_m = 0;
rotate_dx = 0;
newInput(0, nodeValue_Float("Value", self, 0))
.setVisible(true, true);
@ -30,14 +31,16 @@ function Node_Number(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
newInput(4, nodeValue_Float("Step", self, 0.01));
newInput(5, nodeValue_Bool("Clamp to range", self, true));
newInput(5, nodeValue_Bool("Clamp to range", self, false));
newInput(6, nodeValue_Enum_Button("Style", self, 0, { data: [ "Blob", "Flat" ] }));
newInput(7, nodeValue_Float("Rotate speed", self, 1));
newOutput(0, nodeValue_Output("Number", self, VALUE_TYPE.float, 0));
input_display_list = [ 0, 1,
["Display", false], 2, 6, 3, 4, 5,
["Editor", false], 2, 6, 3, 5, 4, 7,
]
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
@ -59,41 +62,28 @@ function Node_Number(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _ww = 96, _hh = 56;
inputs[3].setVisible(disp > 0);
inputs[4].setVisible(disp > 0);
inputs[5].setVisible(disp > 0);
inputs[6].setVisible(disp > 0);
inputs[7].setVisible(disp == 2);
switch(disp) {
case 0 :
inputs[3].setVisible(false);
inputs[4].setVisible(false);
inputs[5].setVisible(false);
inputs[6].setVisible(false);
break;
case 1 :
_ww = 160;
if(styl == 0) _hh = 96;
else if(styl == 1) _hh = 64;
inputs[3].setVisible(true);
inputs[4].setVisible(true);
inputs[5].setVisible(true);
inputs[6].setVisible(true);
break;
case 2 :
_ww = 128; _hh = 128;
inputs[3].setVisible(false);
inputs[4].setVisible(false);
inputs[5].setVisible(false);
inputs[6].setVisible(true);
break;
case 3 :
_ww = 160; _hh = 64;
inputs[3].setVisible(true);
inputs[4].setVisible(true);
inputs[5].setVisible(true);
inputs[6].setVisible(true);
break;
}
@ -124,7 +114,6 @@ function Node_Number(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _res = processNumber(_dat, _int);
outputs[0].setValue(_res);
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
@ -135,6 +124,7 @@ function Node_Number(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var stp = getInputData(4);
var cmp = getInputData(5);
var sty = getInputData(6);
var spd = getInputData(7);
var _col = getColor();
var val = outputs[0].getValue();
@ -272,19 +262,24 @@ function Node_Number(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _r = _ss / 2 - 10 * _s;
draw_circle_ui(bbox.xc, bbox.yc, _r, .04, cola(c1));
var _knx = bbox.xc + lengthdir_x(_r - 2 * _s, raw);
var _kny = bbox.yc + lengthdir_y(_r - 2 * _s, raw);
var _knx = bbox.xc + lengthdir_x(_r - 12 * _s, raw);
var _kny = bbox.yc + lengthdir_y(_r - 12 * _s, raw);
draw_circle_ui(_knx, _kny, 8 * _s, 0, cola(c0));
draw_circle_ui(_knx, _kny, 6 * _s, 0, cola(c0));
}
if(rotator_dragging) {
rotator_m = lerp_float(rotator_m, 1, 4);
var dir = point_direction(bbox.xc, bbox.yc, _mx, _my);
var dx = angle_difference(dir, rotator_p);
rotate_dx += dx;
rotator_p = dir;
if(inputs[0].setValue(raw + dx))
var _val = rotator_s + rotate_dx * spd;
_val = value_snap(_val, stp);
if(cmp) _val = clamp(_val, _minn, _maxx);
if(inputs[0].setValue(_val))
UNDO_HOLDING = true;
if(mouse_release(mb_left)) {
@ -299,6 +294,7 @@ function Node_Number(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
rotator_dragging = true;
rotator_s = raw;
rotator_p = point_direction(bbox.xc, bbox.yc, _mx, _my);
rotate_dx = 0;
}
draggable = false;

View file

@ -4,7 +4,7 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
auto_height = false;
junction_shift_y = 16;
custom_grid = 8;
// custom_grid = 8;
isHovering = false;
hover_scale = 0;
@ -48,15 +48,15 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
}
static pointIn = function(_x, _y, _mx, _my, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
return point_in_circle(_mx, _my, xx, yy, _s * 24);
}
static preDraw = function(_x, _y, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
inputs[0].x = xx;
inputs[0].y = yy;
@ -71,8 +71,8 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
static drawJunctions = function(_draw, _x, _y, _mx, _my, _s) {
var _dval = PANEL_GRAPH.value_dragging;
var hover = _dval == noone || _dval.connect_type == CONNECT_TYPE.input? outputs[0] : inputs[0];
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
isHovering = point_in_circle(_mx, _my, xx, yy, _s * 24);
hover_junction = noone;
@ -91,8 +91,8 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
static drawNode = function(_draw, _x, _y, _mx, _my, _s) {
if(!_draw) return drawJunctions(_draw, _x, _y, _mx, _my, _s);
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
hover_alpha = 0.5;

View file

@ -1017,8 +1017,9 @@ function __initNodes() {
addNodeCatagory("Color", color);
ds_list_add(color, "Colors");
addNodeObject(color, "Color", s_node_color_out, "Node_Color", [1, Node_Color],, "Create color value.");
addNodeObject(color, "RGB Color", s_node_color_from_rgb, "Node_Color_RGB", [1, Node_Color_RGB],, "Create color from RGB value.");
addNodeObject(color, "HSV Color", s_node_color_from_hsv, "Node_Color_HSV", [1, Node_Color_HSV],, "Create color from HSV value.");
addNodeObject(color, "RGB Color", s_node_color_from_rgb, "Node_Color_RGB", [1, Node_Color_RGB],, "Create (rgb) color from value in RGB color space.");
addNodeObject(color, "HSV Color", s_node_color_from_hsv, "Node_Color_HSV", [1, Node_Color_HSV],, "Create (rgb) color from value in HSV color space.");
addNodeObject(color, "OKLCH Color", s_node_color_from_oklch,"Node_Color_OKLCH", [1, Node_Color_OKLCH],, ["oklab"], "Create (rgb) color from value in OKLCH color space.");
addNodeObject(color, "Sampler", s_node_sampler, "Node_Sampler", [1, Node_Sampler],, "Sample color from an image.");
addNodeObject(color, "Color Data", s_node_color_data, "Node_Color_Data", [1, Node_Color_Data], ["red", "green", "blue", "alpha", "brightness", "luminance"], "Get data (rgb, hsv, brightness) from color.");
addNodeObject(color, "Find pixel", s_node_pixel_find, "Node_Find_Pixel", [1, Node_Find_Pixel],, "Get the position of the first pixel with a given color.").setVersion(1130);

View file

@ -65,6 +65,8 @@ function Node_Text(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
newInput(27, nodeValue_Int("Max line width", self, 0 ));
newInput(28, nodeValue_Bool("Round position", self, true ));
input_display_list = [ 0,
["Output", true], 9, 6, 10,
["Alignment", false], 13, 14, 7, 8, 27,
@ -184,6 +186,7 @@ function Node_Text(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
var _typeF = _data[26];
var _lineW = _data[27];
__rnd_pos = _data[28];
generateFont(_font, _size, _aa);
draw_set_font(font);
@ -379,6 +382,8 @@ function Node_Text(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
_ty += lengthdir_y(_wd, _line_ang + 90);
}
if(__rnd_pos) { _tx = round(_tx); _ty = round(_ty); }
draw_text_transformed(_tx, _ty, _chr, 1, 1, _nor);
__temp_tx += string_width(_chr) + __temp_trck;
});
@ -412,6 +417,8 @@ function Node_Text(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
_ty += _wd;
}
if(__rnd_pos) { _tx = round(_tx); _ty = round(_ty); }
draw_text_transformed(_tx, _ty, _chr, __temp_ss, __temp_ss, 0);
__temp_tx += (string_width(_chr) + __temp_trck) * __temp_ss;
});

View file

@ -3,7 +3,7 @@ function Node_Tunnel_In(_x, _y, _group = noone) : Node(_x, _y, _group) construct
color = COLORS.node_blend_tunnel;
is_group_io = true;
preview_draw = false;
custom_grid = 8;
// custom_grid = 8;
setDimension(32, 32);
@ -38,6 +38,12 @@ function Node_Tunnel_In(_x, _y, _group = noone) : Node(_x, _y, _group) construct
static update = function(frame = CURRENT_FRAME) {
onValueUpdate();
var _frm = inputs[1].value_from;
inputs[1].setType( _frm? _frm.type : VALUE_TYPE.any);
inputs[1].setDisplay(_frm? _frm.display_type : VALUE_DISPLAY._default);
inputs[1].updateColor();
}
static resetMap = function() {
@ -100,14 +106,6 @@ function Node_Tunnel_In(_x, _y, _group = noone) : Node(_x, _y, _group) construct
if(index == 0) { RENDER_ALL_REORDER }
}
static onValueFromUpdate = function(index) {
var _frm = inputs[1].value_from;
inputs[1].setType( _frm? _frm.type : VALUE_TYPE.any);
inputs[1].setDisplay(_frm? _frm.display_type : VALUE_DISPLAY._default);
}
static step = function() {
value_validation[VALIDATION.error] = error_notification != noone;
}
@ -140,15 +138,15 @@ function Node_Tunnel_In(_x, _y, _group = noone) : Node(_x, _y, _group) construct
/////////////////////////////////////////////////////////////////////////////
static pointIn = function(_x, _y, _mx, _my, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
return point_in_circle(_mx, _my, xx, yy, _s * 24);
}
static preDraw = function(_x, _y, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
inputs[0].x = xx;
inputs[0].y = yy;
@ -161,8 +159,8 @@ function Node_Tunnel_In(_x, _y, _group = noone) : Node(_x, _y, _group) construct
static drawJunctionNames = function(_x, _y, _mx, _my, _s) {}
static onDrawNodeBehind = function(_x, _y, _mx, _my, _s) {
var xx = _x + x * _s;
var yy = _y + y * _s;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
var hover = isHovering || hover_alpha == 1;
var tun = findPanel("Panel_Tunnels");
@ -187,8 +185,8 @@ function Node_Tunnel_In(_x, _y, _group = noone) : Node(_x, _y, _group) construct
preview_connecting = true;
node.preview_connecting = true;
var tox = _x + node.x * _s;
var toy = _y + node.y * _s;
var tox = _x + node.x * _s;
var toy = _y + (node.y + 8) * _s;
draw_line_dotted(xx, yy, tox, toy, 2 * _s, current_time / 10, 3);
}
@ -196,11 +194,13 @@ function Node_Tunnel_In(_x, _y, _group = noone) : Node(_x, _y, _group) construct
}
static drawJunctions = function(_draw, _x, _y, _mx, _my, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
isHovering = point_in_circle(_mx, _my, xx, yy, _s * 24);
gpu_set_tex_filter(true);
junction_hover = inputs[1].drawJunction(_draw, _s, _mx, _my);
gpu_set_tex_filter(false);
if(!isHovering) return noone;
if(!junction_hover) draw_sprite_ext(THEME.view_pan, 0, _mx + ui(16), _my + ui(24), 1, 1, 0, COLORS._main_accent);
@ -213,8 +213,8 @@ function Node_Tunnel_In(_x, _y, _group = noone) : Node(_x, _y, _group) construct
static drawNode = function(_draw, _x, _y, _mx, _my, _s) {
if(!_draw) return drawJunctions(_draw, _x, _y, _mx, _my, _s);
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
hover_alpha = 0.5;
if(active_draw_index > -1) {

View file

@ -3,7 +3,7 @@ function Node_Tunnel_Out(_x, _y, _group = noone) : Node(_x, _y, _group) construc
color = COLORS.node_blend_tunnel;
is_group_io = true;
preview_draw = false;
custom_grid = 8;
// custom_grid = 8;
setDimension(32, 32);
@ -59,27 +59,28 @@ function Node_Tunnel_Out(_x, _y, _group = noone) : Node(_x, _y, _group) construc
if(ds_map_exists(project.tunnels_in, _key)) {
outputs[0].setType(project.tunnels_in[? _key].type);
outputs[0].display_type = project.tunnels_in[? _key].display_type;
outputs[0].setDisplay(project.tunnels_in[? _key].display_type);
outputs[0].setValue(project.tunnels_in[? _key].getValue());
} else {
outputs[0].setType(VALUE_TYPE.any);
outputs[0].display_type = VALUE_DISPLAY._default;
outputs[0].setDisplay(VALUE_DISPLAY._default);
}
outputs[0].updateColor();
}
/////////////////////////////////////////////////////////////////////////////
static pointIn = function(_x, _y, _mx, _my, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
return point_in_circle(_mx, _my, xx, yy, _s * 24);
}
static preDraw = function(_x, _y, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
inputs[0].x = xx;
inputs[0].y = yy;
@ -92,8 +93,8 @@ function Node_Tunnel_Out(_x, _y, _group = noone) : Node(_x, _y, _group) construc
static drawJunctionNames = function(_x, _y, _mx, _my, _s) {}
static onDrawNodeBehind = function(_x, _y, _mx, _my, _s) {
var xx = _x + x * _s;
var yy = _y + y * _s;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
var hover = isHovering || hover_alpha == 1;
var tun = findPanel("Panel_Tunnels");
@ -112,19 +113,21 @@ function Node_Tunnel_Out(_x, _y, _group = noone) : Node(_x, _y, _group) construc
draw_set_color(outputs[0].color_display);
draw_set_alpha(0.5);
var frx = _x + node.x * _s;
var fry = _y + node.y * _s;
var frx = _x + node.x * _s;
var fry = _y + (node.y + 8) * _s;
draw_line_dotted(frx, fry, xx, yy, 2 * _s, current_time / 10, 3);
draw_set_alpha(1);
}
static drawJunctions = function(_draw, _x, _y, _mx, _my, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
isHovering = point_in_circle(_mx, _my, xx, yy, _s * 24);
gpu_set_tex_filter(true);
junction_hover = outputs[0].drawJunction(_draw, _s, _mx, _my);
gpu_set_tex_filter(false);
if(!isHovering) return noone;
if(!junction_hover) draw_sprite_ext(THEME.view_pan, 0, _mx + ui(16), _my + ui(24), 1, 1, 0, COLORS._main_accent);
@ -136,8 +139,8 @@ function Node_Tunnel_Out(_x, _y, _group = noone) : Node(_x, _y, _group) construc
static drawNode = function(_draw, _x, _y, _mx, _my, _s) {
if(!_draw) return drawJunctions(_draw, _x, _y, _mx, _my, _s);
var xx = x * _s + _x;
var yy = y * _s + _y;
var xx = x * _s + _x;
var yy = (y + 8) * _s + _y;
hover_alpha = 0.5;
if(active_draw_index > -1) {

View file

@ -0,0 +1,541 @@
/// oklch conversion by dkaraush
/// https://gist[1]ithub.com/dkaraush/65d19d61396f5f3cd8ba7d1b4b3c9432
function multiplyMatrices(A, b) {
return [
A[0] * b[0] + A[1] * b[1] + A[2] * b[2],
A[3] * b[0] + A[4] * b[1] + A[5] * b[2],
A[6] * b[0] + A[7] * b[1] + A[8] * b[2]
];
}
function oklch2oklab(lch) {
var l = lch[0];
var c = lch[1];
var h = lch[2];
return [
l,
is_nan(h) ? 0 : c * dcos(h),
is_nan(h) ? 0 : c * dsin(h)
];
}
function oklab2oklch(lab) {
var l = lab[0];
var a = lab[1];
var b = lab[2];
return [
l,
sqrt(a * a + b * b),
abs(a) < 0.0002 && abs(b) < 0.0002 ? NaN : (radtodeg(arctan2(b, a)) % 360 + 360) % 360
];
}
function rgb2srgbLinear(rgb) {
var result = [];
for (var i = 0; i < 3; i++) {
var c = rgb[i];
result[i] = abs(c) <= 0.04045 ? c / 12.92 : (c < 0 ? -1 : 1) * power((abs(c) + 0.055) / 1.055, 2.4);
}
return result;
}
function srgbLinear2rgb(rgb) {
var result = [];
for (var i = 0; i < 3; i++) {
var c = rgb[i];
result[i] = abs(c) > 0.0031308 ? (c < 0 ? -1 : 1) * (1.055 * power(abs(c), 1 / 2.4) - 0.055) : 12.92 * c;
}
return result;
}
////////////////////////////////////////////////////////////////////////////////////////
function oklab2xyz(lab) {
var LMSg = multiplyMatrices([
1, 0.3963377773761749, 0.2158037573099136,
1, -0.1055613458156586, -0.0638541728258133,
1, -0.0894841775298119, -1.2914855480194092,
], lab);
var LMS = [
power(LMSg[0], 3),
power(LMSg[1], 3),
power(LMSg[2], 3),
];
return multiplyMatrices([
1.2268798758459243, -0.5578149944602171, 0.2813910456659647,
-0.0405757452148008, 1.1122868032803170, -0.0717110580655164,
// -0.0763729497467214, -0.4214933239627914, 1.5869240244272418,
-0.0763729366746601, -0.4214933324022432, 1.5869240198367816,
], LMS);
}
////////////////////////////////////////////////////////////////////////////////////////
function xyz2oklab(xyz) {
var LMS = multiplyMatrices([
0.8190224379967030, 0.3619062600528904, -0.1288737815209879,
0.0329836539323885, 0.9292868615863434, 0.0361446663506424,
0.0481771893596242, 0.2642395317527308, 0.6335478284694309
], xyz);
var LMSg = [
power(LMS[0], 1 / 3),
power(LMS[1], 1 / 3),
power(LMS[2], 1 / 3),
];
return multiplyMatrices([
0.2104542683093140, 0.7936177747023054, -0.0040720430116193,
1.9779985324311684, -2.4285922420485799, 0.4505937096174110,
0.0259040424655478, 0.7827717124575296, -0.8086757549230774
], LMSg);
}
////////////////////////////////////////////////////////////////////////////////////////
// function xyz2rgbLinear(xyz) {
// return multiplyMatrices([
// 3.2409699419045226, -1.537383177570094, -0.4986107602930034,
// -0.9692436362808796, 1.8759675015077202, 0.04155505740717559,
// 0.05563007969699366, -0.20397695888897652, 1.0569715142428786
// ], xyz);
// }
// function rgbLinear2xyz(rgb) {
// return multiplyMatrices([
// 0.41239079926595934, 0.357584339383878, 0.1804807884018343,
// 0.21263900587151027, 0.715168678767756, 0.07219231536073371,
// 0.01933081871559182, 0.11919477979462598, 0.9505321522496607
// ], rgb);
// }
// function oklch2rgb(lch) { return srgbLinear2rgb(xyz2rgbLinear(oklab2xyz(oklch2oklab(lch)))); }
// function rgb2oklch(rgb) { return oklab2oklch(xyz2oklab(rgbLinear2xyz(rgb2srgbLinear(rgb)))); }
/// oklab conversion by Björn Ottosson (Oklab OP)
/// https://bottosson[1]ithub.io/posts/oklab/
// black - white is not fix to 0 - 1
function linear_srgb_to_oklab(rgb){
var r = rgb[0];
var g = rgb[1];
var b = rgb[2];
var l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
var m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
var s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
var l_ = power(l, 1 / 3);
var m_ = power(m, 1 / 3);
var s_ = power(s, 1 / 3);
return [
0.2104542683093140 * l_ + 0.7936177747023054 * m_ - 0.0040720430116193 * s_,
1.9779985324311684 * l_ - 2.4285922420485799 * m_ + 0.4505937096174110 * s_,
0.0259040424655478 * l_ + 0.7827717124575296 * m_ - 0.8086757549230774 * s_,
];
}
function oklab_to_linear_srgb(lab) {
var L = lab[0];
var a = lab[1];
var b = lab[2];
var l_ = L + 0.3963377774 * a + 0.2158037573 * b;
var m_ = L - 0.1055613458 * a - 0.0638541728 * b;
var s_ = L - 0.0894841775 * a - 1.2914855480 * b;
var l = power(l_, 3);
var m = power(m_, 3);
var s = power(s_, 3);
return [
+4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s,
];
}
// function oklch2rgb(lch) { return srgbLinear2rgb(oklab_to_linear_srgb(oklch2oklab(lch))); }
// function rgb2oklch(rgb) { return oklab2oklch(linear_srgb_to_oklab(rgb2srgbLinear(rgb))); }
/// oklab conversion by Color.js
/// https://github.com/color-js/color.js/blob/main/src/spaces/oklab.js
// function xyz_to_oklab(rgb){
// static XYZtoLMS_M = [
// 0.8190224379967030, 0.3619062600528904, -0.1288737815209879,
// 0.0329836539323885, 0.9292868615863434, 0.0361446663506424,
// 0.0481771893596242, 0.2642395317527308, 0.6335478284694309,
// ];
// static LMStoLab_M = [
// 0.2104542683093140, 0.7936177747023054, -0.0040720430116193,
// 1.9779985324311684, -2.4285922420485799, 0.4505937096174110,
// 0.0259040424655478, 0.7827717124575296, -0.8086757549230774,
// ];
// rgb = multiplyMatrices(XYZtoLMS_M, rgb);
// rgb[0] = power(rgb[0], 1 / 3);
// rgb[1] = power(rgb[1], 1 / 3);
// rgb[2] = power(rgb[2], 1 / 3);
// return multiplyMatrices(LMStoLab_M, rgb);
// }
// function oklab_to_xyz(lab) {
// static LabtoLMS_M = [
// 1.0000000000000000, 0.3963377773761749, 0.2158037573099136,
// 1.0000000000000000, -0.1055613458156586, -0.0638541728258133,
// 1.0000000000000000, -0.0894841775298119, -1.2914855480194092,
// ];
// static LMStoXYZ_M = [
// 1.2268798758459243, -0.5578149944602171, 0.2813910456659647,
// -0.0405757452148008, 1.1122868032803170, -0.0717110580655164,
// -0.0763729366746601, -0.4214933324022432, 1.5869240198367816,
// ];
// lab = multiplyMatrices(LabtoLMS_M, lab);
// lab[0] = power(lab[0], 3);
// lab[1] = power(lab[1], 3);
// lab[2] = power(lab[2], 3);
// return multiplyMatrices(LMStoXYZ_M, lab);
// }
// function oklch2rgb(lch) { return srgbLinear2rgb(xyz2rgbLinear(oklab_to_xyz(oklch2oklab(lch)))); }
// function rgb2oklch(rgb) { return oklab2oklch(xyz_to_oklab(rgbLinear2xyz(rgb2srgbLinear(rgb)))); }
/// oklab conversion by Culori
/// https://github.com/Evercoder/culori/blob/main/src/oklab/convertOklabToLrgb.js#L1
function convertOklabToLrgb(lab) {
var l = lab[0];
var a = lab[1];
var b = lab[2];
var L = power(l * 0.99999999845051981432 + 0.39633779217376785678 * a + 0.21580375806075880339 * b, 3 );
var M = power(l * 1.0000000088817607767 - 0.1055613423236563494 * a - 0.063854174771705903402 * b, 3 );
var S = power(l * 1.0000000546724109177 - 0.089484182094965759684 * a - 1.2914855378640917399 * b, 3 );
return [ +4.076741661347994 * L - 3.307711590408193 * M + 0.230969928729428 * S,
-1.2684380040921763 * L + 2.6097574006633715 * M - 0.3413193963102197 * S,
-0.004196086541837188 * L - 0.7034186144594493 * M + 1.7076147009309444 * S
];
}
function convertLrgbToOklab(rgb) {
var r = rgb[0];
var g = rgb[1];
var b = rgb[2];
var L = power( 0.41222147079999993 * r + 0.5363325363 * g + 0.0514459929 * b, 1 / 3);
var M = power( 0.2119034981999999 * r + 0.6806995450999999 * g + 0.1073969566 * b, 1 / 3);
var S = power( 0.08830246189999998 * r + 0.2817188376 * g + 0.6299787005000002 * b, 1 / 3);
return [
0.2104542553 * L + 0.793617785 * M - 0.0040720468 * S,
1.9779984951 * L - 2.428592205 * M + 0.4505937099 * S,
0.0259040371 * L + 0.7827717662 * M - 0.808675766 * S
]
};
function oklch2rgb(lch) { return srgbLinear2rgb(convertOklabToLrgb(oklch2oklab(lch))); }
function rgb2oklch(rgb) { return oklab2oklch(convertLrgbToOklab(rgb2srgbLinear(rgb))); }
//////////////////////////////////////////////////// Gamut intersection ////////////////////////////////////////////////////
/// Björn Ottosson
/// https://bottosson[1]ithub.io/posts/gamutclipping/
// Finds the maximum saturation possible for a given hue that fits in sRGB
// Saturation here is defined as S = C/L
// a and b must be normalized so a^2 + b^2 == 1
function compute_max_saturation(a, b) {
// Max saturation will be when one of r, g or b goes below zero.
// Select different coefficients depending on which component goes below zero first
var k0, k1, k2, k3, k4, wl, wm, ws;
if (-1.88170328 * a - 0.80936493 * b > 1) {
// Red component
k0 = +1.19086277; k1 = +1.76576728; k2 = +0.59662641; k3 = +0.75515197; k4 = +0.56771245;
wl = +4.0767416621; wm = -3.3077115913; ws = +0.2309699292;
} else if (1.81444104 * a - 1.19445276 * b > 1) {
// Green component
k0 = +0.73956515; k1 = -0.45954404; k2 = +0.08285427; k3 = +0.12541070; k4 = +0.14503204;
wl = -1.2684380046; wm = +2.6097574011; ws = -0.3413193965;
} else {
// Blue component
k0 = +1.35733652; k1 = -0.00915799; k2 = -1.15130210; k3 = -0.50559606; k4 = +0.00692167;
wl = -0.0041960863; wm = -0.7034186147; ws = +1.7076147010;
}
// Approximate max saturation using a polynomial:
var S = k0 + k1 * a + k2 * b + k3 * a * a + k4 * a * b;
// Do one step Halley's method to get closer
// this gives an error less than 10e6, except for some blue hues where the dS/dh is close to infinite
// this should be sufficient for most applications, otherwise do two/three steps
var k_l = +0.3963377774 * a + 0.2158037573 * b;
var k_m = -0.1055613458 * a - 0.0638541728 * b;
var k_s = -0.0894841775 * a - 1.2914855480 * b;
var l_ = 1. + S * k_l;
var m_ = 1. + S * k_m;
var s_ = 1. + S * k_s;
var l = l_ * l_ * l_;
var m = m_ * m_ * m_;
var s = s_ * s_ * s_;
var l_dS = 3. * k_l * l_ * l_;
var m_dS = 3. * k_m * m_ * m_;
var s_dS = 3. * k_s * s_ * s_;
var l_dS2 = 6. * k_l * k_l * l_;
var m_dS2 = 6. * k_m * k_m * m_;
var s_dS2 = 6. * k_s * k_s * s_;
var f = wl * l + wm * m + ws * s;
var f1 = wl * l_dS + wm * m_dS + ws * s_dS;
var f2 = wl * l_dS2 + wm * m_dS2 + ws * s_dS2;
S = S - f * f1 / (f1 * f1 - 0.5 * f * f2);
return S;
}
// finds L_cusp and C_cusp for a given hue
// a and b must be normalized so a^2 + b^2 == 1
// struct LC { var L; var C; };
function find_cusp(a, b) {
// First, find the maximum saturation (saturation S = C/L)
var S_cusp = compute_max_saturation(a, b);
// Convert to linear sRGB to find the first point where at least one of r,g or b >= 1:
var rgb_at_max = oklab_to_linear_srgb([ 1, S_cusp * a, S_cusp * b ]);
var L_cusp = power(1 / max(rgb_at_max[0], rgb_at_max[1], rgb_at_max[2]), 1 / 3);
var C_cusp = L_cusp * S_cusp;
return [ L_cusp , C_cusp ];
}
// Finds intersection of the line defined by
// L = L0 * (1 - t) + t * L1;
// C = t * C1;
// a and b must be normalized so a^2 + b^2 == 1
function find_gamut_intersection(a, b, L1, C1, L0) {
// Find the cusp of the gamut triangle
var cusp = find_cusp(a, b);
// Find the intersection for upper and lower half seprately
var t;
if (((L1 - L0) * cusp[1] - (cusp[0] - L0) * C1) <= 0.) {
// Lower half
t = cusp[1] * L0 / (C1 * cusp[0] + cusp[1] * (L0 - L1));
} else {
// Upper half
// First intersect with triangle
t = cusp[1] * (L0 - 1.) / (C1 * (cusp[0] - 1.) + cusp[1] * (L0 - L1));
// Then one step Halley's method
var dL = L1 - L0;
var dC = C1;
var k_l = +0.3963377774 * a + 0.2158037573 * b;
var k_m = -0.1055613458 * a - 0.0638541728 * b;
var k_s = -0.0894841775 * a - 1.2914855480 * b;
var l_dt = dL + dC * k_l;
var m_dt = dL + dC * k_m;
var s_dt = dL + dC * k_s;
// If higher accuracy is required, 2 or 3 iterations of the following block can be used:
var L = L0 * (1. - t) + t * L1;
var C = t * C1;
var l_ = L + C * k_l;
var m_ = L + C * k_m;
var s_ = L + C * k_s;
var l = l_ * l_ * l_;
var m = m_ * m_ * m_;
var s = s_ * s_ * s_;
var ldt = 3 * l_dt * l_ * l_;
var mdt = 3 * m_dt * m_ * m_;
var sdt = 3 * s_dt * s_ * s_;
var ldt2 = 6 * l_dt * l_dt * l_;
var mdt2 = 6 * m_dt * m_dt * m_;
var sdt2 = 6 * s_dt * s_dt * s_;
var r = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s - 1;
var r1 = 4.0767416621 * ldt - 3.3077115913 * mdt + 0.2309699292 * sdt;
var r2 = 4.0767416621 * ldt2 - 3.3077115913 * mdt2 + 0.2309699292 * sdt2;
var u_r = r1 / (r1 * r1 - 0.5 * r * r2);
var t_r = -r * u_r;
var g = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s - 1;
var g1 = -1.2684380046 * ldt + 2.6097574011 * mdt - 0.3413193965 * sdt;
var g2 = -1.2684380046 * ldt2 + 2.6097574011 * mdt2 - 0.3413193965 * sdt2;
var u_g = g1 / (g1 * g1 - 0.5 * g * g2);
var t_g = -g * u_g;
var b0 = -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s - 1;
var b1 = -0.0041960863 * ldt - 0.7034186147 * mdt + 1.7076147010 * sdt;
var b2 = -0.0041960863 * ldt2 - 0.7034186147 * mdt2 + 1.7076147010 * sdt2;
var u_b = b1 / (b1 * b1 - 0.5 * b0 * b2);
var t_b = -b0 * u_b;
t_r = u_r >= 0. ? t_r : 99999.;
t_g = u_g >= 0. ? t_g : 99999.;
t_b = u_b >= 0. ? t_b : 99999.;
t += min(t_r, t_g, t_b);
}
return t;
}
//////////////////////////////////////////////////// Gamut clipping ////////////////////////////////////////////////////
function gamut_clip_preserve_chroma(rgb) {
if (rgb[0] < 1 && rgb[1] < 1 && rgb[2] < 1 && rgb[0] > 0 && rgb[1] > 0 && rgb[2] > 0)
return rgb;
var lab = linear_srgb_to_oklab(rgb);
var L = lab[0];
var eps = 0.00001;
var d = is_nan(lab[1]) || is_nan(lab[2])? 0 : sqrt(lab[1] * lab[1] + lab[2] * lab[2]);
var C = max(eps, d);
var a_ = lab[1] / C;
var b_ = lab[2] / C;
var L0 = clamp(L, 0, 1);
var t = find_gamut_intersection(a_, b_, L, C, L0);
var L_clipped = L0 * (1 - t) + t * L;
var C_clipped = t * C;
return oklab_to_linear_srgb([ L_clipped, C_clipped * a_, C_clipped * b_ ]);
}
function gamut_clip_project_to_0_5(rgb) {
if (rgb[0] < 1 && rgb[1] < 1 && rgb[2] < 1 && rgb[0] > 0 && rgb[1] > 0 && rgb[2] > 0)
return rgb;
var lab = linear_srgb_to_oklab(rgb);
var L = lab[0];
var eps = 0.00001;
var d = is_nan(lab[1]) || is_nan(lab[2])? 0 : sqrt(lab[1] * lab[1] + lab[2] * lab[2]);
var C = max(eps, d);
var a_ = lab[1] / C;
var b_ = lab[2] / C;
var L0 = 0.5;
var t = find_gamut_intersection(a_, b_, L, C, L0);
var L_clipped = L0 * (1 - t) + t * L;
var C_clipped = t * C;
return oklab_to_linear_srgb([ L_clipped, C_clipped * a_, C_clipped * b_ ]);
}
function gamut_clip_project_to_L_cusp(rgb) {
if (rgb[0] < 1 && rgb[1] < 1 && rgb[2] < 1 && rgb[0] > 0 && rgb[1] > 0 && rgb[2] > 0)
return rgb;
var lab = linear_srgb_to_oklab(rgb);
var L = lab[0];
var eps = 0.00001;
var d = is_nan(lab[1]) || is_nan(lab[2])? 0 : sqrt(lab[1] * lab[1] + lab[2] * lab[2]);
var C = max(eps, d);
var a_ = lab[1] / C;
var b_ = lab[2] / C;
// The cusp is computed here and in find_gamut_intersection, an optimized solution would only compute it once.
var cusp = find_cusp(a_, b_);
var L0 = cusp[0];
var t = find_gamut_intersection(a_, b_, L, C, L0);
var L_clipped = L0 * (1 - t) + t * L;
var C_clipped = t * C;
return oklab_to_linear_srgb([ L_clipped, C_clipped * a_, C_clipped * b_ ]);
}
function gamut_clip_adaptive_L0_0_5(rgb, alpha = 0.05) {
if (rgb[0] < 1 && rgb[1] < 1 && rgb[2] < 1 && rgb[0] > 0 && rgb[1] > 0 && rgb[2] > 0)
return rgb;
var lab = linear_srgb_to_oklab(rgb);
var L = lab[0];
var eps = 0.00001;
var d = is_nan(lab[1]) || is_nan(lab[2])? 0 : sqrt(lab[1] * lab[1] + lab[2] * lab[2]);
var C = max(eps, d);
var a_ = lab[1] / C;
var b_ = lab[2] / C;
var Ld = L - 0.5;
var e1 = 0.5 + abs(Ld) + alpha * C;
var L0 = 0.5 *(1. + sign(Ld)*(e1 - sqrt(e1*e1 - 2. * abs(Ld))));
var t = find_gamut_intersection(a_, b_, L, C, L0);
var L_clipped = L0 * (1. - t) + t * L;
var C_clipped = t * C;
return oklab_to_linear_srgb([ L_clipped, C_clipped * a_, C_clipped * b_ ]);
}
function gamut_clip_adaptive_L0_L_cusp(rgb, alpha = 0.05) {
if (rgb[0] < 1 && rgb[1] < 1 && rgb[2] < 1 && rgb[0] > 0 && rgb[1] > 0 && rgb[2] > 0)
return rgb;
var lab = linear_srgb_to_oklab(rgb);
var L = lab[0];
var eps = 0.00001;
var d = is_nan(lab[1]) || is_nan(lab[2])? 0 : sqrt(lab[1] * lab[1] + lab[2] * lab[2]);
var C = max(eps, d);
var a_ = lab[1] / C;
var b_ = lab[2] / C;
// The cusp is computed here and in find_gamut_intersection, an optimized solution would only compute it once.
var cusp = find_cusp(a_, b_);
var Ld = L - cusp[0];
var k = 2. * (Ld > 0 ? 1. - cusp[0] : cusp[0]);
var e1 = 0.5 * k + abs(Ld) + alpha * C / k;
var L0 = cusp[0] + 0.5 * (sign(Ld) * (e1 - sqrt(e1 * e1 - 2. * k * abs(Ld))));
var t = find_gamut_intersection(a_, b_, L, C, L0);
var L_clipped = L0 * (1. - t) + t * L;
var C_clipped = t * C;
return oklab_to_linear_srgb([ L_clipped, C_clipped * a_, C_clipped * b_ ]);
}

View file

@ -0,0 +1,13 @@
{
"$GMScript":"v1",
"%Name":"okhsl_function",
"isCompatibility":false,
"isDnD":false,
"name":"okhsl_function",
"parent":{
"name":"value",
"path":"folders/functions/value.yy",
},
"resourceType":"GMScript",
"resourceVersion":"2.0",
}

View file

@ -1735,8 +1735,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
}
if(DOUBLE_CLICK && junction_hovering != noone) {
var _mx = round(mouse_graph_x / project.graphGrid.size) * project.graphGrid.size;
var _my = round(mouse_graph_y / project.graphGrid.size) * project.graphGrid.size;
var _mx = value_snap(mouse_graph_x, project.graphGrid.size);
var _my = value_snap(mouse_graph_y - 8, project.graphGrid.size);
var _pin = nodeBuild("Node_Pin", _mx, _my).skipDefault();
_pin.inputs[0].setFrom(junction_hovering.value_from);
@ -3407,8 +3407,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
var _key = $"{__junction_hovering.name} {seed_random(3)}";
var _ti = nodeBuild("Node_Tunnel_In", _jo.rx + 32, _jo.ry).skipDefault();
var _to = nodeBuild("Node_Tunnel_Out", _ji.rx - 32, _ji.ry).skipDefault();
var _ti = nodeBuild("Node_Tunnel_In", _jo.rx + 32, _jo.ry - 8).skipDefault();
var _to = nodeBuild("Node_Tunnel_Out", _ji.rx - 32, _ji.ry - 8).skipDefault();
_to.inputs[0].setValue(_key);
_ti.inputs[0].setValue(_key);
@ -3418,6 +3418,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
_to.inputs[0].updateColor();
_ti.inputs[1].updateColor();
run_in(1, function() /*=>*/ { RENDER_ALL_REORDER });
}
function createAction() {

View file

@ -792,6 +792,7 @@ function Panel_Inspector() : PanelContent() constructor {
} else if(is_instanceof(jun, Inspector_Label)) { // TEXT
var _txt = jun.text;
if(_txt == "") continue;
draw_set_text(jun.font, fa_left, fa_top, COLORS._main_text_sub);
var _sh = string_height_ext(_txt, -1, con_w - ui(16)) + ui(16);

View file

@ -89,7 +89,7 @@ function Panel_Tunnels() : PanelContent() constructor {
bx -= ui(32);
if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, sc_tunnel.active, sc_tunnel.hover, __txtx("panel_tunnel_create_tunnel", "Create tunnel out"), THEME.tunnel) == 2) {
var _node = nodeBuild("Node_Tunnel_Out", build_x, build_y);
var _node = nodeBuild("Node_Tunnel_Out", build_x, build_y - 8);
_node.inputs[0].setValue(key);
if(in_dialog) instance_destroy();
@ -166,6 +166,6 @@ function Panel_Tunnels() : PanelContent() constructor {
draw_text_add(_ww / 2, _by + _add_h / 2, __txtx("panel_tunnel_create_tunnel", "Create tunnel"));
if(mouse_press(mb_left, pFOCUS && _hov))
nodeBuild("Node_Tunnel_In", build_x, build_y);
nodeBuild("Node_Tunnel_In", build_x, build_y - 8);
}
}

View file

@ -7,5 +7,6 @@ enum SLIDER_UPDATE {
function slider(_min, _max, _step, _onModify = noone, _onRelease = noone) {
return new textBox( TEXTBOX_INPUT.number, _onModify )
.setSlideRange(_min, _max)
.setSlideStep(_step)
.setOnRelease(_onRelease);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -0,0 +1,90 @@
{
"$GMSprite":"",
"%Name":"s_node_color_from_oklch",
"bboxMode":0,
"bbox_bottom":58,
"bbox_left":3,
"bbox_right":60,
"bbox_top":5,
"collisionKind":1,
"collisionTolerance":0,
"DynamicTexturePage":false,
"edgeFiltering":false,
"For3D":false,
"frames":[
{"$GMSpriteFrame":"","%Name":"c7ffe7cd-5579-4d12-9c16-1f5880d2694b","name":"c7ffe7cd-5579-4d12-9c16-1f5880d2694b","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
],
"gridX":0,
"gridY":0,
"height":64,
"HTile":false,
"layers":[
{"$GMImageLayer":"","%Name":"7032c944-6dc2-4c87-9013-5489a072d718","blendMode":0,"displayName":"default","isLocked":false,"name":"7032c944-6dc2-4c87-9013-5489a072d718","opacity":100.0,"resourceType":"GMImageLayer","resourceVersion":"2.0","visible":true,},
],
"name":"s_node_color_from_oklch",
"nineSlice":null,
"origin":4,
"parent":{
"name":"color",
"path":"folders/nodes/icons/value/color.yy",
},
"preMultiplyAlpha":false,
"resourceType":"GMSprite",
"resourceVersion":"2.0",
"sequence":{
"$GMSequence":"",
"%Name":"s_node_color_from_oklch",
"autoRecord":true,
"backdropHeight":768,
"backdropImageOpacity":0.5,
"backdropImagePath":"",
"backdropWidth":1366,
"backdropXOffset":0.0,
"backdropYOffset":0.0,
"events":{
"$KeyframeStore<MessageEventKeyframe>":"",
"Keyframes":[],
"resourceType":"KeyframeStore<MessageEventKeyframe>",
"resourceVersion":"2.0",
},
"eventStubScript":null,
"eventToFunction":{},
"length":1.0,
"lockOrigin":false,
"moments":{
"$KeyframeStore<MomentsEventKeyframe>":"",
"Keyframes":[],
"resourceType":"KeyframeStore<MomentsEventKeyframe>",
"resourceVersion":"2.0",
},
"name":"s_node_color_from_oklch",
"playback":1,
"playbackSpeed":30.0,
"playbackSpeedType":0,
"resourceType":"GMSequence",
"resourceVersion":"2.0",
"showBackdrop":true,
"showBackdropImage":false,
"timeUnits":1,
"tracks":[
{"$GMSpriteFramesTrack":"","builtinName":0,"events":[],"inheritsTrackColour":true,"interpolation":1,"isCreationTrack":false,"keyframes":{"$KeyframeStore<SpriteFrameKeyframe>":"","Keyframes":[
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"c7ffe7cd-5579-4d12-9c16-1f5880d2694b","path":"sprites/s_node_color_from_oklch/s_node_color_from_oklch.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"1623f336-dbe0-492a-a38f-8c4053038b24","IsCreationKey":false,"Key":0.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,
"volume":1.0,
"xorigin":32,
"yorigin":32,
},
"swatchColours":null,
"swfPrecision":0.5,
"textureGroupId":{
"name":"Default",
"path":"texturegroups/Default",
},
"type":0,
"VTile":false,
"width":64,
}