Cycles: Adaptive isolation

Idea here is to select the lowest isolation level that wont compromise quality.
By using the lowest level we save memory and processing time. This will also
help avoid precision issues that have been showing up from using the highest
level (T49179, T49257).

This is a pretty simple heuristic that gives ok results. There's more we could
do here, such as filtering for vertices/edges adjacent geometric features that
need isolation instead of checking them all, but the logic there could get a
bit involved.

There's potential for slight popping of edges during animation if the dice
rate is low, but I don't think this should be a problem since low dice rates
really shouldn't be used in animation anyways.

Reviewed By: brecht, sergey

Differential Revision: https://developer.blender.org/D2240
This commit is contained in:
Mai Lavelle 2016-09-16 18:07:24 -04:00
parent 63b90851ce
commit 8f28441487
Notes: blender-bot 2023-02-14 07:38:31 +01:00
Referenced by issue #49257, Alembic import. Normals are wrong where three edges meet while adaptive subdiv
1 changed files with 39 additions and 1 deletions

View File

@ -16,12 +16,14 @@
#include "mesh.h"
#include "attribute.h"
#include "camera.h"
#include "subd_split.h"
#include "subd_patch.h"
#include "subd_patch_table.h"
#include "util_foreach.h"
#include "util_algorithm.h"
CCL_NAMESPACE_BEGIN
@ -177,7 +179,7 @@ public:
Far::TopologyRefinerFactory<Mesh>::Options(type, options));
/* adaptive refinement */
int max_isolation = 10;
int max_isolation = calculate_max_isolation();
refiner->RefineAdaptive(Far::TopologyRefiner::AdaptiveOptions(max_isolation));
/* create patch table */
@ -248,6 +250,42 @@ public:
}
}
int calculate_max_isolation()
{
/* loop over all edges to find longest in screen space */
const Far::TopologyLevel& level = refiner->GetLevel(0);
Transform objecttoworld = mesh->subd_params->objecttoworld;
Camera* cam = mesh->subd_params->camera;
float longest_edge = 0.0f;
for(size_t i = 0; i < level.GetNumEdges(); i++) {
Far::ConstIndexArray verts = level.GetEdgeVertices(i);
float3 a = mesh->verts[verts[0]];
float3 b = mesh->verts[verts[1]];
float edge_len;
if(cam) {
a = transform_point(&objecttoworld, a);
b = transform_point(&objecttoworld, b);
edge_len = len(a - b) / cam->world_to_raster_size((a + b) * 0.5f);
}
else {
edge_len = len(a - b);
}
longest_edge = max(longest_edge, edge_len);
}
/* calculate isolation level */
int isolation = (int)(log2f(max(longest_edge / mesh->subd_params->dicing_rate, 1.0f)) + 1.0f);
return min(isolation, 10);
}
friend struct OsdPatch;
friend class Mesh;
};