
[vert.glsl]
#version 130

in vec3 in_position;
in vec3 in_Normal;
in vec4 in_color;
in vec2 in_texcoord;

uniform mat4 u_modelview;
uniform mat4 u_view;
uniform mat4 u_projection;
uniform mat3 u_normalmat;

out vec4 pass_vertex; /* View space */
out vec3 pass_tnormal;
out vec4 pass_color;
out vec2 pass_texcoord;

void main(void)
{
    vec4 vertex = u_modelview * vec4(in_position, 1.0);
    vec3 tnorm = normalize(u_normalmat * in_Normal);

    pass_vertex = vertex;
    pass_tnormal = tnorm;
    pass_color = in_color;
    pass_texcoord = in_texcoord;

    gl_Position = u_projection * vertex;
}

[frag.glsl]
#version 130

#if defined GL_ES
precision highp float;
#endif

in vec4 pass_vertex; /* View space */
in vec3 pass_tnormal;
in vec4 pass_color;
in vec2 pass_texcoord;

uniform float u_damage;
uniform mat4 u_view;
uniform mat4 u_inv_view;

uniform vec4 u_lights[8 * 2];

void main(void)
{
    float mode = 0.0;
    if (mode == 0.0)
    {
        gl_FragColor = vec4(mod(pass_texcoord.x, 1.0),
                            0.1,
                            mod(pass_texcoord.y, 1.0), 1.0);
    }
    else
    {
        float col = ((mod(mode, 2.0) == 1.0)?(mod(pass_texcoord.x, 1.0)):(mod(pass_texcoord.y, 1.0)));
        if (mode == 1.0 || mode == 2.0)
        {
            if (col > 1.0/3.0) gl_FragColor.r = 0.0;
            else gl_FragColor.r = min(col, 1.0/3.0);
            if (col > 2.0/3.0) gl_FragColor.g = 0.0;
            else gl_FragColor.g = min(max(col, 1.0/3.0) - 1.0/3.0, 1.0/3.0);
            gl_FragColor.b = min(max(col, 2.0/3.0) - 2.0/3.0, 1.0/3.0);
        }
        else if (mode == 3.0 || mode == 4.0)
        {
            if (col > 0.5) gl_FragColor.r = 0.0;
            else gl_FragColor.r = min(col, 0.5);
            gl_FragColor.g = min(max(col, 0.5) - 0.5, 0.5);
            gl_FragColor.b = 0.1;
        }
        else if (mode == 5.0 || mode == 6.0)
        {
            gl_FragColor.r = col;
            gl_FragColor.g = 0.1;
            gl_FragColor.b = 0.1;
        }
    }

    gl_FragColor.a = 1.0;
    gl_FragColor *=
                 //= pass_color *
                    length(normalize(pass_texcoord)) *
                    length(normalize(pass_color.xyz)) *
                    length(normalize(pass_tnormal));
}

