struct VS_OUTPUT
{
  float4 Position: POSITION;
  float3 Tex0:     TEXCOORD0;
};

float V_Alpha;
float V_InvScreenW;
float V_InvScreenH;

sampler Sampler = sampler_state
{
  MipFilter = LINEAR;
  MinFilter = LINEAR;
  MagFilter = LINEAR;
};

sampler textura : register(s0);

float4 PS(VS_OUTPUT In) : COLOR0
{
  float4 Color;
  
  //pillamos los pixeles de alrededor para hacer una guarra-convolution
  float4 _11 = tex2D(textura, In.Tex0 + float2(-V_InvScreenW, -V_InvScreenH));
  float4 _12 = tex2D(textura, In.Tex0 + float2(            0, -V_InvScreenW));
  float4 _13 = tex2D(textura, In.Tex0 + float2( V_InvScreenW, -V_InvScreenW));
  float4 _21 = tex2D(textura, In.Tex0 + float2(-V_InvScreenW,             0));
  float4 _23 = tex2D(textura, In.Tex0 + float2( V_InvScreenW,             0));
  float4 _31 = tex2D(textura, In.Tex0 + float2(-V_InvScreenW,  V_InvScreenW));
  float4 _32 = tex2D(textura, In.Tex0 + float2(            0,  V_InvScreenW));
  float4 _33 = tex2D(textura, In.Tex0 + float2( V_InvScreenW,  V_InvScreenW));
  
  // No se si es exactamente Sobel, pero tampoco es que me importe mucho... ¬¬;
  float4 x = -_11 - (2*_21) - _31 + _13 + (2*_23) + _33;
  float4 y = +_11 + (2*_12) + _13 - _31 - (2*_32) - _33;
  
  Color = sqrt((x*x)+(y*y));
  Color = ((Color.r + Color.g + Color.b) / 3) + tex2D(textura, In.Tex0);
  Color.a = V_Alpha * Color.a;
 
  return Color;
}

technique Emboss
{
  pass PassEmboss
  {
    PixelShader = compile ps_2_0 PS();
  }
}
