//
//morphlet_Fist
//

vertexshader vshader;
pixelshader pshader;

texture result_texture;

float4x4 proj_matrix;

float4 colors[6];
float  coords[6];

float width,height;

float levelmin,levelmax;

sampler Sampler_result_texture = sampler_state
{
    Texture   = (result_texture);
    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;
   float coord;

   coord = tex2D(Sampler_result_texture, ps_in.tex0).x;
   
   coord = (coord - levelmin) / (levelmax - levelmin);

   if(coord >= coords[0])
   {
        ps_out.color = colors[0];
   }
   else
   if(coord >= coords[1])
   {
        ps_out.color = (coord-coords[1])*colors[0]/(coords[0]-coords[1]) 
                     + (coords[0]-coord)*colors[1]/(coords[0]-coords[1]);
   }
   else
   if(coord >= coords[2])
   {
        ps_out.color = (coord-coords[2])*colors[1]/(coords[1]-coords[2])
                     + (coords[1]-coord)*colors[2]/(coords[1]-coords[2]);
   }
   else
   if(coord >= coords[3])
   {
        ps_out.color = (coord-coords[3])*colors[2]/(coords[2]-coords[3])
                     + (coords[2]-coord)*colors[3]/(coords[2]-coords[3]);
   }
   else
   if(coord >= coords[4])
   {
        ps_out.color = (coord-coords[4])*colors[3]/(coords[3]-coords[4])
                     + (coords[3]-coord)*colors[4]/(coords[3]-coords[4]);
   }
   else
   if(coord >= coords[5])
   {
        ps_out.color = (coord-coords[5])*colors[4]/(coords[4]-coords[5])
                     + (coords[4]-coord)*colors[5]/(coords[4]-coords[5]);
   }
   else
   {
        ps_out.color = colors[5];
   }

   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);
    }
}


