struct C2E2f_Output { 
	float4 color: COLOR;
};


C2E2f_Output main (    float4 oPosition : TEXCOORD1,
                      float2 oUV : TEXCOORD0,
                      float4 HCOL : COLOR, 
                      
	float4 HCOL2 : COLOR1,
                      
                      float3 oLight : TEXCOORD2,
                      float3 oHalf : TEXCOORD4,
                      float2 uvl : TEXCOORD5,
                      float3 oNormal : TEXCOORD3,



                    uniform float3 alpha,  
                    uniform float alpha2,  
                   uniform sampler2D decal,

				   uniform sampler2D light,
                   //uniform samplerCUBE light,
				   uniform sampler2D texture,
				   uniform sampler2D texture2,
//                   uniform samplerCUBE cube
                   uniform sampler2D cubes
//uniform float3 lightPosition

                   ) 
{



	C2E2f_Output OUT;


    float4 basetexture=tex2D (texture2,oUV);
   
//lighttexture=tex2D (lightmap,oUV);
   

float4 normals=tex2D (light,oUV);


float3 normal=((normals.xyz-0.5)*2).xyz;

//float maxx=dot(normal,oLight)+pow (dot(normal,oHalf),20);
float maxx=0.02+0.1*dot(normal,float3 (1,0,0));
//maxx*=maxx;
//if (dot(normal,oHalf)>0) maxx=1; else maxx=0;
float mx=max (0,dot(normal,float3 (0,-1,0)));
mx*=0.2;

//oPosition.w+=0.003*maxx;
//oPosition+=float4 (maxx,0,0,0);

oUV*=0.5;
//float4 cll1=tex2Dproj (decal,oPosition*float2 (800.0f/1024.0f,600.0f/1024.0f));
float4 cll4=(tex2D (light,oUV)+tex2D(light,oUV+alpha2))*0.2;
 float4 cll2=tex2Dproj (decal,cll4+oPosition*float4 (800.0f/1024.0f,600.0f/1024.0f,1,1));
 //cll2+=tex2Dproj (decal,cll4+alpha2+oPosition*float4 (800.0f/1024.0f,600.0f/1024.0f,1,1));
 

float4 cll1=0.7*tex2Dproj (decal,cll4+oPosition);

 //maxx*=maxx; 
 // /oPosition.xyz*=1;
//float4 cll4=texCUBE (light,oPosition.xyz);
//if (cll4.w<0) cll4=float4 (0,0,0,0);
OUT.color=tex2D (texture2,oUV)*cll1+HCOL2*maxx+mx*float4 (0.2,1,1,1)+HCOL;
OUT.color=(cll2)*float4 (0.4,1.1,1.1,1)+1*float4 (0.1,0.2,0.4,1)*cll4.x;
OUT.color=(cll2)*float4 (0.5,0.9,1,1)*(cll4.y*9);
//+1*float4 (0.1,0.2,0.4,1)*cll4.x;

//OUT.color=float4 (1,0,0,0);

//*cll1+HCOL2*maxx+mx*float4 (0.2,1,1,1)+HCOL;

//+float4 (0,0.1,0.1,1);
//float4 (0,0.1,0.1,1);
//OUT.color=float4 (mx,mx,mx,mx);

//OUT.color=flomaxx;
//OUT.color=1;
//OUT.color=0.2+basetexture;
//OUT.color=mx;
//maxx;
//OUT.color=(0.5+0.5*cll1);
//OUT.color=HCOL2+HCOL;


//OUT.color=cll4+(maxx*HCOL2*basetexture+HCOL*mx)*(0.5+0.5*cll1);
//OUT.color=(maxx*basetexture*4*cll4)*(0.5+0.5*cll1);;
//OUT.color=(maxx*(mx*mx*mx+basetexture)*4*cll4)*(0.5+0.5*cll1);;
//OUT.color=round(OUT.color*44)/44;



//OUT.color=HCOL*cll4;

//OUT.color=(maxx*HCOL2);
//OUT.color=mxl1);
//OUT.color=basetexture*0.1+texCUBE (cube,oNormal);
//OUT.color=basetexture*0.5+tex2D (cubes,oUV)*50;

//OUT.color=basetexture*0.2+cll4*1;

//OUT.color=(maxx*HCOL2*basetexture+HCOL*mx);
//OUT.color=basetexture;

//OUT.color=basetexture+0.1;
//OUT.color=(maxx*HCOL2*basetexture+HCOL*mx);

//OUT.color=(maxx*HCOL2*basetexture+HCOL*mx);
//OUT.color.w=0.9;
//OUT.color=(maxx*HCOL2*cll4*cll1);
//OUT.color=(HCOL2);
//OUT.color=HCOL*mx;
//OUT.color=HCOL2;

//OUT.color=cll1;
//if (basetexture.x>0.05) OUT.color.w=1;elseOUT.color.w=0;
//OUT.color=HCOL*maxx;

//OUT.color=(maxx*HCOL2*basetexture+HCOL*mx)*(cll1);
//OUT.color=basetexture*cll1;
//OUT.color=(maxx*HCOL2+HCOL*mx)*(0.5+0.5*cll1);
//OUT.color.xyz*=0.3;
//OUT.color.xyz+=0.05;

//OUT.color=HCOL*mx;
//OUT.color=basetexture;

//OUT.color=Allwhite*basetexture*(cll4+(cll1)-cll4*cll1);


//OUT.color=cll1*(1-cll1);


//k+(1-2*k)*a;

//a
//1-a


//OUT.color=HCOL2*basetexture*(cll1);

//float4 blue=float4 (0,0,0.5,1);
//OUT.color=HCOL2*basetexture*cll1*(blue+0*cll4);

//OUT.color=(HCOL2*basetexture);

//OUT.color=(maxx*Allwhite);

//OUT.color=(mx*HCOL2);
//OUT.color=normals;
//OUT.color=HCOL;

	return OUT;




}









































/* 


  FRAGMENT ENV MAP 



  struct C2E2f_Output { 
	float4 color: COLOR;
};


C2E2f_Output main (    float2 oPosition : TEXCOORD0,
    float2 oPosition2 : TEXCOORD1,
	uniform sampler2D decal,			   
	uniform sampler2D decal2					   
				   ) 
{



	C2E2f_Output OUT;

//float fc=1;
//fc=position.x;
	//float2 norm;
	//norm.x=oNormal.x;
	//norm.y=oNormal.y;

OUT.color=tex2D (decal2,oPosition);

float dx=ddx(OUT.color.x);
float dy=ddx(OUT.color.x);

oPosition2.x+=dx*1;
oPosition2.y+=dy*1;


  OUT.color=tex2D (decal,oPosition2);




  
  
  //OUT.color.y=0;
//OUT.color.z=0;
//  OUT.color-=tex2D (decal,oPosition2);


	return OUT;




}
*/