Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl')
-rw-r--r--source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl45
1 files changed, 32 insertions, 13 deletions
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 c19bf1e7b50..94b066c12e5 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -7,13 +7,23 @@ struct gpMaterial {
vec4 fill_uv_rot_scale;
vec4 fill_uv_offset;
/* Put float/int at the end to avoid padding error */
- float stroke_texture_mix;
- float stroke_u_scale;
- float fill_texture_mix;
- int flag;
+ /* Some drivers are completely messing the alignment or the fetches here.
+ * We are forced to pack these into vec4 otherwise we only get 0.0 as value. */
+ vec4 gp_mat_packed_1;
+ // float stroke_texture_mix;
+ // float stroke_u_scale;
+ // float fill_texture_mix;
+ // int gp_flag;
/* Please ensure 16 byte alignment (multiple of vec4). */
};
+#define MATERIAL(m) materials[m + gpMaterialOffset]
+
+#define stroke_texture_mix gp_mat_packed_1.x
+#define stroke_u_scale gp_mat_packed_1.y
+#define fill_texture_mix gp_mat_packed_1.z
+#define GP_FLAG(m) floatBitsToInt(MATERIAL(m).gp_mat_packed_1.w)
+
/* flag */
#define GP_STROKE_ALIGNMENT_STROKE 1
#define GP_STROKE_ALIGNMENT_OBJECT 2
@@ -24,6 +34,8 @@ 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_HOLDOUT (1 << 7)
+#define GP_FILL_HOLDOUT (1 << 8)
#define GP_FILL_TEXTURE_USE (1 << 10)
#define GP_FILL_TEXTURE_PREMUL (1 << 11)
#define GP_FILL_TEXTURE_CLIP (1 << 12)
@@ -34,7 +46,7 @@ struct gpMaterial {
/* 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 | GP_FILL_GRADIENT_USE | GP_FILL_GRADIENT_RADIAL)
+#define GP_FILL_FLAGS (GP_FILL_TEXTURE_USE | GP_FILL_TEXTURE_PREMUL | GP_FILL_TEXTURE_CLIP | GP_FILL_GRADIENT_USE | GP_FILL_GRADIENT_RADIAL | GP_FILL_HOLDOUT)
/* clang-format on */
#define GP_FLAG_TEST(flag, val) (((flag) & (val)) != 0)
@@ -197,7 +209,6 @@ uniform int gpMaterialOffset;
uniform float thicknessScale;
uniform float thicknessWorldScale;
#define thicknessIsScreenSpace (thicknessWorldScale < 0.0)
-#define MATERIAL(m) materials[m + gpMaterialOffset]
#ifdef GPU_VERTEX_SHADER
@@ -371,8 +382,8 @@ void stroke_vertex()
# ifdef GP_MATERIAL_BUFFER_LEN
if (m != -1) {
- is_dot = GP_FLAG_TEST(MATERIAL(m).flag, GP_STROKE_ALIGNMENT);
- is_squares = !GP_FLAG_TEST(MATERIAL(m).flag, GP_STROKE_DOTS);
+ is_dot = GP_FLAG_TEST(GP_FLAG(m), GP_STROKE_ALIGNMENT);
+ is_squares = !GP_FLAG_TEST(GP_FLAG(m), GP_STROKE_DOTS);
}
# endif
@@ -424,7 +435,7 @@ void stroke_vertex()
if (is_dot) {
# ifdef GP_MATERIAL_BUFFER_LEN
- int alignement = MATERIAL(m).flag & GP_STROKE_ALIGNMENT;
+ int alignement = GP_FLAG(m) & GP_STROKE_ALIGNMENT;
# endif
vec2 x_axis;
@@ -450,6 +461,14 @@ void stroke_vertex()
float rot_cos = abs(uv_rot);
x_axis = mat2(rot_cos, -rot_sin, rot_sin, rot_cos) * x_axis;
+# ifdef GP_MATERIAL_BUFFER_LEN
+ if (is_dot) {
+ float alignment_cos = MATERIAL(m).fill_uv_offset.z;
+ float alignment_sin = MATERIAL(m).fill_uv_offset.w;
+ x_axis = mat2(alignment_cos, -alignment_sin, alignment_sin, alignment_cos) * x_axis;
+ }
+# endif
+
vec2 y_axis = rotate_90deg(x_axis);
strokeAspect = decode_aspect(aspect1);
@@ -509,7 +528,7 @@ void stroke_vertex()
color_output(stroke_col, vert_col, vert_strength * small_line_opacity, mix_tex);
- matFlag = MATERIAL(m).flag & ~GP_FILL_FLAGS;
+ matFlag = GP_FLAG(m) & ~GP_FILL_FLAGS;
# endif
if (strokeOrder3d) {
@@ -517,7 +536,7 @@ void stroke_vertex()
depth = -1.0;
}
# ifdef GP_MATERIAL_BUFFER_LEN
- else if (GP_FLAG_TEST(MATERIAL(m).flag, GP_STROKE_OVERLAP)) {
+ else if (GP_FLAG_TEST(GP_FLAG(m), GP_STROKE_OVERLAP)) {
/* Use the index of the point as depth.
* This means the stroke can overlap itself. */
depth = (point_id1 + strokeIndexOffset + 1.0) * 0.0000002;
@@ -548,7 +567,7 @@ void fill_vertex()
float mix_tex = MATERIAL(m).fill_texture_mix;
/* Special case: We don't modulate alpha in gradient mode. */
- if (GP_FLAG_TEST(MATERIAL(m).flag, GP_FILL_GRADIENT_USE)) {
+ if (GP_FLAG_TEST(GP_FLAG(m), GP_FILL_GRADIENT_USE)) {
fill_col.a = 1.0;
}
@@ -568,7 +587,7 @@ void fill_vertex()
color_output(fill_col, fcol_decode, 1.0, mix_tex);
- matFlag = MATERIAL(m).flag & GP_FILL_FLAGS;
+ matFlag = GP_FLAG(m) & GP_FILL_FLAGS;
matFlag |= m << GP_MATID_SHIFT;
vec2 loc = MATERIAL(m).fill_uv_offset.xy;