texture lastshader;
texture thisframe;

sampler s0 = sampler_state { texture = <thisframe>; AddressU=Clamp; AddressV=Clamp;  };

float2 rcpres;

float numBlocks = 75;

float4 cubism(in float2  uv : TEXCOORD ) : COLOR0
{
	float2 temp_full, temp_frac;
	float2 lerpCoord, coordUL, coordUR, coordDL, coordDR;
	int2 temp_int;
	
	temp_full = uv * numBlocks ;
	lerpCoord = modf(temp_full, coordUL);
	coordUR = coordUL + float2(0,1);
	coordDL = coordUL + float2(1,0);
	coordDR = coordUL + 1;
	
	coordUL /= numBlocks;
	coordUR /= numBlocks;
	coordDL /= numBlocks;
	coordDR /= numBlocks;
	
	float4 cUL = tex2D(s0, coordUL);
	float4 cUR = tex2D(s0, coordUR);
	float4 cDL = tex2D(s0, coordDL);
	float4 cDR = tex2D(s0, coordDR);
	
	float4 finalColor = 0;
	finalColor = ( lerp( lerp(cUL, cDL, lerpCoord.y), lerp(cUR, cDR, lerpCoord.y), lerpCoord.x) );
	return finalColor;
}

Technique T0
{
	Pass cubify
	{
		PixelShader = compile ps_2_0 cubism();
	}
}
