#70267 Retopology Overlay #104599
|
@ -6554,7 +6554,7 @@ class VIEW3D_PT_overlay_edit_mesh_shading(Panel):
|
|||
row.prop(overlay, "show_retopology", text="")
|
||||
sub = row.row()
|
||||
sub.active = overlay.show_retopology
|
||||
sub.prop(overlay, "retopology_bias", text="Retopology")
|
||||
sub.prop(overlay, "retopology_offset", text="Retopology")
|
||||
|
||||
col.prop(overlay, "show_weight", text="Vertex Group Weights")
|
||||
if overlay.show_weight:
|
||||
|
|
|
@ -4014,13 +4014,13 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
|
|||
*/
|
||||
{
|
||||
/* Z bias for retopology overlay. */
|
||||
if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "retopology_bias")) {
|
||||
if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "retopology_offset")) {
|
||||
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
|
||||
if (sl->spacetype == SPACE_VIEW3D) {
|
||||
View3D *v3d = (View3D *)sl;
|
||||
v3d->overlay.retopology_bias = 0.2f;
|
||||
v3d->overlay.retopology_offset = 0.2f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
|
|||
RegionView3D *rv3d = draw_ctx->rv3d;
|
||||
bool show_retopology = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_RETOPOLOGY) != 0;
|
||||
/* Add epsilon to ensure the value is never zero when the effect is enabled. */
|
||||
float retopology_bias = (show_retopology) ? (v3d->overlay.retopology_bias + FLT_EPSILON) : 0.0f;
|
||||
float retopology_offset = (show_retopology) ? (v3d->overlay.retopology_offset + FLT_EPSILON) :
|
||||
bonj marked this conversation as resolved
|
||||
0.0f;
|
||||
|
||||
pd->edit_mesh.do_faces = true;
|
||||
pd->edit_mesh.do_edges = true;
|
||||
|
@ -104,13 +105,18 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
|
|||
/* Run Twice for in-front passes. */
|
||||
for (int i = 0; i < 2; i++) {
|
||||
/* Complementary Depth Pass */
|
||||
state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL |
|
||||
((show_retopology) ? DRWState(0) : DRW_STATE_CULL_BACK);
|
||||
state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK;
|
||||
bonj marked this conversation as resolved
Clément Foucault
commented
Style: Prefer:
Style: Prefer:
```
if (show_retopology) {
/* Do not cull backfaces for retopology. This is because [insert explanation here] */
state &= ~DRW_STATE_CULL_BACK;
}
Jorijn de Graaf
commented
Added an if block and explanation, as discussed in DMs. Added an if block and explanation, as discussed in DMs.
|
||||
if (show_retopology) {
|
||||
/* Do not cull backfaces for retopology depth pass.
|
||||
* This prevents edit overlays from appearing behind any faces.
|
||||
* Doing so reduces visual clutter. */
|
||||
state &= ~DRW_STATE_CULL_BACK;
|
||||
}
|
||||
DRW_PASS_CREATE(psl->edit_mesh_depth_ps[i], state | pd->clipping_state);
|
||||
|
||||
sh = OVERLAY_shader_edit_mesh_depth();
|
||||
grp = pd->edit_mesh_depth_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_depth_ps[i]);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyOffset", retopology_offset);
|
||||
}
|
||||
{
|
||||
/* Normals */
|
||||
|
@ -129,7 +135,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
|
|||
(flag & V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS) != 0);
|
||||
DRW_shgroup_uniform_float_copy(
|
||||
grp, "normalScreenSize", v3d->overlay.normals_constant_screen_size);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyOffset", retopology_offset);
|
||||
}
|
||||
{
|
||||
/* Mesh Analysis Pass */
|
||||
|
@ -155,7 +161,13 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
|
|||
&psl->edit_mesh_faces_cage_ps[i];
|
||||
DRWShadingGroup **shgrp = (j == 0) ? &pd->edit_mesh_faces_grp[i] :
|
||||
&pd->edit_mesh_faces_cage_grp[i];
|
||||
state = state_common | ((show_retopology) ? DRW_STATE_CULL_BACK : DRWState(0));
|
||||
state = state_common;
|
||||
if (show_retopology) {
|
||||
/* Cull backfaces for retopology face pass.
|
||||
* This makes it so backfaces are not drawn.
|
||||
* Doing so lets us distinguish backfaces from frontfaces. */
|
||||
state |= DRW_STATE_CULL_BACK;
|
||||
}
|
||||
DRW_PASS_CREATE(*edit_face_ps, state | pd->clipping_state);
|
||||
|
||||
grp = *shgrp = DRW_shgroup_create(face_sh, *edit_face_ps);
|
||||
|
@ -163,7 +175,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
|
|||
DRW_shgroup_uniform_ivec4(grp, "dataMask", mask, 1);
|
||||
DRW_shgroup_uniform_float_copy(grp, "alpha", face_alpha);
|
||||
DRW_shgroup_uniform_bool_copy(grp, "selectFaces", select_face);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyOffset", retopology_offset);
|
||||
}
|
||||
|
||||
if (do_zbufclip) {
|
||||
|
@ -183,7 +195,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, "retopologyBias", retopology_bias);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyOffset", retopology_offset);
|
||||
|
||||
/* Verts */
|
||||
state |= DRW_STATE_WRITE_DEPTH;
|
||||
|
@ -197,12 +209,12 @@ 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, "retopologyBias", retopology_bias);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyOffset", retopology_offset);
|
||||
|
||||
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]);
|
||||
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyOffset", retopology_offset);
|
||||
}
|
||||
/* Face-dots */
|
||||
if (select_face && show_face_dots) {
|
||||
|
@ -212,7 +224,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, "retopologyBias", retopology_bias);
|
||||
DRW_shgroup_uniform_float_copy(grp, "retopologyOffset", retopology_offset);
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_WRITE_DEPTH);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -18,7 +18,7 @@ GPU_SHADER_CREATE_INFO(overlay_edit_mesh_common)
|
|||
.push_constant(Type::BOOL, "selectFaces")
|
||||
.push_constant(Type::BOOL, "selectEdges")
|
||||
.push_constant(Type::FLOAT, "alpha")
|
||||
.push_constant(Type::FLOAT, "retopologyBias")
|
||||
.push_constant(Type::FLOAT, "retopologyOffset")
|
||||
.push_constant(Type::IVEC4, "dataMask")
|
||||
.vertex_source("overlay_edit_mesh_vert.glsl")
|
||||
.additional_info("draw_modelmat", "draw_globals");
|
||||
|
@ -32,7 +32,7 @@ GPU_SHADER_CREATE_INFO(overlay_edit_mesh_common_no_geom)
|
|||
.push_constant(Type::BOOL, "selectFaces")
|
||||
.push_constant(Type::BOOL, "selectEdges")
|
||||
.push_constant(Type::FLOAT, "alpha")
|
||||
.push_constant(Type::FLOAT, "retopologyBias")
|
||||
.push_constant(Type::FLOAT, "retopologyOffset")
|
||||
.push_constant(Type::IVEC4, "dataMask")
|
||||
.vertex_source("overlay_edit_mesh_vert_no_geom.glsl")
|
||||
.additional_info("draw_modelmat", "draw_globals");
|
||||
|
@ -41,7 +41,7 @@ GPU_SHADER_CREATE_INFO(overlay_edit_mesh_common_no_geom)
|
|||
GPU_SHADER_CREATE_INFO(overlay_edit_mesh_depth)
|
||||
.do_static_compilation(true)
|
||||
.vertex_in(0, Type::VEC3, "pos")
|
||||
.push_constant(Type::FLOAT, "retopologyBias")
|
||||
.push_constant(Type::FLOAT, "retopologyOffset")
|
||||
.vertex_source("overlay_edit_mesh_depth_vert.glsl")
|
||||
.fragment_source("overlay_depth_only_frag.glsl")
|
||||
.additional_info("draw_mesh");
|
||||
|
|
|
@ -54,7 +54,7 @@ vec4 EDIT_MESH_face_color(uint face_flag)
|
|||
{
|
||||
vec4 color = colorFace;
|
||||
vec4 color_active = mix(colorFaceSelect, colorEditMeshActive, 0.5);
|
||||
color = (retopologyBias > 0.0) ? colorFaceRetopology : color;
|
||||
color = (retopologyOffset > 0.0) ? colorFaceRetopology : color;
|
||||
color = ((face_flag & FACE_FREESTYLE) != 0u) ? colorFaceFreestyle : color;
|
||||
color = ((face_flag & FACE_SELECTED) != 0u) ? colorFaceSelect : color;
|
||||
color = ((face_flag & FACE_ACTIVE) != 0u) ? color_active : color;
|
||||
|
|
|
@ -11,7 +11,7 @@ void main()
|
|||
gl_Position = point_view_to_ndc(view_pos);
|
||||
|
||||
/* Offset Z position for retopology overlay. */
|
||||
gl_Position.z -= get_homogenous_z_offset(view_pos.z, gl_Position.w, retopologyBias);
|
||||
gl_Position.z += get_homogenous_z_offset(view_pos.z, gl_Position.w, retopologyOffset);
|
||||
|
||||
view_clipping_distances(world_pos);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ void main()
|
|||
gl_Position = point_view_to_ndc(view_pos);
|
||||
|
||||
/* Offset Z position for retopology overlay. */
|
||||
gl_Position.z -= get_homogenous_z_offset(view_pos.z, gl_Position.w, retopologyBias);
|
||||
gl_Position.z += get_homogenous_z_offset(view_pos.z, gl_Position.w, retopologyOffset);
|
||||
|
||||
uvec4 m_data = data & uvec4(dataMask);
|
||||
|
||||
|
|
|
@ -88,8 +88,8 @@ void main()
|
|||
vec4 out_pos1 = point_view_to_ndc(view_pos1);
|
||||
|
||||
/* Offset Z position for retopology overlay. */
|
||||
out_pos0.z -= get_homogenous_z_offset(view_pos0.z, out_pos0.w, retopologyBias);
|
||||
out_pos1.z -= get_homogenous_z_offset(view_pos1.z, out_pos1.w, retopologyBias);
|
||||
out_pos0.z += get_homogenous_z_offset(view_pos0.z, out_pos0.w, retopologyOffset);
|
||||
out_pos1.z += get_homogenous_z_offset(view_pos1.z, out_pos1.w, retopologyOffset);
|
||||
|
||||
uvec4 m_data0 = uvec4(in_data0) & uvec4(dataMask);
|
||||
uvec4 m_data1 = uvec4(in_data1) & uvec4(dataMask);
|
||||
|
|
|
@ -257,18 +257,18 @@ vec3 point_world_to_view(vec3 p)
|
|||
return (ViewMatrix * vec4(p, 1.0)).xyz;
|
||||
}
|
||||
|
||||
/* From "Projection Matrix Tricks" by Eric Lengyel:
|
||||
* http://www.terathon.com/gdc07_lengyel.pdf (p. 18 Depth Modification)
|
||||
*
|
||||
* View Z is used to adjust for perspective projection.
|
||||
* Homogenous W is used to convert from NDC to homogenous space. */
|
||||
/* View Z is used to adjust for perspective projection.
|
||||
* Homogenous W is used to convert from NDC to homogenous space.
|
||||
bonj marked this conversation as resolved
Clément Foucault
commented
My bad. The equation is actually comming from page 24. My bad. The equation is actually comming from page 24.
Jorijn de Graaf
commented
I thought you picked 18 because it's the start of the section about depth modification. I think it makes sense to point to the whole range of pages (18-26). I thought you picked 18 because it's the start of the section about depth modification. I think it makes sense to point to the whole range of pages (18-26).
Clément Foucault
commented
Yes, but here it is the reference to a specific formula. I also think this reference should be inside the function. Comment on top of function is only for documentation of the function usage. Yes, but here it is the reference to a specific formula. I also think this reference should be inside the function. Comment on top of function is only for documentation of the function usage.
Jorijn de Graaf
commented
Done. Done.
|
||||
* Offset is in viewspace, so positive values are closer to the camera. */
|
||||
float get_homogenous_z_offset(float vs_z, float hs_w, float offset)
|
||||
{
|
||||
if (ProjectionMatrix[3][3] == 0.0) {
|
||||
bonj marked this conversation as resolved
Clément Foucault
commented
Maybe also add a note that offset is in viewspace. So positive values are closer to camera. Maybe also add a note that offset is in viewspace. So positive values are closer to camera.
Jorijn de Graaf
commented
Done, now each parameter has an explanation. Done, now each parameter has an explanation.
|
||||
return -ProjectionMatrix[3][2] * (offset / (vs_z * (vs_z + offset))) * hs_w;
|
||||
/* From "Projection Matrix Tricks" by Eric Lengyel:
|
||||
* http://www.terathon.com/gdc07_lengyel.pdf (p. 24 Depth Modification) */
|
||||
return ProjectionMatrix[3][2] * (offset / (vs_z * (vs_z + offset))) * hs_w;
|
||||
bonj marked this conversation as resolved
Clément Foucault
commented
Remove the negative sign here and everywhere Remove the negative sign here and everywhere `get_homogenous_z_offset` is called.
The negative sign in the equation from the slide is inside `ProjectionMatrix[3][2]`.
Jorijn de Graaf
commented
Done and done. Done and done.
I negated it because then you can subtract from the Z, which is what other offsets in the shader do, but yeah it was unnecessary so now they just use += for this.
|
||||
}
|
||||
else {
|
||||
return -ProjectionMatrix[2][2] * offset * hs_w;
|
||||
return ProjectionMatrix[2][2] * offset * hs_w;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
.flag = V3D_OVERLAY_VIEWER_ATTRIBUTE | V3D_OVERLAY_SCULPT_SHOW_MASK | V3D_OVERLAY_SCULPT_SHOW_FACE_SETS, \
|
||||
.wireframe_threshold = 1.0f, \
|
||||
.wireframe_opacity = 1.0f, \
|
||||
.retopology_bias = 0.2f, \
|
||||
.retopology_offset = 0.2f, \
|
||||
.viewer_attribute_opacity = 1.0f, \
|
||||
.xray_alpha_bone = 0.5f, \
|
||||
.bone_wire_alpha = 1.0f, \
|
||||
|
|
|
@ -221,7 +221,7 @@ typedef struct View3DOverlay {
|
|||
/** Other settings. */
|
||||
float wireframe_threshold;
|
||||
float wireframe_opacity;
|
||||
float retopology_bias;
|
||||
float retopology_offset;
|
||||
|
||||
/** Grease pencil settings. */
|
||||
float gpencil_paper_opacity;
|
||||
|
|
|
@ -4532,11 +4532,12 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
|
|||
RNA_def_property_ui_text(prop, "Retopology", "Use retopology display");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D | NS_VIEW3D_SHADING, NULL);
|
||||
|
||||
prop = RNA_def_property(srna, "retopology_bias", PROP_FLOAT, PROP_FACTOR);
|
||||
RNA_def_property_float_sdna(prop, NULL, "overlay.retopology_bias");
|
||||
RNA_def_property_ui_text(prop, "Retopology Bias", "Z Bias used to draw edit mesh in front");
|
||||
RNA_def_property_range(prop, 0.0f, 100000.0f);
|
||||
RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);
|
||||
prop = RNA_def_property(srna, "retopology_offset", PROP_FLOAT, PROP_DISTANCE);
|
||||
bonj marked this conversation as resolved
Clément Foucault
commented
Now that we fixed the bias equation, the property types should be You will loose the ability to see the blue fill bar but it will be much explicit that this value is in distance unit. You might have to adjust the sensitivity to have kind of the same drag feeling as when it was a factor. Now that we fixed the bias equation, the property types should be `PROP_DISTANCE`.
You will loose the ability to see the blue fill bar but it will be much explicit that this value is in distance unit.
You might have to adjust the sensitivity to have kind of the same drag feeling as when it was a factor.
And bump the soft max to 2 or 10 (seems nicer to discover that this isn't clamped).
This is what control those `RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);`.
Jorijn de Graaf
commented
Made it PROP_DISTANCE and upped the soft max to 10. Made it PROP_DISTANCE and upped the soft max to 10.
I think 0.1 step and 3 digits still feels good so I'll leave those the same.
|
||||
RNA_def_property_float_sdna(prop, NULL, "overlay.retopology_offset");
|
||||
RNA_def_property_ui_text(
|
||||
bonj marked this conversation as resolved
Clément Foucault
commented
Replace description by Maybe @JulienKaspar can agree this is clearer? Replace description by `Offset used to draw the edit mesh in front of other geometry`.
Maybe @JulienKaspar can agree this is clearer? `Z Bias` is too technical in my opinion.
Jorijn de Graaf
commented
I agree. I'll rename it to retopology offset everywhere. I agree. I'll rename it to retopology offset everywhere.
|
||||
prop, "Retopology Offset", "Offset used to draw edit mesh in front of other geometry");
|
||||
bonj marked this conversation as resolved
Clément Foucault
commented
Max should be FLT_MAX. Arbitrary limits like these are not good. Max should be FLT_MAX. Arbitrary limits like these are not good.
Jorijn de Graaf
commented
Done. Done.
|
||||
RNA_def_property_range(prop, 0.0f, FLT_MAX);
|
||||
RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1f, 3);
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
|
||||
|
||||
|
|
Just a small tweak.
Use
max_ff(v3d->overlay.retopology_offset, FLT_EPSILON)
and remove comment as this is then cleaner in the code.Makes sense, I'll do that.