erode width fix

This commit is contained in:
Tanasart 2024-04-21 17:06:54 +07:00
parent 63dae9b547
commit 7dbb693687
9 changed files with 383 additions and 5 deletions

View File

@ -1,4 +1,4 @@
// 2024-04-21 16:47:59
// 2024-04-21 17:05:06
function canvas_tool_selection(selector = noone) : canvas_tool() constructor {
self.selector = selector;

View File

@ -1,4 +1,4 @@
// 2024-04-21 16:47:25
// 2024-04-21 16:57:31
function canvas_tool_selection(selector = noone) : canvas_tool() constructor {
self.selector = selector;

View File

@ -0,0 +1,65 @@
// 2024-04-21 17:00:25
function Node_Erode(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Erode";
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
inputs[| 1] = nodeValue("Width", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
.setMappable(10);
inputs[| 2] = nodeValue("Preserve border",self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
inputs[| 3] = nodeValue("Use alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 4] = nodeValue("Mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
inputs[| 5] = nodeValue("Mix", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 6] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
active_index = 6;
inputs[| 7] = nodeValue("Channel", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0b1111)
.setDisplay(VALUE_DISPLAY.toggle, { data: array_create(4, THEME.inspector_channel) });
__init_mask_modifier(4); // inputs 8, 9,
/////////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 10] = nodeValue("Width map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone)
.setVisible(false, false);
/////////////////////////////////////////////////////////////////////////////////////////////////////
input_display_list = [ 6, 7,
["Surfaces", true], 0, 4, 5, 8, 9,
["Erode", false], 1, 10, 2, 3,
]
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
attribute_surface_depth();
static step = function() { #region
__step_mask_modifier();
inputs[| 1].mappableStep();
} #endregion
static processData = function(_outSurf, _data, _output_index, _array_index) {
surface_set_shader(_outSurf, sh_erode);
shader_set_f("dimension", surface_get_width_safe(_data[0]), surface_get_height_safe(_data[0]));
shader_set_f_map("size" , _data[1], _data[10], inputs[| 1]);
shader_set_i("border" , _data[2]);
shader_set_i("alpha" , _data[3]);
draw_surface_safe(_data[0], 0, 0);
surface_reset_shader();
__process_mask_modifier(_data);
_outSurf = mask_apply(_data[0], _outSurf, _data[4], _data[5]);
_outSurf = channel_apply(_data[0], _outSurf, _data[7]);
return _outSurf;
}
}

View File

@ -0,0 +1,65 @@
// 2024-04-21 16:59:54
function Node_Erode(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Erode";
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
inputs[| 1] = nodeValue("Width", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
.setMappable(10);
inputs[| 2] = nodeValue("Preserve border",self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
inputs[| 3] = nodeValue("Use alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 4] = nodeValue("Mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
inputs[| 5] = nodeValue("Mix", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 6] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
active_index = 6;
inputs[| 7] = nodeValue("Channel", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0b1111)
.setDisplay(VALUE_DISPLAY.toggle, { data: array_create(4, THEME.inspector_channel) });
__init_mask_modifier(4); // inputs 8, 9,
/////////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 10] = nodeValue("Width map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone)
.setVisible(false, false);
/////////////////////////////////////////////////////////////////////////////////////////////////////
input_display_list = [ 6, 7,
["Surfaces", true], 0, 4, 5, 8, 9,
["Erode", false], 1, 10, 2, 3,
]
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
attribute_surface_depth();
static step = function() { #region
__step_mask_modifier();
inputs[| 1].mappableStep();
} #endregion
static processData = function(_outSurf, _data, _output_index, _array_index) {
surface_set_shader(_outSurf, sh_erode);
shader_set_f("dimension", surface_get_width_safe(_data[0]), surface_get_height_safe(_data[0]));
shader_set_f_map("size" , _data[1], _data[10], inputs[| 1]);
shader_set_i("border" , _data[2]);
shader_set_i("alpha" , _data[3]);
draw_surface_safe(_data[0], 0, 0);
surface_reset_shader();
__process_mask_modifier(_data);
_outSurf = mask_apply(_data[0], _outSurf, _data[4], _data[5]);
_outSurf = channel_apply(_data[0], _outSurf, _data[7]);
return _outSurf;
}
}

View File

@ -0,0 +1,107 @@
// 2024-04-21 17:06:08
function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Pin";
w = 32;
h = 32;
auto_height = false;
junction_shift_y = 16;
isHovering = false;
hover_scale = 0;
hover_scale_to = 0;
hover_alpha = 0;
bg_spr = THEME.node_pin_bg;
bg_sel_spr = THEME.node_pin_bg_active;
inputs[| 0] = nodeValue("In", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0 )
.setVisible(true, true);
outputs[| 0] = nodeValue("Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
static step = function() { #region
if(inputs[| 0].isLeaf()) return;
inputs[| 0].setType(inputs[| 0].value_from.type);
outputs[| 0].setType(inputs[| 0].value_from.type);
inputs[| 0].color_display = inputs[| 0].value_from.color_display;
outputs[| 0].color_display = inputs[| 0].color_display;
} #endregion
static update = function() { #region
var _val = getInputData(0);
outputs[| 0].setValue(_val);
} #endregion
static pointIn = function(_x, _y, _mx, _my, _s) { #region
var xx = x * _s + _x;
var yy = y * _s + _y;
return point_in_circle(_mx, _my, xx, yy, _s * 24);
} #endregion
static preDraw = function(_x, _y, _s) { #region
var xx = x * _s + _x;
var yy = y * _s + _y;
inputs[| 0].x = xx;
inputs[| 0].y = yy;
outputs[| 0].x = xx;
outputs[| 0].y = yy;
} #endregion
static drawBadge = function(_x, _y, _s) {}
static drawJunctionNames = function(_x, _y, _mx, _my, _s) {}
static drawJunctions = function(_x, _y, _mx, _my, _s) { #region
isHovering = false;
var hover = noone;
var xx = x * _s + _x;
var yy = y * _s + _y;
var hov = PANEL_GRAPH.value_dragging;
if(hov == noone && point_in_circle(_mx, _my, xx, yy, _s * 24)) {
isHovering = true;
hover_scale_to = 1;
}
if(outputs[| 0].drawJunction(_s, _mx, _my))
hover = outputs[| 0];
return hover;
} #endregion
static drawNode = function(_x, _y, _mx, _my, _s) { #region
if(group != PANEL_GRAPH.getCurrentContext()) return;
var xx = x * _s + _x;
var yy = y * _s + _y;
hover_alpha = 0.5;
if(active_draw_index > -1) {
hover_alpha = 1;
hover_scale_to = 1;
active_draw_index = -1;
}
if(hover_scale > 0) {
draw_set_color(COLORS._main_accent);
draw_set_alpha(hover_alpha);
draw_circle_border(xx, yy, _s * hover_scale * 20, 2);
draw_set_alpha(1);
}
hover_scale = lerp_float(hover_scale, hover_scale_to, 3);
hover_scale_to = 0;
if(renamed && display_name != "" && display_name != "Pin") {
draw_set_text(f_p0, fa_center, fa_bottom, COLORS._main_text);
draw_text_transformed(xx, yy - 12, display_name, _s, _s, 0);
}
return drawJunctions(_x, _y, _mx, _my, _s);
} #endregion
}

View File

@ -0,0 +1,69 @@
// 2024-04-21 17:03:04
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform int border;
uniform int alpha;
uniform vec2 size;
uniform int sizeUseSurf;
uniform sampler2D sizeSurf;
#define TAU 6.283185307179586
float bright(in vec4 col) { return dot(col.rgb, vec3(0.2126, 0.7152, 0.0722)) * col.a; }
void main() {
vec2 pixelPosition = v_vTexcoord * dimension;
vec4 point = texture2D( gm_BaseTexture, v_vTexcoord );
vec4 fill = vec4(0.);
if(alpha == 0) fill.a = 1.;
gl_FragColor = point;
if(alpha == 0 && length(point.rgb) <= 0.) return;
if(alpha == 1 && point.a <= 0.) return;
float siz = size.x;
float sizMax = siz;
if(sizeUseSurf == 1) {
sizMax = max(size.x, size.y);
vec4 _vMap = texture2D( sizeSurf, v_vTexcoord );
siz = mix(size.x, size.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
for(float i = 1.; i <= sizMax; i++) {
if(i > siz) break;
float base = 1.;
float top = 0.;
for(float j = 0.; j <= 64.; j++) {
float ang = top / base * TAU;
top += 2.;
if(top >= base) {
top = 1.;
base *= 2.;
}
vec2 pxs = (pixelPosition + vec2( cos(ang) * i, sin(ang) * i)) / dimension;
if(border == 1)
pxs = clamp(pxs, vec2(0.), vec2(1.));
if(pxs.x < 0. || pxs.x > 1. || pxs.y < 0. || pxs.y > 1.) {
gl_FragColor = fill;
break;
}
vec4 sam = texture2D( gm_BaseTexture, pxs );
if((alpha == 0 && length(sam.rgb) * sam.a == 0.) || (alpha == 1 && sam.a == 0.)) {
gl_FragColor = fill;
break;
}
}
}
}

View File

@ -0,0 +1,69 @@
// 2024-04-21 17:03:03
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform int border;
uniform int alpha;
uniform vec2 size;
uniform int sizeUseSurf;
uniform sampler2D sizeSurf;
#define TAU 6.283185307179586
float bright(in vec4 col) { return dot(col.rgb, vec3(0.2126, 0.7152, 0.0722)) * col.a; }
void main() {
vec2 pixelPosition = v_vTexcoord * dimension;
vec4 point = texture2D( gm_BaseTexture, v_vTexcoord );
vec4 fill = vec4(0.);
if(alpha == 0) fill.a = 1.;
gl_FragColor = point;
if(alpha == 0 && length(point.rgb) <= 0.) return;
if(alpha == 1 && point.a <= 0.) return;
float siz = size.x;
float sizMax = siz;
if(sizeUseSurf == 1) {
sizMax = max(size.x, size.y);
vec4 _vMap = texture2D( sizeSurf, v_vTexcoord );
siz = mix(size.x, size.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
for(float i = 1.; i <= sizMax; i++) {
if(i > siz) break;
float base = 1.;
float top = 0.;
for(float j = 0.; j <= 64.; j++) {
float ang = top / base * TAU;
top += 2.;
if(top >= base) {
top = 1.;
base *= 2.;
}
vec2 pxs = (pixelPosition + vec2( cos(ang) * i, sin(ang) * i)) / dimension;
if(border == 1)
pxs = clamp(pxs, vec2(0.), vec2(1.));
if(pxs.x < 0. || pxs.x > 1. || pxs.y < 0. || pxs.y > 1.) {
gl_FragColor = fill;
break;
}
vec4 sam = texture2D( gm_BaseTexture, pxs );
if((alpha == 0 && length(sam.rgb) * sam.a == 0.) || (alpha == 1 && sam.a == 0.)) {
gl_FragColor = fill;
break;
}
}
}
}

View File

@ -52,6 +52,7 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
outputs[| 0].y = yy;
} #endregion
static drawBadge = function(_x, _y, _s) {}
static drawJunctionNames = function(_x, _y, _mx, _my, _s) {}
static drawJunctions = function(_x, _y, _mx, _my, _s) { #region

View File

@ -28,14 +28,16 @@ void main() {
if(alpha == 1 && point.a <= 0.) return;
float siz = size.x;
float sizMax = max(size.x, size.y);
float sizMax = siz;
if(sizeUseSurf == 1) {
sizMax = max(size.x, size.y);
vec4 _vMap = texture2D( sizeSurf, v_vTexcoord );
siz = mix(size.x, size.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
for(float i = 1.; i < sizMax; i++) {
if(i >= siz) break;
for(float i = 1.; i <= sizMax; i++) {
if(i > siz) break;
float base = 1.;
float top = 0.;