Sculpt: Move sculpt drawing to engines.
Only mask are handled by sculpt mode engine and are multiplied on top of the render. There is room for improvement: - Shaded meshes don't have correct tangents or uvs. - Masks are in range 0.8 - 0.2 thus always darkening at least 20% the render. - It only uses the first material slot of the mesh.
This commit is contained in:
@@ -358,6 +358,7 @@ bool BKE_pbvh_node_vert_update_check_any(PBVH *bvh, PBVHNode *node);
|
||||
//void BKE_pbvh_node_BB_reset(PBVHNode *node);
|
||||
//void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]);
|
||||
|
||||
bool pbvh_has_mask(PBVH *bvh);
|
||||
void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color);
|
||||
|
||||
#endif /* __BKE_PBVH_H__ */
|
||||
|
||||
@@ -2117,22 +2117,22 @@ void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node,
|
||||
vi->vmask = CustomData_get_layer(bvh->vdata, CD_PAINT_MASK);
|
||||
}
|
||||
|
||||
void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color)
|
||||
bool pbvh_has_mask(PBVH *bvh)
|
||||
{
|
||||
bool has_mask = false;
|
||||
|
||||
switch (bvh->type) {
|
||||
case PBVH_GRIDS:
|
||||
has_mask = (bvh->gridkey.has_mask != 0);
|
||||
break;
|
||||
return (bvh->gridkey.has_mask != 0);
|
||||
case PBVH_FACES:
|
||||
has_mask = (bvh->vdata && CustomData_get_layer(bvh->vdata,
|
||||
CD_PAINT_MASK));
|
||||
break;
|
||||
return (bvh->vdata && CustomData_get_layer(bvh->vdata,
|
||||
CD_PAINT_MASK));
|
||||
case PBVH_BMESH:
|
||||
has_mask = (bvh->bm && (CustomData_get_offset(&bvh->bm->vdata, CD_PAINT_MASK) != -1));
|
||||
break;
|
||||
return (bvh->bm && (CustomData_get_offset(&bvh->bm->vdata, CD_PAINT_MASK) != -1));
|
||||
}
|
||||
|
||||
bvh->show_diffuse_color = !has_mask || show_diffuse_color;
|
||||
return false;
|
||||
}
|
||||
|
||||
void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color)
|
||||
{
|
||||
bvh->show_diffuse_color = !pbvh_has_mask(bvh) || show_diffuse_color;
|
||||
}
|
||||
|
||||
@@ -746,17 +746,30 @@ static void CLAY_cache_populate(void *vedata, Object *ob)
|
||||
if (!DRW_object_is_renderable(ob))
|
||||
return;
|
||||
|
||||
bool sculpt_mode = ob->mode & OB_MODE_SCULPT;
|
||||
|
||||
struct Batch *geom = DRW_cache_object_surface_get(ob);
|
||||
if (geom) {
|
||||
IDProperty *ces_mode_ob = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_OBJECT, "");
|
||||
bool do_cull = BKE_collection_engine_property_value_get_bool(ces_mode_ob, "show_backface_culling");
|
||||
|
||||
/* Depth Prepass */
|
||||
DRW_shgroup_call_add((do_cull) ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp, geom, ob->obmat);
|
||||
if (sculpt_mode) {
|
||||
DRW_shgroup_call_sculpt_add((do_cull) ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp, ob, ob->obmat);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_call_add((do_cull) ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp, geom, ob->obmat);
|
||||
}
|
||||
|
||||
/* Shading */
|
||||
clay_shgrp = CLAY_object_shgrp_get(vedata, ob, stl, psl);
|
||||
DRW_shgroup_call_add(clay_shgrp, geom, ob->obmat);
|
||||
|
||||
if (sculpt_mode) {
|
||||
DRW_shgroup_call_sculpt_add(clay_shgrp, ob, ob->obmat);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_call_add(clay_shgrp, geom, ob->obmat);
|
||||
}
|
||||
}
|
||||
|
||||
if (ob->type == OB_MESH) {
|
||||
|
||||
@@ -552,18 +552,25 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
|
||||
EEVEE_TextureList *txl = ((EEVEE_Data *)vedata)->txl;
|
||||
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
|
||||
|
||||
bool sculpt_mode = ob->mode & OB_MODE_SCULPT;
|
||||
|
||||
struct Batch *geom = DRW_cache_object_surface_get(ob);
|
||||
if (geom) {
|
||||
IDProperty *ces_mode_ob = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_OBJECT, "");
|
||||
const bool do_cull = BKE_collection_engine_property_value_get_bool(ces_mode_ob, "show_backface_culling");
|
||||
|
||||
/* Depth Prepass */
|
||||
DRW_shgroup_call_add((do_cull) ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp, geom, ob->obmat);
|
||||
if (sculpt_mode) {
|
||||
DRW_shgroup_call_sculpt_add((do_cull) ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp, ob, ob->obmat);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_call_add((do_cull) ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp, geom, ob->obmat);
|
||||
}
|
||||
|
||||
/* Get per-material split surface */
|
||||
struct Batch **mat_geom = DRW_cache_object_surface_material_get(ob);
|
||||
if (mat_geom) {
|
||||
for (int i = 0; i < MAX2(1, ob->totcol); ++i) {
|
||||
for (int i = 0; i < MAX2(1, (sculpt_mode ? 1 : ob->totcol)); ++i) {
|
||||
Material *ma = give_current_material(ob, i + 1);
|
||||
|
||||
if (ma == NULL)
|
||||
@@ -583,10 +590,7 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
|
||||
"#define MAX_CASCADE_NUM 4\n");
|
||||
|
||||
DRWShadingGroup *shgrp = DRW_shgroup_material_create(gpumat, psl->material_pass);
|
||||
|
||||
if (shgrp) {
|
||||
DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat);
|
||||
|
||||
DRW_shgroup_uniform_block(shgrp, "light_block", stl->light_ubo);
|
||||
DRW_shgroup_uniform_block(shgrp, "shadow_block", stl->shadow_ubo);
|
||||
DRW_shgroup_uniform_int(shgrp, "light_count", &stl->lamps->num_light, 1);
|
||||
@@ -596,6 +600,13 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
|
||||
DRW_shgroup_uniform_texture(shgrp, "ltcMat", e_data.ltc_mat);
|
||||
DRW_shgroup_uniform_texture(shgrp, "brdfLut", e_data.brdf_lut);
|
||||
DRW_shgroup_uniform_texture(shgrp, "probeFiltered", txl->probe_pool);
|
||||
|
||||
if (sculpt_mode) {
|
||||
DRW_shgroup_call_sculpt_add(shgrp, ob, ob->obmat);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Shader failed : pink color */
|
||||
@@ -609,7 +620,13 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
|
||||
DRW_shgroup_uniform_texture(stl->g_data->default_lit_grp, "ltcMat", e_data.ltc_mat);
|
||||
DRW_shgroup_uniform_texture(stl->g_data->default_lit_grp, "brdfLut", e_data.brdf_lut);
|
||||
DRW_shgroup_uniform_texture(stl->g_data->default_lit_grp, "probeFiltered", txl->probe_pool);
|
||||
DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat);
|
||||
|
||||
if (sculpt_mode) {
|
||||
DRW_shgroup_call_sculpt_add(shgrp, ob, ob->obmat);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -620,9 +637,14 @@ static void EEVEE_cache_populate(void *vedata, Object *ob)
|
||||
DRW_shgroup_uniform_texture(stl->g_data->default_lit_grp, "ltcMat", e_data.ltc_mat);
|
||||
DRW_shgroup_uniform_texture(stl->g_data->default_lit_grp, "brdfLut", e_data.brdf_lut);
|
||||
DRW_shgroup_uniform_texture(stl->g_data->default_lit_grp, "probeFiltered", txl->probe_pool);
|
||||
DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat);
|
||||
}
|
||||
|
||||
if (sculpt_mode) {
|
||||
DRW_shgroup_call_sculpt_add(shgrp, ob, ob->obmat);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_call_add(shgrp, mat_geom[i], ob->obmat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// GPUMaterial *gpumat = GPU_material_from_nodetree(struct bNodeTree *ntree, ListBase *gpumaterials, void *engine_type, int options)
|
||||
|
||||
@@ -245,6 +245,7 @@ typedef enum {
|
||||
DRW_STATE_STIPPLE_4 = (1 << 12),
|
||||
DRW_STATE_BLEND = (1 << 13),
|
||||
DRW_STATE_ADDITIVE = (1 << 14),
|
||||
DRW_STATE_MULTIPLY = (1 << 15),
|
||||
|
||||
DRW_STATE_WRITE_STENCIL_SELECT = (1 << 27),
|
||||
DRW_STATE_WRITE_STENCIL_ACTIVE = (1 << 28),
|
||||
@@ -256,7 +257,6 @@ typedef enum {
|
||||
|
||||
|
||||
DRWShadingGroup *DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass);
|
||||
DRWShadingGroup *DRW_shgroup_create_fn(struct GPUShader *shader, DRWPass *pass);
|
||||
DRWShadingGroup *DRW_shgroup_material_create(struct GPUMaterial *material, DRWPass *pass);
|
||||
DRWShadingGroup *DRW_shgroup_material_instance_create(struct GPUMaterial *material, DRWPass *pass, struct Batch *geom);
|
||||
DRWShadingGroup *DRW_shgroup_instance_create(struct GPUShader *shader, DRWPass *pass, struct Batch *geom);
|
||||
@@ -271,6 +271,7 @@ typedef void (DRWCallGenerateFn)(
|
||||
|
||||
void DRW_shgroup_free(struct DRWShadingGroup *shgroup);
|
||||
void DRW_shgroup_call_add(DRWShadingGroup *shgroup, struct Batch *geom, float (*obmat)[4]);
|
||||
void DRW_shgroup_call_sculpt_add(DRWShadingGroup *shgroup, struct Object *ob, float (*obmat)[4]);
|
||||
void DRW_shgroup_call_generate_add(
|
||||
DRWShadingGroup *shgroup, DRWCallGenerateFn *geometry_fn, void *user_data, float (*obmat)[4]);
|
||||
void DRW_shgroup_call_dynamic_add_array(DRWShadingGroup *shgroup, const void *attr[], unsigned int attr_len);
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
#include "BKE_depsgraph.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_pbvh.h"
|
||||
#include "BKE_paint.h"
|
||||
|
||||
#include "BLT_translation.h"
|
||||
#include "BLF_api.h"
|
||||
@@ -192,6 +194,7 @@ typedef struct DRWCall {
|
||||
#ifdef USE_GPU_SELECT
|
||||
int select_id;
|
||||
#endif
|
||||
int type;
|
||||
float (*obmat)[4];
|
||||
Batch *geometry;
|
||||
} DRWCall;
|
||||
@@ -201,6 +204,7 @@ typedef struct DRWCallGenerate {
|
||||
#ifdef USE_GPU_SELECT
|
||||
int select_id;
|
||||
#endif
|
||||
int type;
|
||||
float (*obmat)[4];
|
||||
|
||||
DRWCallGenerateFn *geometry_fn;
|
||||
@@ -236,14 +240,18 @@ struct DRWShadingGroup {
|
||||
/* Used by DRWShadingGroup.type */
|
||||
enum {
|
||||
DRW_SHG_NORMAL,
|
||||
/* same as 'DRW_SHG_NORMAL' but use a callback to generate geometry */
|
||||
DRW_SHG_NORMAL_GENERATE,
|
||||
DRW_SHG_POINT_BATCH,
|
||||
DRW_SHG_LINE_BATCH,
|
||||
DRW_SHG_TRIANGLE_BATCH,
|
||||
DRW_SHG_INSTANCE,
|
||||
};
|
||||
|
||||
/* Used by DRWCall.type */
|
||||
enum {
|
||||
DRW_CALL_SINGLE,
|
||||
DRW_CALL_GENERATE,
|
||||
};
|
||||
|
||||
/* only 16 bits long */
|
||||
enum {
|
||||
STENCIL_SELECT = (1 << 0),
|
||||
@@ -662,15 +670,6 @@ DRWShadingGroup *DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
|
||||
return shgroup;
|
||||
}
|
||||
|
||||
DRWShadingGroup *DRW_shgroup_create_fn(struct GPUShader *shader, DRWPass *pass)
|
||||
{
|
||||
DRWShadingGroup *shgroup = DRW_shgroup_create(shader, pass);
|
||||
|
||||
shgroup->type = DRW_SHG_NORMAL_GENERATE;
|
||||
|
||||
return shgroup;
|
||||
}
|
||||
|
||||
DRWShadingGroup *DRW_shgroup_material_create(struct GPUMaterial *material, DRWPass *pass)
|
||||
{
|
||||
double time = 0.0; /* TODO make time variable */
|
||||
@@ -811,6 +810,7 @@ void DRW_shgroup_call_add(DRWShadingGroup *shgroup, Batch *geom, float (*obmat)[
|
||||
|
||||
DRWCall *call = MEM_callocN(sizeof(DRWCall), "DRWCall");
|
||||
|
||||
call->type = DRW_CALL_SINGLE;
|
||||
call->obmat = obmat;
|
||||
call->geometry = geom;
|
||||
|
||||
@@ -827,12 +827,12 @@ void DRW_shgroup_call_generate_add(
|
||||
float (*obmat)[4])
|
||||
{
|
||||
BLI_assert(geometry_fn != NULL);
|
||||
BLI_assert(shgroup->type == DRW_SHG_NORMAL_GENERATE);
|
||||
|
||||
DRWCallGenerate *call = MEM_callocN(sizeof(DRWCallGenerate), "DRWCallGenerate");
|
||||
|
||||
call->obmat = obmat;
|
||||
|
||||
call->type = DRW_CALL_GENERATE;
|
||||
call->geometry_fn = geometry_fn;
|
||||
call->user_data = user_data;
|
||||
|
||||
@@ -843,6 +843,26 @@ void DRW_shgroup_call_generate_add(
|
||||
BLI_addtail(&shgroup->calls, call);
|
||||
}
|
||||
|
||||
static void sculpt_draw_cb(
|
||||
DRWShadingGroup *shgroup,
|
||||
void (*draw_fn)(DRWShadingGroup *shgroup, Batch *geom),
|
||||
void *user_data)
|
||||
{
|
||||
Object *ob = user_data;
|
||||
PBVH *pbvh = ob->sculpt->pbvh;
|
||||
|
||||
if (pbvh) {
|
||||
BKE_pbvh_draw_cb(
|
||||
pbvh, NULL, NULL, false,
|
||||
(void (*)(void *, Batch *))draw_fn, shgroup);
|
||||
}
|
||||
}
|
||||
|
||||
void DRW_shgroup_call_sculpt_add(DRWShadingGroup *shgroup, Object *ob, float (*obmat)[4])
|
||||
{
|
||||
DRW_shgroup_call_generate_add(shgroup, sculpt_draw_cb, ob, obmat);
|
||||
}
|
||||
|
||||
void DRW_shgroup_call_dynamic_add_array(DRWShadingGroup *shgroup, const void *attr[], unsigned int attr_len)
|
||||
{
|
||||
DRWInterface *interface = shgroup->interface;
|
||||
@@ -1288,7 +1308,7 @@ static void DRW_state_set(DRWState state)
|
||||
{
|
||||
int test;
|
||||
if (CHANGED_ANY_STORE_VAR(
|
||||
DRW_STATE_BLEND | DRW_STATE_ADDITIVE,
|
||||
DRW_STATE_BLEND | DRW_STATE_ADDITIVE | DRW_STATE_MULTIPLY,
|
||||
test))
|
||||
{
|
||||
if (test) {
|
||||
@@ -1297,6 +1317,9 @@ static void DRW_state_set(DRWState state)
|
||||
if ((state & DRW_STATE_BLEND) != 0) {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
else if ((state & DRW_STATE_MULTIPLY) != 0) {
|
||||
glBlendFunc(GL_DST_COLOR, GL_ZERO);
|
||||
}
|
||||
else if ((state & DRW_STATE_ADDITIVE) != 0) {
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
}
|
||||
@@ -1530,7 +1553,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
|
||||
DST.shader = shgroup->shader;
|
||||
}
|
||||
|
||||
const bool is_normal = ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_NORMAL_GENERATE);
|
||||
const bool is_normal = ELEM(shgroup->type, DRW_SHG_NORMAL);
|
||||
|
||||
if (!is_normal) {
|
||||
shgroup_dynamic_batch_from_calls(shgroup);
|
||||
@@ -1624,7 +1647,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (shgroup->type == DRW_SHG_NORMAL) {
|
||||
else {
|
||||
for (DRWCall *call = shgroup->calls.first; call; call = call->next) {
|
||||
bool neg_scale = call->obmat && is_negative_m4(call->obmat);
|
||||
|
||||
@@ -1634,7 +1657,15 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
|
||||
}
|
||||
|
||||
GPU_SELECT_LOAD_IF_PICKSEL(call);
|
||||
draw_geometry(shgroup, call->geometry, call->obmat);
|
||||
|
||||
if (call->type == DRW_CALL_SINGLE) {
|
||||
draw_geometry(shgroup, call->geometry, call->obmat);
|
||||
}
|
||||
else {
|
||||
DRWCallGenerate *callgen = ((DRWCallGenerate *)call);
|
||||
draw_geometry_prepare(shgroup, callgen->obmat);
|
||||
callgen->geometry_fn(shgroup, draw_geometry_execute, callgen->user_data);
|
||||
}
|
||||
|
||||
/* Reset state */
|
||||
if (neg_scale) {
|
||||
@@ -1642,29 +1673,6 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (shgroup->type == DRW_SHG_NORMAL_GENERATE) {
|
||||
/* Same as 'DRW_SHG_NORMAL' but generate batches */
|
||||
for (DRWCallGenerate *call = shgroup->calls.first; call; call = call->next) {
|
||||
bool neg_scale = call->obmat && is_negative_m4(call->obmat);
|
||||
|
||||
/* Negative scale objects */
|
||||
if (neg_scale) {
|
||||
glFrontFace(GL_CW);
|
||||
}
|
||||
|
||||
GPU_SELECT_LOAD_IF_PICKSEL(call);
|
||||
draw_geometry_prepare(shgroup, call->obmat);
|
||||
call->geometry_fn(shgroup, draw_geometry_execute, call->user_data);
|
||||
|
||||
/* Reset state */
|
||||
if (neg_scale) {
|
||||
glFrontFace(GL_CCW);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
BLI_assert(0);
|
||||
}
|
||||
|
||||
/* TODO: remove, (currently causes alpha issue with sculpt, need to investigate) */
|
||||
DRW_state_reset();
|
||||
@@ -1774,16 +1782,9 @@ struct DRWTextStore *DRW_text_cache_ensure(void)
|
||||
bool DRW_object_is_renderable(Object *ob)
|
||||
{
|
||||
Scene *scene = DST.draw_ctx.scene;
|
||||
SceneLayer *sl = DST.draw_ctx.sl;
|
||||
Object *obedit = scene->obedit;
|
||||
Object *obact = OBACT_NEW;
|
||||
|
||||
if (ob->type == OB_MESH) {
|
||||
if (ob == obact) {
|
||||
if (ob->mode & OB_MODE_SCULPT) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (ob == obedit) {
|
||||
IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_EDIT, "");
|
||||
bool do_show_occlude_wire = BKE_collection_engine_property_value_get_bool(props, "show_occlude_wire");
|
||||
|
||||
@@ -135,10 +135,10 @@ static void SCULPT_engine_init(void *vedata)
|
||||
*/
|
||||
|
||||
if (!e_data.shader_flat) {
|
||||
e_data.shader_flat = GPU_shader_get_builtin_shader(GPU_SHADER_SIMPLE_LIGHTING_FLAT_COLOR);
|
||||
e_data.shader_flat = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR);
|
||||
}
|
||||
if (!e_data.shader_smooth) {
|
||||
e_data.shader_smooth = GPU_shader_get_builtin_shader(GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR);
|
||||
e_data.shader_smooth = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SMOOTH_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ static void SCULPT_cache_init(void *vedata)
|
||||
|
||||
{
|
||||
/* Create a pass */
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_MULTIPLY;
|
||||
psl->pass = DRW_pass_create("Sculpt Pass", state);
|
||||
|
||||
/* Create a shadingGroup using a function in draw_common.c or custom one */
|
||||
@@ -165,26 +165,8 @@ static void SCULPT_cache_init(void *vedata)
|
||||
* -- or --
|
||||
* stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
|
||||
*/
|
||||
stl->g_data->group_flat = DRW_shgroup_create_fn(e_data.shader_flat, psl->pass);
|
||||
stl->g_data->group_smooth = DRW_shgroup_create_fn(e_data.shader_smooth, psl->pass);
|
||||
|
||||
/* Uniforms need a pointer to it's value so be sure it's accessible at
|
||||
* any given time (i.e. use static vars) */
|
||||
static float light[3] = {-0.3f, 0.5f, 1.0f};
|
||||
static float alpha = 1.0f;
|
||||
static float world_light = 1.0f;
|
||||
|
||||
DRWShadingGroup *group_arr[2] = {
|
||||
stl->g_data->group_flat,
|
||||
stl->g_data->group_smooth,
|
||||
};
|
||||
|
||||
for (uint i = 0; i < 2; i++) {
|
||||
DRWShadingGroup *group = group_arr[i];
|
||||
DRW_shgroup_uniform_vec3(group, "light", light, 1);
|
||||
DRW_shgroup_uniform_float(group, "global", &world_light, 1);
|
||||
DRW_shgroup_uniform_float(group, "alpha", &alpha, 1);
|
||||
}
|
||||
stl->g_data->group_flat = DRW_shgroup_create(e_data.shader_flat, psl->pass);
|
||||
stl->g_data->group_smooth = DRW_shgroup_create(e_data.shader_smooth, psl->pass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,21 +181,6 @@ static bool object_is_flat(const Object *ob)
|
||||
}
|
||||
}
|
||||
|
||||
static void sculpt_draw_cb(
|
||||
DRWShadingGroup *shgroup,
|
||||
void (*draw_fn)(DRWShadingGroup *shgroup, struct Batch *geom),
|
||||
void *user_data)
|
||||
{
|
||||
Object *ob = user_data;
|
||||
PBVH *pbvh = ob->sculpt->pbvh;
|
||||
|
||||
if (pbvh) {
|
||||
BKE_pbvh_draw_cb(
|
||||
pbvh, NULL, NULL, false,
|
||||
(void (*)(void *, struct Batch *))draw_fn, shgroup);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add geometry to shadingGroups. Execute for each objects */
|
||||
static void SCULPT_cache_populate(void *vedata, Object *ob)
|
||||
{
|
||||
@@ -226,12 +193,15 @@ static void SCULPT_cache_populate(void *vedata, Object *ob)
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
SceneLayer *sl = draw_ctx->sl;
|
||||
|
||||
if (ob == OBACT_NEW) {
|
||||
/* Get geometry cache */
|
||||
DRWShadingGroup *shgroup = object_is_flat(ob) ? stl->g_data->group_flat : stl->g_data->group_smooth;
|
||||
if (ob->sculpt && ob == OBACT_NEW) {
|
||||
PBVH *pbvh = ob->sculpt->pbvh;
|
||||
if (pbvh && pbvh_has_mask(pbvh)) {
|
||||
/* Get geometry cache */
|
||||
DRWShadingGroup *shgroup = object_is_flat(ob) ? stl->g_data->group_flat : stl->g_data->group_smooth;
|
||||
|
||||
/* Add geom to a shading group */
|
||||
DRW_shgroup_call_generate_add(shgroup, sculpt_draw_cb, ob, ob->obmat);
|
||||
/* Add geom to a shading group */
|
||||
DRW_shgroup_call_sculpt_add(shgroup, ob, ob->obmat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user