diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-11-13 23:57:00 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-11-13 23:58:30 +0300 |
commit | 4d33c37c9eb4fc46482f7b2a7227b54c5cfda07a (patch) | |
tree | 94302b76edc357977a3619eebaa5642c03c32161 /source/blender/blenkernel/intern/cdderivedmesh.c | |
parent | 92819425d86017f371fa8e78db54d4fb976a0235 (diff) |
Fix T46726 shading issues in sculpt mode.
This fixes two issues:
* Normals were not being recalculated correctly when not using optimized
drawing for CDDerivedMesh (Multires actually handles that correctly).
* Loop normals (autosmooth option) were also not being calculated. Doing
this calculation is not desirable, since it can't be done correctly
without a severe performance hit. This is easy to test by doing a
dependency flush on the mesh after each scuplt stroke step. Instead they
are now disabled during sculpting.
Diffstat (limited to 'source/blender/blenkernel/intern/cdderivedmesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 3b86c42d8c9..be4f0011e97 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -344,9 +344,6 @@ static void cdDM_update_normals_from_pbvh(DerivedMesh *dm) CDDerivedMesh *cddm = (CDDerivedMesh *) dm; float (*face_nors)[3]; - if (!cddm->pbvh || !cddm->pbvh_draw || !dm->numPolyData) - return; - face_nors = CustomData_get_layer(&dm->polyData, CD_NORMAL); BKE_pbvh_update(cddm->pbvh, PBVH_UpdateNormals, face_nors); @@ -446,18 +443,18 @@ static void cdDM_drawFacesSolid( CDDerivedMesh *cddm = (CDDerivedMesh *) dm; int a; - if (cddm->pbvh && cddm->pbvh_draw) { - if (BKE_pbvh_has_faces(cddm->pbvh)) { + if (cddm->pbvh) { + if (cddm->pbvh_draw && BKE_pbvh_has_faces(cddm->pbvh)) { float (*face_nors)[3] = CustomData_get_layer(&dm->faceData, CD_NORMAL); - cdDM_update_normals_from_pbvh(dm); - BKE_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors, setMaterial, false, false); glShadeModel(GL_FLAT); + return; + } + else { + cdDM_update_normals_from_pbvh(dm); } - - return; } GPU_vertex_setup(dm); @@ -505,14 +502,18 @@ static void cdDM_drawFacesTex_common( * textured view, but object itself will be displayed gray * (the same as it'll display without UV maps in textured view) */ - if (cddm->pbvh && cddm->pbvh_draw && BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH) { - if (BKE_pbvh_has_faces(cddm->pbvh)) { - cdDM_update_normals_from_pbvh(dm); + if (cddm->pbvh) { + if (cddm->pbvh_draw && + BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH && + BKE_pbvh_has_faces(cddm->pbvh)) + { GPU_set_tpage(NULL, false, false); BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false); + return; + } + else { + cdDM_update_normals_from_pbvh(dm); } - - return; } colType = CD_TEXTURE_MLOOPCOL; @@ -878,14 +879,18 @@ static void cdDM_drawMappedFacesGLSL( * will skip using textures (dyntopo currently destroys UV anyway) and * works fine for matcap */ - if (cddm->pbvh && cddm->pbvh_draw && BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH) { - if (BKE_pbvh_has_faces(cddm->pbvh)) { - cdDM_update_normals_from_pbvh(dm); + if (cddm->pbvh) { + if (cddm->pbvh_draw && + BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH && + BKE_pbvh_has_faces(cddm->pbvh)) + { setMaterial(1, &gattribs); BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false); + return; + } + else { + cdDM_update_normals_from_pbvh(dm); } - - return; } matnr = -1; @@ -1147,14 +1152,18 @@ static void cdDM_drawMappedFacesMat( * works fine for matcap */ - if (cddm->pbvh && cddm->pbvh_draw && BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH) { - if (BKE_pbvh_has_faces(cddm->pbvh)) { - cdDM_update_normals_from_pbvh(dm); + if (cddm->pbvh) { + if (cddm->pbvh_draw && + BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH && + BKE_pbvh_has_faces(cddm->pbvh)) + { setMaterial(userData, 1, &gattribs); BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false); + return; + } + else { + cdDM_update_normals_from_pbvh(dm); } - - return; } matnr = -1; @@ -1347,6 +1356,7 @@ static void cdDM_buffer_copy_vertex( static void cdDM_buffer_copy_normal( DerivedMesh *dm, short *varray) { + CDDerivedMesh *cddm = (CDDerivedMesh *)dm; int i, j, totpoly; int start; @@ -1362,6 +1372,10 @@ static void cdDM_buffer_copy_normal( mloop = dm->getLoopArray(dm); totpoly = dm->getNumPolys(dm); + /* we are in sculpt mode, disable loop normals (since they won't get updated) */ + if (cddm->pbvh) + lnors = NULL; + start = 0; for (i = 0; i < totpoly; i++, mpoly++) { const bool smoothnormal = (mpoly->flag & ME_SMOOTH) != 0; |