Commit: 39aa0062605635be64d5422e54fad2a4ec08d708 Author: Siddhartha Jejurkar Date: Wed Jun 30 11:55:18 2021 +0530 Branches: soc-2021-uv-editor-improvements https://developer.blender.org/rB39aa0062605635be64d5422e54fad2a4ec08d708
UV: Replace default grid with subdividing grid Replaces the default static grid with a dynamically subdividing grid. This means that zooming in the UV editor will add more divisions to the grid and vice versa when zooming out. =================================================================== M source/blender/draw/engines/overlay/overlay_grid.c M source/blender/draw/engines/overlay/overlay_private.h M source/blender/draw/engines/overlay/shaders/grid_frag.glsl =================================================================== diff --git a/source/blender/draw/engines/overlay/overlay_grid.c b/source/blender/draw/engines/overlay/overlay_grid.c index bd092062e9c..ab2dcb160b0 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), + DYNAMIC_GRID = (1 << 12), }; void OVERLAY_grid_init(OVERLAY_Data *vedata) @@ -61,18 +63,38 @@ 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; + shd->grid_flag = ED_space_image_has_buffer(sima) ? 0 : PLANE_IMAGE | SHOW_GRID; shd->grid_distance = 1.0f; copy_v3_fl3( shd->grid_size, (float)sima->tile_grid_shape[0], (float)sima->tile_grid_shape[1], 1.0f); - for (int step = 0; step < 8; step++) { - if (sima->flag & SI_DYNAMIC_GRID) { + + /* For a NxN grid */ + int N = 4; + float xzoom = (v2d.cur.xmax - v2d.cur.xmin) / ((float)(v2d.mask.xmax - v2d.mask.xmin)); + float yzoom = (v2d.cur.ymax - v2d.cur.ymin) / ((float)(v2d.mask.ymax - v2d.mask.ymin)); + /* Calculating average of xzoom and yzoom for accuracy. Using only xzoom or yzoom would have + * been sufficient */ + shd->zoom_factor = (xzoom + yzoom) / 2.0f; + /* grid begins to appear when the length of one grid unit is at least + * (N^2) pixels in the UV/Image editor */ + shd->zoom_factor *= (N * N); + + printf("xzoom = %f\n", xzoom); + printf("zoom Factor = %f\n\n", shd->zoom_factor); + + if (sima->flag & SI_DYNAMIC_GRID) { + shd->grid_flag |= DYNAMIC_GRID; + for (int step = 0; step < 8; step++) { /* Temporary fix : dynamic_grid_size is not using the default value (=1) assignd in RNA */ sima->dynamic_grid_size = (sima->dynamic_grid_size == 0) ? 1 : sima->dynamic_grid_size; shd->grid_steps[step] = powf(1, step) * (1.0f / ((float)sima->dynamic_grid_size)); } - else { - shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f); + } + else { + for (int step = 0; step < 8; step++) { + shd->grid_steps[step] = powf(N, step) * (1.0f / (powf(N, 8))); } } return; @@ -245,6 +267,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 a48b46a61fc..8c5c8613585 100644 --- a/source/blender/draw/engines/overlay/overlay_private.h +++ b/source/blender/draw/engines/overlay/overlay_private.h @@ -142,6 +142,7 @@ typedef struct OVERLAY_ShadingData { float grid_steps[8]; float inv_viewport_size[2]; float grid_line_size; + float zoom_factor; /* Length per pixel in the UV editor viewport */ 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..81e3f341a4f 100644 --- a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl @@ -15,6 +15,7 @@ uniform float lineKernel = 0.0; uniform sampler2D depthBuffer; uniform int gridFlag; +uniform float zoomFactor; #define STEPS_LEN 8 uniform float gridSteps[STEPS_LEN] = float[](0.001, 0.01, 0.1, 1.0, 10.0, 100.0, 1000.0, 10000.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) /* For UV/Image Image editor */ +#define DYNAMIC_GRID (1 << 12) /* Dynamic grid is used in the UV/Image Editor */ #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 && (gridFlag & DYNAMIC_GRID) == 0) + {/* grid begins to appear when the length of one grid unit is at least + * (N^2) pixels in the UV/Image editor. + * Value of N defined in overlay_grid.c */ + grid_res = zoomFactor; + } + /* from biggest to smallest */ vec4 scale; #if 0 _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs