diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index 107c0491f66..ed0710e59e8 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -1730,14 +1730,12 @@ static struct { uint colid_id, muted_id, start_color_id, end_color_id; uint dim_factor_id; uint thickness_id; - uint dash_factor_id; - uint dash_alpha_id; + uint dash_params_id; GPUVertBufRaw p0_step, p1_step, p2_step, p3_step; GPUVertBufRaw colid_step, muted_step, start_color_step, end_color_step; GPUVertBufRaw dim_factor_step; GPUVertBufRaw thickness_step; - GPUVertBufRaw dash_factor_step; - GPUVertBufRaw dash_alpha_step; + GPUVertBufRaw dash_params_step; uint count; bool enabled; } g_batch_link; @@ -1757,9 +1755,7 @@ static void nodelink_batch_reset() GPU_vertbuf_attr_get_raw_data( g_batch_link.inst_vbo, g_batch_link.thickness_id, &g_batch_link.thickness_step); GPU_vertbuf_attr_get_raw_data( - g_batch_link.inst_vbo, g_batch_link.dash_factor_id, &g_batch_link.dash_factor_step); - GPU_vertbuf_attr_get_raw_data( - g_batch_link.inst_vbo, g_batch_link.dash_alpha_id, &g_batch_link.dash_alpha_step); + g_batch_link.inst_vbo, g_batch_link.dash_params_id, &g_batch_link.dash_params_step); GPU_vertbuf_attr_get_raw_data( g_batch_link.inst_vbo, g_batch_link.start_color_id, &g_batch_link.start_color_step); GPU_vertbuf_attr_get_raw_data( @@ -1889,10 +1885,8 @@ static void nodelink_batch_init() &format_inst, "dim_factor", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); g_batch_link.thickness_id = GPU_vertformat_attr_add( &format_inst, "thickness", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); - g_batch_link.dash_factor_id = GPU_vertformat_attr_add( - &format_inst, "dash_factor", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); - g_batch_link.dash_alpha_id = GPU_vertformat_attr_add( - &format_inst, "dash_alpha", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); + g_batch_link.dash_params_id = GPU_vertformat_attr_add( + &format_inst, "dash_params", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); g_batch_link.inst_vbo = GPU_vertbuf_create_with_format_ex(&format_inst, GPU_USAGE_STREAM); /* Alloc max count but only draw the range we need. */ GPU_vertbuf_data_alloc(g_batch_link.inst_vbo, NODELINK_GROUP_SIZE); @@ -1980,6 +1974,7 @@ struct NodeLinkDrawConfig { float dim_factor; float thickness; + float dash_width; float dash_factor; float dash_alpha; }; @@ -2012,8 +2007,8 @@ static void nodelink_batch_add_link(const SpaceNode &snode, muted[0] = draw_config.drawmuted; *(float *)GPU_vertbuf_raw_step(&g_batch_link.dim_factor_step) = draw_config.dim_factor; *(float *)GPU_vertbuf_raw_step(&g_batch_link.thickness_step) = draw_config.thickness; - *(float *)GPU_vertbuf_raw_step(&g_batch_link.dash_factor_step) = draw_config.dash_factor; - *(float *)GPU_vertbuf_raw_step(&g_batch_link.dash_alpha_step) = draw_config.dash_alpha; + float3 dash_params(draw_config.dash_width, draw_config.dash_factor, draw_config.dash_alpha); + copy_v3_v3((float *)GPU_vertbuf_raw_step(&g_batch_link.dash_params_step), dash_params); if (g_batch_link.count == NODELINK_GROUP_SIZE) { nodelink_batch_draw(snode); @@ -2085,6 +2080,7 @@ static NodeLinkDrawConfig nodelink_get_draw_config(const bContext &C, const bool field_link = node_link_is_field_link(snode, link); draw_config.dash_factor = field_link ? 0.75f : 1.0f; + draw_config.dash_width = 10.0f * UI_SCALE_FAC; const float scale = UI_view2d_scale_get_x(&v2d); /* Clamp the thickness to make the links more readable when zooming out. */ @@ -2175,8 +2171,9 @@ static void node_draw_link_bezier_ex(const SpaceNode &snode, node_link_data.doMuted = draw_config.drawmuted; node_link_data.dim_factor = draw_config.dim_factor; node_link_data.thickness = draw_config.thickness; - node_link_data.dash_factor = draw_config.dash_factor; - node_link_data.dash_alpha = draw_config.dash_alpha; + node_link_data.dash_params[0] = draw_config.dash_width; + node_link_data.dash_params[1] = draw_config.dash_factor; + node_link_data.dash_params[2] = draw_config.dash_alpha; node_link_data.expandSize = snode.runtime->aspect * LINK_WIDTH; node_link_data.arrowSize = ARROW_SIZE; diff --git a/source/blender/gpu/GPU_shader_shared.h b/source/blender/gpu/GPU_shader_shared.h index dd8a983d413..c627beaba44 100644 --- a/source/blender/gpu/GPU_shader_shared.h +++ b/source/blender/gpu/GPU_shader_shared.h @@ -39,10 +39,10 @@ struct NodeLinkData { bool1 doMuted; float dim_factor; float thickness; - float dash_factor; - float dash_alpha; + float4 dash_params; float expandSize; float arrowSize; + float2 _pad; }; BLI_STATIC_ASSERT_ALIGN(struct NodeLinkData, 16) 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 433aad85cf6..671d314a128 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl @@ -1,5 +1,4 @@ -#define DASH_WIDTH 10.0 #define ANTIALIAS 1.0 #define MINIMUM_ALPHA 0.5 @@ -9,15 +8,15 @@ void main() if ((isMainLine != 0) && (dashFactor < 1.0)) { float distance_along_line = lineLength * lineU; - float normalized_distance = fract(distance_along_line / DASH_WIDTH); + float normalized_distance = fract(distance_along_line / dashWidth); /* 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 dash_center = dashWidth * 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; + 1.0 - abs((fract((distance_along_line - dash_center) / dashWidth)) * 2.0 - 1.0); + float t = ANTIALIAS / dashWidth; float slope = 1.0 / (2.0 * t); float unclamped_alpha = 1.0 - slope * (normalized_distance_triangle - dashFactor + t); 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 95ba3544105..99954095168 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl @@ -30,8 +30,7 @@ void main(void) bool doMuted = node_link_data.doMuted; float dim_factor = node_link_data.dim_factor; float thickness = node_link_data.thickness; - float dash_factor = node_link_data.dash_factor; - float dash_alpha = node_link_data.dash_alpha; + vec3 dash_params = node_link_data.dash_params.xyz; vec4 colShadow = node_link_data.colors[0]; vec4 colStart = node_link_data.colors[1]; @@ -65,8 +64,9 @@ void main(void) /* Parameters for the dashed line. */ isMainLine = expand.y != 1.0 ? 0 : 1; - dashFactor = dash_factor; - dashAlpha = dash_alpha; + dashWidth = 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. */ 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 84ac5187121..a956710352c 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 @@ -14,6 +14,7 @@ GPU_SHADER_INTERFACE_INFO(nodelink_iface, "") .smooth(Type::FLOAT, "lineU") .flat(Type::FLOAT, "lineLength") .flat(Type::FLOAT, "lineThickness") + .flat(Type::FLOAT, "dashWidth") .flat(Type::FLOAT, "dashFactor") .flat(Type::FLOAT, "dashAlpha") .flat(Type::INT, "isMainLine"); @@ -45,8 +46,7 @@ GPU_SHADER_CREATE_INFO(gpu_shader_2D_nodelink_inst) .vertex_in(10, Type::UVEC2, "domuted") .vertex_in(11, Type::FLOAT, "dim_factor") .vertex_in(12, Type::FLOAT, "thickness") - .vertex_in(13, Type::FLOAT, "dash_factor") - .vertex_in(14, Type::FLOAT, "dash_alpha") + .vertex_in(13, Type::VEC3, "dash_params") .vertex_out(nodelink_iface) .fragment_out(0, Type::VEC4, "fragColor") .uniform_buf(0, "NodeLinkInstanceData", "node_link_data", Frequency::PASS)