Edit Mesh: Fix some problem with new implementation
- Add manual depth offset to vertices and edges. - Revert to plain edge decoration. - Fix active edge coloring. - Remove active face display if not in face selection mode. - Add wide line support.
This commit is contained in:
parent
112cf6eadf
commit
a131514d0f
|
@ -289,7 +289,7 @@ typedef enum {
|
|||
DRW_STATE_OFFSET_POSITIVE = (1 << 12),
|
||||
/** Polygon offset. Does not work with lines and points. */
|
||||
DRW_STATE_OFFSET_NEGATIVE = (1 << 13),
|
||||
/* DRW_STATE_STIPPLE_4 = (1 << 14), */ /* Not used */
|
||||
DRW_STATE_WIRE_WIDE = (1 << 14),
|
||||
DRW_STATE_BLEND = (1 << 15),
|
||||
DRW_STATE_ADDITIVE = (1 << 16),
|
||||
DRW_STATE_MULTIPLY = (1 << 17),
|
||||
|
|
|
@ -120,7 +120,6 @@ struct GPUBatch *DRW_mesh_batch_cache_get_edit_lnors(struct Mesh *me);
|
|||
struct GPUBatch *DRW_mesh_batch_cache_get_edit_facedots(struct Mesh *me);
|
||||
/* edit-mesh selection */
|
||||
struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_id(struct Mesh *me);
|
||||
struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_mask(struct Mesh *me);
|
||||
struct GPUBatch *DRW_mesh_batch_cache_get_facedots_with_select_id(struct Mesh *me);
|
||||
struct GPUBatch *DRW_mesh_batch_cache_get_edges_with_select_id(struct Mesh *me);
|
||||
struct GPUBatch *DRW_mesh_batch_cache_get_verts_with_select_id(struct Mesh *me);
|
||||
|
|
|
@ -183,15 +183,23 @@ void drw_state_set(DRWState state)
|
|||
|
||||
/* Wire Width */
|
||||
{
|
||||
if (CHANGED_ANY(DRW_STATE_WIRE | DRW_STATE_WIRE_SMOOTH)) {
|
||||
if ((state & DRW_STATE_WIRE_SMOOTH) != 0) {
|
||||
int test;
|
||||
if (CHANGED_ANY_STORE_VAR(
|
||||
DRW_STATE_WIRE | DRW_STATE_WIRE_WIDE | DRW_STATE_WIRE_SMOOTH,
|
||||
test))
|
||||
{
|
||||
if (test & DRW_STATE_WIRE_WIDE) {
|
||||
GPU_line_width(3.0f);
|
||||
}
|
||||
else if (test & DRW_STATE_WIRE_SMOOTH) {
|
||||
GPU_line_width(2.0f);
|
||||
GPU_line_smooth(true);
|
||||
}
|
||||
else if ((state & DRW_STATE_WIRE) != 0) {
|
||||
else if (test & DRW_STATE_WIRE) {
|
||||
GPU_line_width(1.0f);
|
||||
}
|
||||
else {
|
||||
GPU_line_width(1.0f);
|
||||
GPU_line_smooth(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#include "BKE_editmesh.h"
|
||||
#include "BKE_object.h"
|
||||
|
||||
#include "BIF_glutil.h"
|
||||
|
||||
#include "BLI_dynstr.h"
|
||||
#include "BLI_string_utils.h"
|
||||
|
||||
|
@ -102,6 +104,7 @@ typedef struct EDIT_MESH_Shaders {
|
|||
GPUShader *overlay_vert;
|
||||
GPUShader *overlay_edge;
|
||||
GPUShader *overlay_edge_flat;
|
||||
GPUShader *overlay_edge_deco;
|
||||
GPUShader *overlay_face;
|
||||
GPUShader *overlay_facedot;
|
||||
|
||||
|
@ -134,6 +137,7 @@ typedef struct EDIT_MESH_PrivateData {
|
|||
|
||||
DRWShadingGroup *vert_shgrp;
|
||||
DRWShadingGroup *edge_shgrp;
|
||||
DRWShadingGroup *edge_deco_shgrp;
|
||||
DRWShadingGroup *face_shgrp;
|
||||
DRWShadingGroup *face_cage_shgrp;
|
||||
DRWShadingGroup *facedot_shgrp;
|
||||
|
@ -200,9 +204,14 @@ static void EDIT_MESH_engine_init(void *vedata)
|
|||
});
|
||||
sh_data->overlay_edge_flat = DRW_shader_create_from_arrays({
|
||||
.vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
|
||||
.frag = (const char *[]){datatoc_edit_mesh_overlay_frag_glsl, NULL},
|
||||
.frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
|
||||
.defs = (const char *[]){world_clip_def_or_empty, "#define EDGE\n", "#define FLAT\n", NULL},
|
||||
});
|
||||
sh_data->overlay_edge_deco = DRW_shader_create_from_arrays({
|
||||
.vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
|
||||
.frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
|
||||
.defs = (const char *[]){world_clip_def_or_empty, "#define EDGE_DECORATION\n", "#define FLAT\n", NULL},
|
||||
});
|
||||
sh_data->overlay_vert = DRW_shader_create_from_arrays({
|
||||
.vert = (const char *[]){lib, datatoc_edit_mesh_overlay_vert_glsl, NULL},
|
||||
.frag = (const char *[]){datatoc_gpu_shader_point_varying_color_frag_glsl, NULL},
|
||||
|
@ -253,7 +262,7 @@ static DRWPass *edit_mesh_create_overlay_pass(
|
|||
float *face_alpha, float *edge_width_scale, int *data_mask, bool do_edges, bool UNUSED(xray),
|
||||
DRWState statemod,
|
||||
DRWShadingGroup **r_face_shgrp, DRWShadingGroup **r_face_cage_shgrp, DRWShadingGroup **r_facedot_shgrp,
|
||||
DRWShadingGroup **r_edge_shgrp, DRWShadingGroup **r_vert_shgrp)
|
||||
DRWShadingGroup **r_edge_shgrp, DRWShadingGroup **r_edge_deco_shgrp, DRWShadingGroup **r_vert_shgrp)
|
||||
{
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
RegionView3D *rv3d = draw_ctx->rv3d;
|
||||
|
@ -262,6 +271,14 @@ static DRWPass *edit_mesh_create_overlay_pass(
|
|||
EDIT_MESH_Shaders *sh_data = &e_data.sh_data[draw_ctx->shader_slot];
|
||||
const bool select_vert = (tsettings->selectmode & SCE_SELECT_VERTEX) != 0;
|
||||
const bool select_face = (tsettings->selectmode & SCE_SELECT_FACE) != 0;
|
||||
float winmat[4][4];
|
||||
float viewdist = rv3d->dist;
|
||||
DRW_viewport_matrix_get(winmat, DRW_MAT_WIN);
|
||||
/* special exception for ortho camera (viewdist isnt used for perspective cameras) */
|
||||
if (rv3d->persp == RV3D_CAMOB && rv3d->is_persp == false) {
|
||||
viewdist = 1.0f / max_ff(fabsf(rv3d->winmat[0][0]), fabsf(rv3d->winmat[1][1]));
|
||||
}
|
||||
const float depth_ofs = bglPolygonOffsetCalc((float *)winmat, viewdist, 1.0f);
|
||||
|
||||
DRWPass *pass = DRW_pass_create(
|
||||
"Edit Mesh Face Overlay Pass",
|
||||
|
@ -274,6 +291,7 @@ static DRWPass *edit_mesh_create_overlay_pass(
|
|||
GPUShader *edge_sh = (select_vert) ? sh_data->overlay_edge : sh_data->overlay_edge_flat;
|
||||
GPUShader *face_sh = sh_data->overlay_face;
|
||||
GPUShader *facedot_sh = sh_data->overlay_facedot;
|
||||
GPUShader *edge_deco_sh = sh_data->overlay_edge_deco;
|
||||
/* Faces */
|
||||
if (select_face) {
|
||||
grp = *r_facedot_shgrp = DRW_shgroup_create(facedot_sh, pass);
|
||||
|
@ -292,6 +310,7 @@ static DRWPass *edit_mesh_create_overlay_pass(
|
|||
DRW_shgroup_uniform_float(grp, "edgeScale", edge_width_scale, 1);
|
||||
DRW_shgroup_uniform_ivec4(grp, "dataMask", data_mask, 1);
|
||||
DRW_shgroup_uniform_bool_copy(grp, "doEdges", do_edges);
|
||||
DRW_shgroup_uniform_float_copy(grp, "ofs", 0.0f);
|
||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||
DRW_shgroup_world_clip_planes_from_rv3d(grp, rv3d);
|
||||
}
|
||||
|
@ -301,12 +320,27 @@ static DRWPass *edit_mesh_create_overlay_pass(
|
|||
DRW_shgroup_state_enable(grp, DRW_STATE_OFFSET_NEGATIVE);
|
||||
|
||||
/* Edges */
|
||||
grp = *r_edge_deco_shgrp = DRW_shgroup_create(edge_deco_sh, pass);
|
||||
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
|
||||
DRW_shgroup_uniform_ivec4(grp, "dataMask", data_mask, 1);
|
||||
DRW_shgroup_uniform_bool_copy(grp, "doEdges", do_edges);
|
||||
DRW_shgroup_uniform_float_copy(grp, "ofs", depth_ofs);
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_OFFSET_NEGATIVE);
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_BLEND);
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_WIRE_WIDE);
|
||||
/* To match blender loop structure. */
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_FIRST_VERTEX_CONVENTION);
|
||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||
DRW_shgroup_world_clip_planes_from_rv3d(grp, rv3d);
|
||||
}
|
||||
|
||||
grp = *r_edge_shgrp = DRW_shgroup_create(edge_sh, pass);
|
||||
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
|
||||
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
||||
DRW_shgroup_uniform_float(grp, "edgeScale", edge_width_scale, 1);
|
||||
DRW_shgroup_uniform_ivec4(grp, "dataMask", data_mask, 1);
|
||||
DRW_shgroup_uniform_bool_copy(grp, "doEdges", do_edges);
|
||||
DRW_shgroup_uniform_float_copy(grp, "ofs", depth_ofs);
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_WRITE_DEPTH);
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_OFFSET_NEGATIVE);
|
||||
/* To match blender loop structure. */
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_FIRST_VERTEX_CONVENTION);
|
||||
|
@ -320,6 +354,7 @@ static DRWPass *edit_mesh_create_overlay_pass(
|
|||
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
|
||||
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
||||
DRW_shgroup_uniform_float(grp, "edgeScale", edge_width_scale, 1);
|
||||
DRW_shgroup_uniform_float_copy(grp, "ofs", depth_ofs);
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_OFFSET_NEGATIVE | DRW_STATE_WRITE_DEPTH);
|
||||
DRW_shgroup_state_disable(grp, DRW_STATE_BLEND);
|
||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||
|
@ -375,6 +410,9 @@ static void EDIT_MESH_cache_init(void *vedata)
|
|||
stl->g_data->data_mask[0] &= ~(VFLAG_FACE_SELECTED & VFLAG_FACE_FREESTYLE);
|
||||
stl->g_data->do_faces = false;
|
||||
}
|
||||
if ((tsettings->selectmode & SCE_SELECT_FACE) == 0) {
|
||||
stl->g_data->data_mask[0] &= ~VFLAG_FACE_ACTIVE;
|
||||
}
|
||||
if ((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_SEAMS) == 0) {
|
||||
stl->g_data->data_mask[1] &= ~VFLAG_EDGE_SEAM;
|
||||
}
|
||||
|
@ -473,6 +511,7 @@ static void EDIT_MESH_cache_init(void *vedata)
|
|||
&stl->g_data->face_cage_shgrp,
|
||||
&stl->g_data->facedot_shgrp,
|
||||
&stl->g_data->edge_shgrp,
|
||||
&stl->g_data->edge_deco_shgrp,
|
||||
&stl->g_data->vert_shgrp);
|
||||
}
|
||||
else {
|
||||
|
@ -484,6 +523,7 @@ static void EDIT_MESH_cache_init(void *vedata)
|
|||
&stl->g_data->face_cage_shgrp,
|
||||
&stl->g_data->facedot_shgrp,
|
||||
&stl->g_data->edge_shgrp,
|
||||
&stl->g_data->edge_deco_shgrp,
|
||||
&stl->g_data->vert_shgrp);
|
||||
|
||||
/* however we loose the front faces value (because we need the depth of occluded wires and
|
||||
|
@ -533,11 +573,13 @@ static void edit_mesh_add_ob_to_pass(
|
|||
DRWShadingGroup *face_shgrp = (has_edit_mesh_cage) ? g_data->face_cage_shgrp : g_data->face_shgrp;
|
||||
DRWShadingGroup *vert_shgrp = g_data->vert_shgrp;
|
||||
DRWShadingGroup *edge_shgrp = g_data->edge_shgrp;
|
||||
DRWShadingGroup *edge_deco_shgrp = g_data->edge_deco_shgrp;
|
||||
|
||||
geom_tris = DRW_mesh_batch_cache_get_edit_triangles(ob->data);
|
||||
geom_edges = DRW_mesh_batch_cache_get_edit_edges(ob->data);
|
||||
DRW_shgroup_call_add(face_shgrp, geom_tris, ob->obmat);
|
||||
DRW_shgroup_call_add(edge_shgrp, geom_edges, ob->obmat);
|
||||
DRW_shgroup_call_add(edge_deco_shgrp, geom_edges, ob->obmat);
|
||||
|
||||
if (facefill_shgrp) {
|
||||
DRW_shgroup_call_add(facefill_shgrp, geom_tris, ob->obmat);
|
||||
|
|
|
@ -19,12 +19,8 @@ vec4 EDIT_MESH_edge_color_outer(int edge_flag, int face_flag, float crease, floa
|
|||
vec4 EDIT_MESH_edge_color_inner(int edge_flag)
|
||||
{
|
||||
vec4 color = colorWireEdit;
|
||||
#ifdef EDGE_SELECTION
|
||||
color = ((edge_flag & EDGE_SELECTED) != 0) ? colorEdgeSelect : color;
|
||||
color = ((edge_flag & EDGE_ACTIVE) != 0) ? colorEditMeshActive : color;
|
||||
#else
|
||||
color = (doEdges && (edge_flag & EDGE_SELECTED) != 0) ? colorEdgeSelect : color;
|
||||
#endif
|
||||
return color;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
|
||||
uniform float edgeScale;
|
||||
uniform bool isXray = false;
|
||||
|
||||
flat in vec4 finalColorStipple;
|
||||
in float dist;
|
||||
flat in float base_dist;
|
||||
|
||||
#ifdef FLAT
|
||||
flat in vec4 finalColor;
|
||||
#else
|
||||
|
@ -19,12 +12,6 @@ out vec4 FragColor;
|
|||
|
||||
void main()
|
||||
{
|
||||
float dist_px = dist - base_dist;
|
||||
dist_px /= fwidth(dist_px);
|
||||
float mix_fac = step(0.5, fract(abs(dist_px) * (1.0 / 20.0)));
|
||||
if (finalColorStipple.a == 0.0) {
|
||||
mix_fac = 1.0;
|
||||
}
|
||||
#if defined(EDGE) && !defined(FLAT)
|
||||
vec4 prim_col = mix(colorEditMeshMiddle, colorEdgeSelect, finalColor.a);
|
||||
prim_col = (selectOveride != 0) ? prim_col : finalColor;
|
||||
|
@ -32,5 +19,5 @@ void main()
|
|||
#else
|
||||
# define prim_col finalColor
|
||||
#endif
|
||||
FragColor = mix(finalColorStipple, prim_col, mix_fac);
|
||||
FragColor = prim_col;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ uniform mat4 ModelViewProjectionMatrix;
|
|||
uniform mat4 ModelMatrix;
|
||||
uniform float faceAlphaMod;
|
||||
uniform ivec4 dataMask = ivec4(0xFF);
|
||||
uniform float ofs;
|
||||
|
||||
in ivec4 data;
|
||||
in vec3 pos;
|
||||
|
@ -16,12 +17,6 @@ in vec4 norAndFlag;
|
|||
# define vnor norAndFlag.xyz
|
||||
#endif
|
||||
|
||||
#ifdef EDGE
|
||||
flat out vec4 finalColorStipple;
|
||||
flat out float base_dist;
|
||||
out float dist;
|
||||
#endif
|
||||
|
||||
#ifdef FLAT
|
||||
flat out vec4 finalColor;
|
||||
#else
|
||||
|
@ -33,7 +28,15 @@ flat out int selectOveride;
|
|||
|
||||
void main()
|
||||
{
|
||||
#if !defined(FACE)
|
||||
mat4 projmat = ProjectionMatrix;
|
||||
projmat[3][2] -= ofs;
|
||||
|
||||
gl_Position = projmat * (ModelViewMatrix * vec4(pos, 1.0));
|
||||
#else
|
||||
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
||||
#endif
|
||||
|
||||
ivec4 m_data = data & dataMask;
|
||||
|
||||
|
@ -57,10 +60,10 @@ void main()
|
|||
selectOveride = (m_data.y & EDGE_SELECTED);
|
||||
# endif
|
||||
|
||||
#elif defined(EDGE_DECORATION)
|
||||
float crease = float(m_data.z) / 255.0;
|
||||
float bweight = float(m_data.w) / 255.0;
|
||||
finalColorStipple = EDIT_MESH_edge_color_outer(m_data.y, m_data.x, crease, bweight);
|
||||
base_dist = dist = float(gl_VertexID % 128);
|
||||
finalColor = EDIT_MESH_edge_color_outer(m_data.y, m_data.x, crease, bweight);
|
||||
|
||||
#elif defined(FACE)
|
||||
finalColor = EDIT_MESH_face_color(m_data.x);
|
||||
|
@ -74,7 +77,8 @@ void main()
|
|||
|
||||
#endif
|
||||
|
||||
#ifndef FACE
|
||||
#if !defined(FACE) && !defined(EDGE_DECORATION)
|
||||
/* Facing based color blend */
|
||||
vec4 vpos = ModelViewMatrix * vec4(pos, 1.0);
|
||||
vec3 view_normal = normalize(NormalMatrix * vnor);
|
||||
vec3 view_vec = (ProjectionMatrix[3][3] == 0.0)
|
||||
|
|
|
@ -106,6 +106,7 @@ void set_inverted_drawing(int enable);
|
|||
void setlinestyle(int nr);
|
||||
|
||||
/* own working polygon offset */
|
||||
float bglPolygonOffsetCalc(const float winmat[16], float viewdist, float dist);
|
||||
void bglPolygonOffset(float viewdist, float dist);
|
||||
|
||||
/* **** Color management helper functions for GLSL display/transform ***** */
|
||||
|
|
|
@ -341,6 +341,34 @@ void immDrawPixelsTex_clipping(IMMDrawPixelsTexState *state,
|
|||
|
||||
/* *************** glPolygonOffset hack ************* */
|
||||
|
||||
float bglPolygonOffsetCalc(const float winmat[16], float viewdist, float dist)
|
||||
{
|
||||
if (winmat[15] > 0.5f) {
|
||||
#if 1
|
||||
return 0.00001f * dist * viewdist; // ortho tweaking
|
||||
#else
|
||||
static float depth_fac = 0.0f;
|
||||
if (depth_fac == 0.0f) {
|
||||
int depthbits;
|
||||
glGetIntegerv(GL_DEPTH_BITS, &depthbits);
|
||||
depth_fac = 1.0f / (float)((1 << depthbits) - 1);
|
||||
}
|
||||
offs = (-1.0 / winmat[10]) * dist * depth_fac;
|
||||
|
||||
UNUSED_VARS(viewdist);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
/* This adjustment effectively results in reducing the Z value by 0.25%.
|
||||
*
|
||||
* winmat[14] actually evaluates to `-2 * far * near / (far - near)`,
|
||||
* is very close to -0.2 with default clip range, and is used as the coefficient multiplied by `w / z`,
|
||||
* thus controlling the z dependent part of the depth value.
|
||||
*/
|
||||
return winmat[14] * -0.0025f * dist;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \note \a viewdist is only for ortho at the moment.
|
||||
*/
|
||||
|
@ -349,8 +377,6 @@ void bglPolygonOffset(float viewdist, float dist)
|
|||
static float winmat[16], offset = 0.0f;
|
||||
|
||||
if (dist != 0.0f) {
|
||||
float offs;
|
||||
|
||||
// glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
// glPolygonOffset(-1.0, -1.0);
|
||||
|
||||
|
@ -359,30 +385,7 @@ void bglPolygonOffset(float viewdist, float dist)
|
|||
|
||||
/* dist is from camera to center point */
|
||||
|
||||
if (winmat[15] > 0.5f) {
|
||||
#if 1
|
||||
offs = 0.00001f * dist * viewdist; // ortho tweaking
|
||||
#else
|
||||
static float depth_fac = 0.0f;
|
||||
if (depth_fac == 0.0f) {
|
||||
int depthbits;
|
||||
glGetIntegerv(GL_DEPTH_BITS, &depthbits);
|
||||
depth_fac = 1.0f / (float)((1 << depthbits) - 1);
|
||||
}
|
||||
offs = (-1.0 / winmat[10]) * dist * depth_fac;
|
||||
|
||||
UNUSED_VARS(viewdist);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
/* This adjustment effectively results in reducing the Z value by 0.25%.
|
||||
*
|
||||
* winmat[14] actually evaluates to `-2 * far * near / (far - near)`,
|
||||
* is very close to -0.2 with default clip range, and is used as the coefficient multiplied by `w / z`,
|
||||
* thus controlling the z dependent part of the depth value.
|
||||
*/
|
||||
offs = winmat[14] * -0.0025f * dist;
|
||||
}
|
||||
float offs = bglPolygonOffsetCalc(winmat, viewdist, dist);
|
||||
|
||||
winmat[14] -= offs;
|
||||
offset += offs;
|
||||
|
|
Loading…
Reference in New Issue