//------------------------------------
float4x4 worldViewProj : WorldViewProjection;
float k_blend;
float k_blend_pictures;
float k_blend_showing;

//------------------------------------
struct vertexInputFocus {
   float4 position  : POSITION;
   float2 texcoord : TEXCOORD0;
};

struct vertexOutputFocus {
   float4 position : POSITION;
   float2 texcoord : TEXCOORD0;
};

struct pixelInputFocus {
   float2 texcoord  : TEXCOORD0;
};

//------------------------------------
struct vertexInputText {
   float4 position  : POSITION;
   float4 color     : COLOR0;
   float2 texcoord  : TEXCOORD0;
};

//------------------------------------
struct vertexOutputText {
   float4 position  : POSITION;
   float4 color     : COLOR0;
   float2 texcoord  : TEXCOORD0;
};

//------------------------------------
struct vertexOutputColor {
   float4 position  : POSITION;
   //float4 color     : COLOR0;
};

//------------------------------------
texture DefaultPic;
sampler defSampler = sampler_state
{
    texture = <DefaultPic>;
    //MinFilter = LINEAR;
    //MagFilter = LINEAR;
    //MipFilter = LINEAR;
 
    AddressU = CLAMP;
    AddressV = CLAMP;
    AddressW = CLAMP;
};

texture DefaultPicNext;

sampler defNextSampler = sampler_state
{
    texture = <DefaultPicNext>;
    //MinFilter = LINEAR;
    //MagFilter = LINEAR;
    //MipFilter = LINEAR;
 
    AddressU = CLAMP;
    AddressV = CLAMP;
    AddressW = CLAMP;
};


//------------------------------------
vertexOutputFocus VS_FocusBlend(vertexInputFocus IN) 
{
    vertexOutputFocus OUT;
    OUT.position = IN.position;//mul(IN.position, worldViewProj);
    OUT.texcoord = IN.texcoord;
    return OUT;
}

//------------------------------------
float4 PS_FocusBlend(pixelInputFocus IN): COLOR
{
  float4 color1 = tex2D(defSampler, IN.texcoord);
  float4 color2 = tex2D(defNextSampler, IN.texcoord);
  float4 result = color1 * (1.0f - k_blend_pictures) + color2 * k_blend_pictures;
  float3 adding_res = (k_blend / 5.0f);
  if (k_blend > 1.5f) adding_res = float3(0.3f, 0.2f, 0.0f);
  return float4(result.xyz += adding_res, result.w * k_blend_showing);
}

//------------------------------------
vertexOutputFocus VS_FocusBlend2(vertexInputFocus IN) 
{
    vertexOutputFocus OUT;
    OUT.position = IN.position;//mul(IN.position, worldViewProj);
    OUT.texcoord = IN.texcoord;
    return OUT;
}

//------------------------------------
float4 PS_FocusBlend2(pixelInputFocus IN): COLOR
{
  float4 color1 = tex2D(defSampler, IN.texcoord);
  float4 color2 = tex2D(defNextSampler, IN.texcoord);
  float4 result = color1 * (1.0f - k_blend) + color2 * k_blend;
  //float3 adding_res = (k_blend / 5.0f);
  //if (k_blend > 1.5f) adding_res = float3(0.3f, 0.2f, 0.0f);
  return float4(result.xyz, 1.0f);
}

//------------------------------------
vertexOutputText VS_TextBlend(vertexInputText IN) 
{
    vertexOutputText OUT;
    OUT.position = mul(IN.position, worldViewProj);
    OUT.color = float4(IN.color.xyz, k_blend_showing);
    OUT.texcoord = IN.texcoord;
    return OUT;
}

//------------------------------------
vertexOutputFocus VS_DefShader(vertexInputFocus IN) 
{
    vertexOutputFocus OUT;
    OUT.position = IN.position;//mul(IN.position, worldViewProj);
    OUT.texcoord = IN.texcoord;
    return OUT;
}

//------------------------------------
float4 PS_DefShader(pixelInputFocus IN): COLOR
{
  return tex2D(defSampler, IN.texcoord);
}

//------------------------------------
vertexOutputColor VS_ColorShader(vertexOutputColor IN) 
{
    vertexOutputColor OUT;
    OUT.position = IN.position;//mul(IN.position, worldViewProj);
    //OUT.color = IN.color;
    return OUT;
}

//------------------------------------
float4 PS_ColorShader() : COLOR
{
    float4 color = float4(1.0f, 1.0f, 1.0f, 1.0f);
    return color;
}

//-----------------------------------
technique FocusBlend
{
    pass p0 
    {		
		VertexShader = compile vs_1_1 VS_FocusBlend();
		PixelShader  = compile ps_2_0 PS_FocusBlend();
    }
}

//-----------------------------------
technique FocusBlend2
{
    pass p0 
    {		
		VertexShader = compile vs_1_1 VS_FocusBlend2();
		PixelShader  = compile ps_2_0 PS_FocusBlend2();
    }
}

//-----------------------------------
technique DefShader
{
    pass p0 
    {		
		VertexShader = compile vs_1_1 VS_DefShader();
		PixelShader  = compile ps_2_0 PS_DefShader();
    }
}

//-----------------------------------
technique TextBlend
{
    pass p0 
    {		
		VertexShader = compile vs_1_1 VS_TextBlend();
		PixelShader  = NULL;
    }
}

//-----------------------------------
technique OutColor
{
    pass p0 
    {		
		VertexShader = compile vs_1_1 VS_ColorShader();
		PixelShader  = compile ps_2_0 PS_ColorShader();
    }
}
