//varying lowp vec4 DestinationColor;
varying vec2 TexCoordOut; // New
uniform sampler2D Texture; // New

uniform vec4 colorValue;
uniform vec2 imageSize;

float findEdge(in vec2 coords){
    float dxtex = 1.0 / imageSize.x /*image width*/;
    float dytex = 1.0 / imageSize.y /*image height*/;
    float pix[9];
    int k = -1;
    float delta;
    
    
    // read neighboring pixel intensities
    for (int i=-1; i<2; i++) {
        for(int j=-1; j<2; j++) {
            k++;
            pix[k] = texture2D(Texture,coords + vec2(dxtex*float(i), dytex*float(j))).a;
            
        }
    }
    
    float value = (pix[0]+pix[1]+pix[2]+pix[3]+pix[4]+pix[5]+pix[6]+pix[7]+pix[8])/9.0;
    return value;
}



void main()
{
    
    vec4 color = texture2D(Texture,TexCoordOut);
    float testValue = findEdge(TexCoordOut);
    if ( testValue<1.0&&testValue!=0.0){;
        
        if (testValue>0.5){
            gl_FragColor = color*testValue+colorValue*(1.0-testValue);
      
        } else {
            gl_FragColor = vec4(colorValue.r,colorValue.g,colorValue.b,testValue*3.0);
   
        }
    } else {
        gl_FragColor = color;
    }
}