[Bf-blender-cvs] [6200ea886c9] greasepencil-refactor: GPencil: Refactor: Implement Checker Fill type
Clément Foucault
noreply at git.blender.org
Wed Dec 11 03:08:01 CET 2019
Commit: 6200ea886c90e50a03c0694972b263541ec90ba7
Author: Clément Foucault
Date: Wed Dec 11 03:06:33 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB6200ea886c90e50a03c0694972b263541ec90ba7
GPencil: Refactor: Implement Checker Fill type
This is not matching the old implementation as the tranform order is
different. We may patch older files to match new impelementation.
===================================================================
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/draw/engines/gpencil/shaders/gpencil_vert.glsl
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index 89124e6785b..52e67cb2030 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -110,6 +110,7 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
mat_data->flag = 0;
+ /* Stroke Style */
if ((gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) && (gp_style->sima)) {
/* TODO finish. */
bool premul;
@@ -118,12 +119,13 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
mat_data->flag |= premul ? GP_STROKE_TEXTURE_PREMUL : 0;
copy_v4_v4(mat_data->stroke_color, gp_style->stroke_rgba);
}
- else /* if (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) */ {
+ else /* if (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_SOLID) */ {
pool->tex_stroke[mat_id] = NULL;
mat_data->flag &= ~GP_STROKE_TEXTURE_USE;
copy_v4_v4(mat_data->stroke_color, gp_style->stroke_rgba);
}
+ /* Fill Style */
if ((gp_style->fill_style == GP_STYLE_FILL_STYLE_TEXTURE) && (gp_style->ima)) {
bool use_clip = (gp_style->flag & GP_STYLE_COLOR_TEX_CLAMP) != 0;
bool premul;
@@ -136,6 +138,12 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
gp_style->texture_angle,
mat_data->fill_uv_transform);
copy_v4_fl4(mat_data->fill_color, 1.0f, 1.0f, 1.0f, gp_style->texture_opacity);
+ if (gp_style->flag & GP_STYLE_FILL_TEX_MIX) {
+ copy_v4_v4(mat_data->fill_mix_color, gp_style->mix_rgba);
+ }
+ else {
+ copy_v4_fl(mat_data->fill_mix_color, 0.0f);
+ }
}
else if (gp_style->fill_style == GP_STYLE_FILL_STYLE_TEXTURE) {
/* TODO implement gradient as a texture. */
@@ -144,10 +152,17 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
copy_v4_v4(mat_data->fill_color, gp_style->fill_rgba);
}
else if (gp_style->fill_style == GP_STYLE_FILL_STYLE_CHECKER) {
- /* TODO implement checker as a texture. */
- pool->tex_fill[mat_id] = NULL;
- mat_data->flag &= ~GP_FILL_TEXTURE_USE;
+ pool->tex_fill[mat_id] = pd->checker_tex;
+ mat_data->flag |= GP_FILL_TEXTURE_USE;
+ gpencil_uv_transform_get(gp_style->gradient_shift,
+ gp_style->gradient_scale,
+ gp_style->gradient_angle,
+ mat_data->fill_uv_transform);
copy_v4_v4(mat_data->fill_color, gp_style->fill_rgba);
+ copy_v4_v4(mat_data->fill_mix_color, gp_style->mix_rgba);
+ if (gp_style->flag & GP_STYLE_COLOR_FLIP_FILL) {
+ swap_v4_v4(mat_data->fill_color, mat_data->fill_mix_color);
+ }
}
else /* if (gp_style->fill_style == GP_STYLE_FILL_STYLE_SOLID) */ {
pool->tex_fill[mat_id] = NULL;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 6996f0bae00..96b2bbe02f5 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -288,6 +288,14 @@ static void GPENCIL_engine_init_new(void *ved)
DRW_texture_ensure_2d(&txl->dummy_texture, 1, 1, GPU_R8, 0);
+ if (txl->checker_texture == NULL) {
+ float pixels[4][4] = {{1.0f, 1.0f, 1.0f, 1.0f},
+ {0.0f, 0.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, 0.0f, 0.0f},
+ {1.0f, 1.0f, 1.0f, 1.0f}};
+ txl->checker_texture = DRW_texture_create_2d(2, 2, GPU_RGBA8, DRW_TEX_WRAP, (float *)pixels);
+ }
+
GPENCIL_ViewLayerData *vldata = GPENCIL_view_layer_data_ensure();
/* Resize and reset memblocks. */
@@ -301,6 +309,7 @@ static void GPENCIL_engine_init_new(void *ved)
stl->pd->gp_layer_pool = vldata->gp_layer_pool;
stl->pd->gp_vfx_pool = vldata->gp_vfx_pool;
stl->pd->last_material_pool = NULL;
+ stl->pd->checker_tex = txl->checker_texture;
}
void GPENCIL_engine_init(void *vedata)
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 50879529460..e7cd360f48e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -61,6 +61,7 @@ struct GPUVertFormat;
typedef struct gpMaterial {
float stroke_color[4];
float fill_color[4];
+ float fill_mix_color[4];
float fill_uv_transform[3][2], _pad0[2];
float stroke_texture_mix;
float stroke_uv_factor;
@@ -314,6 +315,8 @@ typedef struct GPENCIL_FramebufferList {
typedef struct GPENCIL_TextureList {
/* Dummy texture to avoid errors cause by empty sampler. */
struct GPUTexture *dummy_texture;
+ /* Checker texture used in checkerboard fill type. */
+ struct GPUTexture *checker_texture;
/* multisample textures */
struct GPUTexture *multisample_color;
@@ -386,6 +389,8 @@ typedef struct GPENCIL_PrivateData {
struct BLI_memblock *gp_material_pool;
/* Last used material pool. */
GPENCIL_MaterialPool *last_material_pool;
+ /* Copy of txl pointer. */
+ struct GPUTexture *checker_tex;
/* Current frame */
int cfra;
} GPENCIL_PrivateData;
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 33ce0e937bf..0a84ab87d16 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -3,6 +3,7 @@
struct gpMaterial {
vec4 stroke_color;
vec4 fill_color;
+ vec4 fill_mix_color;
vec4 fill_uv_rot_scale;
vec4 fill_uv_offset;
/* Put float/int at the end to avoid padding error */
@@ -26,7 +27,10 @@ struct gpMaterial {
#define GP_FILL_TEXTURE_PREMUL (1 << 11)
#define GP_FILL_TEXTURE_CLIP (1 << 12)
+/* Multiline defines can crash blender with certain GPU drivers. */
+/* clang-format off */
#define GP_FILL_FLAGS (GP_FILL_TEXTURE_USE | GP_FILL_TEXTURE_PREMUL | GP_FILL_TEXTURE_CLIP)
+/* clang-format on */
#define GP_FLAG_TEST(flag, val) (((flag) & (val)) != 0)
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
index a23732a3e96..96a5573578b 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
@@ -5,6 +5,7 @@ uniform sampler2D gpStrokeTexture;
in vec4 finalColor;
in vec2 finalUvs;
flat in int matFlag;
+flat in vec4 finalMixColor;
out vec4 fragColor;
@@ -19,6 +20,7 @@ void main()
vec2 uvs = (use_clip) ? clamp(finalUvs, 0.0, 1.0) : finalUvs;
bool premul = GP_FLAG_TEST(matFlag, GP_FILL_TEXTURE_PREMUL);
fragColor = texture_read_as_srgb(gpFillTexture, premul, uvs) * finalColor;
+ fragColor = fragColor + (1.0 - fragColor.a) * finalMixColor;
}
else {
fragColor = finalColor;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
index 9ed45597856..3af0f1d7d33 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
@@ -26,6 +26,7 @@ in vec2 uv2;
out vec4 finalColor;
out vec2 finalUvs;
flat out int matFlag;
+flat out vec4 finalMixColor;
void discard_vert()
{
@@ -127,6 +128,7 @@ void stroke_vertex()
gl_Position.xy += miter * sizeViewportInv.xy * y;
finalColor = materials[ma1].stroke_color;
+ finalMixColor = vec4(0.0);
matFlag = materials[ma1].flag & ~GP_FILL_FLAGS;
finalUvs = (x == 0.0) ? uv1 : uv2;
}
@@ -145,6 +147,7 @@ void fill_vertex()
gl_Position.z += 1e-2;
finalColor = materials[ma1].fill_color;
+ finalMixColor = materials[ma1].fill_mix_color;
matFlag = materials[ma1].flag & GP_FILL_FLAGS;
vec2 loc = materials[ma1].fill_uv_offset.xy;
More information about the Bf-blender-cvs
mailing list