我正在尝试编写一个着色器,以在文字周围加上边框。它可以编译并运行,但边框很粗糙且有走样。请问有什么建议可以让它更好吗?
这是我写的第一个着色器,因此对API没有太多了解。请注释一下示例代码,好让我能够理解。
此外,当我缩小文本时会遇到问题,最好通过这张图片来说明。请问有什么修复建议吗?
边缘检测也可以更好。到目前为止,我利用了输入的抗锯齿纹理具有0.0 < alpha < 1.0
边缘的事实。
到目前为止,我的代码如下:
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texCoord;
uniform sampler2D u_texture;
uniform vec4 u_borderColor;
uniform float u_width;
uniform float u_height;
void main()
{
mediump vec4 total = vec4(0.0);
float alpha = texture2D(u_texture, v_texCoord).a;
//If somewhere between complete transparent and completely opaque
if (alpha > 0.0 && alpha < 1.0)
{
total.rgb = u_borderColor.rgb;
total.a *= u_borderColor.a;
gl_FragColor = u_borderColor;
}
else
{
gl_FragColor = texture2D(u_texture, v_texCoord);
}
}