WIP: Use a different method for overlay edit mesh bias #104921

Closed
Jorijn de Graaf wants to merge 1 commits from bonj/blender:overlay-edit-mesh-offset into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 14 additions and 7 deletions

View File

@ -58,6 +58,9 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
bool select_face = pd->edit_mesh.select_face = (tsettings->selectmode & SCE_SELECT_FACE) != 0;
bool select_edge = pd->edit_mesh.select_edge = (tsettings->selectmode & SCE_SELECT_EDGE) != 0;
RegionView3D *rv3d = draw_ctx->rv3d;
float offset_scale = (rv3d->is_persp) ? (v3d->clip_start) : (1.0f / v3d->clip_end);
bool do_occlude_wire = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) != 0;
bool show_face_dots = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_DOT) != 0 ||
pd->edit_mesh.do_zbufclip;
@ -175,6 +178,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
DRW_shgroup_uniform_bool_copy(grp, "selectEdges", pd->edit_mesh.do_edges || select_edge);
DRW_shgroup_uniform_bool_copy(grp, "do_smooth_wire", do_smooth_wire);
DRW_shgroup_uniform_float_copy(grp, "offsetScale", offset_scale);
/* Verts */
state |= DRW_STATE_WRITE_DEPTH;
@ -188,6 +192,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
DRW_shgroup_uniform_ivec4_copy(grp, "dataMask", vert_mask);
DRW_shgroup_uniform_float_copy(grp, "offsetScale", offset_scale);
sh = OVERLAY_shader_edit_mesh_skin_root();
grp = pd->edit_mesh_skin_roots_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_verts_ps[i]);
@ -201,6 +206,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
DRW_shgroup_uniform_ivec4_copy(grp, "dataMask", vert_mask);
DRW_shgroup_uniform_float_copy(grp, "offsetScale", offset_scale);
DRW_shgroup_state_enable(grp, DRW_STATE_WRITE_DEPTH);
}
else {

View File

@ -19,6 +19,7 @@ GPU_SHADER_CREATE_INFO(overlay_edit_mesh_common)
.push_constant(Type::BOOL, "selectEdges")
.push_constant(Type::FLOAT, "alpha")
.push_constant(Type::IVEC4, "dataMask")
.push_constant(Type::FLOAT, "offsetScale")
.vertex_source("overlay_edit_mesh_vert.glsl")
.additional_info("draw_modelmat", "draw_globals");
@ -32,6 +33,7 @@ GPU_SHADER_CREATE_INFO(overlay_edit_mesh_common_no_geom)
.push_constant(Type::BOOL, "selectEdges")
.push_constant(Type::FLOAT, "alpha")
.push_constant(Type::IVEC4, "dataMask")
.push_constant(Type::FLOAT, "offsetScale")
.vertex_source("overlay_edit_mesh_vert_no_geom.glsl")
.additional_info("draw_modelmat", "draw_globals");
#endif

View File

@ -39,10 +39,10 @@ void main()
gl_PointSize = sizeVertex * ((vertexCrease > 0.0) ? 3.0 : 2.0);
/* Make selected and active vertex always on top. */
if ((data.x & VERT_SELECTED) != 0u) {
gl_Position.z -= 5e-7 * abs(gl_Position.w);
gl_Position.z -= 5e-5 * offsetScale / abs(gl_Position.w);
}
if ((data.x & VERT_ACTIVE) != 0u) {
gl_Position.z -= 5e-7 * abs(gl_Position.w);
gl_Position.z -= 5e-5 * offsetScale / abs(gl_Position.w);
}
bool occluded = test_occlusion();
@ -61,7 +61,7 @@ void main()
finalColorOuter = EDIT_MESH_edge_color_outer(m_data.y, m_data.x, edge_crease, bweight);
if (finalColorOuter.a > 0.0) {
gl_Position.z -= 5e-7 * abs(gl_Position.w);
gl_Position.z -= 5e-5 * offsetScale / abs(gl_Position.w);
}
bool occluded = false; /* Done in fragment shader */
@ -73,8 +73,7 @@ void main()
#elif defined(FACEDOT)
finalColor = EDIT_MESH_facedot_color(norAndFlag.w);
/* Bias Facedot Z position in clipspace. */
gl_Position.z -= (drw_view.winmat[3][3] == 0.0) ? 0.00035 : 1e-6;
gl_Position.z -= 1e-4 * offsetScale / abs(gl_Position.w);
gl_PointSize = sizeFaceDot;
bool occluded = test_occlusion();

View File

@ -108,10 +108,10 @@ void main()
out_finalColorOuter[1] = EDIT_MESH_edge_color_outer(m_data1.y, m_data1.x, crease1, bweight1);
if (out_finalColorOuter[0].a > 0.0) {
out_pos0.z -= 5e-7 * abs(out_pos0.w);
out_pos0.z -= 5e-5 * offsetScale / abs(out_pos0.w);
}
if (out_finalColorOuter[1].a > 0.0) {
out_pos1.z -= 5e-7 * abs(out_pos1.w);
out_pos1.z -= 5e-5 * offsetScale / abs(out_pos1.w);
}
/* Occlusion done in fragment shader. */