[vert.glsl]
#version 120

attribute vec3 in_Position;
attribute vec4 in_Color;
attribute vec4 in_TexCoord;

uniform mat4  in_model_view;
uniform mat3  in_normal_mat;
uniform mat4  in_proj;
uniform float in_sprite_orientation;

varying vec4 pass_texcoord;
varying vec4 pass_color;

void main(void)
{
    vec4 vertex = in_model_view * vec4(in_Position - vec3(0.0,0.5,0.0), 1.0);

    vec3 v_offset = vec3(1.0 * in_TexCoord.z, -1.0 * in_TexCoord.w, 0.0);

    float sinX = sin(in_sprite_orientation);
    float cosX = cos(in_sprite_orientation);
    float sinY = sinX;
    mat2 rotationMatrix = mat2(cosX, -sinX, sinY, cosX);

    v_offset.xy = rotationMatrix * v_offset.xy;

    //Billboard calculations
    vertex.xyz += v_offset;

    //pass datas
    pass_texcoord = in_TexCoord;
    pass_color = in_Color;

    gl_Position = in_proj * vertex;
}

[frag.glsl]
#version 120

#if defined GL_ES
precision highp float;
#endif

uniform sampler2D   in_texture;
uniform float       in_sprite_flip;

varying vec4 pass_texcoord;
varying vec4 pass_color;

const float cos_45      = 0.70710678118;
const float PI = 3.14159265358979323846264;

vec3 rgb2hsv(vec3 c)
{
    vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
    vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
    vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);

    float d = q.x - min(q.w, q.y);
    float e = 1.0e-10;
    return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}

vec3 hsv2rgb(vec3 c)
{
    vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
    vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
    return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}

const int sample_nb = 2;

void main(void)
{
    vec2 texcoord = pass_texcoord.xy - vec2(pass_texcoord.z * in_sprite_flip, 0.0);
    vec4 color = texture2D(in_texture, texcoord) * pass_color;

    //need 130 : ivec2 tex_size = textureSize(in_texture, 0);
    if (color.a < 0.9)
    {
        bool break_loop = false;
        for (int x = -sample_nb; x <= sample_nb; x++)
        {
            for (int y = -sample_nb; y <= sample_nb; y++)
            {
                if (x != 0 && y != 0)
                {
                    vec2 new_tc = clamp(texcoord + (vec2(x, y) / 1024.0), vec2(0.0), vec2(1.0));
                    vec4 new_col = texture2D(in_texture, new_tc);
                    //need 130 : vec4 new_col = texelFetch(in_texture, ivec2(tex_size * texcoord) + ivec2(x, y), 0);
                    if (new_col.a > 0.9)
                    {
                        color = vec4(0.0, 0.0, 0.0, 1.0);
                        break_loop = true;
                        //x = sample_nb + 1;
                        //y = sample_nb + 1;
                    }
                    if (break_loop)
                        break;
                }
            }
            if (break_loop)
                break;
        }
    }
    if (color.a < 0.01)
        discard;
    vec3 hsv = rgb2hsv(color.rgb);
    hsv.x = fract(hsv.x + rgb2hsv(pass_color.rgb).x);
    gl_FragColor = vec4(hsv2rgb(hsv), color.a);
}