sampler texture0 : register(s0);
sampler texture1 : register(s1); // ripples.png (256x256)

float4x4 WorldViewProjectionTransform  : WORLDVIEWPROJ;
float fCurrentTime;
float fAmount;

struct VS_OUTPUT 
{
   float4 Position  : POSITION;
   float2 TexCoord  : TEXCOORD0;
};

struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  // Pixel color    
};

VS_OUTPUT vertexMain(
				float4 vPosition : POSITION,
				float2 texCoord0 : TEXCOORD0)
{
	VS_OUTPUT Output; 

	Output.Position = mul(vPosition, WorldViewProjectionTransform);
	Output.TexCoord = texCoord0;   

	return Output;
}

float2 coord(float2 input, float x, float y)
{
	float2 result;
	result.x = input.x + x;
	result.y = input.y + y;
	return result;
}

PS_OUTPUT pixelMain(VS_OUTPUT In)
{
	float offset = fCurrentTime / 15000.f;

	float4 normal = tex2D(texture1, In.TexCoord + offset);
	float dist = dot(normal.xy, normal.xy) - 0.16;
	normal = (normal * 2.f) - 1.f;
	
	float2 targetCoord = In.TexCoord + normal.xy * fAmount;

	// get rid of those nasty borders
	if (targetCoord.x < 0.01f)
		targetCoord.x = 0.01f;
	if (targetCoord.y < 0.01f)
		targetCoord.y = 0.01f;
	if (targetCoord.x > 0.99f)
		targetCoord.x = 0.99f;
	if (targetCoord.y > 0.99f)
		targetCoord.y = 0.99f;

	PS_OUTPUT output;
	output.RGBColor = tex2D(texture0, targetCoord);
	output.RGBColor.rgb *= float3(1.f, 1.f, 1.f)  + float3(1.f, 1.f, 1.f) * dist;
	output.RGBColor = saturate(output.RGBColor);
	return output;
}