struct C2E2f_Output { 
	float4 color: COLOR;
};



C2E2f_Output main (    float2 oPosition : TEXCOORD0,
	uniform sampler2D decal,			   
	uniform sampler2D decal2,			   
//uniform sampler2D decal3,
//float4 cl : COLOR
//float4 HCOL2 : COLOR0
 uniform float alpha,
 uniform float RightV,
 uniform float UpV

 ) 
{


	C2E2f_Output OUT;





	float4 cl;

float PI=3.1415926535;
float2 UV=oPosition;

UV-=float2 (0.5,0.5);
UV*=2.0;


float3 DirV =float3 (UV.x,UV.y,0.6);
//normalize (DirV);
float lgn=length (DirV);
DirV/=lgn;
//DirV/=length (DirV);
//UV.x=UV.x+(sin ((UV.x)*PI/2.0)-UV.x)*0.5;
//UV.y=UV.y+(sin ((UV.y)*PI/2.0)-UV.y)*0.5;
//UV.y=sin ((UV.y)*PI/2.0);
//UV.y=sin (UV.y*3.1415926535/2.0);
//UV.x=pow (UV.x,2);
//UV.y=pow (UV.y,2);
float2 VV1=float2 (0.0030,0.0)*UV*1;
float2 VV2=float2 (0.00,0.0055)*UV*1;


UV.xy=UV.xy+(DirV.xy-UV.xy)*alpha;
//alpha;



//float r = atan2(sqrt(UV.x*UV.x+y*y),p.z) / pi
//float phi = atan2(y,x) 







UV*=0.5;
UV+=float2 (0.5,0.5);

OUT.color=2*tex2D(decal,UV)+
tex2D(decal,UV+VV1)*float4 (1,1,1,1)+
tex2D(decal,UV+VV2)*float4 (1,0,0,1)+
tex2D(decal,UV-VV1)*float4 (0,0,1,1)+
tex2D(decal,UV-VV2)*float4 (2,3,2,1);


//OUT.color=tex2D(decal,UV)*float4 (1,0,0,1);
//OUT.color+=tex2D(decal,UV+VV1)*float4 (0,1,0,1);
//OUT.color+=tex2D(decal,UV+VV1*2)*float4 (0,0,1,1);


//saturate(lgn);
float rec=saturate(1-0.4*lgn);
//rec=1;
/*
OUT.color=tex2D(decal2,UV)+(OUT.color-tex2D(decal2,UV))*rec;
VV1*=2;
OUT.color+=tex2D(decal2,UV)*float4 (1,0,0,1);
OUT.color+=tex2D(decal2,UV+VV1)*float4 (0,1,0,1);
OUT.color+=tex2D(decal2,UV+VV1*2)*float4 (0,0,1,1);

*/

float2 Clt=float2 (RightV,UpV)*1.0/8.0;

OUT.color/=6.0f;
//OUT.color=tex2D(decal2,UV);

float4 ress=float4 (0,0,0,0);


if ((length (Clt)>0.0015) && (length (Clt)<0.0035))
{ 
	 
for (int r=0;r<4;r++) { 
ress+=tex2D (decal,UV+Clt*r*0.20)/4.0f;
};
OUT.color=OUT.color+(ress-OUT.color)*0.5;

}
else
if (length (Clt)>0.0035) 
{ 
	 
for (int r=0;r<8;r++) { 
ress+=tex2D (decal,UV+Clt*r*0.20*0.35)/8.0f;
};
OUT.color=OUT.color+(ress-OUT.color)*0.5;
//OUT.color+=float4 (0.1,0.2,0,1);
}





OUT.color*=saturate (2-1.2*lgn);





//OUT.color=OUT.color+(2*tex2D(decal2,UV)-OUT.color)*0.5;
//OUT.color=tex2D(decal,UV)*3-tex2D(decal,UV+VV1)*1-tex2D(decal,UV-VV1)*1;
//OUT.color*=saturate(pow(1.5*rec,5));
//*float4 (0,1,0.5,0.5);

//OUT.color=1;

//OUT.color=0.4+noise (oPosition.x*1000);

/*
OUT.color.z=cl.x/11.9f;
OUT.color.y=cl.y/11.9f;
OUT.color.x=cl.z/11.9f;

*/


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;




}
*/