Hi Defold Masters
I have a problem with outline shader for sprites.
First of all I’m not sure if this is the right way to do it.
i’ll be glad if anyone can help me.
My problems:
- Since var_texcoord0 is based on the whole atlas, I couldn’t find a way to calculate the correct offset value. If the atlas is big, than I need a very small float like ‘0.001’. if it is small need something bigger like ‘1.0’. How can I(or should I) calculate the right offset for all ?
Here is the difference ( Small Atlas / Large Atlas):
- My other problem is; playing a sprite anim cause a change on outline’s static area. I’m not sure how to handle Flip-book animations:
This is the simple fragment code that I use:
varying mediump vec2 var_texcoord0;
uniform lowp sampler2D DIFFUSE_TEXTURE;
uniform lowp vec4 spriteSize; //Fragment Constant for sprite size
const vec4 bordercolor = vec4(1.0, 1.0, 1.0, 0.0);
void main()
{
vec4 col = texture2D(DIFFUSE_TEXTURE, var_texcoord0);
float offset = 0.001; //float offset = 1.0/spriteSize.x;
if (col.a > 0.1)
gl_FragColor = col;
else {
float a = texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x + offset, var_texcoord0.y)).a ;
a += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x, var_texcoord0.y - offset)).a;
a += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x - offset, var_texcoord0.y)).a;
a += texture2D(DIFFUSE_TEXTURE, vec2(var_texcoord0.x, var_texcoord0.y + offset)).a;
if ( a > 0.9)
gl_FragColor = bordercolor;
else
gl_FragColor = col;
}
}