[Bf-blender-cvs] [4e1399a182e] greasepencil-object: First test of material masking
Antonio Vazquez
noreply at git.blender.org
Thu Jul 9 17:04:19 CEST 2020
Commit: 4e1399a182e83163645c54d689fb2d776eb517c5
Author: Antonio Vazquez
Date: Mon Jun 8 12:00:05 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB4e1399a182e83163645c54d689fb2d776eb517c5
First test of material masking
This is to open holes in fill areas
===================================================================
M release/scripts/startup/bl_ui/properties_material_gpencil.py
M source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M source/blender/draw/engines/gpencil/gpencil_draw_data.c
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
M source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
M source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
M source/blender/makesdna/DNA_material_types.h
M source/blender/makesrna/intern/rna_material.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index 5d10a2cef4a..d1e1a87ea00 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -70,6 +70,9 @@ class GPENCIL_UL_matslots(UIList):
row.prop(ma, "name", text="", emboss=False, icon_value=icon)
row = layout.row(align=True)
+ icon_mask = 'MOD_MASK' if gpcolor.use_masking else 'LAYER_ACTIVE'
+ row.prop(gpcolor, "use_masking", text="", icon=icon_mask, emboss=False)
+
if gpcolor.ghost is True:
icon = 'ONIONSKIN_OFF'
else:
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index 2b811f1d52e..f52778bc55f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -58,6 +58,16 @@ GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_PrivateData *pd, Object *ob)
tgp_ob->is_drawmode3d = (gpd->draw_mode == GP_DRAWMODE_3D) || pd->draw_depth_only;
tgp_ob->object_scale = mat4_to_scale(ob->obmat);
+ /* Check if any material with material masking. */
+ tgp_ob->do_mat_masking = false;
+ for (int i = 0; i < ob->totcol; i++) {
+ MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, i + 1);
+ if (gp_style->flag & GP_MATERIAL_IS_MASK) {
+ tgp_ob->do_mat_masking = true;
+ break;
+ }
+ }
+
/* Find the normal most likely to represent the gpObject. */
/* TODO: This does not work quite well if you use
* strokes not aligned with the object axes. Maybe we could try to
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index 6e6b35e19ca..512a8b5e6a6 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -237,6 +237,11 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
mat_data->flag |= GP_STROKE_OVERLAP;
}
+ /* Material with masking. */
+ if (gp_style->flag & GP_MATERIAL_IS_MASK) {
+ mat_data->flag |= GP_STROKE_MASK;
+ }
+
gp_style = gpencil_viewport_material_overrides(pd, ob, color_type, gp_style);
/* Stroke Style */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 495de7ef10b..ccb9e710634 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -188,6 +188,53 @@ void GPENCIL_engine_init(void *ved)
}
}
+static void GPENCIL_mat_masking_start(GPENCIL_Data *vedata)
+{
+ GPENCIL_PrivateData *pd = vedata->stl->pd;
+ GPENCIL_FramebufferList *fbl = vedata->fbl;
+ GPENCIL_TextureList *txl = vedata->txl;
+
+ const float *size = DRW_viewport_size_get();
+ DRW_texture_ensure_2d(&txl->mat_mask_depth_tx, size[0], size[1], GPU_DEPTH24_STENCIL8, 0);
+ DRW_texture_ensure_2d(&txl->mat_mask_color_tx, size[0], size[1], GPU_R11F_G11F_B10F, 0);
+ DRW_texture_ensure_2d(&txl->mat_mask_reveal_tx, size[0], size[1], GPU_R11F_G11F_B10F, 0);
+
+ GPU_framebuffer_ensure_config(&fbl->mat_mask_fb,
+ {
+ GPU_ATTACHMENT_TEXTURE(txl->mat_mask_depth_tx),
+ GPU_ATTACHMENT_TEXTURE(txl->mat_mask_color_tx),
+ GPU_ATTACHMENT_TEXTURE(txl->mat_mask_reveal_tx),
+ });
+
+ pd->mat_mask_depth_tx = txl->mat_mask_depth_tx;
+ pd->mat_mask_color_tx = txl->mat_mask_color_tx;
+ pd->mat_mask_reveal_tx = txl->mat_mask_reveal_tx;
+}
+
+static void GPENCIL_mat_masking_copy(GPENCIL_Data *vedata)
+{
+ GPENCIL_FramebufferList *fbl = vedata->fbl;
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+
+ /* Copy actual image. */
+ if (dfbl->default_fb != NULL) {
+ GPU_framebuffer_blit(dfbl->default_fb, 0, fbl->mat_mask_fb, 0, GPU_DEPTH_BIT);
+ GPU_framebuffer_blit(fbl->gpencil_fb, 0, fbl->mat_mask_fb, 0, GPU_COLOR_BIT);
+ GPU_framebuffer_blit(fbl->gpencil_fb, 1, fbl->mat_mask_fb, 1, GPU_COLOR_BIT);
+ }
+}
+
+static void GPENCIL_mat_masking_end(GPENCIL_Data *vedata)
+{
+ GPENCIL_FramebufferList *fbl = vedata->fbl;
+ GPENCIL_TextureList *txl = vedata->txl;
+
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->mat_mask_fb);
+ DRW_TEXTURE_FREE_SAFE(txl->mat_mask_depth_tx);
+ DRW_TEXTURE_FREE_SAFE(txl->mat_mask_color_tx);
+ DRW_TEXTURE_FREE_SAFE(txl->mat_mask_reveal_tx);
+}
+
void GPENCIL_cache_init(void *ved)
{
GPENCIL_Data *vedata = (GPENCIL_Data *)ved;
@@ -333,6 +380,11 @@ void GPENCIL_cache_init(void *ved)
/* Disable DoF blur scalling. */
pd->camera = NULL;
}
+
+ /* Material masking framebuffer. */
+ if (txl->mat_mask_color_tx == NULL) {
+ GPENCIL_mat_masking_start(vedata);
+ }
}
#define DRAW_NOW 2
@@ -474,6 +526,9 @@ static void gpencil_layer_cache_populate(bGPDlayer *gpl,
DRW_shgroup_uniform_texture(grp, "gpFillTexture", iter->tex_fill);
DRW_shgroup_uniform_texture(grp, "gpStrokeTexture", iter->tex_stroke);
DRW_shgroup_uniform_int_copy(grp, "gpMaterialOffset", iter->mat_ofs);
+ DRW_shgroup_uniform_texture(grp, "matMaskDepthTexture", pd->mat_mask_depth_tx);
+ DRW_shgroup_uniform_texture(grp, "matMaskColorTexture", pd->mat_mask_color_tx);
+ DRW_shgroup_uniform_texture(grp, "matMaskRevealTexture", pd->mat_mask_reveal_tx);
DRW_shgroup_uniform_float_copy(grp, "strokeIndexOffset", iter->stroke_index_offset);
}
@@ -522,6 +577,9 @@ static void gpencil_stroke_cache_populate(bGPDlayer *gpl,
DRW_shgroup_uniform_texture(iter->grp, "gpStrokeTexture", tex_stroke);
iter->tex_stroke = tex_stroke;
}
+ DRW_shgroup_uniform_texture(iter->grp, "matMaskDepthTexture", iter->pd->mat_mask_depth_tx);
+ DRW_shgroup_uniform_texture(iter->grp, "matMaskColorTexture", iter->pd->mat_mask_color_tx);
+ DRW_shgroup_uniform_texture(iter->grp, "matMaskRevealTexture", iter->pd->mat_mask_reveal_tx);
/* TODO(fclem): This is a quick workaround but
* ideally we should have this as a permanent bind. */
@@ -938,9 +996,14 @@ void GPENCIL_draw_scene(void *ved)
}
LISTBASE_FOREACH (GPENCIL_tObject *, ob, &pd->tobjects) {
+ if (ob->do_mat_masking) {
+ GPENCIL_mat_masking_copy(vedata);
+ }
GPENCIL_draw_object(vedata, ob);
}
+ GPENCIL_mat_masking_end(vedata);
+
if (pd->do_fast_drawing) {
GPENCIL_fast_draw_end(vedata);
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index cedd75af813..efe4501949a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -75,6 +75,7 @@ typedef struct gpMaterial {
#define GP_STROKE_TEXTURE_STENCIL (1 << 4)
#define GP_STROKE_TEXTURE_PREMUL (1 << 5)
#define GP_STROKE_DOTS (1 << 6)
+#define GP_STROKE_MASK (1 << 7)
#define GP_FILL_TEXTURE_USE (1 << 10)
#define GP_FILL_TEXTURE_PREMUL (1 << 11)
#define GP_FILL_TEXTURE_CLIP (1 << 12)
@@ -189,6 +190,10 @@ typedef struct GPENCIL_tObject {
float plane_mat[4][4];
bool is_drawmode3d;
+
+ /* Use Material Masking. */
+ bool do_mat_masking;
+
} GPENCIL_tObject;
/* *********** LISTS *********** */
@@ -218,6 +223,7 @@ typedef struct GPENCIL_FramebufferList {
struct GPUFrameBuffer *mask_fb;
struct GPUFrameBuffer *smaa_edge_fb;
struct GPUFrameBuffer *smaa_weight_fb;
+ struct GPUFrameBuffer *mat_mask_fb;
} GPENCIL_FramebufferList;
typedef struct GPENCIL_TextureList {
@@ -233,6 +239,11 @@ typedef struct GPENCIL_TextureList {
/* Textures used during render. Containing underlying rendered scene. */
struct GPUTexture *render_depth_tx;
struct GPUTexture *render_color_tx;
+ /* Mask textures for supporting material masking. */
+ struct GPUTexture *mat_mask_depth_tx;
+ struct GPUTexture *mat_mask_color_tx;
+ struct GPUTexture *mat_mask_reveal_tx;
+
} GPENCIL_TextureList;
typedef struct GPENCIL_Data {
@@ -283,6 +294,10 @@ typedef struct GPENCIL_PrivateData {
GPUFrameBuffer *scene_fb;
/* Copy of txl->dummy_tx */
GPUTexture *dummy_tx;
+ /* Pointer to material masking textures. */
+ GPUTexture *mat_mask_depth_tx;
+ GPUTexture *mat_mask_color_tx;
+ GPUTexture *mat_mask_reveal_tx;
/* Copy of v3d->shading.single_color. */
float v3d_single_color[3];
/* Copy of v3d->shading.color_type or -1 to ignore. */
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
index 1e75f6dd5bb..49aa36634b1 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -24,6 +24,7 @@ struct gpMaterial {
#define GP_STROKE_TEXTURE_STENCIL (1 << 4)
#define GP_STROKE_TEXTURE_PREMUL (1 << 5)
#define GP_STROKE_DOTS (1 << 6)
+#define GP_STROKE_MASK (1 << 7)
#define GP_FILL_TEXTURE_USE (1 << 10)
#define GP_FILL_TEXTURE_PREMUL (1 << 11)
#define GP_FILL_TEXTURE_CLIP (1 << 12)
@@ -573,6 +574,11 @@ void fill_vertex()
color_output(fill_col, fcol_decode, 1.0, mix_tex);
matFlag = MATERIAL(m).flag & GP_FILL_FLAGS;
+
+ if (GP_FLAG_TEST(MATERIAL(m).flag, GP_STROKE_MASK)) {
+ matFlag |= GP_STROKE_MASK;
+ }
+
matFlag |= m << GP_MATID_SHIFT;
vec2 loc = MATERIAL(m).fill_uv_offset.xy;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
index d81c6f4fe0b..2c6aee5428a 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
@@ -3,6 +3,10 @@ uniform sampler2D gpFillTexture;
uniform sampler2D gpStrokeTexture;
uniform sampler2D gpSceneDepthTexture;
uniform sampler2D gpMaskTexture;
+/* Textures for handling material masking for holes. */
+unifo
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list