//
//morphlet_Fist
//

vertexshader vshader;
pixelshader pshader;

texture morphlet_texture;
texture result_texture;

float4x4 proj_matrix;
float width,height;

float opacity[8];

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

sampler Sampler_morphlet_texture = sampler_state
{
    Texture   = (morphlet_texture);
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = NONE;
    ADDRESSU = BORDER;
    ADDRESSV = BORDER;
    BORDERCOLOR = 0;
};

struct VS_INPUT
{
    float3 pos : POSITION;
    float2 tex0 : TEXCOORD0;
    float2 tex1 : TEXCOORD1;
    float2 tex2 : TEXCOORD2;
    float2 tex3 : TEXCOORD3;
    float2 tex4 : TEXCOORD4;
    float2 tex5 : TEXCOORD5;
    float2 tex6 : TEXCOORD6;
    float2 tex7 : TEXCOORD7;
};

struct VS_OUTPUT
{
    float4 pos   : POSITION;
    float2 tex0 : TEXCOORD0;
    float2 tex1 : TEXCOORD1;
    float2 tex2 : TEXCOORD2;
    float2 tex3 : TEXCOORD3;
    float2 tex4 : TEXCOORD4;
    float2 tex5 : TEXCOORD5;
    float2 tex6 : TEXCOORD6;
    float2 tex7 : TEXCOORD7;
};

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


    vertex_out.pos = float4(vertex_in.pos,1);
    vertex_out.pos.x *= width;
    vertex_out.pos.y *= height;
    vertex_out.pos = mul(vertex_out.pos,proj_matrix);
    vertex_out.tex0 = vertex_in.tex0;
    vertex_out.tex1 = (vertex_in.tex1+1.)/2.;
    vertex_out.tex2 = (vertex_in.tex2+1.)/2.;
    vertex_out.tex3 = (vertex_in.tex3+1.)/2.;
    vertex_out.tex4 = (vertex_in.tex4+1.)/2.;
    vertex_out.tex5 = (vertex_in.tex5+1.)/2.;
    vertex_out.tex6 = (vertex_in.tex6+1.)/2.;
    vertex_out.tex7 = (vertex_in.tex7+1.)/2.;

    return vertex_out;
}

struct PS_INPUT
{
  float2 tex0 : TEXCOORD0;
  float2 tex1 : TEXCOORD1;
  float2 tex2 : TEXCOORD2;
  float2 tex3 : TEXCOORD3;
  float2 tex4 : TEXCOORD4;
  float2 tex5 : TEXCOORD5;
  float2 tex6 : TEXCOORD6;
  float2 tex7 : TEXCOORD7;

};

struct PS_OUTPUT
{
  float4 color : COLOR;
};


PS_OUTPUT PS(PS_INPUT ps_in)
{
   PS_OUTPUT ps_out = (PS_OUTPUT)0;

   ps_out.color = max(tex2D(Sampler_result_texture, ps_in.tex0), tex2D(Sampler_morphlet_texture, ps_in.tex1)*opacity[1]);
   ps_out.color = max(ps_out.color, tex2D(Sampler_morphlet_texture, ps_in.tex2)*opacity[2]);
   ps_out.color = max(ps_out.color , tex2D(Sampler_morphlet_texture, ps_in.tex3)*opacity[3]);
   ps_out.color = max(ps_out.color , tex2D(Sampler_morphlet_texture, ps_in.tex4)*opacity[4]);
   ps_out.color = max(ps_out.color , tex2D(Sampler_morphlet_texture, ps_in.tex5)*opacity[5]);
   ps_out.color = max(ps_out.color , tex2D(Sampler_morphlet_texture, ps_in.tex6)*opacity[6]);
   ps_out.color = max(ps_out.color , tex2D(Sampler_morphlet_texture, ps_in.tex7)*opacity[7]);

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


