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:
authorSergey Sharybin <sergey.vfx@gmail.com>2019-02-22 18:56:54 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2019-02-22 19:02:51 +0300
commit3b132778deaac733baa78653685471e344b6b7c8 (patch)
tree568e05c772008ef3e1d3149c55dfb0e20719d950 /source/blender/blenkernel/intern/subdiv_ccg_material.c
parentb6c61945aed51d86dc474df616761f9a25d71d09 (diff)
Multires: Support smooth shading when sculpting
On CCG side it is done similar to displacement, where we have a dedicated functor which evaluates displacement. Might be seemed as an overkill, but allows to decouple SubdivCCG from mesh entirely, and maybe even free up coarse mesh in order to save some memory. Some weak-looking aspect is the call to update normals from the draw manager. Ideally, the manager will only draw what is already evaluated. But it's a bit tricky to find a best place for this since we avoid dependency graph updates during sculpt as much as possible. The new code mimics the old code, this is how it was in 2.7. Fix shading part of T58307.
Diffstat (limited to 'source/blender/blenkernel/intern/subdiv_ccg_material.c')
-rw-r--r--source/blender/blenkernel/intern/subdiv_ccg_material.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/subdiv_ccg_material.c b/source/blender/blenkernel/intern/subdiv_ccg_material.c
new file mode 100644
index 00000000000..0dc86095cff
--- /dev/null
+++ b/source/blender/blenkernel/intern/subdiv_ccg_material.c
@@ -0,0 +1,67 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2018 by Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "BKE_subdiv_ccg.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_mesh_types.h"
+
+typedef struct CCGMaterialFromMeshData {
+ const Mesh *mesh;
+} CCGMaterialFromMeshData;
+
+static DMFlagMat subdiv_ccg_material_flags_eval(
+ SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator,
+ const int coarse_face_index)
+{
+ CCGMaterialFromMeshData *data =
+ (CCGMaterialFromMeshData *)material_flags_evaluator->user_data;
+ const Mesh *mesh = data->mesh;
+ BLI_assert(coarse_face_index < mesh->totpoly);
+ const MPoly *mpoly = mesh->mpoly;
+ const MPoly *poly = &mpoly[coarse_face_index];
+ DMFlagMat material_flags;
+ material_flags.flag = poly->flag;
+ material_flags.mat_nr = poly->mat_nr;
+ return material_flags;
+}
+
+static void subdiv_ccg_material_flags_free(
+ SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator)
+{
+ MEM_freeN(material_flags_evaluator->user_data);
+}
+
+void BKE_subdiv_ccg_material_flags_init_from_mesh(
+ SubdivCCGMaterialFlagsEvaluator *material_flags_evaluator,
+ const Mesh *mesh)
+{
+ CCGMaterialFromMeshData *data = MEM_mallocN(
+ sizeof(CCGMaterialFromMeshData), "ccg material eval");
+ data->mesh = mesh;
+ material_flags_evaluator->eval_material_flags =
+ subdiv_ccg_material_flags_eval;
+ material_flags_evaluator->free = subdiv_ccg_material_flags_free;
+ material_flags_evaluator->user_data = data;
+} \ No newline at end of file