diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_paint.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 3 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_pbvh.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/pbvh.c | 30 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 3 | ||||
-rw-r--r-- | source/blender/gpu/GPU_buffers.h | 10 | ||||
-rw-r--r-- | source/blender/gpu/GPU_draw.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_buffers.c | 182 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 15 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_scene_types.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_material.c | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_sculpt_paint.c | 23 |
13 files changed, 214 insertions, 64 deletions
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index a93e542fe15..c452c177143 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -94,6 +94,7 @@ typedef struct SculptSession { /* PBVH acceleration structure */ struct PBVH *pbvh; + int show_diffuse_color; /* Paiting on deformed mesh */ int modifiers_active; /* object is deformed with some modifiers */ diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 8934f556425..7c13f041e98 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -273,6 +273,8 @@ static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) cddm->pbvh = BLI_pbvh_new(); cddm->pbvh_draw = can_pbvh_draw(ob, dm); + pbvh_show_diffuse_color_set(cddm->pbvh, ob->sculpt->show_diffuse_color); + BKE_mesh_tessface_ensure(me); BLI_pbvh_build_mesh(cddm->pbvh, me->mface, me->mvert, diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 0d1e2276a9f..6f3063ce8e3 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -3020,6 +3020,9 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) me->totface, me->totvert, &me->vdata); } + if (ccgdm->pbvh) + pbvh_show_diffuse_color_set(ccgdm->pbvh, ob->sculpt->show_diffuse_color); + return ccgdm->pbvh; } diff --git a/source/blender/blenlib/BLI_pbvh.h b/source/blender/blenlib/BLI_pbvh.h index 810b3b56386..9483d068bb9 100644 --- a/source/blender/blenlib/BLI_pbvh.h +++ b/source/blender/blenlib/BLI_pbvh.h @@ -263,5 +263,7 @@ void BLI_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***nodes, int *totnode); //void BLI_pbvh_node_BB_reset(PBVHNode *node); //void BLI_pbvh_node_BB_expand(PBVHNode *node, float co[3]); +void pbvh_show_diffuse_color_set(PBVH *bvh, int show_diffuse_color); + #endif /* __BLI_PBVH_H__ */ diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index bf237ffd75a..2ac84062d0c 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -157,6 +157,8 @@ struct PBVH { /* flag are verts/faces deformed */ int deformed; + + int show_diffuse_color; }; #define STACK_FIXED_DEPTH 100 @@ -1001,7 +1003,7 @@ static int update_search_cb(PBVHNode *node, void *data_v) if (node->flag & PBVH_Leaf) return (node->flag & flag); - + return 1; } @@ -1165,7 +1167,8 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode) bvh->grid_flag_mats, node->prim_indices, node->totprim, - &bvh->gridkey); + &bvh->gridkey, + bvh->show_diffuse_color); break; case PBVH_FACES: GPU_update_mesh_buffers(node->draw_buffers, @@ -1174,7 +1177,9 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode) node->uniq_verts + node->face_verts, CustomData_get_layer(bvh->vdata, - CD_PAINT_MASK)); + CD_PAINT_MASK), + node->face_vert_indices, + bvh->show_diffuse_color); break; } @@ -1667,11 +1672,23 @@ int BLI_pbvh_node_planes_exclude_AABB(PBVHNode *node, void *data) return test_planes_aabb(bb_min, bb_max, data) != ISECT_INSIDE; } +static void pbvh_node_check_diffuse_changed(PBVH *bvh, PBVHNode *node) +{ + if (!node->draw_buffers) + return; + + if (GPU_buffers_diffuse_changed(node->draw_buffers, bvh->show_diffuse_color)) + node->flag |= PBVH_UpdateDrawBuffers; +} + void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], DMSetMaterial setMaterial) { PBVHNode **nodes; - int totnode; + int a, totnode; + + for (a = 0; a < bvh->totnode; a++) + pbvh_node_check_diffuse_changed(bvh, &bvh->nodes[a]); BLI_pbvh_search_gather(bvh, update_search_cb, SET_INT_IN_POINTER(PBVH_UpdateNormals | PBVH_UpdateDrawBuffers), &nodes, &totnode); @@ -1876,3 +1893,8 @@ void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node, if (!vi->grids) vi->vmask = CustomData_get_layer(bvh->vdata, CD_PAINT_MASK); } + +void pbvh_show_diffuse_color_set(PBVH *bvh, int show_diffuse_color) +{ + bvh->show_diffuse_color = show_diffuse_color; +} diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 07bd6a66bdf..23a64008fae 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -3076,6 +3076,7 @@ void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, MultiresModifierData *mmd = sculpt_multires_active(scene, ob); ss->modifiers_active = sculpt_modifiers_active(scene, sd, ob); + ss->show_diffuse_color = sd->flags & SCULPT_SHOW_DIFFUSE; if (need_mask) { if (mmd == NULL) { @@ -3130,6 +3131,8 @@ void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, ss->pbvh = dm->getPBVH(ob, dm); ss->pmap = (need_pmap && dm->getPolyMap) ? dm->getPolyMap(ob, dm) : NULL; + pbvh_show_diffuse_color_set(ss->pbvh, ss->show_diffuse_color); + if (ss->modifiers_active) { if (!ss->orig_cos) { int a; diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index 1729ac06f5a..de83a717bce 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -162,18 +162,22 @@ GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4], struct MFace *mface, struct MVert *mvert, int *face_indices, int totface); -void GPU_update_mesh_buffers(GPU_Buffers *buffers, struct MVert *mvert, - int *vert_indices, int totvert, const float *vmask); +void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert, + int *vert_indices, int totvert, const float *vmask, + int (*face_vert_indices)[4], int show_diffuse_color); GPU_Buffers *GPU_build_grid_buffers(int *grid_indices, int totgrid, unsigned int **grid_hidden, int gridsize); void GPU_update_grid_buffers(GPU_Buffers *buffers, struct CCGElem **grids, const struct DMFlagMat *grid_flag_mats, - int *grid_indices, int totgrid, const struct CCGKey *key); + int *grid_indices, int totgrid, const struct CCGKey *key, + int show_diffuse_color); void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial); +int GPU_buffers_diffuse_changed(GPU_Buffers *buffers, int show_diffuse_color); + void GPU_free_buffers(GPU_Buffers *buffers); #endif diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index 285acb6bdde..7d829bd57bf 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -75,6 +75,8 @@ void GPU_end_object_materials(void); int GPU_enable_material(int nr, void *attribs); void GPU_disable_material(void); +void GPU_material_diffuse_get(int nr, float diff[4]); + void GPU_set_material_alpha_blend(int alphablend); int GPU_get_material_alpha_blend(void); diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 2986ce85c88..7caecd989df 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -54,6 +54,7 @@ #include "DNA_userdef_types.h" #include "GPU_buffers.h" +#include "GPU_draw.h" typedef enum { GPU_BUFFER_VERTEX_STATE = 1, @@ -1316,6 +1317,9 @@ struct GPU_Buffers { /* The PBVH ensures that either all faces in the node are smooth-shaded or all faces are flat-shaded */ int smooth; + + int show_diffuse_color; + float diffuse_color[4]; }; typedef enum { VBO_ENABLED, @@ -1339,24 +1343,24 @@ static void gpu_colors_disable(VBO_State vbo_state) static float gpu_color_from_mask(float mask) { - return (1.0f - mask) * 0.5f + 0.25f; + return 1.0f - mask * 0.75f; } -static void gpu_color_from_mask_copy(float mask, unsigned char out[3]) +static void gpu_color_from_mask_copy(float mask, const float diffuse_color[4], unsigned char out[3]) { - unsigned char color; - - color = gpu_color_from_mask(mask) * 255.0f; + float mask_color; + + mask_color = gpu_color_from_mask(mask) * 255.0f; - out[0] = color; - out[1] = color; - out[2] = color; + out[0] = diffuse_color[0] * mask_color; + out[1] = diffuse_color[1] * mask_color; + out[2] = diffuse_color[2] * mask_color; } -static void gpu_color_from_mask_set(float mask) +static void gpu_color_from_mask_set(float mask, float diffuse_color[4]) { float color = gpu_color_from_mask(mask); - glColor3f(color, color, color); + glColor3f(diffuse_color[0] * color, diffuse_color[1] * color, diffuse_color[2] * color); } static float gpu_color_from_mask_quad(const CCGKey *key, @@ -1372,37 +1376,50 @@ static float gpu_color_from_mask_quad(const CCGKey *key, static void gpu_color_from_mask_quad_copy(const CCGKey *key, CCGElem *a, CCGElem *b, CCGElem *c, CCGElem *d, + const float *diffuse_color, unsigned char out[3]) { - unsigned char color = + float mask_color = gpu_color_from_mask((*CCG_elem_mask(key, a) + *CCG_elem_mask(key, b) + *CCG_elem_mask(key, c) + *CCG_elem_mask(key, d)) * 0.25f) * 255.0f; - out[0] = color; - out[1] = color; - out[2] = color; + out[0] = diffuse_color[0] * mask_color; + out[1] = diffuse_color[1] * mask_color; + out[2] = diffuse_color[2] * mask_color; } static void gpu_color_from_mask_quad_set(const CCGKey *key, CCGElem *a, CCGElem *b, - CCGElem *c, CCGElem *d) + CCGElem *c, CCGElem *d, + float diffuse_color[4]) { float color = gpu_color_from_mask_quad(key, a, b, c, d); - glColor3f(color, color, color); + glColor3f(diffuse_color[0] * color, diffuse_color[1] * color, diffuse_color[2] * color); } void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert, - int *vert_indices, int totvert, const float *vmask) + int *vert_indices, int totvert, const float *vmask, + int (*face_vert_indices)[4], int show_diffuse_color) { VertexBufferFormat *vert_data; int i, j, k; buffers->vmask = vmask; + buffers->show_diffuse_color = show_diffuse_color; if (buffers->vert_buf) { int totelem = (buffers->smooth ? totvert : (buffers->tot_tri * 3)); + float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f}; + + if (buffers->show_diffuse_color) { + MFace *f = buffers->mface + buffers->face_indices[0]; + + GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color); + } + + copy_v4_v4(buffers->diffuse_color, diffuse_color); /* Build VBO */ glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf); @@ -1423,11 +1440,27 @@ void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert, copy_v3_v3(out->co, v->co); memcpy(out->no, v->no, sizeof(short) * 3); - if (vmask) { - gpu_color_from_mask_copy(vmask[vert_indices[i]], - out->color); - } } + +#define UPDATE_VERTEX(face, vertex, index, diffuse_color) \ + { \ + VertexBufferFormat *out = vert_data + face_vert_indices[face][index]; \ + if (vmask) \ + gpu_color_from_mask_copy(vmask[vertex], diffuse_color, out->color); \ + else \ + rgb_float_to_uchar(out->color, diffuse_color); \ + } (void)0 + + for (i = 0; i < buffers->totface; i++) { + MFace *f = buffers->mface + buffers->face_indices[i]; + + UPDATE_VERTEX(i, f->v1, 0, diffuse_color); + UPDATE_VERTEX(i, f->v2, 1, diffuse_color); + UPDATE_VERTEX(i, f->v3, 2, diffuse_color); + if (f->v4) + UPDATE_VERTEX(i, f->v4, 3, diffuse_color); + } +#undef UPDATE_VERTEX } else { for (i = 0; i < buffers->totface; ++i) { @@ -1473,8 +1506,11 @@ void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert, copy_v3_v3(out->co, v->co); memcpy(out->no, no, sizeof(short) * 3); + if (vmask) - gpu_color_from_mask_copy(fmask, out->color); + gpu_color_from_mask_copy(fmask, diffuse_color, out->color); + else + rgb_float_to_uchar(out->color, diffuse_color); vert_data++; } @@ -1508,6 +1544,8 @@ GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4], buffers->index_type = GL_UNSIGNED_SHORT; buffers->smooth = mface[face_indices[0]].flag & ME_SMOOTH; + buffers->show_diffuse_color = FALSE; + /* Count the number of visible triangles */ for (i = 0, tottri = 0; i < totface; ++i) { const MFace *f = &mface[face_indices[i]]; @@ -1576,16 +1614,27 @@ GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4], void GPU_update_grid_buffers(GPU_Buffers *buffers, CCGElem **grids, const DMFlagMat *grid_flag_mats, int *grid_indices, - int totgrid, const CCGKey *key) + int totgrid, const CCGKey *key, int show_diffuse_color) { VertexBufferFormat *vert_data; int i, j, k, x, y; + buffers->show_diffuse_color = show_diffuse_color; + /* Build VBO */ if (buffers->vert_buf) { int totvert = key->grid_area * totgrid; int smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH; const int has_mask = key->has_mask; + float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f}; + + if (buffers->show_diffuse_color) { + const DMFlagMat *flags = &grid_flag_mats[grid_indices[0]]; + + GPU_material_diffuse_get(flags->mat_nr + 1, diffuse_color); + } + + copy_v4_v4(buffers->diffuse_color, diffuse_color); glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf); glBufferDataARB(GL_ARRAY_BUFFER_ARB, @@ -1603,12 +1652,11 @@ void GPU_update_grid_buffers(GPU_Buffers *buffers, CCGElem **grids, copy_v3_v3(vd->co, CCG_elem_co(key, elem)); if (smooth) { - normal_float_to_short_v3(vd->no, - CCG_elem_no(key, elem)); + normal_float_to_short_v3(vd->no, CCG_elem_no(key, elem)); if (has_mask) { gpu_color_from_mask_copy(*CCG_elem_mask(key, elem), - vd->color); + diffuse_color, vd->color); } } vd++; @@ -1644,6 +1692,7 @@ void GPU_update_grid_buffers(GPU_Buffers *buffers, CCGElem **grids, elems[1], elems[2], elems[3], + diffuse_color, vd->color); } } @@ -1812,6 +1861,8 @@ GPU_Buffers *GPU_build_grid_buffers(int *grid_indices, int totgrid, buffers->grid_hidden = grid_hidden; buffers->totgrid = totgrid; + buffers->show_diffuse_color = FALSE; + /* Count the number of quads */ totquad = gpu_count_grid_quads(grid_hidden, grid_indices, totgrid, gridsize); @@ -1856,6 +1907,11 @@ static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers) const MVert *mvert = buffers->mvert; int i, j; const int has_mask = (buffers->vmask != NULL); + const MFace *face = &buffers->mface[buffers->face_indices[0]]; + float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f}; + + if (buffers->show_diffuse_color) + GPU_material_diffuse_get(face->mat_nr + 1, diffuse_color); if (has_mask) { gpu_colors_enable(VBO_DISABLED); @@ -1874,7 +1930,7 @@ static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers) if (buffers->smooth) { for (j = 0; j < S; j++) { if (has_mask) { - gpu_color_from_mask_set(buffers->vmask[fv[j]]); + gpu_color_from_mask_set(buffers->vmask[fv[j]], diffuse_color); } glNormal3sv(mvert[fv[j]].no); glVertex3fv(mvert[fv[j]].co); @@ -1903,7 +1959,7 @@ static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers) fmask = (fmask + buffers->vmask[fv[3]]) * 0.25; else fmask /= 3.0f; - gpu_color_from_mask_set(fmask); + gpu_color_from_mask_set(fmask, diffuse_color); } for (j = 0; j < S; j++) @@ -1923,6 +1979,11 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers) const CCGKey *key = &buffers->gridkey; int i, j, x, y, gridsize = buffers->gridkey.grid_size; const int has_mask = key->has_mask; + const DMFlagMat *flags = &buffers->grid_flag_mats[buffers->grid_indices[0]]; + float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f}; + + if (buffers->show_diffuse_color) + GPU_material_diffuse_get(flags->mat_nr + 1, diffuse_color); if (has_mask) { gpu_colors_enable(VBO_DISABLED); @@ -1954,7 +2015,7 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers) if (buffers->smooth) { for (j = 0; j < 4; j++) { if (has_mask) { - gpu_color_from_mask_set(*CCG_elem_mask(key, e[j])); + gpu_color_from_mask_set(*CCG_elem_mask(key, e[j]), diffuse_color); } glNormal3fv(CCG_elem_no(key, e[j])); glVertex3fv(CCG_elem_co(key, e[j])); @@ -1970,7 +2031,7 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers) glNormal3fv(fno); if (has_mask) { - gpu_color_from_mask_quad_set(key, e[0], e[1], e[2], e[3]); + gpu_color_from_mask_quad_set(key, e[0], e[1], e[2], e[3], diffuse_color); } for (j = 0; j < 4; j++) @@ -1989,12 +2050,12 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers) CCGElem *b = CCG_grid_elem(key, grid, x, y + 1); if (has_mask) { - gpu_color_from_mask_set(*CCG_elem_mask(key, a)); + gpu_color_from_mask_set(*CCG_elem_mask(key, a), diffuse_color); } glNormal3fv(CCG_elem_no(key, a)); glVertex3fv(CCG_elem_co(key, a)); if (has_mask) { - gpu_color_from_mask_set(*CCG_elem_mask(key, b)); + gpu_color_from_mask_set(*CCG_elem_mask(key, b), diffuse_color); } glNormal3fv(CCG_elem_no(key, b)); glVertex3fv(CCG_elem_co(key, b)); @@ -2022,7 +2083,7 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers) glNormal3fv(fno); if (has_mask) { - gpu_color_from_mask_quad_set(key, a, b, c, d); + gpu_color_from_mask_quad_set(key, a, b, c, d, diffuse_color); } } @@ -2041,8 +2102,6 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers) void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial) { - const int has_mask = (buffers->vmask || buffers->gridkey.has_mask); - if (buffers->totface) { const MFace *f = &buffers->mface[buffers->face_indices[0]]; if (!setMaterial(f->mat_nr + 1, NULL)) @@ -2059,13 +2118,7 @@ void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial) if (buffers->vert_buf) { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); - if (has_mask) { - gpu_colors_enable(VBO_ENABLED); - } - else { - gpu_colors_enable(VBO_DISABLED); - glColor4ub(0xff, 0xff, 0xff, 0xff); - } + gpu_colors_enable(VBO_ENABLED); glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf); @@ -2080,10 +2133,8 @@ void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial) offset + offsetof(VertexBufferFormat, co)); glNormalPointer(GL_SHORT, sizeof(VertexBufferFormat), offset + offsetof(VertexBufferFormat, no)); - if (has_mask) { - glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VertexBufferFormat), - offset + offsetof(VertexBufferFormat, color)); - } + glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VertexBufferFormat), + offset + offsetof(VertexBufferFormat, color)); glDrawElements(GL_QUADS, buffers->tot_quad * 4, buffers->index_type, 0); @@ -2097,10 +2148,8 @@ void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial) (void *)offsetof(VertexBufferFormat, co)); glNormalPointer(GL_SHORT, sizeof(VertexBufferFormat), (void *)offsetof(VertexBufferFormat, no)); - if (has_mask) { - glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VertexBufferFormat), - (void *)offsetof(VertexBufferFormat, color)); - } + glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VertexBufferFormat), + (void *)offsetof(VertexBufferFormat, color)); if (buffers->index_buf) glDrawElements(GL_TRIANGLES, totelem, buffers->index_type, 0); @@ -2114,12 +2163,7 @@ void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial) glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); - if (has_mask) { - gpu_colors_disable(VBO_ENABLED); - } - else { - gpu_colors_disable(VBO_DISABLED); - } + gpu_colors_disable(VBO_ENABLED); } /* fallbacks if we are out of memory or VBO is disabled */ else if (buffers->totface) { @@ -2130,6 +2174,32 @@ void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial) } } +int GPU_buffers_diffuse_changed(GPU_Buffers *buffers, int show_diffuse_color) +{ + float diffuse_color[4]; + + if (buffers->show_diffuse_color != show_diffuse_color) + return TRUE; + + if (buffers->show_diffuse_color == FALSE) + return FALSE; + + if (buffers->mface) { + MFace *f = buffers->mface + buffers->face_indices[0]; + + GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color); + } + else { + const DMFlagMat *flags = &buffers->grid_flag_mats[buffers->grid_indices[0]]; + + GPU_material_diffuse_get(flags->mat_nr + 1, diffuse_color); + } + + return diffuse_color[0] != buffers->diffuse_color[0] || + diffuse_color[1] != buffers->diffuse_color[1] || + diffuse_color[2] != buffers->diffuse_color[2]; +} + void GPU_free_buffers(GPU_Buffers *buffers) { if (buffers) { diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 0796a6c2ee0..96ba0bf0ec7 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -1469,6 +1469,21 @@ void GPU_disable_material(void) GPU_set_material_alpha_blend(GPU_BLEND_SOLID); } +void GPU_material_diffuse_get(int nr, float diff[4]) +{ + /* prevent index to use un-initialized array items */ + if (nr >= GMS.totmat) + nr = 0; + + /* no GPU_begin_object_materials, use default material */ + if (!GMS.matbuf) { + mul_v3_v3fl(diff, &defmaterial.r, defmaterial.ref + defmaterial.emit); + } + else { + copy_v4_v4(diff, GMS.matbuf[nr].diff); + } +} + void GPU_end_object_materials(void) { GPU_disable_material(); diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index c59b3393236..2ba5efce3fd 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1454,6 +1454,7 @@ typedef enum SculptFlags { SCULPT_SYMMETRY_FEATHER = (1<<6), SCULPT_USE_OPENMP = (1<<7), SCULPT_ONLY_DEFORM = (1<<8), + SCULPT_SHOW_DIFFUSE = (1<<9), } SculptFlags; /* ImagePaintSettings.flag */ diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index 20e9d133b02..4152ccc1f9b 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -81,12 +81,14 @@ EnumPropertyItem ramp_blend_items[] = { #include "MEM_guardedalloc.h" #include "DNA_node_types.h" +#include "DNA_object_types.h" #include "BKE_depsgraph.h" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_texture.h" #include "BKE_node.h" +#include "BKE_paint.h" #include "ED_node.h" @@ -105,7 +107,7 @@ static void rna_Material_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *p } } -static void rna_Material_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) +static void rna_Material_draw_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr) { Material *ma = ptr->id.data; diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c index 58d676555c1..84e76fae896 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.c +++ b/source/blender/makesrna/intern/rna_sculpt_paint.c @@ -60,6 +60,8 @@ static EnumPropertyItem particle_edit_hair_brush_items[] = { #include "BKE_particle.h" #include "BKE_depsgraph.h" +#include "BLI_pbvh.h" + #include "ED_particle.h" static EnumPropertyItem particle_edit_disconnected_hair_brush_items[] = { @@ -206,6 +208,21 @@ static void rna_Sculpt_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNU } } +static void rna_Sculpt_ShowDiffuseColor_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr)) +{ + Object *ob = (scene->basact) ? scene->basact->object : NULL; + + if (ob) { + Sculpt *sd = scene->toolsettings->sculpt; + ob->sculpt->show_diffuse_color = sd->flags & SCULPT_SHOW_DIFFUSE; + + if (ob->sculpt->pbvh) + pbvh_show_diffuse_color_set(ob->sculpt->pbvh, ob->sculpt->show_diffuse_color); + + WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob); + } +} + #else static void rna_def_paint(BlenderRNA *brna) @@ -297,6 +314,12 @@ static void rna_def_sculpt(BlenderRNA *brna) "Use only deformation modifiers (temporary disable all " "constructive modifiers except multi-resolution)"); RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Sculpt_update"); + + prop = RNA_def_property(srna, "show_diffuse_color", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flags", SCULPT_SHOW_DIFFUSE); + RNA_def_property_ui_text(prop, "Show Diffuse Color", + "Show diffuse color of object and overlay sculpt mask on top of it"); + RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Sculpt_ShowDiffuseColor_update"); } |