[Bf-blender-cvs] [d674891da39] greasepencil-object: Add new UV data parameters to shaders

Antonio Vazquez noreply at git.blender.org
Tue Feb 20 17:02:08 CET 2018


Commit: d674891da3967632fd48f1908e2e1d9d10f35d0f
Author: Antonio Vazquez
Date:   Mon Feb 19 11:01:21 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBd674891da3967632fd48f1908e2e1d9d10f35d0f

Add new UV data parameters to shaders

Add new parameters to transfer UV data information in order to texture the stroke along the path.

WIP: Still not working

===================================================================

M	source/blender/draw/engines/gpencil/gpencil_geom.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_point_geom.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl

===================================================================

diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index 7dfbee04e31..630cb1ad8f3 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -54,7 +54,7 @@
 static void gpencil_set_stroke_point(
         Gwn_VertBuf *vbo, float matrix[4][4], const bGPDspoint *pt, int idx,
         uint pos_id, uint color_id,
-        uint thickness_id, short thickness,
+        uint thickness_id, uint uvdata_id, short thickness,
         const float ink[4])
 {
 	float viewfpt[3];
@@ -66,6 +66,10 @@ static void gpencil_set_stroke_point(
 
 	GWN_vertbuf_attr_set(vbo, color_id, idx, col);
 
+	/* transfer both values using the same shader variable */
+	float uvdata[2] = { pt->uv_fac , pt->uv_rot };
+	GWN_vertbuf_attr_set(vbo, uvdata_id, idx, uvdata);
+
 	/* the thickness of the stroke must be affected by zoom, so a pixel scale is calculated */
 	mul_v3_m4v3(viewfpt, matrix, &pt->x);
 	float thick = max_ff(pt->pressure * thickness, 1.0f);
@@ -120,11 +124,12 @@ Gwn_Batch *DRW_gpencil_get_stroke_geom(bGPDframe *gpf, bGPDstroke *gps, short th
 	int cyclic_add = (gps->flag & GP_STROKE_CYCLIC) ? 1 : 0;
 
 	static Gwn_VertFormat format = { 0 };
-	static uint pos_id, color_id, thickness_id;
+	static uint pos_id, color_id, thickness_id, uvdata_id;
 	if (format.attrib_ct == 0) {
 		pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
 		color_id = GWN_vertformat_attr_add(&format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
 		thickness_id = GWN_vertformat_attr_add(&format, "thickness", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+		uvdata_id = GWN_vertformat_attr_add(&format, "uvdata", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
 	}
 
 	Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
@@ -137,30 +142,36 @@ Gwn_Batch *DRW_gpencil_get_stroke_geom(bGPDframe *gpf, bGPDstroke *gps, short th
 		/* first point for adjacency (not drawn) */
 		if (i == 0) {
 			if (gps->flag & GP_STROKE_CYCLIC && totpoints > 2) {
-				gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[totpoints - 1], idx, pos_id, color_id, thickness_id, thickness, ink);
+				gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[totpoints - 1], idx, 
+										 pos_id, color_id, thickness_id, uvdata_id, thickness, ink);
 				++idx;
 			}
 			else {
-				gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[1], idx, pos_id, color_id, thickness_id, thickness, ink);
+				gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[1], idx, 
+										 pos_id, color_id, thickness_id, uvdata_id, thickness, ink);
 				++idx;
 			}
 		}
 		/* set point */
-		gpencil_set_stroke_point(vbo, gpf->viewmatrix, pt, idx, pos_id, color_id, thickness_id, thickness, ink);
+		gpencil_set_stroke_point(vbo, gpf->viewmatrix, pt, idx, 
+								 pos_id, color_id, thickness_id, uvdata_id, thickness, ink);
 		++idx;
 	}
 
 	if (gps->flag & GP_STROKE_CYCLIC && totpoints > 2) {
 		/* draw line to first point to complete the cycle */
-		gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[0], idx, pos_id, color_id, thickness_id, thickness, ink);
+		gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[0], idx, 
+								 pos_id, color_id, thickness_id, uvdata_id, thickness, ink);
 		++idx;
 		/* now add adjacency point (not drawn) */
-		gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[1], idx, pos_id, color_id, thickness_id, thickness, ink);
+		gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[1], idx, 
+								 pos_id, color_id, thickness_id, uvdata_id, thickness, ink);
 		++idx;
 	}
 	/* last adjacency point (not drawn) */
 	else {
-		gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[totpoints - 2], idx, pos_id, color_id, thickness_id, thickness, ink);
+		gpencil_set_stroke_point(vbo, gpf->viewmatrix, &points[totpoints - 2], idx, 
+								 pos_id, color_id, thickness_id, uvdata_id, thickness, ink);
 	}
 
 	return GWN_batch_create_ex(GWN_PRIM_LINE_STRIP_ADJ, vbo, NULL, GWN_BATCH_OWNS_VBO);
@@ -216,11 +227,12 @@ Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, float matrix[4][4],
 	int totpoints = gpd->sbuffer_size;
 
 	static Gwn_VertFormat format = { 0 };
-	static uint pos_id, color_id, thickness_id;
+	static uint pos_id, color_id, thickness_id, uvdata_id;
 	if (format.attrib_ct == 0) {
 		pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
 		color_id = GWN_vertformat_attr_add(&format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
 		thickness_id = GWN_vertformat_attr_add(&format, "thickness", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+		uvdata_id = GWN_vertformat_attr_add(&format, "uvdata", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
 	}
 
 	Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
@@ -244,25 +256,30 @@ Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, float matrix[4][4],
 		if (i == 0) {
 			if (totpoints > 1) {
 				gpencil_tpoint_to_point(scene, ar, v3d, origin, &points[1], &pt2);
-				gpencil_set_stroke_point(vbo, matrix, &pt2, idx, pos_id, color_id, thickness_id, thickness, gpd->scolor);
+				gpencil_set_stroke_point(vbo, matrix, &pt2, idx, 
+										 pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->scolor);
 			}
 			else {
-				gpencil_set_stroke_point(vbo, matrix, &pt, idx, pos_id, color_id, thickness_id, thickness, gpd->scolor);
+				gpencil_set_stroke_point(vbo, matrix, &pt, idx, 
+										 pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->scolor);
 			}
 			idx++;
 		}
 		/* set point */
-		gpencil_set_stroke_point(vbo, matrix, &pt, idx, pos_id, color_id, thickness_id, thickness, gpd->scolor);
+		gpencil_set_stroke_point(vbo, matrix, &pt, idx, 
+								 pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->scolor);
 		idx++;
 	}
 
 	/* last adjacency point (not drawn) */
 	if (totpoints > 2) {
 		gpencil_tpoint_to_point(scene, ar, v3d, origin, &points[totpoints - 2], &pt2);
-		gpencil_set_stroke_point(vbo, matrix, &pt2, idx, pos_id, color_id, thickness_id, thickness, gpd->scolor);
+		gpencil_set_stroke_point(vbo, matrix, &pt2, idx, 
+								 pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->scolor);
 	}
 	else {
-		gpencil_set_stroke_point(vbo, matrix, &pt, idx, pos_id, color_id, thickness_id, thickness, gpd->scolor);
+		gpencil_set_stroke_point(vbo, matrix, &pt, idx, 
+								 pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->scolor);
 	}
 
 	return GWN_batch_create_ex(GWN_PRIM_LINE_STRIP_ADJ, vbo, NULL, GWN_BATCH_OWNS_VBO);
@@ -283,11 +300,12 @@ Gwn_Batch *DRW_gpencil_get_buffer_point_geom(bGPdata *gpd, float matrix[4][4], s
 	int totpoints = gpd->sbuffer_size;
 
 	static Gwn_VertFormat format = { 0 };
-	static uint pos_id, color_id, thickness_id;
+	static uint pos_id, color_id, thickness_id, uvdata_id;
 	if (format.attrib_ct == 0) {
 		pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
 		color_id = GWN_vertformat_attr_add(&format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
 		thickness_id = GWN_vertformat_attr_add(&format, "thickness", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+		uvdata_id = GWN_vertformat_attr_add(&format, "uvdata", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
 	}
 
 	Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
@@ -308,7 +326,8 @@ Gwn_Batch *DRW_gpencil_get_buffer_point_geom(bGPdata *gpd, float matrix[4][4], s
 		ED_gp_project_point_to_plane(ob, rv3d, origin, ts->gp_sculpt.lock_axis - 1, ts->gpencil_src, &pt);
 
 		/* set point */
-		gpencil_set_stroke_point(vbo, matrix, &pt, idx, pos_id, color_id, thickness_id, thickness, gpd->scolor);
+		gpencil_set_stroke_point(vbo, matrix, &pt, idx, 
+								 pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->scolor);
 		++idx;
 	}
 
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_point_geom.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_point_geom.glsl
index e5aa7cf654b..6aff535d6ed 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_geom.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_geom.glsl
@@ -7,6 +7,7 @@ layout(triangle_strip, max_vertices = 4) out;
 
 in vec4 finalColor[1];
 in float finalThickness[1];
+in vec2 finaluvdata[1];
 
 out vec4 mColor;
 out vec2 mTexCoord;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
index 77b2061879b..d86b0b6fdfa 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
@@ -10,9 +10,11 @@ uniform int pixfactor;
 in vec3 pos;
 in vec4 color;
 in float thickness;
+in vec2 uvdata;
 
 out vec4 finalColor;
 out float finalThickness;
+out vec2 finaluvdata;
 
 #define TRUE 1
 
@@ -31,4 +33,5 @@ void main()
 		finalThickness = max(size * objscale, 4.0); /* minimum 4 pixels */
 	}
 	
+	finaluvdata = uvdata;
 }
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
index ef9e5e4c1d6..80bdf8682ad 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
@@ -3,6 +3,7 @@ uniform sampler2D myTexture;
 
 in vec4 mColor;
 in vec2 mTexCoord;
+in float uvfac;
 
 out vec4 fragColor;
 
@@ -15,7 +16,7 @@ out vec4 fragColor;
 
 void main()
 {
-	const vec2 center = vec2(0, 1.0);
+	vec2 center = vec2(uvfac, 1.0);
 	vec4 tColor = vec4(mColor);
 	/* if alpha < 0, then encap */
 	if (mColor.a < 0) {
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
index 6cce2564de0..2b0e32f2445 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl
@@ -7,9 +7,11 @@ layout(triangle_strip, max_vertices = 13) out;
 
 in vec4 finalColor[4];
 in float finalThickness[4];
+in vec2 finaluvdata[4];
 
 out vec4 mColor;
 out vec2 mTexCoord;
+out float uvfac;
 
 #define GP_XRAY_FRONT 0
 #define GP_XRAY_3DSPACE 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list