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.
This commit is contained in:
@@ -344,9 +344,6 @@ static void cdDM_update_normals_from_pbvh(DerivedMesh *dm)
|
|||||||
CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
|
CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
|
||||||
float (*face_nors)[3];
|
float (*face_nors)[3];
|
||||||
|
|
||||||
if (!cddm->pbvh || !cddm->pbvh_draw || !dm->numPolyData)
|
|
||||||
return;
|
|
||||||
|
|
||||||
face_nors = CustomData_get_layer(&dm->polyData, CD_NORMAL);
|
face_nors = CustomData_get_layer(&dm->polyData, CD_NORMAL);
|
||||||
|
|
||||||
BKE_pbvh_update(cddm->pbvh, PBVH_UpdateNormals, face_nors);
|
BKE_pbvh_update(cddm->pbvh, PBVH_UpdateNormals, face_nors);
|
||||||
@@ -446,18 +443,18 @@ static void cdDM_drawFacesSolid(
|
|||||||
CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
|
CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
|
||||||
int a;
|
int a;
|
||||||
|
|
||||||
if (cddm->pbvh && cddm->pbvh_draw) {
|
if (cddm->pbvh) {
|
||||||
if (BKE_pbvh_has_faces(cddm->pbvh)) {
|
if (cddm->pbvh_draw && BKE_pbvh_has_faces(cddm->pbvh)) {
|
||||||
float (*face_nors)[3] = CustomData_get_layer(&dm->faceData, CD_NORMAL);
|
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,
|
BKE_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors,
|
||||||
setMaterial, false, false);
|
setMaterial, false, false);
|
||||||
glShadeModel(GL_FLAT);
|
glShadeModel(GL_FLAT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cdDM_update_normals_from_pbvh(dm);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GPU_vertex_setup(dm);
|
GPU_vertex_setup(dm);
|
||||||
@@ -505,14 +502,18 @@ static void cdDM_drawFacesTex_common(
|
|||||||
* textured view, but object itself will be displayed gray
|
* textured view, but object itself will be displayed gray
|
||||||
* (the same as it'll display without UV maps in textured view)
|
* (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 (cddm->pbvh) {
|
||||||
if (BKE_pbvh_has_faces(cddm->pbvh)) {
|
if (cddm->pbvh_draw &&
|
||||||
cdDM_update_normals_from_pbvh(dm);
|
BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH &&
|
||||||
|
BKE_pbvh_has_faces(cddm->pbvh))
|
||||||
|
{
|
||||||
GPU_set_tpage(NULL, false, false);
|
GPU_set_tpage(NULL, false, false);
|
||||||
BKE_pbvh_draw(cddm->pbvh, NULL, NULL, 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;
|
colType = CD_TEXTURE_MLOOPCOL;
|
||||||
@@ -878,14 +879,18 @@ static void cdDM_drawMappedFacesGLSL(
|
|||||||
* will skip using textures (dyntopo currently destroys UV anyway) and
|
* will skip using textures (dyntopo currently destroys UV anyway) and
|
||||||
* works fine for matcap
|
* works fine for matcap
|
||||||
*/
|
*/
|
||||||
if (cddm->pbvh && cddm->pbvh_draw && BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH) {
|
if (cddm->pbvh) {
|
||||||
if (BKE_pbvh_has_faces(cddm->pbvh)) {
|
if (cddm->pbvh_draw &&
|
||||||
cdDM_update_normals_from_pbvh(dm);
|
BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH &&
|
||||||
|
BKE_pbvh_has_faces(cddm->pbvh))
|
||||||
|
{
|
||||||
setMaterial(1, &gattribs);
|
setMaterial(1, &gattribs);
|
||||||
BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
|
BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cdDM_update_normals_from_pbvh(dm);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
matnr = -1;
|
matnr = -1;
|
||||||
@@ -1147,14 +1152,18 @@ static void cdDM_drawMappedFacesMat(
|
|||||||
* works fine for matcap
|
* works fine for matcap
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (cddm->pbvh && cddm->pbvh_draw && BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH) {
|
if (cddm->pbvh) {
|
||||||
if (BKE_pbvh_has_faces(cddm->pbvh)) {
|
if (cddm->pbvh_draw &&
|
||||||
cdDM_update_normals_from_pbvh(dm);
|
BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH &&
|
||||||
|
BKE_pbvh_has_faces(cddm->pbvh))
|
||||||
|
{
|
||||||
setMaterial(userData, 1, &gattribs);
|
setMaterial(userData, 1, &gattribs);
|
||||||
BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
|
BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cdDM_update_normals_from_pbvh(dm);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
matnr = -1;
|
matnr = -1;
|
||||||
@@ -1347,6 +1356,7 @@ static void cdDM_buffer_copy_vertex(
|
|||||||
static void cdDM_buffer_copy_normal(
|
static void cdDM_buffer_copy_normal(
|
||||||
DerivedMesh *dm, short *varray)
|
DerivedMesh *dm, short *varray)
|
||||||
{
|
{
|
||||||
|
CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
|
||||||
int i, j, totpoly;
|
int i, j, totpoly;
|
||||||
int start;
|
int start;
|
||||||
|
|
||||||
@@ -1362,6 +1372,10 @@ static void cdDM_buffer_copy_normal(
|
|||||||
mloop = dm->getLoopArray(dm);
|
mloop = dm->getLoopArray(dm);
|
||||||
totpoly = dm->getNumPolys(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;
|
start = 0;
|
||||||
for (i = 0; i < totpoly; i++, mpoly++) {
|
for (i = 0; i < totpoly; i++, mpoly++) {
|
||||||
const bool smoothnormal = (mpoly->flag & ME_SMOOTH) != 0;
|
const bool smoothnormal = (mpoly->flag & ME_SMOOTH) != 0;
|
||||||
|
@@ -1912,6 +1912,10 @@ static void ccgDM_buffer_copy_normal(
|
|||||||
int shademodel;
|
int shademodel;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
|
|
||||||
|
/* we are in sculpt mode, disable loop normals (since they won't get updated) */
|
||||||
|
if (ccgdm->pbvh)
|
||||||
|
lnors = NULL;
|
||||||
|
|
||||||
CCG_key_top_level(&key, ss);
|
CCG_key_top_level(&key, ss);
|
||||||
|
|
||||||
for (i = 0; i < totface; i++) {
|
for (i = 0; i < totface; i++) {
|
||||||
|
@@ -5149,6 +5149,9 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
|
|||||||
paint_cursor_start(C, sculpt_poll_view3d);
|
paint_cursor_start(C, sculpt_poll_view3d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ob->derivedFinal) /* VBO no longer valid */
|
||||||
|
GPU_drawobject_free(ob->derivedFinal);
|
||||||
|
|
||||||
WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
|
||||||
|
|
||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
|
Reference in New Issue
Block a user