A dither shader:
varying mediump vec4 position;
varying mediump vec2 var_texcoord0;
uniform lowp sampler2D texture_sampler;
uniform lowp vec4 tint;
uniform mediump vec4 nomalized_sprite_ps;
uniform mediump vec4 alpha;
float DitherPlastic(vec2 pos)
{
return 2.0 * abs(fract(dot(pos, vec2(0.75487767, 0.56984029))) - 0.5);
}
void main()
{
// Pre-multiply alpha since all runtime textures already are
lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
// Normalize var_texcoord0 using offset and scale
vec2 invertedTexCoords = vec2(var_texcoord0.x, 1 - var_texcoord0.y);
vec2 normalizedTexCoords = (invertedTexCoords - nomalized_sprite_ps.xy) / nomalized_sprite_ps.zw;
vec2 normalizedPixel = floor(normalizedTexCoords * vec2(640,320));
gl_FragColor = vec4(step(alpha.x, DitherPlastic(normalizedPixel)), 0,0,1);
}
I tried using the floor when normalizing the coords, but still have the same issue. Not sure if it can be fixed. I want to use that value as alpha.