diff options
author | Siddhartha Jejurkar <sidd017> | 2021-09-29 10:47:32 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-09-29 10:48:35 +0300 |
commit | bf06f76be6316be92a4655a41391e163d2fb1221 (patch) | |
tree | 5dac6a12fb65f0897806739d5ef8e00407112041 /source/blender/draw/engines | |
parent | 008ae26712f85475a8a9dc4d031447e12fb05522 (diff) |
UV Editor: Grid and snapping improvements
Implements T89789, T89792, custom grid (described as dynamic grid in
T78389) and UV grid snapping (T78391)
Replaces the default UV editor grid with 2 new types of grid :
* Custom grid: Allows the user to create an NxN grid, where the value
of N is specified by the user.
* Subdividing grid: Subdivides the UV editor grid when the user
zooms in the viewport and vice versa when zooming out.
UV snapping improvements :
* Increment snapping: Increment values for snapping are calculated based
on which grid type is being used in the UV editor
(subdividing or custom). In general the increment value is equal to
the distance between 2 visible grid lines.
* Absolute grid snap: New toggle added to increment snapping option in
the UV editor, allows UV grid snapping during translation.
Reviewed By: campbellbarton
Ref D12684
Diffstat (limited to 'source/blender/draw/engines')
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_grid.c | 16 | ||||
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_private.h | 3 | ||||
-rw-r--r-- | source/blender/draw/engines/overlay/shaders/grid_frag.glsl | 15 |
3 files changed, 28 insertions, 6 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_grid.c b/source/blender/draw/engines/overlay/overlay_grid.c index 60cda9f2d61..31c8ed9d664 100644 --- a/source/blender/draw/engines/overlay/overlay_grid.c +++ b/source/blender/draw/engines/overlay/overlay_grid.c @@ -23,6 +23,7 @@ #include "DRW_render.h" #include "DNA_camera_types.h" +#include "DNA_screen_types.h" #include "DEG_depsgraph_query.h" @@ -46,6 +47,7 @@ enum { GRID_BACK = (1 << 9), GRID_CAMERA = (1 << 10), PLANE_IMAGE = (1 << 11), + CUSTOM_GRID = (1 << 12), }; void OVERLAY_grid_init(OVERLAY_Data *vedata) @@ -61,6 +63,7 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata) if (pd->space_type == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + View2D *v2d = &draw_ctx->region->v2d; if (sima->mode == SI_MODE_UV || !ED_space_image_has_buffer(sima)) { shd->grid_flag = GRID_BACK | PLANE_IMAGE | SHOW_GRID; } @@ -68,15 +71,21 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata) shd->grid_flag = 0; } + if (sima->flag & SI_CUSTOM_GRID) { + shd->grid_flag |= CUSTOM_GRID; + } + shd->grid_distance = 1.0f; copy_v3_fl3(shd->grid_size, 1.0f, 1.0f, 1.0f); if (sima->mode == SI_MODE_UV) { shd->grid_size[0] = (float)sima->tile_grid_shape[0]; shd->grid_size[1] = (float)sima->tile_grid_shape[1]; } - for (int step = 0; step < 8; step++) { - shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f); - } + + const int grid_size = SI_GRID_STEPS_LEN; + shd->zoom_factor = ED_space_image_zoom_level(v2d, grid_size); + ED_space_image_grid_steps(sima, shd->grid_steps, grid_size); + return; } @@ -248,6 +257,7 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata) grp = DRW_shgroup_create(sh, psl->grid_ps); DRW_shgroup_uniform_int(grp, "gridFlag", &shd->grid_flag, 1); + DRW_shgroup_uniform_float_copy(grp, "zoomFactor", shd->zoom_factor); DRW_shgroup_uniform_vec3(grp, "planeAxes", shd->grid_axes, 1); DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h index 23df571e8de..def278f98df 100644 --- a/source/blender/draw/engines/overlay/overlay_private.h +++ b/source/blender/draw/engines/overlay/overlay_private.h @@ -139,9 +139,10 @@ typedef struct OVERLAY_ShadingData { /** Grid */ float grid_axes[3], grid_distance; float zplane_axes[3], grid_size[3]; - float grid_steps[8]; + float grid_steps[SI_GRID_STEPS_LEN]; float inv_viewport_size[2]; float grid_line_size; + float zoom_factor; /* Only for UV editor */ int grid_flag; int zpos_flag; int zneg_flag; diff --git a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl index 3220adbff36..9feca644bd3 100644 --- a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl @@ -15,8 +15,9 @@ uniform float lineKernel = 0.0; uniform sampler2D depthBuffer; uniform int gridFlag; +uniform float zoomFactor; -#define STEPS_LEN 8 +#define STEPS_LEN 8 /* Match: #SI_GRID_STEPS_LEN */ uniform float gridSteps[STEPS_LEN] = float[](0.001, 0.01, 0.1, 1.0, 10.0, 100.0, 1000.0, 10000.0); #define AXIS_X (1 << 0) @@ -28,6 +29,8 @@ uniform float gridSteps[STEPS_LEN] = float[](0.001, 0.01, 0.1, 1.0, 10.0, 100.0, #define PLANE_YZ (1 << 6) #define GRID_BACK (1 << 9) /* grid is behind objects */ #define GRID_CAMERA (1 << 10) /* In camera view */ +#define PLANE_IMAGE (1 << 11) /* UV/Image Image editor */ +#define CUSTOM_GRID (1 << 12) /* UV Editor only */ #define M_1_SQRTPI 0.5641895835477563 /* 1/sqrt(pi) */ @@ -122,9 +125,17 @@ void main() * would be more accurate, but not really necessary. */ float grid_res = dot(dFdxPos, screenVecs[0].xyz); - /* The gride begins to appear when it comprises 4 pixels */ + /* The grid begins to appear when it comprises 4 pixels */ grid_res *= 4; + /* For UV/Image editor use zoomFactor */ + if ((gridFlag & PLANE_IMAGE) != 0 && + /* Grid begins to appear when the length of one grid unit is at least + * (256/grid_size) pixels Value of grid_size defined in `overlay_grid.c`. */ + (gridFlag & CUSTOM_GRID) == 0) { + grid_res = zoomFactor; + } + /* from biggest to smallest */ vec4 scale; #if 0 |