[Bf-blender-cvs] [eb3fe4c8486] greasepencil-refactor: GPencil: Refactor: Change Mask Behavior
Clément Foucault
noreply at git.blender.org
Sat Dec 14 18:59:01 CET 2019
Commit: eb3fe4c8486fe1253cf8725b6083238dca7d256e
Author: Clément Foucault
Date: Sat Dec 14 18:58:41 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBeb3fe4c8486fe1253cf8725b6083238dca7d256e
GPencil: Refactor: Change Mask Behavior
This is a work in progress Masking now done by a particular layer and
applied on all layers underneath.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M source/blender/draw/engines/gpencil/shaders/gpencil_layer_blend_frag.glsl
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index 00a9b1c05e9..4a63702638a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -76,18 +76,26 @@ GPENCIL_tLayer *gpencil_layer_cache_add_new(GPENCIL_PrivateData *pd, Object *ob,
}
if (!pd->draw_depth_only) {
- if (gpl->flag & GP_LAYER_USE_MASK) {
- state |= DRW_STATE_STENCIL_EQUAL;
- }
- else {
- state |= DRW_STATE_WRITE_STENCIL | DRW_STATE_STENCIL_ALWAYS;
- }
+ state |= DRW_STATE_WRITE_STENCIL | DRW_STATE_STENCIL_ALWAYS;
}
tgp_layer->geom_ps = DRW_pass_create("GPencil Layer", state);
}
- if ((gpl->blend_mode != eGplBlendMode_Regular) || (gpl->opacity < 1.0f)) {
+ if (gpl->flag & GP_LAYER_USE_MASK) {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_EQUAL |
+ DRW_STATE_BLEND_ALPHA_PREMUL;
+ tgp_layer->blend_ps = DRW_pass_create("GPencil Mask Layer", state);
+
+ GPUShader *sh = GPENCIL_shader_layer_blend_get(&en_data);
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, tgp_layer->blend_ps);
+ DRW_shgroup_uniform_int_copy(grp, "blendMode", 333);
+ DRW_shgroup_uniform_texture_ref(grp, "colorBuf", &pd->reveal_layer_tx);
+ DRW_shgroup_uniform_texture_ref(grp, "revealBuf", &pd->reveal_layer_tx);
+ DRW_shgroup_stencil_mask(grp, 0xFF);
+ DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
+ }
+ else if ((gpl->blend_mode != eGplBlendMode_Regular) || (gpl->opacity < 1.0f)) {
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_EQUAL;
switch (gpl->blend_mode) {
case eGplBlendMode_Regular:
@@ -122,7 +130,6 @@ GPENCIL_tLayer *gpencil_layer_cache_add_new(GPENCIL_PrivateData *pd, Object *ob,
DRW_shgroup_uniform_texture_ref(grp, "colorBuf", &pd->color_layer_tx);
DRW_shgroup_uniform_texture_ref(grp, "revealBuf", &pd->reveal_layer_tx);
DRW_shgroup_stencil_mask(grp, 0xFF);
- /* TODO only blend pixels that have been rendered. */
DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
if (gpl->blend_mode == eGplBlendMode_Overlay) {
@@ -133,7 +140,6 @@ GPENCIL_tLayer *gpencil_layer_cache_add_new(GPENCIL_PrivateData *pd, Object *ob,
DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ADD);
DRW_shgroup_uniform_int_copy(grp, "blendMode", 999);
DRW_shgroup_uniform_texture_ref(grp, "colorBuf", &pd->color_layer_tx);
- /* TODO only blend pixels that have been rendered. */
DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
}
}
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_layer_blend_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_layer_blend_frag.glsl
index ed3a6c53b4b..1398e6deadd 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_layer_blend_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_layer_blend_frag.glsl
@@ -18,6 +18,7 @@ layout(location = 1) out vec4 fragRevealage;
#define MODE_SUB 3
#define MODE_MULTIPLY 4
#define MODE_DIVIDE 5
+#define MODE_MASK 333
#define MODE_OVERLAY_SECOND_PASS 999
void main()
@@ -78,5 +79,10 @@ void main()
fragColor = color * color.a;
fragRevealage = vec4(0.0);
break;
+ case MODE_MASK:
+ /* Reminder: Blending func is premult alpha blend (dst.rgba * (1 - src.a) + src.rgb).*/
+ fragColor = vec4(0.0, 0.0, 0.0, 1.0 - color.a);
+ fragRevealage = vec4(1.0 - color.aaa, 1.0 - color.a);
+ break;
}
}
More information about the Bf-blender-cvs
mailing list