texture g_texturea;
texture g_textureb;

sampler2D g_samSrcColor =
sampler_state
{
    Texture = <g_texturea>;
};


sampler2D g_samNrmColor =
sampler_state
{
    Texture = <g_textureb>;
};


float2 TwelveKernelBase[12] =
{
    { 1.0f,  0.0f},
    { 0.5f,  0.8660f},
    {-0.5f,  0.8660f},
    {-1.0f,  0.0f},
    {-0.5f, -0.8660f},
    { 0.5f, -0.8660f},
    
    { 1.5f,  0.8660f},
    { 0.0f,  1.7320f},
    {-1.5f,  0.8660f},
    {-1.5f, -0.8660f},
    { 0.0f, -1.7320f},
    { 1.5f, -0.8660f},
};


float4 Refract( float2 Tex : TEXCOORD0  ) : COLOR0
{

    float4 Color;
    float4 NrmColor;
    float alpha;
    
   	NrmColor = tex2D( g_samNrmColor, Tex.xy );
   	
    Tex.x += ( -0.5019f + (NrmColor.r) ) * 0.25f; 
    Tex.y += ( -0.5019f + (NrmColor.g) ) * 0.25f;
 
	if (NrmColor.b > 0.0f)
	{
		Color = 0.0f;
		NrmColor.b *= 0.005f;
	
		for( int i = 0; i < 12; i++)
		{
			Color += tex2D( g_samSrcColor, Tex + (NrmColor.b * TwelveKernelBase[i])  );
		}
	 
		Color /= 12.0f;
	}
	else
	{
		Color = tex2D( g_samSrcColor, Tex );
	}
 
  	
    return Color;
}

technique PostProcess
{
    pass p0
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 Refract();
    }

}