Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2021-01-14 18:33:52 +0300
committerBrecht Van Lommel <brecht@blender.org>2022-05-18 17:45:38 +0300
commit342e12d6d92198bba8355562600a2f97bb45fed5 (patch)
treea5f1e10205e7d66e5c6672fb416883a04475782c /source/blender/blenkernel/intern/subdiv_eval.c
parentf517b3a29568fd43b722973c7c46d3c358ba0dda (diff)
Subdiv: support interpolating orco coordinates in subdivision surfaces
This makes changes to the opensubdiv module to support additional vertex data besides the vertex position, that is smootly interpolated the same way. This is different than varying data which is interpolated linearly. Fixes T96596: wrong generated texture coordinates with GPU subdivision. In that bug lazy subdivision would not interpolate orcos. Later on, this implementation can also be used to remove the modifier stack mechanism where modifiers are evaluated a second time for orcos, which is messy and inefficient. But that's a more risky change, this is just the part to fix the bug in 3.2. Differential Revision: https://developer.blender.org/D14973
Diffstat (limited to 'source/blender/blenkernel/intern/subdiv_eval.c')
-rw-r--r--source/blender/blenkernel/intern/subdiv_eval.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/subdiv_eval.c b/source/blender/blenkernel/intern/subdiv_eval.c
index 9edd9815400..d03c0f89948 100644
--- a/source/blender/blenkernel/intern/subdiv_eval.c
+++ b/source/blender/blenkernel/intern/subdiv_eval.c
@@ -44,7 +44,8 @@ static eOpenSubdivEvaluator opensubdiv_evalutor_from_subdiv_evaluator_type(
bool BKE_subdiv_eval_begin(Subdiv *subdiv,
eSubdivEvaluatorType evaluator_type,
- OpenSubdiv_EvaluatorCache *evaluator_cache)
+ OpenSubdiv_EvaluatorCache *evaluator_cache,
+ const OpenSubdiv_EvaluatorSettings *settings)
{
BKE_subdiv_stats_reset(&subdiv->stats, SUBDIV_STATS_EVALUATOR_CREATE);
if (subdiv->topology_refiner == NULL) {
@@ -57,7 +58,7 @@ bool BKE_subdiv_eval_begin(Subdiv *subdiv,
opensubdiv_evalutor_from_subdiv_evaluator_type(evaluator_type);
BKE_subdiv_stats_begin(&subdiv->stats, SUBDIV_STATS_EVALUATOR_CREATE);
subdiv->evaluator = openSubdiv_createEvaluatorFromTopologyRefiner(
- subdiv->topology_refiner, opensubdiv_evaluator_type, evaluator_cache);
+ subdiv->topology_refiner, opensubdiv_evaluator_type, evaluator_cache, settings);
BKE_subdiv_stats_end(&subdiv->stats, SUBDIV_STATS_EVALUATOR_CREATE);
if (subdiv->evaluator == NULL) {
return false;
@@ -179,13 +180,52 @@ static void set_face_varying_data_from_uv(Subdiv *subdiv,
MEM_freeN(buffer);
}
+static void set_vertex_data_from_orco(Subdiv *subdiv, const Mesh *mesh)
+{
+ const float(*orco)[3] = CustomData_get_layer(&mesh->vdata, CD_ORCO);
+ const float(*cloth_orco)[3] = CustomData_get_layer(&mesh->vdata, CD_CLOTH_ORCO);
+
+ if (orco || cloth_orco) {
+ OpenSubdiv_TopologyRefiner *topology_refiner = subdiv->topology_refiner;
+ OpenSubdiv_Evaluator *evaluator = subdiv->evaluator;
+ const int num_verts = topology_refiner->getNumVertices(topology_refiner);
+
+ if (orco && cloth_orco) {
+ /* Set one by one if have both. */
+ for (int i = 0; i < num_verts; i++) {
+ float data[6];
+ copy_v3_v3(data, orco[i]);
+ copy_v3_v3(data + 3, cloth_orco[i]);
+ evaluator->setVertexData(evaluator, data, i, 1);
+ }
+ }
+ else {
+ /* Faster single call if we have either. */
+ if (orco) {
+ evaluator->setVertexData(evaluator, orco[0], 0, num_verts);
+ }
+ else if (cloth_orco) {
+ evaluator->setVertexData(evaluator, cloth_orco[0], 0, num_verts);
+ }
+ }
+ }
+}
+
+static void get_mesh_evaluator_settings(OpenSubdiv_EvaluatorSettings *settings, const Mesh *mesh)
+{
+ settings->num_vertex_data = (CustomData_has_layer(&mesh->vdata, CD_ORCO) ? 3 : 0) +
+ (CustomData_has_layer(&mesh->vdata, CD_CLOTH_ORCO) ? 3 : 0);
+}
+
bool BKE_subdiv_eval_begin_from_mesh(Subdiv *subdiv,
const Mesh *mesh,
const float (*coarse_vertex_cos)[3],
eSubdivEvaluatorType evaluator_type,
OpenSubdiv_EvaluatorCache *evaluator_cache)
{
- if (!BKE_subdiv_eval_begin(subdiv, evaluator_type, evaluator_cache)) {
+ OpenSubdiv_EvaluatorSettings settings = {0};
+ get_mesh_evaluator_settings(&settings, mesh);
+ if (!BKE_subdiv_eval_begin(subdiv, evaluator_type, evaluator_cache, &settings)) {
return false;
}
return BKE_subdiv_eval_refine_from_mesh(subdiv, mesh, coarse_vertex_cos);
@@ -208,6 +248,8 @@ bool BKE_subdiv_eval_refine_from_mesh(Subdiv *subdiv,
const MLoopUV *mloopuv = CustomData_get_layer_n(&mesh->ldata, CD_MLOOPUV, layer_index);
set_face_varying_data_from_uv(subdiv, mesh, mloopuv, layer_index);
}
+ /* Set vertex data to orco. */
+ set_vertex_data_from_orco(subdiv, mesh);
/* Update evaluator to the new coarse geometry. */
BKE_subdiv_stats_begin(&subdiv->stats, SUBDIV_STATS_EVALUATOR_REFINE);
subdiv->evaluator->refine(subdiv->evaluator);
@@ -281,6 +323,12 @@ void BKE_subdiv_eval_limit_point_and_normal(Subdiv *subdiv,
normalize_v3(r_N);
}
+void BKE_subdiv_eval_vertex_data(
+ Subdiv *subdiv, const int ptex_face_index, const float u, const float v, float r_vertex_data[])
+{
+ subdiv->evaluator->evaluateVertexData(subdiv->evaluator, ptex_face_index, u, v, r_vertex_data);
+}
+
void BKE_subdiv_eval_face_varying(Subdiv *subdiv,
const int face_varying_channel,
const int ptex_face_index,