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 /intern/cycles/scene/mesh_subdivision.cpp | |
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 'intern/cycles/scene/mesh_subdivision.cpp')
-rw-r--r-- | intern/cycles/scene/mesh_subdivision.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/intern/cycles/scene/mesh_subdivision.cpp b/intern/cycles/scene/mesh_subdivision.cpp index 35f15cfafbc..7c88e310527 100644 --- a/intern/cycles/scene/mesh_subdivision.cpp +++ b/intern/cycles/scene/mesh_subdivision.cpp @@ -82,24 +82,54 @@ template<> bool TopologyRefinerFactory<ccl::Mesh>::assignComponentTags(TopologyRefiner &refiner, ccl::Mesh const &mesh) { + /* Historical maximum crease weight used at Pixar, influencing the maximum in OpenSubDiv. */ + static constexpr float CREASE_SCALE = 10.0f; + size_t num_creases = mesh.get_subd_creases_weight().size(); + size_t num_vertex_creases = mesh.get_subd_vert_creases().size(); + + /* The last loop is over the vertices, so early exit to avoid iterating them needlessly. */ + if (num_creases == 0 && num_vertex_creases == 0) { + return true; + } for (int i = 0; i < num_creases; i++) { ccl::Mesh::SubdEdgeCrease crease = mesh.get_subd_crease(i); Index edge = findBaseEdge(refiner, crease.v[0], crease.v[1]); if (edge != INDEX_INVALID) { - setBaseEdgeSharpness(refiner, edge, crease.crease * 10.0f); + setBaseEdgeSharpness(refiner, edge, crease.crease * CREASE_SCALE); } } + std::map<int, float> vertex_creases; + + for (size_t i = 0; i < num_vertex_creases; ++i) { + const int vertex_idx = mesh.get_subd_vert_creases()[i]; + const float weight = mesh.get_subd_vert_creases_weight()[i]; + + vertex_creases[vertex_idx] = weight * CREASE_SCALE; + } + for (int i = 0; i < mesh.get_verts().size(); i++) { + float sharpness = 0.0f; + std::map<int, float>::const_iterator iter = vertex_creases.find(i); + + if (iter != vertex_creases.end()) { + sharpness = iter->second; + } + ConstIndexArray vert_edges = getBaseVertexEdges(refiner, i); if (vert_edges.size() == 2) { - float sharpness = refiner.getLevel(0).getEdgeSharpness(vert_edges[0]); - sharpness = ccl::min(sharpness, refiner.getLevel(0).getEdgeSharpness(vert_edges[1])); + const float sharpness0 = refiner.getLevel(0).getEdgeSharpness(vert_edges[0]); + const float sharpness1 = refiner.getLevel(0).getEdgeSharpness(vert_edges[1]); + + sharpness += ccl::min(sharpness0, sharpness1); + sharpness = ccl::min(sharpness, CREASE_SCALE); + } + if (sharpness != 0.0f) { setBaseVertexSharpness(refiner, i, sharpness); } } |