
float NumTiles;
float Threshold;

uniform sampler2D RT: register(s0);

float4 Tiling_ps(float4 inPos : POSITION,
				float2 iTexCoord : TEXCOORD0
				) : COLOR
{

	//horizental edge color
	float3 EdgeColor = {0.7, 0.7, 0.7};
    //single tile size
    float size = 1.0/NumTiles;
	//get left top of current tile
    float2 Pbase = iTexCoord - fmod(iTexCoord, size.xx);
	//get center of current tile
    float2 PCenter = Pbase + (size/2.0).xx;
	//used to determine position
    float2 st = (iTexCoord - Pbase)/size;
    float4 c1 = (float4)0;
    float4 c2 = (float4)0;
	//verticle edge color
    float4 invOff = float4((1-EdgeColor),1);
    if (st.x > st.y) { c1 = invOff; }
    float threshholdB =  1.0 - Threshold;
    if (st.x > threshholdB) { c2 = c1; }
    if (st.y > threshholdB) { c2 = c1; }
    float4 cBottom = c2;
    c1 = (float4)0;
    c2 = (float4)0;
    if (st.x > st.y) { c1 = invOff; }
    if (st.x < Threshold) { c2 = c1; }
    if (st.y < Threshold) { c2 = c1; }
    float4 cTop = c2;
    float4 tileColor = tex2D(RT, PCenter);
    float4 result = tileColor + cTop - cBottom;
    return result;
}

