diff options
4 files changed, 39 insertions, 15 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_grid.c b/source/blender/draw/engines/overlay/overlay_grid.c index 7445dfc2e3d..5c87b68515c 100644 --- a/source/blender/draw/engines/overlay/overlay_grid.c +++ b/source/blender/draw/engines/overlay/overlay_grid.c @@ -29,6 +29,8 @@ #include "ED_image.h" #include "ED_view3d.h" +#include "UI_resources.h" + #include "overlay_private.h" enum { @@ -61,7 +63,8 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata) SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; shd->grid_flag = ED_space_image_has_buffer(sima) ? 0 : PLANE_IMAGE | SHOW_GRID; shd->grid_distance = 1.0f; - shd->grid_mesh_size = 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++) { shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f); } @@ -169,11 +172,11 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata) } if (winmat[3][3] == 0.0f) { - shd->grid_mesh_size = dist; + copy_v3_fl(shd->grid_size, dist); } else { float viewdist = 1.0f / min_ff(fabsf(winmat[0][0]), fabsf(winmat[1][1])); - shd->grid_mesh_size = viewdist * dist; + copy_v3_fl(shd->grid_size, viewdist * dist); } shd->grid_distance = dist / 2.0f; @@ -203,18 +206,19 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata) struct GPUBatch *geom = DRW_cache_grid_get(); if (pd->is_image_editor) { + float mat[4][4]; + /* add quad background */ sh = OVERLAY_shader_grid_image(); grp = DRW_shgroup_create(sh, psl->grid_ps); - DRW_shgroup_call(grp, DRW_cache_quad_get(), NULL); float color_back[4]; interp_v4_v4v4(color_back, G_draw.block.colorBackground, G_draw.block.colorGrid, 0.5); DRW_shgroup_uniform_vec4_copy(grp, "color", color_back); - - /* add wire border */ - grp = DRW_shgroup_create(sh, psl->grid_ps); - DRW_shgroup_call(grp, DRW_cache_quad_wires_get(), NULL); - DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.colorGrid); + unit_m4(mat); + mat[0][0] = shd->grid_size[0]; + mat[1][1] = shd->grid_size[1]; + mat[2][2] = shd->grid_size[2]; + DRW_shgroup_call_obmat(grp, DRW_cache_quad_get(), mat); } sh = OVERLAY_shader_grid(); @@ -225,7 +229,7 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata) DRW_shgroup_uniform_vec3(grp, "planeAxes", shd->zplane_axes, 1); DRW_shgroup_uniform_float(grp, "gridDistance", &shd->grid_distance, 1); DRW_shgroup_uniform_float_copy(grp, "lineKernel", shd->grid_line_size); - DRW_shgroup_uniform_float_copy(grp, "meshSize", shd->grid_mesh_size); + DRW_shgroup_uniform_vec3(grp, "gridSize", shd->grid_size, 1); DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); if (shd->zneg_flag) { @@ -250,6 +254,26 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata) if (shd->zpos_flag) { DRW_shgroup_call(grp, geom, NULL); } + + if (pd->is_image_editor) { + float theme_color[4]; + UI_GetThemeColorShade4fv(TH_BACK, 60, theme_color); + srgb_to_linearrgb_v4(theme_color, theme_color); + + float mat[4][4]; + /* add wire border */ + sh = OVERLAY_shader_grid_image(); + grp = DRW_shgroup_create(sh, psl->grid_ps); + DRW_shgroup_uniform_vec4_copy(grp, "color", theme_color); + unit_m4(mat); + for (int x = 0; x < shd->grid_size[0]; x++) { + mat[3][0] = x; + for (int y = 0; y < shd->grid_size[1]; y++) { + mat[3][1] = y; + DRW_shgroup_call_obmat(grp, DRW_cache_quad_wires_get(), mat); + } + } + } } void OVERLAY_grid_draw(OVERLAY_Data *vedata) diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h index c684f420b19..b84b66ca83d 100644 --- a/source/blender/draw/engines/overlay/overlay_private.h +++ b/source/blender/draw/engines/overlay/overlay_private.h @@ -127,7 +127,7 @@ typedef struct OVERLAY_PassList { typedef struct OVERLAY_ShadingData { /** Grid */ float grid_axes[3], grid_distance; - float zplane_axes[3], grid_mesh_size; + float zplane_axes[3], grid_size[3]; float grid_steps[8]; float inv_viewport_size[2]; float grid_line_size; diff --git a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl index d0b68df0625..9cf6898cf18 100644 --- a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl @@ -10,7 +10,7 @@ out vec4 FragColor; uniform vec3 planeAxes; uniform float gridDistance; -uniform float meshSize; +uniform vec3 gridSize; uniform float lineKernel = 0.0; uniform sampler2D depthBuffer; @@ -73,7 +73,7 @@ vec3 get_axes(vec3 co, vec3 fwidthCos, float line_size) void main() { - vec3 wPos = local_pos * meshSize; + vec3 wPos = local_pos * gridSize; vec3 dFdxPos = dFdx(wPos); vec3 dFdyPos = dFdy(wPos); vec3 fwidthPos = abs(dFdxPos) + abs(dFdyPos); diff --git a/source/blender/draw/engines/overlay/shaders/grid_vert.glsl b/source/blender/draw/engines/overlay/shaders/grid_vert.glsl index 6df4ead9f2a..d77d6012e06 100644 --- a/source/blender/draw/engines/overlay/shaders/grid_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/grid_vert.glsl @@ -3,7 +3,7 @@ * Clément Foucault */ uniform vec3 planeAxes; -uniform float meshSize; +uniform vec3 gridSize; uniform int gridFlag; @@ -37,7 +37,7 @@ void main() local_pos = vert_pos; - vec3 real_pos = cameraPos * planeAxes + vert_pos * meshSize; + vec3 real_pos = cameraPos * planeAxes + vert_pos * gridSize; /* Used for additional Z axis */ if ((gridFlag & CLIP_Z_POS) != 0) { |