[Bf-blender-cvs] [384f870f4dc] greasepencil-refactor: GPencil: Refactor: Add back gradient fill mode
Clément Foucault
noreply at git.blender.org
Thu Jan 2 02:02:07 CET 2020
Commit: 384f870f4dc5ff209b1bd7f4951ae8498b6cdca9
Author: Clément Foucault
Date: Thu Jan 2 02:01:54 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB384f870f4dc5ff209b1bd7f4951ae8498b6cdca9
GPencil: Refactor: Add back gradient fill mode
For more consistent behavior, the radial gradient is drawn inside the 0..1
uv space as if it was a texture.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_data.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 156a5f10cfa..c22b43716f9 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -181,16 +181,24 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
copy_v4_v4(mat_data->fill_color, gp_style->fill_rgba);
mat_data->fill_texture_mix = 1.0f - gp_style->mix_factor;
}
- else if (gp_style->fill_style == GP_STYLE_FILL_STYLE_TEXTURE) {
- /* TODO implement gradient as a texture. */
+ else if (gp_style->fill_style == GP_STYLE_FILL_STYLE_GRADIENT) {
+ bool use_radial = (gp_style->gradient_type == GP_STYLE_GRADIENT_RADIAL);
pool->tex_fill[mat_id] = NULL;
- mat_data->flag &= ~GP_FILL_TEXTURE_USE;
+ mat_data->flag |= GP_FILL_GRADIENT_USE;
+ mat_data->flag |= use_radial ? GP_FILL_GRADIENT_RADIAL : 0;
+ 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);
- mat_data->fill_texture_mix = 0.0f;
+ copy_v4_v4(mat_data->fill_mix_color, gp_style->mix_rgba);
+ mat_data->fill_texture_mix = 1.0f - gp_style->mix_factor;
+ 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;
- mat_data->flag &= ~GP_FILL_TEXTURE_USE;
copy_v4_v4(mat_data->fill_color, gp_style->fill_rgba);
mat_data->fill_texture_mix = 0.0f;
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index ffe821f4f3c..44df7f5329d 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -86,6 +86,8 @@ typedef struct gpMaterial {
#define GP_FILL_TEXTURE_USE (1 << 10)
#define GP_FILL_TEXTURE_PREMUL (1 << 11)
#define GP_FILL_TEXTURE_CLIP (1 << 12)
+#define GP_FILL_GRADIENT_USE (1 << 13)
+#define GP_FILL_GRADIENT_RADIAL (1 << 14)
#define GPENCIL_LIGHT_BUFFER_LEN 128
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 4981f4f7f56..00a83b8e214 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -27,10 +27,14 @@ struct gpMaterial {
#define GP_FILL_TEXTURE_USE (1 << 10)
#define GP_FILL_TEXTURE_PREMUL (1 << 11)
#define GP_FILL_TEXTURE_CLIP (1 << 12)
+#define GP_FILL_GRADIENT_USE (1 << 13)
+#define GP_FILL_GRADIENT_RADIAL (1 << 14)
+/* High bits are used to pass material ID to fragment shader. */
+#define GP_MATID_SHIFT 16
/* 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)
+#define GP_FILL_FLAGS (GP_FILL_TEXTURE_USE | GP_FILL_TEXTURE_PREMUL | GP_FILL_TEXTURE_CLIP | GP_FILL_GRADIENT_USE | GP_FILL_GRADIENT_RADIAL)
/* 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 cc0fb0bf930..0498986ed04 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_frag.glsl
@@ -98,6 +98,12 @@ void main()
bool premul = GP_FLAG_TEST(matFlag, GP_FILL_TEXTURE_PREMUL);
col = texture_read_as_linearrgb(gpFillTexture, premul, uvs);
}
+ else if (GP_FLAG_TEST(matFlag, GP_FILL_GRADIENT_USE)) {
+ bool radial = GP_FLAG_TEST(matFlag, GP_FILL_GRADIENT_RADIAL);
+ float fac = clamp(radial ? length(finalUvs * 2.0 - 1.0) : finalUvs.x, 0.0, 1.0);
+ int matid = matFlag >> GP_MATID_SHIFT;
+ col = mix(materials[matid].fill_color, materials[matid].fill_mix_color, fac);
+ }
else /* SOLID */ {
col = vec4(1.0);
}
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
index 370818fa809..d71c08d75c5 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
@@ -292,9 +292,15 @@ void fill_vertex()
vec4 fill_col = materials[m].fill_color;
float mix_tex = materials[m].fill_texture_mix;
+ /* Special case: We don't modulate alpha in gradient mode. */
+ if (GP_FLAG_TEST(materials[m].flag, GP_FILL_GRADIENT_USE)) {
+ fill_col.a = 1.0;
+ }
+
color_output(fill_col, vec4(0.0), 1.0, mix_tex);
matFlag = materials[m].flag & GP_FILL_FLAGS;
+ matFlag |= m << GP_MATID_SHIFT;
vec2 loc = materials[m].fill_uv_offset.xy;
mat2x2 rot_scale = mat2x2(materials[m].fill_uv_rot_scale.xy, materials[m].fill_uv_rot_scale.zw);
More information about the Bf-blender-cvs
mailing list