diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-02-22 18:56:54 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-02-22 19:02:51 +0300 |
commit | 3b132778deaac733baa78653685471e344b6b7c8 (patch) | |
tree | 568e05c772008ef3e1d3149c55dfb0e20719d950 /source/blender/draw/modes/sculpt_mode.c | |
parent | b6c61945aed51d86dc474df616761f9a25d71d09 (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/draw/modes/sculpt_mode.c')
-rw-r--r-- | source/blender/draw/modes/sculpt_mode.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/source/blender/draw/modes/sculpt_mode.c b/source/blender/draw/modes/sculpt_mode.c index 5d008a35a61..bb13cb36c01 100644 --- a/source/blender/draw/modes/sculpt_mode.c +++ b/source/blender/draw/modes/sculpt_mode.c @@ -29,6 +29,7 @@ #include "BKE_pbvh.h" #include "BKE_paint.h" +#include "BKE_subdiv_ccg.h" /* If builtin shaders are needed */ #include "GPU_shader.h" @@ -154,6 +155,22 @@ static void sculpt_draw_mask_cb( } } +static void sculpt_update_pbvh_normals(Object *object) +{ + Mesh *mesh = object->data; + PBVH *pbvh = object->sculpt->pbvh; + SubdivCCG *subdiv_ccg = mesh->runtime.subdiv_ccg; + if (pbvh == NULL || subdiv_ccg == NULL) { + return; + } + struct CCGFace **faces; + int num_faces; + BKE_pbvh_get_grid_updates(pbvh, 1, (void ***)&faces, &num_faces); + if (num_faces > 0) { + BKE_subdiv_ccg_update_normals(subdiv_ccg, faces, num_faces); + } +} + /* Add geometry to shadingGroups. Execute for each objects */ static void SCULPT_cache_populate(void *vedata, Object *ob) { @@ -166,6 +183,8 @@ static void SCULPT_cache_populate(void *vedata, Object *ob) const DRWContextState *draw_ctx = DRW_context_state_get(); if (ob->sculpt && (ob == draw_ctx->obact)) { + sculpt_update_pbvh_normals(ob); + /* XXX, needed for dyntopo-undo (which clears). * probably depsgraph should handlle? in 2.7x getting derived-mesh does this (mesh_build_data) */ if (ob->sculpt->pbvh == NULL) { |