Overlay: Add support for per object wirefram options

This patch has a known bug on AMD + mesa because of the drivers. I will
send a bug report to mesa.
This commit is contained in:
2018-08-20 10:45:02 +02:00
parent d2e70455cf
commit 52d75d5127
2 changed files with 47 additions and 41 deletions

View File

@@ -1220,11 +1220,9 @@ static void drw_engines_enable_from_mode(int mode)
use_drw_engine(&draw_engine_gpencil_type);
}
static void drw_engines_enable_from_overlays(int overlay_flag)
static void drw_engines_enable_from_overlays(int UNUSED(overlay_flag))
{
if (overlay_flag) {
use_drw_engine(&draw_engine_overlay_type);
}
use_drw_engine(&draw_engine_overlay_type);
}
/**
* Use for select and depth-drawing.

View File

@@ -41,6 +41,7 @@ typedef struct OVERLAY_StorageList {
typedef struct OVERLAY_PassList {
struct DRWPass *face_orientation_pass;
struct DRWPass *face_wireframe_pass;
struct DRWPass *face_wireframe_full_pass;
} OVERLAY_PassList;
typedef struct OVERLAY_Data {
@@ -52,11 +53,11 @@ typedef struct OVERLAY_Data {
} OVERLAY_Data;
typedef struct OVERLAY_PrivateData {
GPUShader *wire_sh; /* reference */
DRWShadingGroup *face_orientation_shgrp;
View3DOverlay overlay;
float wire_step_param[2];
bool ghost_stencil_test;
bool show_overlays;
} OVERLAY_PrivateData; /* Transient data */
/* *********** STATIC *********** */
@@ -128,42 +129,45 @@ static void overlay_cache_init(void *vedata)
View3D *v3d = DCS->v3d;
if (v3d) {
stl->g_data->overlay = v3d->overlay;
stl->g_data->show_overlays = (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0;
}
else {
memset(&stl->g_data->overlay, 0, sizeof(stl->g_data->overlay));
stl->g_data->show_overlays = false;
}
/* Face Orientation Pass */
if (stl->g_data->overlay.flag & V3D_OVERLAY_FACE_ORIENTATION) {
{
/* Face Orientation Pass */
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND;
psl->face_orientation_pass = DRW_pass_create("Face Orientation", state);
stl->g_data->face_orientation_shgrp = DRW_shgroup_create(
e_data.face_orientation_sh, psl->face_orientation_pass);
}
if (stl->g_data->overlay.flag & V3D_OVERLAY_WIREFRAMES) {
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND;
psl->face_wireframe_pass = DRW_pass_create("Face Wires", state);
/* Sticky uniforms (don't need to respecify each time since shader does not change). */
stl->g_data->wire_sh = (stl->g_data->overlay.wireframe_threshold == 1.0f) ? e_data.face_wireframe_sh
: e_data.face_wireframe_pretty_sh;
DRWShadingGroup *shgrp = DRW_shgroup_create(stl->g_data->wire_sh, psl->face_wireframe_pass);
DRW_shgroup_uniform_vec2(shgrp, "viewportSize", DRW_viewport_size_get(), 1);
if (stl->g_data->overlay.wireframe_threshold < 1.0f) {
/**
* The wireframe threshold ranges from 0.0 to 1.0
* When 1.0 we show all the edges, when 0.5 we show as many as 2.7.
*
* If we wanted 0.0 to match 2.7, factor would need to be 0.003f.
* The range controls the falloff effect. If range was 0.0f we would get a hard cut (as in 2.7).
* That said we are using a different algorithm so the results will always differ.
*/
const float factor = 0.0045f;
const float range = 0.00125f;
stl->g_data->wire_step_param[1] = (1.0f - factor) + stl->g_data->overlay.wireframe_threshold * factor;
stl->g_data->wire_step_param[0] = stl->g_data->wire_step_param[1] + range;
DRW_shgroup_uniform_vec2(shgrp, "wireStepParam", stl->g_data->wire_step_param, 1);
}
{
/* Wireframe */
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND;
psl->face_wireframe_full_pass = DRW_pass_create("All Face Wires", state);
DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.face_wireframe_sh, psl->face_wireframe_full_pass);
DRW_shgroup_uniform_vec2(shgrp, "viewportSize", DRW_viewport_size_get(), 1);
psl->face_wireframe_pass = DRW_pass_create("Face Wires", state);
shgrp = DRW_shgroup_create(e_data.face_wireframe_pretty_sh, psl->face_wireframe_pass);
DRW_shgroup_uniform_vec2(shgrp, "viewportSize", DRW_viewport_size_get(), 1);
/**
* The wireframe threshold ranges from 0.0 to 1.0
* When 1.0 we show all the edges, when 0.5 we show as many as 2.7.
*
* If we wanted 0.0 to match 2.7, factor would need to be 0.003f.
* The range controls the falloff effect. If range was 0.0f we would get a hard cut (as in 2.7).
* That said we are using a different algorithm so the results will always differ.
*/
const float factor = 0.0045f;
const float range = 0.00125f;
stl->g_data->wire_step_param[1] = (1.0f - factor) + stl->g_data->overlay.wireframe_threshold * factor;
stl->g_data->wire_step_param[0] = stl->g_data->wire_step_param[1] + range;
DRW_shgroup_uniform_vec2(shgrp, "wireStepParam", stl->g_data->wire_step_param, 1);
}
}
@@ -175,6 +179,9 @@ static void overlay_cache_populate(void *vedata, Object *ob)
OVERLAY_PassList *psl = data->psl;
const DRWContextState *draw_ctx = DRW_context_state_get();
if (!stl->g_data->show_overlays)
return;
if (!DRW_object_is_renderable(ob))
return;
@@ -185,7 +192,7 @@ static void overlay_cache_populate(void *vedata, Object *ob)
}
}
if (stl->g_data->overlay.flag & V3D_OVERLAY_WIREFRAMES) {
if ((stl->g_data->overlay.flag & V3D_OVERLAY_WIREFRAMES) || (ob->dtx & OB_DRAWWIRE)) {
/* Don't do that in edit mode. */
if ((ob != draw_ctx->object_edit) && !BKE_object_is_in_editmode(ob)) {
int tri_count;
@@ -196,7 +203,12 @@ static void overlay_cache_populate(void *vedata, Object *ob)
if ((ob->base_flag & BASE_SELECTED) != 0) {
rim_col = (ob == draw_ctx->obact) ? ts.colorActive : ts.colorSelect;
}
DRWShadingGroup *shgrp = DRW_shgroup_create(stl->g_data->wire_sh, psl->face_wireframe_pass);
const bool all_wires = (stl->g_data->overlay.wireframe_threshold == 1.0f) ||
(ob->dtx & OB_DRAW_ALL_EDGES);
DRWPass *pass = (all_wires) ? psl->face_wireframe_full_pass : psl->face_wireframe_pass;
GPUShader *sh = (all_wires) ? e_data.face_wireframe_sh : e_data.face_wireframe_pretty_sh;
DRWShadingGroup *shgrp = DRW_shgroup_create(sh, pass);
DRW_shgroup_stencil_mask(shgrp, (ob->dtx & OB_DRAWXRAY) ? 0x00 : 0xFF);
DRW_shgroup_uniform_texture(shgrp, "vertData", verts);
DRW_shgroup_uniform_texture(shgrp, "faceIds", faceids);
@@ -223,8 +235,9 @@ static void overlay_cache_finish(void *vedata)
/* only in solid mode */
if (v3d->shading.type == OB_SOLID && (v3d->shading.flag & V3D_SHADING_XRAY) == 0) {
if (stl->g_data->ghost_stencil_test && (psl->face_wireframe_pass != NULL)) {
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);
}
}
}
@@ -233,15 +246,10 @@ static void overlay_draw_scene(void *vedata)
{
OVERLAY_Data * data = (OVERLAY_Data *)vedata;
OVERLAY_PassList *psl = data->psl;
OVERLAY_StorageList *stl = data->stl;
OVERLAY_PrivateData *pd = stl->g_data;
if (pd->overlay.flag & V3D_OVERLAY_FACE_ORIENTATION) {
DRW_draw_pass(psl->face_orientation_pass);
}
if (pd->overlay.flag & V3D_OVERLAY_WIREFRAMES) {
DRW_draw_pass(psl->face_wireframe_pass);
}
DRW_draw_pass(psl->face_orientation_pass);
DRW_draw_pass(psl->face_wireframe_pass);
DRW_draw_pass(psl->face_wireframe_full_pass);
}
static void overlay_engine_free(void)