
struct appdata
{
    float4 position : POSITION;
    float3 normal : NORMAL;
    //float3 color : DIFFUSE;
    float4 diffuse : DIFFUSE;
    float2 uvs :TEXCOORD0;
    float3 tangent :TEXCOORD1;
    //
	//float3 TestColor : SPECULAR;
};





struct vfconn
{

    float4 HPOS : POSITION;
    //oat4 Nrm : NORMAL;
	float4 HCOL : COLOR;
	float4 HCOL2 : COLOR1;
	float3 Ramp : TEXCOORD7;
    float4 oPosition : TEXCOORD1;
    float4 oPosition2 : TEXCOORD5;
    float4 oThePos : TEXCOORD6;
    float2 oUV : TEXCOORD0;
                      float3 oNormal : TEXCOORD3;

float3 oHalf : TEXCOORD4;
                                                float3 oLight : TEXCOORD2;
  
};








vfconn main(appdata IN,
                uniform float3 LightPos,
                uniform float3 CameraPos,
          uniform float3 Reduction,

uniform float4x4 ModelViewLightProj,
uniform float4x4 ModelViewObject,
			uniform float4x4 ModelViewProj)
{
    vfconn OUT;

    
//
	//ModelViewProj=mul(ModelViewProj,ModelViewObject);
    //ModelViewLightProj=mul(ModelViewLightProj,ModelViewObject);
    //ModelViewLightProj=mul(ModelViewObject,ModelViewLightProj);
    	OUT.oPosition2=IN.position;
   
  float4 MotionBlurPos_current=mul(ModelViewObject,IN.position);
float4 MotionBlurPos_previous=mul(ModelViewLightProj,IN.position);
		
		
		IN.position=mul(ModelViewObject,IN.position);
  OUT.oThePos=IN.position*1;


  IN.normal=mul((float3x3   )ModelViewObject,IN.normal);
IN.tangent=mul((float3x3   )ModelViewObject,IN.tangent);
    OUT.oUV=IN.uvs*1;



float3 MotionBlurmotionVector=MotionBlurPos_current.xyz-MotionBlurPos_previous.xyz;




float3 MotionBlurNormalDirection=float3 (0,0,0)-OUT.oPosition2;
  MotionBlurNormalDirection=mul((float3x3   )ModelViewObject,MotionBlurNormalDirection);

//MotionBlurNormalDirection=IN.normal;
normalize (MotionBlurNormalDirection);



float MotionBlurflag=dot (MotionBlurmotionVector,MotionBlurNormalDirection);
float4 MotionBlurstretch ;

float smm=0;
if (MotionBlurflag>0)
{
	MotionBlurstretch = MotionBlurPos_current+(MotionBlurPos_previous-MotionBlurPos_current)*1; 
}
else
{
	MotionBlurstretch= MotionBlurPos_current;
}


    OUT.HPOS = mul(ModelViewProj, MotionBlurstretch);

MotionBlurPos_current.xyz=MotionBlurPos_current.xyz/MotionBlurPos_current.w;
MotionBlurstretch.xyz=MotionBlurstretch.xyz/MotionBlurstretch.w;


float3 MotionBlur_dP=MotionBlurstretch.xyz-MotionBlurPos_current.xyz;
MotionBlur_dP+=float4 (1,1,1,1);
MotionBlur_dP*=0.5;




OUT.HCOL=MotionBlur_dP.xyzz;



//OUT.HCOL=MotionBlurmotionVector.xyzz;

//OUT.HCOL2=IN.normal.xyzz;
//+specularL*float4 (1,1,1,1);
//float4(m,m,m,m)*IN.diffuse;
//OUT.HCOL2=IN.diffuse;

//OUT.HCOL=AllWhite;
//OUT.HCOL2=AllWhite;


//OUT.HCOL=float4 (1,1,1,1);

//if (LightP.x<111110) OUT.HCOL.x=1;

//float g=IN.color.x;
/*
OUT.HCOL.x=0.1+diff*0.7;
OUT.HCOL.y=0.1+diff*0.9;
OUT.HCOL.z=0.1+diff*1.9;
*/

    return OUT;
} // main




























/*


  VERTEX ENV MAP



  
struct appdata
{
    float4 position : POSITION;
    float3 normal : NORMAL;
    float3 color : DIFFUSE;
    float3 TestColor : SPECULAR;
};

struct vfconn
{
    float4 HPOS : POSITION;
    float2 oPosition : TEXCOORD0;
    float2 oNormal : TEXCOORD1;
};

vfconn main(appdata IN,
            uniform float3 Kd,
            uniform float4x4 ModelViewProj)
{
    vfconn OUT;

    

	OUT.HPOS = mul(ModelViewProj, IN.position);
float3 normal=mul((float3x3)ModelViewProj,IN.normal);
normalize(normal);


float4 normpos=normalize(OUT.HPOS);
float3 refl=reflect (normal,normpos);


float magn=1.5*sqrt (refl.x*refl.x+refl.y*refl.y+(refl.z+1)*(refl.z+1));






float4 normpos2=normalize(IN.position);
float3 refl2=reflect (IN.normal,normpos);


float magn2=1.5*sqrt (refl2.x*refl2.x+refl2.y*refl2.y+(refl2.z+1)*(refl2.z+1));




//diss/=length(diss);


//float cl=dot (normal,diss-OUT.HPOS);
OUT.oNormal.x=refl.x/magn+0.5;
OUT.oNormal.y=refl.y/magn+0.5;


//normalize(diss);

OUT.oPosition.x=IN.position.x*2;
OUT.oPosition.y=IN.position.y*2;

//OUT.oNormal.x=normal.x*0.3;
//OUT.oNormal.y=normal.y*0.3;

    return OUT;
} // main

 */
