diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl index 860386d366b..522bf14ba27 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl @@ -2,15 +2,25 @@ * * SPDX-License-Identifier: GPL-2.0-or-later */ -#define ANTIALIAS 1.5 -#define MINIMUM_ALPHA 0.5 +#define ANTIALIAS 0.75 + +float get_line_alpha(float center, float relative_radius) { + float radius = relative_radius * lineThickness; + float sdf = abs(lineThickness * (lineUV.y - center)); + return smoothstep(radius, radius - ANTIALIAS, sdf); +} void main() { - fragColor = finalColor; + if (isMainLine == 0) { + fragColor = finalColor; + fragColor.a *= get_line_alpha(0.5, 0.5); + return; + } - if ((isMainLine != 0) && (dashFactor < 1.0)) { - float distance_along_line = lineLength * lineU; + float dash_frag_alpha = 1.0; + if (dashFactor < 1.0) { + float distance_along_line = lineLength * lineUV.x; float normalized_distance = fract(distance_along_line / dashLength); /* Checking if `normalized_distance <= dashFactor` is already enough for a basic @@ -25,8 +35,9 @@ void main() float unclamped_alpha = 1.0 - slope * (normalized_distance_triangle - dashFactor + t); float alpha = max(dashAlpha, min(unclamped_alpha, 1.0)); - fragColor.a *= alpha; + dash_frag_alpha = alpha; } - fragColor.a *= smoothstep(lineThickness, lineThickness - ANTIALIAS, abs(colorGradient)); + fragColor = finalColor; + fragColor.a *= get_line_alpha(0.5, 0.5) * dash_frag_alpha; } diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl index cc7e3a49cfb..cd640f50abd 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl @@ -42,8 +42,9 @@ void main(void) #endif float line_thickness = thickness; + bool is_outline_pass = gl_VertexID < MID_VERTEX; - if (gl_VertexID < MID_VERTEX) { + if (is_outline_pass) { /* Outline pass. */ finalColor = colShadow; } @@ -67,15 +68,15 @@ void main(void) } aspect = node_link_data.aspect; + isMainLine = expand.y == 1.0 && !is_outline_pass ? 1 : 0; /* Parameters for the dashed line. */ - isMainLine = expand.y != 1.0 ? 0 : 1; dashLength = dash_params.x; dashFactor = dash_params.y; dashAlpha = dash_params.z; /* Approximate line length, no need for real bezier length calculation. */ lineLength = distance(P0, P3); /* TODO: Incorrect U, this leads to non-uniform dash distribution. */ - lineU = uv.x; + lineUV = uv; float t = uv.x; float t2 = t * t; @@ -106,7 +107,6 @@ void main(void) ModelViewProjectionMatrix[1].xy * exp_axis.yy; float expand_dist = line_thickness * (uv.y * 2.0 - 1.0); - colorGradient = expand_dist; lineThickness = line_thickness; finalColor[3] *= dim_factor; diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh index 23c3d340ce5..e4bb590514e 100644 --- a/source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh +++ b/source/blender/gpu/shaders/infos/gpu_shader_2D_nodelink_info.hh @@ -10,8 +10,7 @@ GPU_SHADER_INTERFACE_INFO(nodelink_iface, "") .smooth(Type::VEC4, "finalColor") - .smooth(Type::FLOAT, "colorGradient") - .smooth(Type::FLOAT, "lineU") + .smooth(Type::VEC2, "lineUV") .flat(Type::FLOAT, "lineLength") .flat(Type::FLOAT, "lineThickness") .flat(Type::FLOAT, "dashLength")