diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-01-20 14:20:30 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-01-20 14:21:34 +0300 |
commit | 4425e0cd64ff23b77c553041858a150665a32ba3 (patch) | |
tree | 45c76d67d99499377dc719679c22e87effc86d8f /source/blender/draw/intern/mesh_extractors | |
parent | 9b4c017031f94237d75320349e933462772d773e (diff) |
Subdivision: add support for vertex creasing
This adds vertex creasing support for OpenSubDiv for modeling, rendering,
Alembic and USD I/O.
For modeling, vertex creasing follows the edge creasing implementation with an
operator accessible through the Vertex menu in Edit Mode, and some parameter in
the properties panel. The option in the Subsurf and Multires to use edge
creasing also affects vertex creasing.
The vertex crease data is stored as a CustomData layer, unlike edge creases
which for now are stored in `MEdge`, but will in the future also be moved to
a `CustomData` layer. See comments for details on the difference in behavior
for the `CD_CREASE` layer between egdes and vertices.
For Cycles this adds sockets on the Mesh node to hold data about which vertices
are creased (one socket for the indices, one for the weigths).
Viewport rendering of vertex creasing reuses the same color scheme as for edges
and creased vertices are drawn bigger than uncreased vertices.
For Alembic and USD, vertex crease support follows the edge crease
implementation, they are always read, but only exported if a `Subsurf` modifier
is present on the Mesh.
Reviewed By: brecht, fclem, sergey, sybren, campbellbarton
Differential Revision: https://developer.blender.org/D10145
Diffstat (limited to 'source/blender/draw/intern/mesh_extractors')
-rw-r--r-- | source/blender/draw/intern/mesh_extractors/extract_mesh.h | 5 | ||||
-rw-r--r-- | source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc | 15 |
2 files changed, 15 insertions, 5 deletions
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.h b/source/blender/draw/intern/mesh_extractors/extract_mesh.h index 834f378c07a..bb55d0c5b2c 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh.h +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.h @@ -84,7 +84,8 @@ typedef struct MeshRenderData { const float (*bm_poly_centers)[3]; int *v_origindex, *e_origindex, *p_origindex; - int crease_ofs; + int edge_crease_ofs; + int vert_crease_ofs; int bweight_ofs; int freestyle_edge_ofs; int freestyle_face_ofs; @@ -308,6 +309,8 @@ void mesh_render_data_update_looptris(MeshRenderData *mr, typedef struct EditLoopData { uchar v_flag; uchar e_flag; + /* This is used for both vertex and edge creases. The edge crease value is stored in the bottom 4 + * bits, while the vertex crease is stored in the upper 4 bits. */ uchar crease; uchar bweight; } EditLoopData; diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc index 3cc1375329e..0002b95c867 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc @@ -72,11 +72,11 @@ static void mesh_render_data_edge_flag(const MeshRenderData *mr, } } - /* Use a byte for value range */ - if (mr->crease_ofs != -1) { - float crease = BM_ELEM_CD_GET_FLOAT(eed, mr->crease_ofs); + /* Use half a byte for value range */ + if (mr->edge_crease_ofs != -1) { + float crease = BM_ELEM_CD_GET_FLOAT(eed, mr->edge_crease_ofs); if (crease > 0) { - eattr->crease = (uchar)(crease * 255.0f); + eattr->crease = (uchar)ceil(crease * 15.0f); } } /* Use a byte for value range */ @@ -107,6 +107,13 @@ static void mesh_render_data_vert_flag(const MeshRenderData *mr, if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { eattr->e_flag |= VFLAG_VERT_SELECTED; } + /* Use half a byte for value range */ + if (mr->vert_crease_ofs != -1) { + float crease = BM_ELEM_CD_GET_FLOAT(eve, mr->vert_crease_ofs); + if (crease > 0) { + eattr->crease |= (uchar)ceil(crease * 15.0f) << 4; + } + } } static GPUVertFormat *get_edit_data_format() |