[Bf-blender-cvs] [f883a9c9bbf] greasepencil-refactor: GPencil: Refactor: Add UV / Texture support to strokes
Clément Foucault
noreply at git.blender.org
Thu Dec 12 02:24:26 CET 2019
Commit: f883a9c9bbf83d0bb7a7205e78d274c315762e39
Author: Clément Foucault
Date: Wed Dec 11 17:18:44 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBf883a9c9bbf83d0bb7a7205e78d274c315762e39
GPencil: Refactor: Add UV / Texture support to strokes
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 2d6c64bdd70..630cd55135c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -67,22 +67,23 @@ static GPUVertBuf *gpencil_dummy_buffer_get(void)
/* MUST match the format below. */
typedef struct gpStrokeVert {
- int mat;
+ /** Mat is float because we need to pack other float attribs with it. */
+ float mat, strength;
/** Position and thickness packed in the same attribute. */
float pos[3], thickness;
float col[4];
/** UV and strength packed in the same attribute. */
- float uv[2], strength;
+ float uv[2], u_stroke, v_rot;
} gpStrokeVert;
static GPUVertFormat *gpencil_stroke_format(void)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
- GPU_vertformat_attr_add(&format, "ma", GPU_COMP_I32, 1, GPU_FETCH_INT);
+ GPU_vertformat_attr_add(&format, "ma", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
GPU_vertformat_attr_add(&format, "col", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
- GPU_vertformat_attr_add(&format, "uv", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ GPU_vertformat_attr_add(&format, "uv", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
/* IMPORTANT: This means having only 4 attributes to fit into opengl limit of 16 attrib. */
GPU_vertformat_multiload_enable(&format, 4);
}
@@ -117,6 +118,10 @@ static void gpencil_buffer_add_point(gpStrokeVert *verts,
copy_v2_v2(verts->uv, pt->uv_fill);
copy_v4_v4(verts->col, pt->mix_color);
verts->strength = pt->strength;
+ verts->u_stroke = pt->uv_fac;
+ /* Rotation are in [-90°..90°] range, so we can encode the sign of the angle + the cosine
+ * because the cosine will always be positive. */
+ verts->v_rot = cosf(pt->uv_rot) * signf(pt->uv_rot);
verts->thickness = gps->thickness * pt->pressure;
/* Tag endpoint material to -1 so they get discarded by vertex shader. */
verts->mat = (is_endpoint) ? -1 : (gps->mat_nr % GPENCIL_MATERIAL_BUFFER_LEN);
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
index 051c84ca9a1..26fbbe2fafd 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
@@ -12,16 +12,18 @@ uniform float thicknessWorldScale;
/* Per Layer */
uniform float thicknessOffset;
-in int ma1;
-in int ma2;
+in vec2 ma1;
+in vec2 ma2;
+#define strength1 ma1.y
+#define strength2 ma2.y
/* Position contains thickness in 4th component. */
in vec4 pos; /* Prev adj vert */
in vec4 pos1; /* Current edge */
in vec4 pos2; /* Current edge */
in vec4 pos3; /* Next adj vert */
-
-in vec3 uv1;
-in vec3 uv2;
+/* xy is UV for fills, z is U of stroke, w is cosine of UV angle with sign of sine. */
+in vec4 uv1;
+in vec4 uv2;
in vec4 col1;
in vec4 col2;
@@ -72,7 +74,7 @@ vec2 safe_normalize(vec2 v)
void stroke_vertex()
{
/* Enpoints, we discard the vertices. */
- if (ma1 == -1 || ma2 == -1) {
+ if (ma1.x == -1.0 || ma2.x == -1.0) {
discard_vert();
return;
}
@@ -126,19 +128,24 @@ void stroke_vertex()
thickness *= thicknessWorldScale * ProjectionMatrix[1][1] * sizeViewport.y;
}
/* Multiply scalars first. */
- y *= thickness;
+ thickness *= y;
- gl_Position.xy += miter * sizeViewportInv.xy * y;
+ gl_Position.xy += miter * sizeViewportInv.xy * thickness;
vec4 vert_col = (x == 0.0) ? col1 : col2;
- float vert_strength = (x == 0.0) ? uv1.z : uv2.z;
- vec4 stroke_col = materials[ma1].stroke_color;
+ float vert_strength = (x == 0.0) ? strength1 : strength2;
+
+ int m = int(ma1.x);
+
+ vec4 stroke_col = materials[m].stroke_color;
finalColor.rgb = mix(stroke_col.rgb, vert_col.rgb, vert_col.a);
finalColor.a = clamp(stroke_col.a * vert_strength, 0.0, 1.0);
- // finalColor *= vert_col;
finalMixColor = vec4(0.0);
- matFlag = materials[ma1].flag & ~GP_FILL_FLAGS;
- finalUvs = (x == 0.0) ? uv1.xy : uv2.xy;
+
+ matFlag = materials[m].flag & ~GP_FILL_FLAGS;
+
+ finalUvs.x = (x == 0.0) ? uv1.z : uv2.z;
+ finalUvs.y = y * 0.5 + 0.5;
}
void dots_vertex()
@@ -154,13 +161,14 @@ void fill_vertex()
gl_Position = point_world_to_ndc(wpos);
gl_Position.z += 1e-2;
- finalColor = materials[ma1].fill_color;
- finalMixColor = materials[ma1].fill_mix_color;
- matFlag = materials[ma1].flag & GP_FILL_FLAGS;
+ int m = int(ma1.x);
+
+ finalColor = materials[m].fill_color;
+ finalMixColor = materials[m].fill_mix_color;
+ matFlag = materials[m].flag & GP_FILL_FLAGS;
- vec2 loc = materials[ma1].fill_uv_offset.xy;
- mat2x2 rot_scale = mat2x2(materials[ma1].fill_uv_rot_scale.xy,
- materials[ma1].fill_uv_rot_scale.zw);
+ 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);
finalUvs = rot_scale * uv1.xy + loc;
}
More information about the Bf-blender-cvs
mailing list