uniform sampler2D tex;
uniform float cellSize;
void main(void)
{
	
	vec2 thisTCoord=vec2(gl_TexCoord[0]);
        vec4 distVal = texture2D(tex,vec2(gl_TexCoord[0]));
        float dis = (distVal.r+distVal.g+distVal.b)/100.0;
        float cellSizeR = (cellSize-100.0)*0.5 +cos(dis*50.0 -52.0)*cellSize/5.0;
        if(cellSize==0.0)
         cellSizeR=300.0;
        thisTCoord *= (cellSizeR);

//        thisTCoord.x += sin(dis*00.5 -52.0)*cellSize/55.0 ;
  //      thisTCoord.y += cos(dis*0.51 -52.0)*cellSize/55.0 ;

        thisTCoord = ceil (thisTCoord);
                thisTCoord /=(cellSizeR);
//thisTCoord.x +=0.5;	
//thisTCoord.y +=0.5;
thisTCoord = clamp(thisTCoord,vec2(0.0,0.0),vec2(1.0,1.0));
        vec4 value = texture2D(tex,thisTCoord);
	gl_FragColor = value;
}

