diff options
-rw-r--r-- | release/datafiles/userdef/userdef_default_theme.c | 2 | ||||
-rw-r--r-- | release/scripts/presets/interface_theme/Blender_Light.xml | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_blender_version.h | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_userdef.c | 4 | ||||
-rw-r--r-- | source/blender/editors/include/ED_node.h | 2 | ||||
-rw-r--r-- | source/blender/editors/include/UI_view2d.h | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d.c | 83 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_userdef.c | 4 |
8 files changed, 58 insertions, 45 deletions
diff --git a/release/datafiles/userdef/userdef_default_theme.c b/release/datafiles/userdef/userdef_default_theme.c index 292080ef629..08f91781aa0 100644 --- a/release/datafiles/userdef/userdef_default_theme.c +++ b/release/datafiles/userdef/userdef_default_theme.c @@ -833,7 +833,7 @@ const bTheme U_theme_default = { .outline_width = 1, .facedot_size = 4, .noodle_curving = 4, - .grid_levels = 7, + .grid_levels = 3, .dash_alpha = 0.5f, .syntaxl = RGBA(0x303030ff), .syntaxs = RGBA(0x973c3cff), diff --git a/release/scripts/presets/interface_theme/Blender_Light.xml b/release/scripts/presets/interface_theme/Blender_Light.xml index 9a315763c8b..49955bc3ff9 100644 --- a/release/scripts/presets/interface_theme/Blender_Light.xml +++ b/release/scripts/presets/interface_theme/Blender_Light.xml @@ -955,7 +955,7 @@ matte_node="#977474" distor_node="#749797" noodle_curving="4" - grid_levels="7" + grid_levels="3" dash_alpha="0.5" input_node="#cb3d4a" output_node="#cb3d4a" diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 7686fce3aca..604c8cb7a06 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -25,7 +25,7 @@ extern "C" { /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 7 +#define BLENDER_FILE_SUBVERSION 8 /* Minimum Blender version that supports reading file written with the current * version. Older Blender versions will test this and show a warning if the file diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c index 3b966fe5358..ec76f516780 100644 --- a/source/blender/blenloader/intern/versioning_userdef.c +++ b/source/blender/blenloader/intern/versioning_userdef.c @@ -324,6 +324,10 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme) if (!USER_VERSION_ATLEAST(301, 2)) { FROM_DEFAULT_V4_UCHAR(space_sequencer.mask); } + + if (!USER_VERSION_ATLEAST(302, 8)) { + btheme->space_node.grid_levels = U_theme_default.space_node.grid_levels; + } /** * Versioning code until next subversion bump goes here. * diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h index 8c9fa7e4494..c30b8c5ec6a 100644 --- a/source/blender/editors/include/ED_node.h +++ b/source/blender/editors/include/ED_node.h @@ -33,7 +33,7 @@ typedef enum { NODE_RIGHT = 8, } NodeBorder; -#define NODE_GRID_STEP_SIZE 10 +#define NODE_GRID_STEP_SIZE U.widget_unit /* Based on the grid nodes snap to. */ #define NODE_EDGE_PAN_INSIDE_PAD 2 #define NODE_EDGE_PAN_OUTSIDE_PAD 0 /* Disable clamping for node panning, use whole screen. */ #define NODE_EDGE_PAN_SPEED_RAMP 1 diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index b69d3008f1d..4282465c0ca 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -178,12 +178,12 @@ void UI_view2d_multi_grid_draw( * \param grid_color_id: The theme color used for the points. Faded dynamically based on zoom. * \param min_step: The base size of the grid. At different zoom levels, the visible grid may have * a larger step size. - * \param grid_levels: The maximum grid depth. Larger grid levels will subdivide the grid more. + * \param grid_subdivisions: The maximum number of sub-levels drawn at once. */ void UI_view2d_dot_grid_draw(const struct View2D *v2d, int grid_color_id, float min_step, - int grid_levels); + int grid_subdivisions); void UI_view2d_draw_lines_y__values(const struct View2D *v2d); void UI_view2d_draw_lines_x__values(const struct View2D *v2d); diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 8962e1462b6..bf3c8362ce6 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -1268,59 +1268,67 @@ static void grid_axis_start_and_count( } } -typedef struct DotGridLevelInfo { - /* The factor applied to the #min_step argument. This could be easily computed in runtime, - * but seeing it together with the other values is helpful. */ - float step_factor; - /* The normalized zoom level at which the grid level starts to fade in. - * At lower zoom levels, the points will not be visible and the level will be skipped. */ - float fade_in_start_zoom; - /* The normalized zoom level at which the grid finishes fading in. - * At higher zoom levels, the points will be opaque. */ - float fade_in_end_zoom; -} DotGridLevelInfo; - -static const DotGridLevelInfo level_info[9] = { - {6.4f, -0.1f, 0.01f}, - {3.2f, 0.0f, 0.025f}, - {1.6f, 0.025f, 0.15f}, - {0.8f, 0.05f, 0.2f}, - {0.4f, 0.1f, 0.25f}, - {0.2f, 0.125f, 0.3f}, - {0.1f, 0.25f, 0.5f}, - {0.05f, 0.7f, 0.9f}, - {0.025f, 0.6f, 0.9f}, -}; - void UI_view2d_dot_grid_draw(const View2D *v2d, const int grid_color_id, const float min_step, - const int grid_levels) + const int grid_subdivisions) { - BLI_assert(grid_levels >= 0 && grid_levels < 10); + BLI_assert(grid_subdivisions >= 0 && grid_subdivisions < 4); + if (grid_subdivisions == 0) { + return; + } + const float zoom_x = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur); - const float zoom_normalized = (zoom_x - v2d->minzoom) / (v2d->maxzoom - v2d->minzoom); GPUVertFormat *format = immVertexFormat(); const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); const uint color_id = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); - GPU_point_size(3.0f * UI_DPI_FAC); - float color[4]; - UI_GetThemeColor3fv(grid_color_id, color); + /* Scaling the dots fully with the zoom looks too busy, but a bit of size variation is nice. */ + const float min_point_size = 2.0f * UI_DPI_FAC; + const float point_size_factor = 1.5f; + const float max_point_size = point_size_factor * min_point_size; + + /* Each consecutive grid level is five times larger than the previous. */ + const int subdivision_scale = 5; + + const float view_level = logf(min_step / zoom_x) / logf(subdivision_scale); + const int largest_visible_level = (int)view_level; - for (int level = 0; level < grid_levels; level++) { - const DotGridLevelInfo *info = &level_info[level]; - const float step = min_step * info->step_factor * U.widget_unit; + for (int level_offset = 0; level_offset <= grid_subdivisions; level_offset++) { + const int level = largest_visible_level - level_offset; - const float alpha_factor = (zoom_normalized - info->fade_in_start_zoom) / - (info->fade_in_end_zoom - info->fade_in_start_zoom); - color[3] = clamp_f(BLI_easing_cubic_ease_in_out(alpha_factor, 0.0f, 1.0f, 1.0f), 0.0f, 1.0f); - if (color[3] == 0.0f) { + if (level < 0) { break; } + const float level_scale = powf(subdivision_scale, level); + const float point_size_precise = min_point_size * level_scale * zoom_x; + const float point_size_draw = ceilf( + clamp_f(point_size_precise, min_point_size, max_point_size)); + + /* To compensate the for the clamped point_size we adjust the alpha to make the overall + * brightness of the grid background more consistent. */ + const float alpha = pow2f(point_size_precise / point_size_draw); + + /* Make sure we don't draw points once the alpha gets too low. */ + const float alpha_cutoff = 0.01f; + if (alpha < alpha_cutoff) { + break; + } + const float alpha_clamped = clamp_f((1.0f + alpha_cutoff) * alpha - alpha_cutoff, 0.0f, 1.0f); + + /* If we have don't draw enough subdivision levels so they fade out naturally, we apply an + * additional fade to the last level to avoid pop in. */ + const bool last_level = level_offset == grid_subdivisions; + const float subdivision_fade = last_level ? (1.0f - fractf(view_level)) : 1.0f; + + float color[4]; + UI_GetThemeColor3fv(grid_color_id, color); + color[3] = alpha_clamped * subdivision_fade; + + const float step = min_step * level_scale; int count_x; float start_x; grid_axis_start_and_count(step, v2d->cur.xmin, v2d->cur.xmax, &start_x, &count_x); @@ -1331,6 +1339,7 @@ void UI_view2d_dot_grid_draw(const View2D *v2d, continue; } + GPU_point_size(point_size_draw); immBegin(GPU_PRIM_POINTS, count_x * count_y); /* Theoretically drawing on top of lower grid levels could be avoided, but it would also diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 164564241ed..fd2bb9cb7cc 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2923,8 +2923,8 @@ static void rna_def_userdef_theme_space_node(BlenderRNA *brna) prop = RNA_def_property(srna, "grid_levels", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "grid_levels"); - RNA_def_property_int_default(prop, 7); - RNA_def_property_range(prop, 0, 9); + RNA_def_property_int_default(prop, 3); + RNA_def_property_range(prop, 0, 3); RNA_def_property_ui_text( prop, "Grid Levels", "Number of subdivisions for the dot grid displayed in the background"); RNA_def_property_update(prop, 0, "rna_userdef_theme_update"); |