Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dalai@blender.org>2021-09-28 18:02:47 +0300
committerDalai Felinto <dalai@blender.org>2021-09-28 18:03:03 +0300
commitff7e67afd5de2d0ce6614ecfda9a70735a2479ba (patch)
treefda70f5c7a799713c08f2559a27d30f336f2f2d1 /source/blender/gpu
parent728ae33f3720894a59009e28d33ae82f77c380b3 (diff)
Geometry Nodes: Dashed lines for function flow
Use dashes to represent the function flow (while keeping continuous lines for the data-flow). It is important to tell both flows apart (the data and the function flow). The sockets help with that, the noodles help this further. The "data flow" is evaluated at every single node. A user can inspect the output sockets of those nodes and have a glimpse at their values. The "function flow" (nodes) however is only evaluated in the geometry nodes. The noodles are not transporting data in the same sense of the "data flow". All that can be inspected are the attributes the functions depend on. Having this clearly communicated should help users to inspect the nodetrees, read and understand the different flows in the same tree. --- Known limitations: At the moment the dash lines are not equidistant: * It would be nice to get the "uv.x" to be resampled for the bezier curve so the dashes are equally distributed in the curve. * Using distance between the P3 and P0 instead of the real bezier curve length seems to be fine. --- Full disclaimer: Changes with that much of a visual impact tend to be controversial. So far the main feedback is that dashed lines can be associated to broken link, and that there are better ways to represent the flows (or different information that should be visually represented). I'm fully aware of that. However dashed lines are already used in the viewport and outliner to indicate (hierarchical) relation. Besides, other approaches (double-lines, having the data flow to be more distinct, ...) didn't pan out in the end (or didn't look as good as this). --- Impact in other editors: The compositor uses mostly a "data flow" nodetree, so no change is expected there. The shader nodetree is one that could but doesn't have to change its visual language. The shader nodetree uses mostly "function flow" with some "data flow" nodes. One can argue that it should be adapted to follow the same pattern as geometry nodes (with the new noodles and the diamond sockets). Oh the other hand, a shader nodetree has a single context. When a node depends on the "UV", there is only one UV at a time for the entire nodetree. So it can also be treated as a psedo "data flow" nodetree if we want to avoid too many changes in other parts of Blender. Differential Revision: https://developer.blender.org/D12602
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl30
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl14
2 files changed, 44 insertions, 0 deletions
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 f07bd7f1d6f..55d5d941290 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl
@@ -1,11 +1,41 @@
in float colorGradient;
in vec4 finalColor;
+in float lineU;
+flat in float lineLength;
+flat in float dashFactor;
+flat in int isMainLine;
out vec4 fragColor;
+#define DASH_WIDTH 20.0
+#define ANTIALIAS 1.0
+
void main()
{
fragColor = finalColor;
+
+ if ((isMainLine != 0) && (dashFactor < 1.0)) {
+ float distance_along_line = lineLength * lineU;
+ float normalized_distance = fract(distance_along_line / DASH_WIDTH);
+
+ /* Checking if `normalized_distance <= dashFactor` is already enough for a basic
+ * dash, however we want to handle a nice antialias. */
+
+ float dash_center = DASH_WIDTH * dashFactor * 0.5;
+ float normalized_distance_triangle =
+ 1.0 - abs((fract((distance_along_line - dash_center) / DASH_WIDTH)) * 2.0 - 1.0);
+ float t = ANTIALIAS / DASH_WIDTH;
+ float slope = 1.0 / (2.0 * t);
+
+ float alpha = min(1.0, max(0.0, slope * (normalized_distance_triangle - dashFactor + t)));
+
+ if (alpha < 0.0) {
+ discard;
+ }
+
+ fragColor.a *= 1.0 - alpha;
+ }
+
fragColor.a *= smoothstep(1.0, 0.1, abs(colorGradient));
}
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 2194d23a4ea..8f46c8eda4b 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl
@@ -20,6 +20,7 @@ in ivec4 colid_doarrow;
in ivec2 domuted;
in float dim_factor;
in float thickness;
+in float dash_factor;
uniform vec4 colors[6];
@@ -43,6 +44,7 @@ uniform bool doArrow;
uniform bool doMuted;
uniform float dim_factor;
uniform float thickness;
+uniform float dash_factor;
# define colShadow colors[0]
# define colStart colors[1]
@@ -56,9 +58,21 @@ uniform mat4 ModelViewProjectionMatrix;
out float colorGradient;
out vec4 finalColor;
+out float lineU;
+flat out float lineLength;
+flat out float dashFactor;
+flat out int isMainLine;
void main(void)
{
+ /* Parameters for the dashed line. */
+ isMainLine = expand.y != 1.0 ? 0 : 1;
+ dashFactor = dash_factor;
+ /* 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;
+
float t = uv.x;
float t2 = t * t;
float t2_3 = 3.0 * t2;