Nodes: simplify node link drawing shader
* Better separation between drawing backdrop and main line. * Pass u and v coordinates of line to fragment shader for further processing. * Remove `colorGradient` which can also be computed from `lineUV`. * Simplify drawing potentially more than one parallel line as is done in #112677.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user