From 3b31efa3f1b7e608174941e10c1ee02d499f6928 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Mon, 17 Apr 2023 17:04:43 +0200 Subject: [PATCH 1/5] Geometry Nodes: Set Simulation Zone background color There is no more real transparency. Right now we use the alpha to blend between the background and the zone color. This way they don't look darker when they overlap. See #106810 --- release/datafiles/userdef/userdef_default_theme.c | 2 +- source/blender/blenloader/intern/versioning_userdef.c | 5 +---- source/blender/editors/space_node/node_draw.cc | 7 ++++--- source/blender/makesrna/intern/rna_userdef.c | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/release/datafiles/userdef/userdef_default_theme.c b/release/datafiles/userdef/userdef_default_theme.c index 69e06e25bd7..14c1b9d2a94 100644 --- a/release/datafiles/userdef/userdef_default_theme.c +++ b/release/datafiles/userdef/userdef_default_theme.c @@ -869,7 +869,7 @@ const bTheme U_theme_default = { .nodeclass_layout = RGBA(0x6c696fff), .nodeclass_geometry = RGBA(0x00d6a3ff), .nodeclass_attribute = RGBA(0x001566ff), - .node_zone_simulation = RGBA(0x00000011), + .node_zone_simulation = RGBA(0x66416233), .movie = RGBA(0x0f0f0fcc), .gp_vertex_size = 3, .gp_vertex = RGBA(0x97979700), diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c index 399e7b6366b..ea61273ca39 100644 --- a/source/blender/blenloader/intern/versioning_userdef.c +++ b/source/blender/blenloader/intern/versioning_userdef.c @@ -108,10 +108,7 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme) */ { /* Keep this block, even when empty. */ - - if (btheme->space_node.node_zone_simulation[3] == 0) { - btheme->space_node.node_zone_simulation[3] = 0x11; - } + FROM_DEFAULT_V4_UCHAR(space_node.node_zone_simulation); } #undef FROM_DEFAULT_V4_UCHAR diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index ccd48a748a7..779ef8c2888 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -3164,8 +3164,10 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); - GPU_blend(GPU_BLEND_ALPHA); - immUniformThemeColor(TH_NODE_ZONE_SIMULATION); + float zone_color[4]; + UI_GetThemeColor4fv(TH_NODE_ZONE_SIMULATION, zone_color); + immUniformThemeColorBlend(TH_BACK, TH_NODE_ZONE_SIMULATION, zone_color[3]); + immBegin(GPU_PRIM_TRI_FAN, fillet_boundary_positions.size() + 1); for (const float3 &p : fillet_boundary_positions) { immVertex3fv(pos, p); @@ -3181,7 +3183,6 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, immEnd(); immUnbindProgram(); - GPU_blend(GPU_BLEND_NONE); } } diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 6b6b6eb52ab..e0ebc2f916d 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -3057,7 +3057,7 @@ static void rna_def_userdef_theme_space_node(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Attribute Node", ""); RNA_def_property_update(prop, 0, "rna_userdef_theme_update"); - prop = RNA_def_property(srna, "simulation_region", PROP_FLOAT, PROP_COLOR_GAMMA); + prop = RNA_def_property(srna, "simulation_zone", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_float_sdna(prop, NULL, "node_zone_simulation"); RNA_def_property_array(prop, 4); RNA_def_property_ui_text(prop, "Simulation Zone", ""); -- 2.30.2 From 6b9deddbe93efc4b7ac31b7c733bb9b64d1a2e3e Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 18 Apr 2023 10:30:06 +0200 Subject: [PATCH 2/5] Simulation Zones: Use smooth lines for the countour --- .../blender/editors/space_node/node_draw.cc | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 779ef8c2888..28a26a0f1bf 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -3122,6 +3122,7 @@ static void find_bounds_by_zone_recursive(const SpaceNode &snode, } static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, + const ARegion ®ion, const SpaceNode &snode, const bNodeTree &ntree) { @@ -3162,8 +3163,9 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, const uint pos = GPU_vertformat_attr_add( immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); + /* Draw the background. */ + immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); float zone_color[4]; UI_GetThemeColor4fv(TH_NODE_ZONE_SIMULATION, zone_color); immUniformThemeColorBlend(TH_BACK, TH_NODE_ZONE_SIMULATION, zone_color[3]); @@ -3174,6 +3176,20 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, } immVertex3fv(pos, fillet_boundary_positions[0]); immEnd(); + + /* Draw the countour lines. */ + immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); + float scale; + const View2D &v2d = region.v2d; + UI_view2d_scale_get(&v2d, &scale, nullptr); + float line_width = 1.0f * scale; + + float viewport[4] = {}; + GPU_viewport_size_get_f(viewport); + + immUniform2fv("viewportSize", &viewport[2]); + immUniform1f("lineWidth", line_width * U.pixelsize); + immUniformThemeColorAlpha(TH_NODE_ZONE_SIMULATION, 1.0f); immBegin(GPU_PRIM_LINE_STRIP, fillet_boundary_positions.size() + 1); for (const float3 &p : fillet_boundary_positions) { @@ -3353,7 +3369,7 @@ static void draw_nodetree(const bContext &C, } node_update_nodetree(C, tree_draw_ctx, ntree, nodes, blocks); - node_draw_zones(tree_draw_ctx, *snode, ntree); + node_draw_zones(tree_draw_ctx, region, *snode, ntree); node_draw_nodetree(C, tree_draw_ctx, region, *snode, ntree, nodes, blocks, parent_key); } -- 2.30.2 From 43344af260d86c6b31b08b3aa889bd855475b1ee Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 18 Apr 2023 10:41:18 +0200 Subject: [PATCH 3/5] Simulation Zones: Draw the countours on top Since we now draw the zones fully opaque, we need to make sure a zone can't hide another one that may be inside it. --- .../blender/editors/space_node/node_draw.cc | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 28a26a0f1bf..fee5949f864 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -3132,6 +3132,8 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, } Array> bounds_by_zone(zones->zones.size()); + Array fillet_curve_by_zone(zones->zones.size()); + for (const int zone_i : zones->zones.index_range()) { const TreeZone &zone = *zones->zones[zone_i]; @@ -3152,18 +3154,25 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, } boundary_curve.tag_topology_changed(); - bke::CurvesGeometry fillet_curve = geometry::fillet_curves_poly( + fillet_curve_by_zone[zone_i] = geometry::fillet_curves_poly( boundary_curve, IndexRange(1), VArray::ForSingle(UI_UNIT_X / 2, boundary_positions_num), VArray::ForSingle(5, boundary_positions_num), true, {}); - const Span fillet_boundary_positions = fillet_curve.positions(); + } - const uint pos = GPU_vertformat_attr_add( - immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + const uint pos = GPU_vertformat_attr_add( + immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + /** + * Draw all the countour lines after to prevent them from getting hidden. + * Once we support other zones (e.g., for loops) we will need to sort them in a smarter way. + */ + + for (const int zone_i : zones->zones.index_range()) { + const Span fillet_boundary_positions = fillet_curve_by_zone[zone_i].positions(); /* Draw the background. */ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); float zone_color[4]; @@ -3176,7 +3185,10 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, } immVertex3fv(pos, fillet_boundary_positions[0]); immEnd(); + } + for (const int zone_i : zones->zones.index_range()) { + const Span fillet_boundary_positions = fillet_curve_by_zone[zone_i].positions(); /* Draw the countour lines. */ immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); float scale; -- 2.30.2 From 05a02b00a30387a84e61768b5e20e5d5f5dcf8a4 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 18 Apr 2023 11:20:20 +0200 Subject: [PATCH 4/5] Simulation Zones: Make the round corners smaller There is no reason to make them not match the nodes and Frame radius. --- source/blender/editors/space_node/node_draw.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index fee5949f864..356a76903c9 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -3157,7 +3157,7 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, fillet_curve_by_zone[zone_i] = geometry::fillet_curves_poly( boundary_curve, IndexRange(1), - VArray::ForSingle(UI_UNIT_X / 2, boundary_positions_num), + VArray::ForSingle(BASIS_RAD, boundary_positions_num), VArray::ForSingle(5, boundary_positions_num), true, {}); -- 2.30.2 From c202e47ed001684740941ab116acc50a2901ba10 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 18 Apr 2023 11:24:35 +0200 Subject: [PATCH 5/5] Simulation Zones: Draw background when alpha = 0.0 --- .../blender/editors/space_node/node_draw.cc | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 356a76903c9..63eb4e19c6a 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -3163,20 +3163,29 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, {}); } + const View2D &v2d = region.v2d; + float scale; + UI_view2d_scale_get(&v2d, &scale, nullptr); + float line_width = 1.0f * scale; + float viewport[4] = {}; + GPU_viewport_size_get_f(viewport); + float zone_color[4]; + UI_GetThemeColor4fv(TH_NODE_ZONE_SIMULATION, zone_color); + const uint pos = GPU_vertformat_attr_add( immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); /** * Draw all the countour lines after to prevent them from getting hidden. * Once we support other zones (e.g., for loops) we will need to sort them in a smarter way. - */ - + */ for (const int zone_i : zones->zones.index_range()) { + if (zone_color[3] == 0.0f) { + break; + } const Span fillet_boundary_positions = fillet_curve_by_zone[zone_i].positions(); /* Draw the background. */ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); - float zone_color[4]; - UI_GetThemeColor4fv(TH_NODE_ZONE_SIMULATION, zone_color); immUniformThemeColorBlend(TH_BACK, TH_NODE_ZONE_SIMULATION, zone_color[3]); immBegin(GPU_PRIM_TRI_FAN, fillet_boundary_positions.size() + 1); @@ -3191,13 +3200,6 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/, const Span fillet_boundary_positions = fillet_curve_by_zone[zone_i].positions(); /* Draw the countour lines. */ immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); - float scale; - const View2D &v2d = region.v2d; - UI_view2d_scale_get(&v2d, &scale, nullptr); - float line_width = 1.0f * scale; - - float viewport[4] = {}; - GPU_viewport_size_get_f(viewport); immUniform2fv("viewportSize", &viewport[2]); immUniform1f("lineWidth", line_width * U.pixelsize); -- 2.30.2