uniform sampler2D texture;
uniform int effect;
uniform int ceffect;
uniform sampler2D displacement;
uniform float magnitude;
uniform float Time;
uniform bool isGetDamage;

void main()
{
    // lookup the pixel in the texture
    vec4 pixel;

    if (effect == 0) pixel = texture2D(texture, gl_TexCoord[0].xy);
    else if (effect == 1){
        vec2 distuv = vec2(gl_TexCoord[0].x + Time,  gl_TexCoord[0].y + Time);
        vec2 disp = texture2D(displacement, distuv).xy;
        disp = ((disp * 2) - 1) * magnitude;
        pixel = texture2D(texture, gl_TexCoord[0].xy + disp);
    }

    // multiply it by the color
    gl_FragColor = gl_Color * pixel;

    if (ceffect == 1) {
        vec4 color = gl_Color * pixel;
        float gray = dot(color.rgb, vec3(0.22, 0.707, 0.071));
        gl_FragColor =  vec4(gray, gray, gray, color.a);
    }
    else if (ceffect == 2){
        vec4 color = gl_Color * pixel;
        vec4 oppo = vec4(1.f - color.r, 1.f - color.g, 1.f - color.b, color.a);
        gl_FragColor = oppo;
    }

    if (isGetDamage) gl_FragColor += vec4(0.1, 0.1, 0.1, 0);
}