void main ( 
		   float4 oPosition : TEXCOORD1,
		   float4 oPosition2 : TEXCOORD5,
		   float4 oThePos : TEXCOORD6,
                      float2 oUV : TEXCOORD0,
                      float4 HCOL : COLOR, 
                      
	float4 HCOL2 : COLOR1,
	float3 Ramp : TEXCOORD7,
                      
                      float3 oLight : TEXCOORD2,
                      float3 oHalf : TEXCOORD4,
                      float2 uvl : TEXCOORD5,
                      float3 oNormal : TEXCOORD3,



                    uniform float3 alpha,  
                    uniform float alpha2,  
                    uniform float planecut,  
                   uniform sampler2D decal,
				   uniform sampler2D light,
                 uniform samplerCUBE cube,
				   uniform sampler2D texture,
                   uniform sampler1D oned,
				   uniform sampler2D texture2,
				   out float4 oColor1: COLOR0,
out float4 oColor2: COLOR1
//                   uniform samplerCUBE cube
//                   uniform sampler2D cubes
//uniform float3 lightPosition

                   ) 
{





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


//if (length (oThePos.xy)<22) discard;



float flame=planecut;

float mltc=0;

float therange=tex2D(decal,oPosition2.xy*0.003).x;

if (therange<flame) discard;
if (therange<flame+0.1) mltc=1;



//if (sin(oThePos.x*0.16+planecut*10)*cos(oThePos.z*0.16)>0.3) discard;

float3 normal=((tex2D (texture,oUV)-0.5)*2);

//float maxx=dot(normal,oLight)+pow (dot(/normal,oHalf),20);
float maxx=0.7+0.7*dot(oNormal,oLight);
//maxx*=maxx;
//if (dot(normal,oHalf)>0) maxx=1; else maxx=0;
float mx=max (0,dot(normal,oHalf));
mx=pow(mx,30);
mx*=2.5;

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


float4 cll1=tex2Dproj (decal,oPosition);





basetexture=tex2D (texture2,oUV)+0.4;




//if (oThePos.y>0.1) discard;

//if (oThePos.y>tex2D(texture2.oUV).x*10) discard;

//oPosition2.xy*=2;
 float4 cll4=tex2Dproj (decal,oPosition.xyw);
 
cll4=1;
 
// if (-tex2D (decal,oThePos.yx*0.005).x*3+tex2D (decal,oThePos.xz*0.005).x*5<planecut) discard;

 
// if (tex2D (texture2,oThePos.xz*0.025).x*5+3*oThePos.y>planecut) discard;
//if (tex2D (texture2,oThePos.xz*0.025).x*5+3*oThePos.y>planecut) discard;

//if (tex2D (decal,oThePos.xz*0.017+0.5).x*5+	10*oThePos.y>3) discard;

float cc=tex2D (decal,oThePos.xz*0.076+0.5+float2 (0,-0.1)).x;
cc=pow(cc,4)*10;
//if (oThePos.y>-0.4) if (cc>0.2) discard;
//if (tex2D (texture2,oPosition.xy*0.015).x*35+	24*(oThePos.y-0.0)>28) discard;




float4 mm=1;
//+tex2D (texture2,oPosition.xy*0.012).yxzz;

// TODO UNDERWTAER
// if (tex2D (decal,oThePos.xz*0.055).x*15+abs(10.2*oThePos.x)>12) discard;



float multt= tex2D (texture2,oPosition.xy*0.01).x*10-oPosition2.y*4.2;
if (multt>+3.05) multt=0.1; else multt=0;
//multt*=0.05;
//multt=1;
//if (sin(oThePos.y*planecut)*cos(oThePos.z*planecut)>0.9) discard;

float4 nrr=oThePos.xyzz;

//if ((sin(oThePos.y*planecut)+cos(oThePos.x*planecut))>0.9) discard;


//float zmm=1+abs(10*(sin(oThePos.y*planecut)*(sin(oThePos.x*planecut))));

//if (pow(sin(oThePos.y*planecut),10)+pow(sin(oThePos.z*planecut),10)>0.9) discard;


//oPosition2.xy+=cll4.xy*1.5;
//oPosition2.xyz+=cll4.xyz*0.01;
 basetexture=2*(tex2D (texture2,-134*oPosition2.xy))+1.5;
basetexture*=cll4+0.2;
 //oPosition2.xy+=cll4.xy*20;
// oPosition.xyw+=100*HCOL2.xyz;
 //float4 cll4n=tex2Dproj (decal,oPosition.xyw);




 //if (tex2D (light,-1*oPosition2.xy).x*10<planecut) discard;




 //oPosition2.xy+=HCOL2.xy;

/*
OUT.color=(HCOL2*basetexture*maxx+mx*cll4);
OUT.color=(maxx*HCOL2*basetexture+HCOL*mx)*(0.5+0.5*cll1);
*/
//OUT.color=maxx*((basetexture*HCOL2+HCOL2+0.3*mx))*(0.6+0.4*cll1);
//OUT.color=maxx*((basetexture*HCOL2+HCOL2+0.3*mx));
//
float4 coll=tex2D(light,-oUV*0.5)*float4 (0.8,0.3,0.2,1);
//OUT.color=(tex2D (decal,oUV*9))*0.7*(cll4+0.5)*(basetexture)*0.4*HCOL2;
//OUT.color=(tex2D (decal,oUV*11))*(cll4+0.5)*(basetexture)*HCOL2;







oColor1=(oNormal.xyzz+1)*0.5;
//oColor1*=saturate (pow(Ramp.x*5,10));
//if (cll4.x< 

//if ((oPosition.z)/oPosition.w<cll4+0.0001)  cll4=1; else cll4=0;

oColor2=(HCOL*basetexture+HCOL2*166*float4 (0.2,0.6,0.89,0.1))*1+multt*float4 (0.4,0.2,0,0)*1;


oColor2=multt*0.1*float4 (0.7,1,1.3,1)*0.3;
//(HCOL*basetexture+HCOL2*166*float4 (0.2,0.6,0.89,0.1))*1+multt*float4 (0.4,0.2,0,0)*1;
//oColor2*=0.8+cc*20;
oColor2+=cc*float4 (1,1.4,1.9,1)*0.3*0.1;
oColor2=HCOL+mltc*float4 (1,0.3,0.1,1)*0.1;
oColor2.w=Ramp.x*80;

//+multt*float4 (0.2,0.4,0.5,1);
//oColor2=0.5;
// TODO UNDERWATER
//oColor2*=4*float4 (1.3,0.6,0.2,1);



//oColor2=HCOL2*8*float4 (0.2,0.3,1,1)*mm;
//oColor2.x+=-oThePos.y*0.04;
//oColor2=HCOL2*10*float4 (1.0,0.2,0.1,1);
//oColor2.w=1;
//*(1+8*pow(tex2D (texture2,oThePos.xz*0.015),8));
//oColor2=HCOL2;
//oColor2=basetexture;
//oColor2=(oNormal.xyzz+1)*0.1;
//+HCOL2*float4 (0.2,0.3,0.4,0.1));
//oColor2=HCOL2;
//oNormal.xyzz;
//(HCOL*basetexture+HCOL2*float4 (0.2,0.3,0.4,0.1));
//oColor2=HCOL2*basetexture;





//oColor2=HCOL*0.1;;
//*basetexture;
//*cll4;
//*cll4;
//oColor2=cll4;
//OUT.color=(tex2D (decal,oUV*10))*(cll4+0.5+coll)*(basetexture)*HCOL2;

//OUT.color=*basetexture;
//basetexture*float4 (0.4,0.2,0.2,0.1);



//OUT.color=cll4;






}









































/* 


  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;




}
*/