原效果
加了我写的描边shader之后的效果
我的frag shader如下
思路是取像素的周围8个点的颜色,如果不透明,就绘制白色描边
在cocos的shader基础上改的,代码里color0和else部分是我加的
const char* ccLabelNormal_frag = STRINGIFY(
\n#ifdef GL_ES\n
precision lowp float;
\n#endif\n
uniform mat4 u_colorMultiplier;
uniform vec4 u_colorOffset;
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform vec4 u_textColor;
void main()
{
vec4 color = v_fragmentColor * vec4(u_textColor.rgb,// RGB from uniform\n
u_textColor.a * texture2D(CC_Texture0, v_texCoord).a// A from texture & uniform\n
);
//描边
float ra=1;
vec4 color01=texture2D(CC_Texture0,vec2(v_texCoord.x-ra,v_texCoord.y));
color01+=texture2D(CC_Texture0,vec2(v_texCoord.x-ra,v_texCoord.y-ra));
color01+=texture2D(CC_Texture0,vec2(v_texCoord.x-ra,v_texCoord.y+ra));
color01+=texture2D(CC_Texture0,vec2(v_texCoord.x+ra,v_texCoord.y));
color01+=texture2D(CC_Texture0,vec2(v_texCoord.x+ra,v_texCoord.y-ra));
color01+=texture2D(CC_Texture0,vec2(v_texCoord.x+ra,v_texCoord.y+ra));
color01+=texture2D(CC_Texture0,vec2(v_texCoord.x,v_texCoord.y-ra));
color01+=texture2D(CC_Texture0,vec2(v_texCoord.x,v_texCoord.y+ra));
if(color.a>0.6)
gl_FragColor = u_colorMultiplier*color + u_colorOffset;
else
if(color01.a>0.6){gl_FragColor =vec4(1,1,1,1);}//用本行或者下一行都显示混乱
//if(color01.a>0.6){gl_FragColor = u_colorMultiplier*vec4(1,1,1,1)+u_colorOffset;}
}
);
感谢指点