Add An Opacity Slider to Overlay Wireframe

This patch adds an opacity slider to the wireframe overlay. The previous
wireframe in dense geometry scenes could be too dark and sometimes the
user just wants an impression of the geometry during modelling.

Reviewed By: Jeroen Bakker

Differential Revision: https://developer.blender.org/D7622
This commit is contained in:
Jun Mizutani 2020-11-13 08:07:07 +01:00 committed by Jeroen Bakker
parent f00ebd4dba
commit db7d8281c5
Notes: blender-bot 2023-02-13 23:16:02 +01:00
Referenced by commit 07bd8eab97, Fix unreported wireframe opacity color blending broken
13 changed files with 40 additions and 10 deletions

@ -1 +1 @@
Subproject commit 8f5a0e027f131104974763d30db36b1a9ffae16a
Subproject commit 848613f1edf09495bb764144461730662ac0b061

@ -1 +1 @@
Subproject commit 33eae7da675d532bbb9c12b129c0e30228f5f000
Subproject commit 35c23b4db494e58538a677c4fb0ec9ec1e8ffaa8

View File

@ -6127,6 +6127,7 @@ class VIEW3D_PT_overlay_geometry(Panel):
sub = row.row()
sub.active = overlay.show_wireframes or is_wireframes
sub.prop(overlay, "wireframe_threshold", text="Wireframe")
sub.prop(overlay, "wireframe_opacity", text="Opacity")
row = col.row(align=True)
if context.mode not in {

View File

@ -1139,5 +1139,18 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
*/
{
/* Keep this block, even when empty. */
/* Initialize the opacity of the overlay wireframe */
if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "wireframe_opacity")) {
for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
v3d->overlay.wireframe_opacity = 1.0f;
}
}
}
}
}
}
}

View File

@ -90,6 +90,7 @@ static void OVERLAY_engine_init(void *vedata)
V3D_OVERLAY_HIDE_BONES | V3D_OVERLAY_HIDE_OBJECT_XTRAS |
V3D_OVERLAY_HIDE_OBJECT_ORIGINS;
pd->overlay.wireframe_threshold = v3d->overlay.wireframe_threshold;
pd->overlay.wireframe_opacity = v3d->overlay.wireframe_opacity;
}
if (v3d->shading.type == OB_WIRE) {

View File

@ -140,6 +140,7 @@ typedef struct OVERLAY_ShadingData {
int zneg_flag;
/** Wireframe */
float wire_step_param;
float wire_opacity;
/** Edit Curve */
float edit_curve_normal_length;
/** Edit Mesh */

View File

@ -62,6 +62,7 @@ void OVERLAY_wireframe_cache_init(OVERLAY_Data *vedata)
View3DShading *shading = &draw_ctx->v3d->shading;
pd->shdata.wire_step_param = pd->overlay.wireframe_threshold - 254.0f / 255.0f;
pd->shdata.wire_opacity = pd->overlay.wireframe_opacity;
bool is_wire_shmode = (shading->type == OB_WIRE);
bool is_material_shmode = (shading->type > OB_SOLID);
@ -95,6 +96,7 @@ void OVERLAY_wireframe_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tx);
DRW_shgroup_uniform_float_copy(grp, "wireStepParam", pd->shdata.wire_step_param);
DRW_shgroup_uniform_float_copy(grp, "wireOpacity", pd->shdata.wire_opacity);
DRW_shgroup_uniform_bool_copy(grp, "useColoring", use_coloring);
DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0);
DRW_shgroup_uniform_bool_copy(grp, "isObjectColor", is_object_color);

View File

@ -5,7 +5,7 @@ uniform sampler2D depthTex;
flat in vec2 edgeStart;
#ifndef SELECT_EDGES
in vec3 finalColor;
in vec4 finalColor;
noperspective in vec2 edgePos;
layout(location = 0) out vec4 fragColor;
@ -22,8 +22,7 @@ void main()
#ifndef SELECT_EDGES
lineOutput = pack_line_data(gl_FragCoord.xy, edgeStart, edgePos);
fragColor.rgb = finalColor;
fragColor.a = 1.0;
fragColor = finalColor;
# ifdef CUSTOM_DEPTH_BIAS
vec2 dir = lineOutput.xy * 2.0 - 1.0;

View File

@ -1,5 +1,6 @@
uniform float wireStepParam;
uniform float wireOpacity;
uniform bool useColoring;
uniform bool isTransform;
uniform bool isObjectColor;
@ -14,7 +15,7 @@ in float wd; /* wiredata */
flat out vec2 edgeStart;
#ifndef SELECT_EDGES
out vec3 finalColor;
out vec4 finalColor;
noperspective out vec2 edgePos;
#endif
@ -156,8 +157,9 @@ void main()
rim_col = pow(rim_col, vec3(1.0 / 2.2));
wire_col = pow(wire_col, vec3(1.0 / 2.2));
vec3 final_front_col = mix(rim_col, wire_col, 0.35);
finalColor = mix(rim_col, final_front_col, facing);
finalColor = pow(finalColor, vec3(2.2));
finalColor.rgb = mix(rim_col, final_front_col, facing);
finalColor.rgb = pow(finalColor.rgb, vec3(2.2));
finalColor.a = wireOpacity;
#endif
/* Cull flat edges below threshold. */

View File

@ -51,6 +51,7 @@
#define _DNA_DEFAULT_View3DOverlay \
{ \
.wireframe_threshold = 1.0f, \
.wireframe_opacity = 1.0f, \
.xray_alpha_bone = 0.5f, \
.fade_alpha = 0.40f, \
.texture_paint_mode_opacity = 1.0f, \

View File

@ -223,6 +223,7 @@ typedef struct View3DOverlay {
/** Other settings. */
float wireframe_threshold;
float wireframe_opacity;
/** Grease pencil settings. */
float gpencil_paper_opacity;
@ -233,7 +234,6 @@ typedef struct View3DOverlay {
float gpencil_vertex_paint_opacity;
/** Handles display type for curves. */
int handle_display;
char _pad[4];
} View3DOverlay;
/* View3DOverlay->handle_display */

View File

@ -3716,6 +3716,16 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "wireframe_opacity", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "overlay.wireframe_opacity");
RNA_def_property_ui_text(prop,
"Wireframe Opacity",
"Opacity of the displayed edges "
"(1.0 for opaque)");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_paint_wire", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "overlay.paint_flag", V3D_OVERLAY_PAINT_WIRE);
RNA_def_property_ui_text(prop, "Show Wire", "Use wireframe display in painting modes");

@ -1 +1 @@
Subproject commit 7011d02c292ac1c91a5c9cc1a075ea2727982cee
Subproject commit 660be0ca10abc8261178159afcd1032be662e386