texture     texL0;
texture     texL1;
texture     texL2;
texture     texL3;
float4x4    World;
float4x3    WorldView;
float4x4    View;       //co klatke
float4x4    ViewProj;   //co klatke
float4x4    Projection; //co klatke
float Time;
float4 Lgh;
float4 Cam;

struct VS_OUTPUT
{
    float4 Pos      : POSITION;
    float4 Diffuse  : COLOR;
    float3 TexL0    : TEXCOORD0;
    float3 TexL1    : TEXCOORD1;               
    float3 TexL2    : TEXCOORD2;    
    float3 TexL3    : TEXCOORD3;
};


VS_OUTPUT VS
    (    
    float3 Pos         :  POSITION,
    float3 Norm        :  NORMAL,
    float4 Diffuse     :  COLOR,
    float3 Tci0        :  TEXCOORD0,
    float3 Tci1        :  TEXCOORD1,
    float3 Tci2        :  TEXCOORD2,
    float3 Tci3        :  TEXCOORD3
    )
{

 VS_OUTPUT Out = (VS_OUTPUT)0;
 
 Out.Diffuse.r =Out.Diffuse.g =Out.Diffuse.b =Out.Diffuse.a=1.0f;
 
 float3 P = mul(float4(Pos, 1), World);
 Out.Pos = mul(float4(P, 1), ViewProj);
 float3 N=normalize(mul(Norm,(float3x3)World));  
 float3 PC=normalize(Cam-P);
 float3 OL=normalize(Lgh-P) ;
 float3 G = normalize(2 * dot(N, PC) * N - PC);
 G=(G-OL)+float3(0,1,0);
 Out.TexL0=Tci0;        //BAZOWA
 Out.TexL1=Tci1;        //LIGHTMAP
 Out.TexL2=Tci0;        //SPECULAR 
 Out.TexL3=G;           //SPEC. LVL

 return Out;
}


samplerCUBE SamplerSP= sampler_state
{
    Texture   = < texL3 >;
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
};
sampler base= sampler_state
{
    Texture   = < texL0 >;
    //MipFilter = LINEAR;
    //MinFilter = LINEAR;
    //MagFilter = LINEAR;
};
sampler lightmap= sampler_state
{
    Texture   = < texL1 >;
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
};
sampler speclevel = sampler_state
{
    Texture   = < texL2 >;
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
};

float4 PS(
    float4 Pos      : POSITION,
    float4 Diffuse  : COLOR,
    float3 TexL0    : TEXCOORD0,
    float3 TexL1    : TEXCOORD1,               
    float3 TexL2    : TEXCOORD2,    
    float3 TexL3    : TEXCOORD3

) :COLOR
{
    float4 OutColor;
    
    OutColor=(tex2D(base, TexL0)+ 1.5f*texCUBE(SamplerSP, TexL3)*tex2D(speclevel, TexL2))
            * (tex2D(lightmap,TexL1));                           
    OutColor.a=tex2D(base, TexL0).a;
    return OutColor;
}


technique t0
{
  pass p0
    {
        VertexShader =  compile vs_1_1 VS();
       //PixelShader  =  compile ps_1_1 PS();
        PixelShader  =  asm
                   { 
                        ps.1.1
                        def c0, 1.5 , 1.5 , 1.5 , 1
                        tex t0
                        tex t1
                        tex t2
                        tex t3
                        mul r0, t2, t3
                        mad r0, r0, c0, t0
                        mul r0, r0, t1
                        mov r0.a , t0.a
                   };

        Texture[0]   = < texL0 >;
        Texture[1]   = < texL1 >;
        Texture[2]   = < texL2 >;
        Texture[3]   = < texL3 >; 
        Texcoordindex[0]   = 0;
        Texcoordindex[1]   = 1;
        Texcoordindex[2]   = 2;
        Texcoordindex[3]   = 3;
     
        //AlphaBlendEnable=true;
        //alpharef=220;
        //alphatestenable=true;

        lighting=false;
        alphablendenable=true;
        SrcBlend    =  srcalpha;
        DestBlend   =  invsrcalpha;
    }
}




