//
//morphlet_Fist
//

vertexshader vshader;
pixelshader pshader;

texture result_texture;
texture Intexture1;
texture Intexture2;

float levelmin,levelmax;

float4x4 proj_matrix;
float width,height;

sampler Sampler_result_texture = sampler_state
{
    Texture   = (result_texture);
    MipFilter = NONE;
    MinFilter = NONE;
    MagFilter = NONE;
    ADDRESSU = BORDER;
    ADDRESSV = BORDER;
    BORDERCOLOR = 0;
};

sampler Sampler_Intexture1 = sampler_state
{
    Texture   = (Intexture1);
    MipFilter = NONE;
    MinFilter = NONE;
    MagFilter = NONE;
    ADDRESSU = BORDER;
    ADDRESSV = BORDER;
    BORDERCOLOR = 0;
};

sampler Sampler_Intexture2 = sampler_state
{
    Texture   = (Intexture2);
    MipFilter = NONE;
    MinFilter = NONE;
    MagFilter = NONE;
    ADDRESSU = BORDER;
    ADDRESSV = BORDER;
    BORDERCOLOR = 0;
};

struct VS_INPUT
{
    float3 pos : POSITION;
    float2 tex0 : TEXCOORD0;
};

struct VS_OUTPUT
{
    float4 pos   : POSITION;
    float2 tex0  : TEXCOORD0;
};

VS_OUTPUT VS(VS_INPUT vertex_in)
{
    VS_OUTPUT vertex_out = (VS_OUTPUT)0;

    vertex_in.pos.x *= width;
    vertex_in.pos.y *= height;
    
    vertex_out.pos = mul(float4(vertex_in.pos,1),proj_matrix);
    vertex_out.tex0 = (vertex_in.tex0 + 1.0)/2.;

    return vertex_out;
}

struct PS_INPUT
{
  float2 tex0 : TEXCOORD0;
};

struct PS_OUTPUT
{
  float4 color : COLOR;
};


PS_OUTPUT PS(PS_INPUT ps_in)
{
   PS_OUTPUT ps_out = (PS_OUTPUT)0;
   float4 v;
   float4 Min = float4(levelmin,levelmin,levelmin,levelmin);
   float4 Max = float4(levelmax,levelmax,levelmax,levelmax);

   v = tex2D(Sampler_result_texture, ps_in.tex0);
   v = (v - Min) / (Max - Min);

   ps_out.color = tex2D(Sampler_Intexture2, ps_in.tex0);//lerp( tex2D(Sampler_Intexture1, ps_in.tex0), tex2D(Sampler_Intexture2, ps_in.tex0), v);



   return ps_out;
}


technique T0
{

    pass P0
    {
        Lighting     = FALSE;
        CullMode     = NONE;
        ZWriteEnable = FALSE;
        AlphaBlendEnable = FALSE;
        ZENABLE = FALSE;
        CLIPPING = FALSE;
        FILLMODE = SOLID;

        VertexShader = (vshader);
        PixelShader  = (pshader);
    }
}


