static const float2 TexProt[5] = 
{0.0, 0.0,
 0.0, 0.0,
 0.5, 0.0,
 0.0, 0.5,
 0.5, 0.5};

float4x4 matAll;
float FogStart;
float FogEnd;
float4 Pos[40];
float4 Col[40];
float4 RotScl[40];
float4x4 mat;
int TexCprot[40];

struct VS_INPUT
{
  	float4 position  : POSITION;
   	float2 tex0 : TEXCOORD0;
};

struct VS_OUTPUT
{
     	float4 position: POSITION;
   	float2 tex0 : 	 TEXCOORD0;
  	float4 diffuse : TEXCOORD1;
	float  fog: 	 TEXCOORD2;
};

VS_OUTPUT main( VS_INPUT IN )
{
	VS_OUTPUT OUT;
	int ins=round(IN.position.z);
	float3 pns = float3(Pos[ins].xyz);
	float3 dx=float3(RotScl[ins].y,RotScl[ins].z,0);
	float3 dy=float3(RotScl[ins].x,RotScl[ins].y,0);
	float3 ppos= ((IN.position.x*Pos[ins].w)*dx+(IN.position.y*RotScl[ins].w)*dy);
	float4 pos;
	pos.xyz = pns.xyz + mul(ppos,mat);
	pos.w = 1.0;
	OUT.position = mul( pos , matAll);

		int txpro=TexCprot[ins];
		if (txpro!=0) {OUT.tex0=IN.tex0*0.5+TexProt[txpro];}
		else {OUT.tex0=IN.tex0;}

	OUT.diffuse = Col[ins];

	float fogy=(OUT.position.z-FogStart)/(FogEnd-FogStart);
	if (fogy>1) {fogy=1;}
	OUT.fog=fogy;

	return OUT;
}