Wireframe/Xray: Make Xray option local to wireframe mode

This commit make the Xray option for the wireframe different from the other
shading mode. This makes it possible to rapidly switch between wireframe +
Xray and Solid mode without Xray.

Xray alpha is also decoupled.

Both variables are duplicated and exposed separately through RNA.
This commit is contained in:
Clément Foucault 2018-09-26 20:31:14 +02:00
parent ebd234eee5
commit 5732d9e1dc
Notes: blender-bot 2023-02-14 08:25:14 +01:00
Referenced by issue #66649, X-Ray still active after changing from wireframe to solid
14 changed files with 81 additions and 28 deletions

View File

@ -261,6 +261,14 @@ class VIEW3D_HT_header(Header):
sub.active = overlay.show_overlays
sub.popover(panel="VIEW3D_PT_overlay")
row = layout.row()
row.active = (shading.type in {'WIREFRAME', 'SOLID'}) or object_mode in {'EDIT'}
if shading.type == 'WIREFRAME':
row.prop(shading, "show_xray_wireframe", text="", icon='ORTHO')
else:
row.prop(shading, "show_xray", text="", icon='ORTHO')
row = layout.row(align=True)
row.prop(shading, "type", text="", expand=True)
sub = row.row(align=True)
@ -3786,7 +3794,10 @@ class VIEW3D_MT_shading_pie(Menu):
sub = pie.row()
sub.active = False
sub.prop(view.shading, "show_xray", text="Toggle X-Ray", icon='ORTHO')
if view.shading.type == 'WIREFRAME':
sub.prop(view.shading, "show_xray_wireframe", text="Toggle X-Ray", icon='ORTHO')
else:
sub.prop(view.shading, "show_xray", text="Toggle X-Ray", icon='ORTHO')
pie.prop(view.overlay, "show_overlays", text="Toggle Overlays", icon='OVERLAY')
pie.prop_enum(view.shading, "type", value='MATERIAL')
@ -4126,10 +4137,11 @@ class VIEW3D_PT_shading_options(Panel):
is_shadows = shading.show_shadows
row = col.row()
row.prop(shading, "show_xray", text="")
sub = row.row()
sub.active = is_xray
sub.prop(shading, "xray_alpha", text="X-Ray")
row.active = is_xray
if shading.type == 'WIREFRAME':
row.prop(shading, "xray_alpha_wireframe", text="X-Ray")
else:
row.prop(shading, "xray_alpha", text="X-Ray")
if shading.type == 'SOLID':
row = col.row()
@ -4426,7 +4438,10 @@ class VIEW3D_PT_overlay_edit_mesh(Panel):
sub = split.column()
sub.prop(overlay, "show_faces", text="Faces")
sub = split.column()
sub.active = shading.show_xray
if shading.type == 'WIREFRAME':
sub.active = shading.show_xray_wireframe
else:
sub.active = shading.show_xray
sub.prop(overlay, "show_face_center", text="Center")
row = col.row(align=True)

View File

@ -787,10 +787,11 @@ void BKE_screen_view3d_shading_init(View3DShading *shading)
shading->type = OB_SOLID;
shading->prev_type = OB_SOLID;
shading->flag = V3D_SHADING_SPECULAR_HIGHLIGHT;
shading->flag = V3D_SHADING_SPECULAR_HIGHLIGHT | V3D_SHADING_XRAY_WIREFRAME;
shading->light = V3D_LIGHTING_STUDIO;
shading->shadow_intensity = 0.5f;
shading->xray_alpha = 0.5f;
shading->xray_alpha_wire = 0.5f;
shading->cavity_valley_factor = 1.0f;
shading->cavity_ridge_factor = 1.0f;
copy_v3_fl(shading->single_color, 0.8f);

View File

@ -2107,5 +2107,29 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha_wire")) {
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
v3d->shading.xray_alpha_wire = 0.5f;
}
}
}
}
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
v3d->shading.flag |= V3D_SHADING_XRAY_WIREFRAME;
}
}
}
}
}
}
}

View File

@ -365,12 +365,13 @@ void workbench_forward_engine_init(WORKBENCH_Data *vedata)
{
float blend_threshold = 0.0f;
if (draw_ctx->v3d->shading.flag & V3D_SHADING_XRAY) {
blend_threshold = 0.75f - wpd->shading.xray_alpha * 0.5f;
if (draw_ctx->v3d->shading.flag & XRAY_FLAG(draw_ctx->v3d)) {
blend_threshold = 0.75f - XRAY_ALPHA(wpd) * 0.5f;
}
if (draw_ctx->v3d->shading.type == OB_WIRE) {
wpd->shading.xray_alpha = 0.0f;
wpd->shading.xray_alpha_wire = 0.0f;
}
int state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS;
@ -445,7 +446,7 @@ static void workbench_forward_cache_populate_particles(WORKBENCH_Data *vedata, O
DRW_shgroup_uniform_vec4(shgrp, "viewvecs[0]", (float *)wpd->viewvecs, 3);
/* Hairs have lots of layer and can rapidly become the most prominent surface.
* So lower their alpha artificially. */
float hair_alpha = wpd->shading.xray_alpha * 0.33f;
float hair_alpha = XRAY_ALPHA(wpd) * 0.33f;
DRW_shgroup_uniform_float_copy(shgrp, "alpha", hair_alpha);
if (STUDIOLIGHT_ORIENTATION_VIEWNORMAL_ENABLED(wpd)) {
BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE);
@ -611,7 +612,7 @@ void workbench_forward_draw_scene(WORKBENCH_Data *vedata)
GPU_framebuffer_clear_color(fbl->object_outline_fb, clear_outline);
DRW_draw_pass(psl->object_outline_pass);
if (wpd->shading.xray_alpha > 0.0) {
if (XRAY_ALPHA(wpd) > 0.0) {
const float clear_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
GPU_framebuffer_bind(fbl->transparent_accum_fb);
GPU_framebuffer_clear_color(fbl->transparent_accum_fb, clear_color);

View File

@ -137,7 +137,7 @@ void workbench_render(WORKBENCH_Data *data, RenderEngine *engine, RenderLayer *r
return;
}
const bool deferred = (scene->display.shading.flag & V3D_SHADING_XRAY) == 0;
const bool deferred = (scene->display.shading.flag & XRAY_FLAG(draw_ctx->v3d)) == 0;
if (deferred) {
/* Init engine. */

View File

@ -592,6 +592,8 @@ typedef struct DRWContextState {
const DRWContextState *DRW_context_state_get(void);
#define XRAY_ENABLED(v3d) ((((v3d)->shading.flag & V3D_SHADING_XRAY) != 0) && ((v3d)->shading.xray_alpha < 1.0f))
#define XRAY_ALPHA(v3d) (((v3d)->shading.type == OB_WIRE) ? (v3d)->shading.xray_alpha_wire : (v3d)->shading.xray_alpha)
#define XRAY_FLAG(v3d) (((v3d)->shading.type == OB_WIRE) ? V3D_SHADING_XRAY_WIREFRAME : V3D_SHADING_XRAY)
#define XRAY_ENABLED(v3d) ((((v3d)->shading.flag & XRAY_FLAG(v3d)) != 0) && (XRAY_ALPHA(v3d) < 1.0f))
#endif /* __DRW_RENDER_H__ */

View File

@ -393,7 +393,7 @@ static void EDIT_MESH_cache_init(void *vedata)
stl->g_data->do_faces = true;
stl->g_data->do_edges = true;
stl->g_data->do_zbufclip = ((v3d)->shading.flag & V3D_SHADING_XRAY) != 0;
stl->g_data->do_zbufclip = ((v3d)->shading.flag & XRAY_FLAG(v3d)) != 0;
/* Applies on top of the theme edge width, so edge-mode can have thick edges. */
stl->g_data->edge_width_scale = (tsettings->selectmode & (SCE_SELECT_EDGE)) ? 1.75f : 1.0f;
@ -692,7 +692,7 @@ static void EDIT_MESH_draw_scene(void *vedata)
const DRWContextState *draw_ctx = DRW_context_state_get();
View3D *v3d = draw_ctx->v3d;
if (v3d->shading.type == OB_SOLID && (v3d->shading.flag & V3D_SHADING_XRAY) == 0) {
if (v3d->shading.type == OB_SOLID && (v3d->shading.flag & XRAY_FLAG(v3d)) == 0) {
if (stl->g_data->ghost_ob == 1 && stl->g_data->edit_ob == 1) {
/* In the case of single ghost object edit (common case for retopology):
* we duplicate the depht+stencil buffer and clear all depth to 1.0f where

View File

@ -1680,7 +1680,7 @@ static void DRW_shgroup_camera(OBJECT_ShadingGroupList *sgl, Object *ob, ViewLay
const bool is_select = DRW_state_is_select();
const bool is_solid_bundle = (v3d->bundle_drawtype == OB_EMPTY_SPHERE) &&
((v3d->shading.type != OB_SOLID) ||
((v3d->shading.flag & V3D_SHADING_XRAY) == 0));
((v3d->shading.flag & XRAY_FLAG(v3d)) == 0));
MovieTracking *tracking = &clip->tracking;
/* Index must start in 1, to mimic BKE_tracking_track_get_indexed. */

View File

@ -290,7 +290,7 @@ static void overlay_cache_populate(void *vedata, Object *ob)
GPUShader *sh = (all_wires) ? e_data.face_wireframe_sh : e_data.face_wireframe_pretty_sh;
if ((DRW_state_is_select() || DRW_state_is_depth()) &&
(v3d->shading.flag & V3D_SHADING_XRAY) != 0)
(v3d->shading.flag & XRAY_FLAG(v3d)) != 0)
{
static float params[2] = {1.2f, 1.0f}; /* Parameters for all wires */
@ -332,7 +332,7 @@ static void overlay_cache_finish(void *vedata)
View3D *v3d = ctx->v3d;
/* only in solid mode */
if (v3d->shading.type == OB_SOLID && (v3d->shading.flag & V3D_SHADING_XRAY) == 0) {
if (v3d->shading.type == OB_SOLID && (v3d->shading.flag & XRAY_FLAG(v3d)) == 0) {
if (stl->g_data->ghost_stencil_test) {
DRW_pass_state_add(psl->face_wireframe_pass, DRW_STATE_STENCIL_EQUAL);
DRW_pass_state_add(psl->face_wireframe_full_pass, DRW_STATE_STENCIL_EQUAL);

View File

@ -535,8 +535,8 @@ void ED_view3d_operator_properties_viewmat_get(struct wmOperator *op, int *winx,
void ED_view3d_stop_render_preview(struct wmWindowManager *wm, struct ARegion *ar);
void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrArea *sa);
#define V3D_IS_ZBUF(v3d) \
(((v3d)->shading.flag & V3D_SHADING_XRAY) == 0)
#define V3D_XRAY_FLAG(v3d) (((v3d)->shading.type == OB_WIRE) ? V3D_SHADING_XRAY_WIREFRAME : V3D_SHADING_XRAY)
#define V3D_IS_ZBUF(v3d) (((v3d)->shading.flag & V3D_XRAY_FLAG(v3d)) == 0)
void ED_view3d_id_remap(struct View3D *v3d, const struct ID *old_id, struct ID *new_id);

View File

@ -1009,7 +1009,7 @@ int view3d_opengl_select(
}
/* If in xray mode, we select the wires in priority. */
if (v3d->shading.flag & V3D_SHADING_XRAY) {
if (v3d->shading.flag & V3D_XRAY_FLAG(v3d)) {
/* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
* because the OpenGL context created & destroyed inside this function. */
struct DrawSelectLoopUserData drw_select_loop_user_data = {

View File

@ -2601,7 +2601,7 @@ static short transform_snap_context_project_view3d_mixed_impl(
bool use_occlusion_test =
params->use_occlusion_test &&
!(sctx->v3d_data.v3d->shading.flag & V3D_SHADING_XRAY);
!(sctx->v3d_data.v3d->shading.flag & V3D_XRAY_FLAG(sctx->v3d_data.v3d));
if (snap_to_flag & SCE_SNAP_MODE_FACE || use_occlusion_test) {
float ray_start[3], ray_normal[3];

View File

@ -156,12 +156,12 @@ typedef struct View3DShading {
float object_outline_color[3];
float xray_alpha;
float xray_alpha_wire;
float cavity_valley_factor;
float cavity_ridge_factor;
float background_color[3];
int pad;
} View3DShading;
@ -388,6 +388,7 @@ enum {
V3D_SHADING_CAVITY = (1 << 5),
V3D_SHADING_MATCAP_FLIP_X = (1 << 6),
V3D_SHADING_SCENE_WORLD = (1 << 7),
V3D_SHADING_XRAY_WIREFRAME = (1 << 8),
};
/* View3DShading->color_type */

View File

@ -2551,6 +2551,12 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Show X-Ray", "Show whole scene transparent");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_xray_wireframe", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_XRAY_WIREFRAME);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_ui_text(prop, "Show X-Ray", "Show whole scene transparent");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "xray_alpha", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "xray_alpha");
RNA_def_property_float_default(prop, 0.5);
@ -2559,6 +2565,14 @@ static void rna_def_space_view3d_shading(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, "xray_alpha_wireframe", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "xray_alpha_wire");
RNA_def_property_float_default(prop, 0.5);
RNA_def_property_ui_text(prop, "X-Ray Alpha", "Amount of alpha to use");
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, "use_scene_lights", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_SCENE_LIGHTS);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@ -2772,11 +2786,6 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Show Wire", "Use wireframe display in painting modes");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_occlude_wire", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_OCCLUDE_WIRE);
RNA_def_property_ui_text(prop, "Hidden Wire", "Use hidden wireframe display in edit mode");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_weight", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_WEIGHT);
RNA_def_property_ui_text(prop, "Show Weights", "Display weights in editmode");