struct fragment {
	float4 position  : POSITION;
	float4 color0    : COLOR0;
	float2 texcoord0 : TEXCOORD0;
};

struct pixel {
	float4 color0 : COLOR0;
};

float blah(float c)
{
	#define pi 3.14159

	//return c*(sin(-pi/2 + c*pi)*0.5+0.5);

	if (c < 0.2) return 0;
	else if (c > 0.3) return 1;
	else return (c-0.2)/0.1;
	/*
	else if (c > 0.5) return 1;
	else return (c-0.2)/0.3;
	*/

}

float klamp(float c, float a, float b)
{
	if (c < a) return a;
	if (c > b) return b;
	return c;
}

pixel main(fragment IN, 
		   uniform sampler2D texture)
{
	pixel OUT;


	/*
	// contrast or something..
	float4 col = tex2D(texture, IN.texcoord0);

	OUT.color0.r = blah(col.r);
	OUT.color0.g = blah(col.g);
	OUT.color0.b = blah(col.b);
	OUT.color0.a = 1;
	*/


	
	// find edges
	float ox = 1.0 / 512.0;
	float oy = 1.0 / 256.0;

	float4 col = -4.0*tex2D(texture, IN.texcoord0) +
		tex2D(texture, IN.texcoord0 + float2(-ox,   0)) +
		tex2D(texture, IN.texcoord0 + float2( ox,   0)) +
		tex2D(texture, IN.texcoord0 + float2(  0, -oy)) +
		tex2D(texture, IN.texcoord0 + float2(  0,  oy));
	

	/*
	// emboss
	float ox = 1.0 / 512.0;
	float oy = 1.0 / 256.0;

	OUT.color0 = tex2D(texture, IN.texcoord0) +
		-1*tex2D(texture, IN.texcoord0 + float2(-ox,   0)) +
		tex2D(texture, IN.texcoord0 + float2( ox,   0)) +
		-1*tex2D(texture, IN.texcoord0 + float2(  0, -oy)) +
		tex2D(texture, IN.texcoord0 + float2(  0,  oy)) +
		-2*tex2D(texture, IN.texcoord0 + float2(-ox, -oy)) +
		2*tex2D(texture, IN.texcoord0 + float2( ox, oy));
	*/	 


	//OUT.color0 = tex2D(texture, IN.texcoord0) * IN.color0;
	/*   
	OUT.color0.r = klamp(OUT.color0.r, 0, 1);
	OUT.color0.g = klamp(OUT.color0.g, 0, 1);
	OUT.color0.b = klamp(OUT.color0.b, 0, 1);
	*/


	OUT.color0.a = 1;
	OUT.color0.rgb = float3(1, 1, 1) - col.rgb * 8;


	return OUT;
}
