varying vec2 texCoord;
uniform sampler2D jellymask1;
uniform sampler2D jellymask2;
uniform sampler2D bigtexture;
uniform sampler2D bigtexture2;
uniform float frame;
uniform float mixpercent;

float xs[16]={0.0f/16.0f, 1.0f/16.0f, 2.0f/16.0f, 3.0f/16.0f, 4.0f/16.0f, 5.0f/16.0f, 6.0f/16.0f, 7.0f/16.0f,
            8.0f/16.0f, 9.0f/16.0f, 10.0f/16.0f, 11.0f/16.0f, 12.0f/16.0f, 13.0f/16.0f, 14.0f/16.0f, 15.0f/16.0f,
            };
//float xs[8]={7.0f/16.0f, 6.0f/16.0f, 5.0f/16.0f, 4.0f/16.0f, 3.0f/16.0f, 2.0f/16.0f, 1.0f/16.0f, 0.0f/16.0f};
float ys[15]={0.0f/15.0f, 1.0f/15.0f, 2.0f/15.0f, 3.0f/15.0f, 4.0f/15.0f, 5.0f/15.0f, 6.0f/15.0f, 7.0f/15.0f, 8.0f/15.0f, 9.0f/15.0f, 10.0f/15.0f, 11.0f/15.0f, 12.0f/15.0f, 13.0f/15.0f, 14.0f/15.0f};
           // 15.0f/30.0f, 16.0f/30.0f, 17.0f/30.0f, 18.0f/30.0f, 19.0f/30.0f, 20.0f/30.0f, 21.0f/30.0f, 22.0f/30.0f, 23.0f/30.0f, 24.0f/30.0f, 25.0f/30.0f, 26.0f/30.0f, 27.0f/30.0f, 28.0f/30.0f, 29.0f/30.0f};
float ys2[4]={0.0f/4.0f, 1.0f/4.0f, 2.0f/4.0f, 3.0f/4.0f};
//float ys2[1]={0.0f/1.0f};

vec2 nutexCoord;

void main (void)
{
    float frame1=texture2D(jellymask1, texCoord).x*mixpercent;
    float frame2=texture2D(jellymask2, texCoord).x*(1.0f-mixpercent);
    float frameresult=frame1+frame2+frame;
//float frameresult=texture2D(jellymask1, texCoord).x+frame;
    if (frameresult>=1.0f) frameresult-=(int)(frameresult);
    frameresult=300.0f*frameresult; //256 is total number of frames stored in big textures 240+16
    if (frameresult<240.0f)
    {
        int yf=frameresult/16; int xf=frameresult-yf*16;
        nutexCoord.x=texCoord.x/16.0f+xs[xf];
        nutexCoord.y=texCoord.y/15.0f+ys[yf];
        if (texture2D(bigtexture,  nutexCoord)==vec4(0.0f,1.0f,0.0f,1.0f))
            gl_FragColor = vec4(0.0f,1.0f,0.0f,0.0f); //if it's utter green mask it out with alpha=0
        else
            gl_FragColor = texture2D(bigtexture,  nutexCoord); //otherwise all cool
	} else {
        frameresult-=240.0f;
        int yf=frameresult/16; int xf=frameresult-yf*16;
        nutexCoord.x=texCoord.x/16.0f+xs[xf];
        nutexCoord.y=texCoord.y/4.0f+ys2[yf];
        if (texture2D(bigtexture2,  nutexCoord)==vec4(0.0f,1.0f,0.0f,1.0f))
            gl_FragColor = vec4(0.0f,1.0f,0.0f,0.0f); //if it's utter green mask it out with alpha=0
        else
            gl_FragColor = texture2D(bigtexture2,  nutexCoord); //otherwise all cool
	}

}


