ok, i’ve just taken a look at your shader code.
you are still using the same method from cpp test, only changing the texture offset values.
The issue in this shader is that it will accumulate the alpha values of those pixels around it. Those outline having higher opacity are those pixels with more neighbouring pixels that are non-transparent.
And how this shader works is that it will draw the outline on transparent pixels surrounding the colored pixels. So, when there is no transparent pixel above (just fit size), then there is no outline there.
If you change the shader to be like the unity one (in my first post), it will work differently. It will replace the colored pixel at the edge with outline color, instead of outline on the transparent pixel.
fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
the first part of the unity shader is almost the same as this part of your shader
normal = texture2D(CC_Texture0, vec2(v_texCoord.x, v_texCoord.y));
except that it multiplies with IN.color, which is equivalent to
and as such it has already factored the opacity.
As you see, the very last part of the shader before returning the final color, it multiplies by the opacity that was factored in the first part, so there won’t be any issues with the opacity.
c.rgb *= c.a;
EDIT: Seeing that you have a
u_thickness variable, it seems drawing the outline on transparent pixels is what will make the thickness work.
And regards to your #2 issue, it must have transparent pixels at the edge for the outline.
You should change the accumulate method to be using 4 different variables instead (for each of the surrounding pixels).
accum.rgb = u_outlineColor * accum.a;
accum.a = 1;
And instead of this, rgb should not be multiplied by alpha, while accum.a should be the max of the 4 pixels’ alpha.