[Bf-blender-cvs] [0925574c2cb] greasepencil-object: Add clamp support for textures

Antonio Vazquez noreply at git.blender.org
Mon May 8 20:41:24 CEST 2017


Commit: 0925574c2cbd46d3d8bce71652af11a66f1233d5
Author: Antonio Vazquez
Date:   Mon May 8 20:35:01 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB0925574c2cbd46d3d8bce71652af11a66f1233d5

Add clamp support for textures

The texture is clamp using clamp of the UVs, because if we clamp the texture using GPU_texture_wrap_mode, any place where this texture is used would be affected.

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

M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 18114b44eec..6e62b5c4039 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -58,6 +58,7 @@ typedef struct GPENCIL_Storage {
 	int pal_id;
 	int t_mix[MAX_GPENCIL_MAT];
 	int t_flip[MAX_GPENCIL_MAT];
+	int t_clamp[MAX_GPENCIL_MAT];
 	int fill_style[MAX_GPENCIL_MAT];
 	PaletteColor *materials[MAX_GPENCIL_MAT];
 	DRWShadingGroup *shgrps_fill[MAX_GPENCIL_MAT];
@@ -203,15 +204,8 @@ static DRWShadingGroup *GPENCIL_shgroup_fill_create(GPENCIL_Data *vedata, DRWPas
 			GPUTexture *texture = GPU_texture_from_blender(palcolor->ima, &iuser, GL_TEXTURE_2D, true, 0.0, 0);
 			DRW_shgroup_uniform_texture(grp, "myTexture", texture, 0);
 
-			// TODO: How apply these parameters
-			//if (flag & PAC_COLOR_TEX_CLAMP) {
-			//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
-			//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-			//}
-			//else {
-			//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-			//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-			//}
+			stl->storage->t_clamp[id] = palcolor->flag & PAC_COLOR_TEX_CLAMP ? 1 : 0;
+			DRW_shgroup_uniform_int(grp, "t_clamp", &stl->storage->t_clamp[id], 1);
 
 			BKE_image_release_ibuf(image, ibuf, NULL);
 		}
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
index 8959c2409af..eeea3bd916e 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
@@ -16,6 +16,7 @@ uniform int t_flip;
 uniform float t_opacity;
 
 uniform sampler2D myTexture;
+uniform int t_clamp;
 
 /* keep this list synchronized with list in DNA_brush_types.h */
 #define SOLID 0
@@ -102,7 +103,13 @@ void main()
 	vec2 t_center = vec2(0.5, 0.5);
 	mat2 matrot_tex = mat2(cos(t_angle), -sin(t_angle), sin(t_angle), cos(t_angle));
 	vec2 rot_tex = (matrot_tex * (texCoord_interp - t_center)) + t_center + t_shift;
-	vec4 tmp_color = texture2D(myTexture, rot_tex * t_scale);
+	vec4 tmp_color;
+	if (t_clamp == 0) {
+		tmp_color = texture2D(myTexture, rot_tex * t_scale);
+	}
+	else {
+		tmp_color = texture2D(myTexture, clamp(rot_tex * t_scale, 0.0, 1.0));
+	}
 	vec4 text_color = vec4(tmp_color[0], tmp_color[1], tmp_color[2], tmp_color[3] * t_opacity);
 	vec4 chesscolor;




More information about the Bf-blender-cvs mailing list