Refactor: Grease Pencil: Port depth merge and mask invert to new draw manager
_No response_ Pull Request: https://projects.blender.org/blender/blender/pulls/130326
This commit is contained in:
committed by
Clément Foucault
parent
366c8e247a
commit
1d48d8428c
@@ -154,12 +154,7 @@ typedef struct GPENCIL_StorageList {
|
||||
} GPENCIL_StorageList;
|
||||
|
||||
typedef struct GPENCIL_PassList {
|
||||
/* Composite the main GPencil buffer onto the rendered image. */
|
||||
struct DRWPass *composite_ps;
|
||||
/* Composite the object depth to the default depth buffer to occlude overlays. */
|
||||
struct DRWPass *merge_depth_ps;
|
||||
/* Invert mask buffer content. */
|
||||
struct DRWPass *mask_invert_ps;
|
||||
struct DRWPass *dummy;
|
||||
} GPENCIL_PassList;
|
||||
|
||||
typedef struct GPENCIL_FramebufferList {
|
||||
@@ -192,6 +187,10 @@ struct GPENCIL_Instance {
|
||||
blender::draw::PassSimple smaa_edge_ps = {"smaa_edge"};
|
||||
blender::draw::PassSimple smaa_weight_ps = {"smaa_weight"};
|
||||
blender::draw::PassSimple smaa_resolve_ps = {"smaa_resolve"};
|
||||
/* Composite the object depth to the default depth buffer to occlude overlays. */
|
||||
blender::draw::PassSimple merge_depth_ps = {"merge_depth_ps"};
|
||||
/* Invert mask buffer content. */
|
||||
blender::draw::PassSimple mask_invert_ps = {"mask_invert_ps"};
|
||||
};
|
||||
|
||||
struct GPENCIL_Data {
|
||||
@@ -263,7 +262,7 @@ typedef struct GPENCIL_PrivateData {
|
||||
bool draw_wireframe;
|
||||
/* Used by the depth merge step. */
|
||||
int is_stroke_order_3d;
|
||||
float object_bound_mat[4][4];
|
||||
float4x4 object_bound_mat;
|
||||
/* Used for computing object distance to camera. */
|
||||
float camera_z_axis[3], camera_z_offset;
|
||||
float camera_pos[3];
|
||||
|
||||
@@ -185,11 +185,10 @@ void GPENCIL_cache_init(void *ved)
|
||||
{
|
||||
using namespace blender::draw;
|
||||
GPENCIL_Data *vedata = (GPENCIL_Data *)ved;
|
||||
GPENCIL_PassList *psl = vedata->psl;
|
||||
GPENCIL_Instance *inst = vedata->instance;
|
||||
GPENCIL_TextureList *txl = vedata->txl;
|
||||
GPENCIL_FramebufferList *fbl = vedata->fbl;
|
||||
GPENCIL_PrivateData *pd = vedata->stl->pd;
|
||||
DRWShadingGroup *grp;
|
||||
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
pd->cfra = int(DEG_get_ctime(draw_ctx->depsgraph));
|
||||
@@ -274,23 +273,21 @@ void GPENCIL_cache_init(void *ved)
|
||||
}
|
||||
|
||||
{
|
||||
DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
|
||||
DRW_PASS_CREATE(psl->merge_depth_ps, state);
|
||||
|
||||
GPUShader *sh = GPENCIL_shader_depth_merge_get();
|
||||
grp = DRW_shgroup_create(sh, psl->merge_depth_ps);
|
||||
DRW_shgroup_uniform_texture_ref(grp, "depthBuf", &pd->depth_tx);
|
||||
DRW_shgroup_uniform_bool(grp, "strokeOrder3d", &pd->is_stroke_order_3d, 1);
|
||||
DRW_shgroup_uniform_vec4(grp, "gpModelMatrix", pd->object_bound_mat[0], 4);
|
||||
DRW_shgroup_call_procedural_triangles(grp, nullptr, 1);
|
||||
blender::draw::PassSimple &pass = inst->merge_depth_ps;
|
||||
pass.init();
|
||||
pass.state_set(DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
|
||||
pass.shader_set(GPENCIL_shader_depth_merge_get());
|
||||
pass.bind_texture("depthBuf", &pd->depth_tx);
|
||||
pass.push_constant("strokeOrder3d", &pd->is_stroke_order_3d);
|
||||
pass.push_constant("gpModelMatrix", &pd->object_bound_mat);
|
||||
pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
|
||||
}
|
||||
{
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_LOGIC_INVERT;
|
||||
DRW_PASS_CREATE(psl->mask_invert_ps, state);
|
||||
|
||||
GPUShader *sh = GPENCIL_shader_mask_invert_get();
|
||||
grp = DRW_shgroup_create(sh, psl->mask_invert_ps);
|
||||
DRW_shgroup_call_procedural_triangles(grp, nullptr, 1);
|
||||
blender::draw::PassSimple &pass = inst->mask_invert_ps;
|
||||
pass.init();
|
||||
pass.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_LOGIC_INVERT);
|
||||
pass.shader_set(GPENCIL_shader_mask_invert_get());
|
||||
pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
|
||||
}
|
||||
|
||||
Camera *cam = static_cast<Camera *>(
|
||||
@@ -744,7 +741,9 @@ static void GPENCIL_draw_scene_depth_only(void *ved)
|
||||
|
||||
static void gpencil_draw_mask(GPENCIL_Data *vedata, GPENCIL_tObject *ob, GPENCIL_tLayer *layer)
|
||||
{
|
||||
GPENCIL_PassList *psl = vedata->psl;
|
||||
GPENCIL_Instance *inst = vedata->instance;
|
||||
blender::draw::Manager *manager = DRW_manager_get();
|
||||
|
||||
GPENCIL_FramebufferList *fbl = vedata->fbl;
|
||||
const float clear_col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
float clear_depth = ob->is_drawmode3d ? 1.0f : 0.0f;
|
||||
@@ -764,7 +763,7 @@ static void gpencil_draw_mask(GPENCIL_Data *vedata, GPENCIL_tObject *ob, GPENCIL
|
||||
|
||||
if (BLI_BITMAP_TEST_BOOL(layer->mask_invert_bits, i) != inverted) {
|
||||
if (cleared) {
|
||||
DRW_draw_pass(psl->mask_invert_ps);
|
||||
manager->submit(inst->mask_invert_ps);
|
||||
}
|
||||
inverted = !inverted;
|
||||
}
|
||||
@@ -785,7 +784,7 @@ static void gpencil_draw_mask(GPENCIL_Data *vedata, GPENCIL_tObject *ob, GPENCIL
|
||||
|
||||
if (!inverted) {
|
||||
/* Blend shader expect an opacity mask not a reavealage buffer. */
|
||||
DRW_draw_pass(psl->mask_invert_ps);
|
||||
manager->submit(inst->mask_invert_ps);
|
||||
}
|
||||
|
||||
DRW_stats_group_end();
|
||||
@@ -793,9 +792,9 @@ static void gpencil_draw_mask(GPENCIL_Data *vedata, GPENCIL_tObject *ob, GPENCIL
|
||||
|
||||
static void GPENCIL_draw_object(GPENCIL_Data *vedata, GPENCIL_tObject *ob)
|
||||
{
|
||||
GPENCIL_Instance *inst = vedata->instance;
|
||||
blender::draw::Manager *manager = DRW_manager_get();
|
||||
|
||||
GPENCIL_PassList *psl = vedata->psl;
|
||||
GPENCIL_PrivateData *pd = vedata->stl->pd;
|
||||
GPENCIL_FramebufferList *fbl = vedata->fbl;
|
||||
const float clear_cols[2][4] = {{0.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}};
|
||||
@@ -837,12 +836,12 @@ static void GPENCIL_draw_object(GPENCIL_Data *vedata, GPENCIL_tObject *ob)
|
||||
manager->submit(*vfx->vfx_ps);
|
||||
}
|
||||
|
||||
copy_m4_m4(pd->object_bound_mat, ob->plane_mat);
|
||||
pd->object_bound_mat = float4x4(ob->plane_mat);
|
||||
pd->is_stroke_order_3d = ob->is_drawmode3d;
|
||||
|
||||
if (pd->scene_fb) {
|
||||
GPU_framebuffer_bind(pd->scene_fb);
|
||||
DRW_draw_pass(psl->merge_depth_ps);
|
||||
manager->submit(inst->merge_depth_ps);
|
||||
}
|
||||
|
||||
DRW_stats_group_end();
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 model_matrix = mat4(gpModelMatrix[0], gpModelMatrix[1], gpModelMatrix[2], gpModelMatrix[3]);
|
||||
int v = gl_VertexID % 3;
|
||||
float x = -1.0 + float((v & 1) << 2);
|
||||
float y = -1.0 + float((v & 2) << 1);
|
||||
gl_Position = drw_view.winmat * (drw_view.viewmat * (model_matrix * vec4(x, y, 0.0, 1.0)));
|
||||
gl_Position = drw_view.winmat * (drw_view.viewmat * (gpModelMatrix * vec4(x, y, 0.0, 1.0)));
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ GPU_SHADER_CREATE_END()
|
||||
|
||||
GPU_SHADER_CREATE_INFO(gpencil_depth_merge)
|
||||
DO_STATIC_COMPILATION()
|
||||
PUSH_CONSTANT_ARRAY(VEC4, gpModelMatrix, 4)
|
||||
PUSH_CONSTANT(MAT4, gpModelMatrix)
|
||||
PUSH_CONSTANT(BOOL, strokeOrder3d)
|
||||
SAMPLER(0, DEPTH_2D, depthBuf)
|
||||
VERTEX_SOURCE("gpencil_depth_merge_vert.glsl")
|
||||
|
||||
Reference in New Issue
Block a user