Fix T62917 UV editor: Edge overlay not shown when edge overlay type is Dash

Fix by changing the shader to always compute dash for uv and just change
dash size to something really big for other overlay types.
This commit is contained in:
Clément Foucault 2020-06-22 17:30:45 +02:00
parent b175bb2503
commit 336a8f283f
Notes: blender-bot 2023-02-14 03:14:34 +01:00
Referenced by issue #62917, UV editor: Edge overlay not shown when edge overlay type is set to 'Dash'
5 changed files with 79 additions and 61 deletions

View File

@ -409,70 +409,49 @@ static void draw_uvs(SpaceImage *sima,
GPU_blend(true);
}
switch (sima->dt_uv) {
case SI_UVDT_DASH: {
float dash_colors[2][4] = {
{0.56f, 0.56f, 0.56f, overlay_alpha},
{0.07f, 0.07f, 0.07f, overlay_alpha},
};
float viewport_size[4];
GPU_viewport_size_get_f(viewport_size);
{
/* We could modify the vbo's data filling
* instead of modifying the provoking vert. */
glProvokingVertex(GL_FIRST_VERTEX_CONVENTION);
GPU_line_width(1.0f);
GPU_batch_program_set_builtin(batch->edges, GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
GPU_batch_uniform_4fv_array(batch->edges, "colors", 2, (float *)dash_colors);
GPU_batch_uniform_2f(batch->edges,
"viewport_size",
viewport_size[2] / UI_DPI_FAC,
viewport_size[3] / UI_DPI_FAC);
GPU_batch_uniform_1i(batch->edges, "colors_len", 2); /* "advanced" mode */
GPU_batch_uniform_1f(batch->edges, "dash_width", 4.0f);
GPU_batch_uniform_1f(batch->edges, "dash_factor", 0.5f);
UI_GetThemeColor3fv(TH_EDGE_SELECT, col2);
col2[3] = overlay_alpha;
float dash_width = (sima->dt_uv & SI_UVDT_DASH) ? (4.0f * UI_DPI_FAC) : 9999.0f;
GPU_batch_program_set_builtin(
batch->edges, (interpedges) ? GPU_SHADER_2D_UV_EDGES_SMOOTH : GPU_SHADER_2D_UV_EDGES);
if (sima->dt_uv == SI_UVDT_OUTLINE) {
/* Black Outline. */
GPU_line_width(3.0f);
GPU_batch_uniform_4f(batch->edges, "edgeColor", 0.0f, 0.0f, 0.0f, overlay_alpha);
GPU_batch_uniform_4f(batch->edges, "selectColor", 0.0f, 0.0f, 0.0f, overlay_alpha);
GPU_batch_uniform_1f(batch->edges, "dashWidth", dash_width);
GPU_batch_draw(batch->edges);
break;
UI_GetThemeColor3fv(TH_WIRE_EDIT, col1);
}
case SI_UVDT_BLACK:
case SI_UVDT_WHITE:
case SI_UVDT_OUTLINE: {
/* We could modify the vbo's data filling
* instead of modifying the provoking vert. */
glProvokingVertex(GL_FIRST_VERTEX_CONVENTION);
UI_GetThemeColor3fv(TH_EDGE_SELECT, col2);
col2[3] = overlay_alpha;
GPU_batch_program_set_builtin(
batch->edges, (interpedges) ? GPU_SHADER_2D_UV_EDGES_SMOOTH : GPU_SHADER_2D_UV_EDGES);
if (sima->dt_uv == SI_UVDT_OUTLINE) {
/* Black Outline. */
GPU_line_width(3.0f);
GPU_batch_uniform_4f(batch->edges, "edgeColor", 0.0f, 0.0f, 0.0f, overlay_alpha);
GPU_batch_uniform_4f(batch->edges, "selectColor", 0.0f, 0.0f, 0.0f, overlay_alpha);
GPU_batch_draw(batch->edges);
UI_GetThemeColor3fv(TH_WIRE_EDIT, col1);
}
else if (sima->dt_uv == SI_UVDT_WHITE) {
copy_v3_fl3(col1, 1.0f, 1.0f, 1.0f);
}
else {
copy_v3_fl3(col1, 0.0f, 0.0f, 0.0f);
}
col1[3] = overlay_alpha;
/* Inner Line. Use depth test to insure selection is drawn on top. */
GPU_depth_test(true);
GPU_line_width(1.0f);
GPU_batch_uniform_4fv(batch->edges, "edgeColor", col1);
GPU_batch_uniform_4fv(batch->edges, "selectColor", col2);
GPU_batch_draw(batch->edges);
GPU_depth_test(false);
glProvokingVertex(GL_LAST_VERTEX_CONVENTION);
break;
else if (sima->dt_uv == SI_UVDT_BLACK) {
copy_v3_fl3(col1, 0.0f, 0.0f, 0.0f);
}
else {
copy_v3_fl3(col1, 1.0f, 1.0f, 1.0f);
}
col1[3] = overlay_alpha;
/* Inner Line. Use depth test to insure selection is drawn on top. */
GPU_depth_test(true);
GPU_line_width(1.0f);
GPU_batch_uniform_4fv(batch->edges, "edgeColor", col1);
GPU_batch_uniform_4fv(batch->edges, "selectColor", col2);
GPU_batch_uniform_1f(batch->edges, "dashWidth", dash_width);
GPU_batch_draw(batch->edges);
GPU_depth_test(false);
glProvokingVertex(GL_LAST_VERTEX_CONVENTION);
}
if (sima->flag & SI_SMOOTH_UV) {
GPU_line_smooth(false);
GPU_blend(false);
@ -481,6 +460,7 @@ static void draw_uvs(SpaceImage *sima,
GPU_blend(false);
}
}
if (batch->verts || batch->facedots) {
UI_GetThemeColor4fv(TH_VERTEX_SELECT, col2);
if (batch->verts) {

View File

@ -210,6 +210,7 @@ data_to_c_simple(shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_
data_to_c_simple(shaders/gpu_shader_2D_edituvs_points_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_edituvs_facedots_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_edituvs_edges_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_edituvs_edges_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_edituvs_faces_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_edituvs_stretch_vert.glsl SRC)

View File

@ -117,6 +117,7 @@ extern char datatoc_gpu_shader_2D_point_uniform_size_varying_color_outline_aa_ve
extern char datatoc_gpu_shader_2D_edituvs_points_vert_glsl[];
extern char datatoc_gpu_shader_2D_edituvs_facedots_vert_glsl[];
extern char datatoc_gpu_shader_2D_edituvs_edges_vert_glsl[];
extern char datatoc_gpu_shader_2D_edituvs_edges_frag_glsl[];
extern char datatoc_gpu_shader_2D_edituvs_faces_vert_glsl[];
extern char datatoc_gpu_shader_2D_edituvs_stretch_vert_glsl[];
@ -1171,12 +1172,12 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
[GPU_SHADER_2D_UV_EDGES] =
{
.vert = datatoc_gpu_shader_2D_edituvs_edges_vert_glsl,
.frag = datatoc_gpu_shader_flat_color_frag_glsl,
.frag = datatoc_gpu_shader_2D_edituvs_edges_frag_glsl,
},
[GPU_SHADER_2D_UV_EDGES_SMOOTH] =
{
.vert = datatoc_gpu_shader_2D_edituvs_edges_vert_glsl,
.frag = datatoc_gpu_shader_2D_smooth_color_frag_glsl,
.frag = datatoc_gpu_shader_2D_edituvs_edges_frag_glsl,
.defs = "#define SMOOTH_COLOR\n",
},
[GPU_SHADER_2D_UV_FACES] =

View File

@ -0,0 +1,30 @@
uniform float dashWidth;
#ifdef SMOOTH_COLOR
noperspective in vec4 finalColor;
#else
flat in vec4 finalColor;
#endif
noperspective in vec2 stipple_pos;
flat in vec2 stipple_start;
out vec4 fragColor;
void main()
{
fragColor = finalColor;
/* Avoid passing viewport size */
vec2 dd = fwidth(stipple_pos);
float dist = distance(stipple_start, stipple_pos) / max(dd.x, dd.y);
if (fract(dist / dashWidth) > 0.5) {
fragColor.rgb = vec3(0.0);
}
fragColor = blender_srgb_to_framebuffer_space(fragColor);
}

View File

@ -12,6 +12,9 @@ noperspective out vec4 finalColor;
flat out vec4 finalColor;
#endif
noperspective out vec2 stipple_pos;
flat out vec2 stipple_start;
/* TODO: Port drawing to draw manager and
* remove constants duplications. */
#define VERT_UV_SELECT (1 << 3)
@ -28,5 +31,8 @@ void main()
gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
gl_Position.z = float(!is_select);
/* Avoid precision loss. */
stipple_start = stipple_pos = 500.0 + 500.0 * (gl_Position.xy / gl_Position.w);
finalColor = (is_select) ? selectColor : edgeColor;
}