Fix T81392: subdivision surface poor shading without limit surface

When the limit surface is disabled OpenSubdiv generates a set of linear
patches which are only C0 continuous, not C1. This makes it impossible to
evaluate derivatives at vertices which, in this mode, are by definition put
at boundaries of patches. Normals are calculated from those derivatives.

Solution is to disable normal calculation and let it be done downstream, as
for other modifiers. This limitation is also the reason that non feature
adaptive subdivision is badly suited for GPU evaluation.

Differential Revision: https://developer.blender.org/D9103
This commit is contained in:
Piotr Ostrowski 2020-10-05 16:20:06 +02:00 committed by Brecht Van Lommel
parent 0a0e88b645
commit eedd7b27f9
Notes: blender-bot 2023-03-24 17:05:22 +01:00
Referenced by issue #81392, Bad surface shading quality when use limit surface is disabled.
1 changed files with 7 additions and 4 deletions

View File

@ -499,7 +499,9 @@ static void subdiv_accumulate_vertex_normal_and_displacement(SubdivMeshContext *
BKE_subdiv_eval_displacement(subdiv, ptex_face_index, u, v, dPdu, dPdv, D);
add_v3_v3(subdiv_vert->co, D);
}
++ctx->accumulated_counters[subdiv_vertex_index];
if (ctx->accumulated_counters) {
++ctx->accumulated_counters[subdiv_vertex_index];
}
}
/** \} */
@ -573,11 +575,11 @@ static void evaluate_vertex_and_apply_displacement_copy(const SubdivMeshContext
MVert *subdiv_vert)
{
const int subdiv_vertex_index = subdiv_vert - ctx->subdiv_mesh->mvert;
const float inv_num_accumulated = 1.0f / ctx->accumulated_counters[subdiv_vertex_index];
/* Displacement is accumulated in subdiv vertex position.
* Needs to be backed up before copying data from original vertex. */
float D[3] = {0.0f, 0.0f, 0.0f};
if (ctx->have_displacement) {
const float inv_num_accumulated = 1.0f / ctx->accumulated_counters[subdiv_vertex_index];
copy_v3_v3(D, subdiv_vert->co);
mul_v3_fl(D, inv_num_accumulated);
}
@ -606,11 +608,11 @@ static void evaluate_vertex_and_apply_displacement_interpolate(
MVert *subdiv_vert)
{
const int subdiv_vertex_index = subdiv_vert - ctx->subdiv_mesh->mvert;
const float inv_num_accumulated = 1.0f / ctx->accumulated_counters[subdiv_vertex_index];
/* Displacement is accumulated in subdiv vertex position.
* Needs to be backed up before copying data from original vertex. */
float D[3] = {0.0f, 0.0f, 0.0f};
if (ctx->have_displacement) {
const float inv_num_accumulated = 1.0f / ctx->accumulated_counters[subdiv_vertex_index];
copy_v3_v3(D, subdiv_vert->co);
mul_v3_fl(D, inv_num_accumulated);
}
@ -621,6 +623,7 @@ static void evaluate_vertex_and_apply_displacement_interpolate(
add_v3_v3(subdiv_vert->co, D);
/* Copy normal from accumulated storage. */
if (ctx->can_evaluate_normals) {
const float inv_num_accumulated = 1.0f / ctx->accumulated_counters[subdiv_vertex_index];
float N[3];
copy_v3_v3(N, ctx->accumulated_normals[subdiv_vertex_index]);
mul_v3_fl(N, inv_num_accumulated);
@ -1213,7 +1216,7 @@ Mesh *BKE_subdiv_to_mesh(Subdiv *subdiv,
subdiv_context.coarse_mesh = coarse_mesh;
subdiv_context.subdiv = subdiv;
subdiv_context.have_displacement = (subdiv->displacement_evaluator != NULL);
subdiv_context.can_evaluate_normals = !subdiv_context.have_displacement;
subdiv_context.can_evaluate_normals = !subdiv_context.have_displacement && subdiv_context.subdiv->settings.is_adaptive;
/* Multi-threaded traversal/evaluation. */
BKE_subdiv_stats_begin(&subdiv->stats, SUBDIV_STATS_SUBDIV_TO_MESH_GEOMETRY);
SubdivForeachContext foreach_context;