Fix artefacts with GPU subdiv and weight paint face selection

Addendum to previous fix, which was for point selection, this fixes the
face selection mode. The issue is caused by wrong flags used for paint
mode (the edit mode flag was always used). Also add back flag which was
accidentally removed in 16f5d51109.
This commit is contained in:
Kévin Dietrich 2022-06-20 14:32:48 +02:00
parent ff1883307f
commit 72a5bb8ba9
Notes: blender-bot 2023-02-14 08:08:54 +01:00
Referenced by issue #98661, 3.2: Potential candidates for corrective releases
4 changed files with 22 additions and 2 deletions

View File

@ -1204,7 +1204,7 @@ struct DRWSubdivUboStorage {
* of out of bond accesses as compute dispatch are of fixed size. */
uint total_dispatch_size;
int _pad0;
int is_edit_mode;
int _pad2;
int _pad3;
};
@ -1236,6 +1236,7 @@ static void draw_subdiv_init_ubo_storage(const DRWSubdivCache *cache,
ubo->coarse_face_hidden_mask = SUBDIV_COARSE_FACE_FLAG_HIDDEN_MASK;
ubo->coarse_face_loopstart_mask = SUBDIV_COARSE_FACE_LOOP_START_MASK;
ubo->total_dispatch_size = total_dispatch_size;
ubo->is_edit_mode = cache->is_edit_mode;
}
static void draw_subdiv_ubo_update_and_bind(const DRWSubdivCache *cache,
@ -2084,6 +2085,11 @@ static bool draw_subdiv_create_requested_buffers(Object *ob,
ob, mesh, is_editmode, is_paint_mode, is_mode_active, obmat, do_final, do_uvedit, ts);
mr->use_hide = use_hide;
/* Used for setting loop normals flags. Mapped extraction is only used during edit mode.
* See comments in #extract_lnor_iter_poly_mesh.
*/
draw_cache->is_edit_mode = mr->edit_bmesh != nullptr;
draw_subdiv_cache_update_extra_coarse_face_data(draw_cache, mesh_eval, mr);
blender::draw::mesh_buffer_cache_create_requested_subdiv(batch_cache, mbc, draw_cache, mr);

View File

@ -177,6 +177,9 @@ typedef struct DRWSubdivCache {
/* UBO to store settings for the various compute shaders. */
struct GPUUniformBuf *ubo;
/* Extra flags, passed to the UBO. */
bool is_edit_mode;
} DRWSubdivCache;
/* Only frees the data of the cache, caller is responsible to free the cache itself if necessary.

View File

@ -36,6 +36,8 @@ layout(std140) uniform shader_data
/* Total number of elements to process. */
uint total_dispatch_size;
bool is_edit_mode;
};
uint get_global_invocation_index()

View File

@ -26,6 +26,11 @@ bool is_face_selected(uint coarse_quad_index)
return (extra_coarse_face_data[coarse_quad_index] & coarse_face_select_mask) != 0;
}
bool is_face_hidden(uint coarse_quad_index)
{
return (extra_coarse_face_data[coarse_quad_index] & coarse_face_hidden_mask) != 0;
}
void main()
{
/* We execute for each quad. */
@ -69,9 +74,13 @@ void main()
for (int i = 0; i < 4; i++) {
int origindex = input_vert_origindex[start_loop_index + i];
float flag = 0.0;
if (origindex == -1) {
/* Flag for paint mode overlay and normals drawing in edit-mode. */
if (is_face_hidden(coarse_quad_index) || (is_edit_mode && origindex == -1)) {
flag = -1.0;
}
else if (is_face_selected(coarse_quad_index)) {
flag = 1.0;
}
loop_normal.flag = flag;
output_lnor[start_loop_index + i] = loop_normal;