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,
                      float3 oEye : TEXCOORD5,
                      float3 oNormal : TEXCOORD3,



                    uniform float3 alpha,  
                    uniform float alpha2,  
                   uniform sampler2D decal,
				   uniform sampler2D light,
                 uniform samplerCUBE cube,
				   uniform sampler2D texture,
                   uniform sampler1D oned,
				   uniform sampler2D texture2
                  //uniform samplerCUBE cube
//                   uniform sampler2D cubes
//uniform float3 lightPosition

                   ) 
{



	C2E2f_Output OUT;
float depth=0;
depth=tex2D(decal,oUV);

//depth*=5*(tex2D (light,oUV));

//depth*=depth;
//depth=min(0.1,depth);

float height=(tex2D(decal,oUV)-0.5)*0.13;

//height*=tex2D(light,oUV);
//float3 tanEyeVec = normalize((oEye-0.5)*2);
float3 tanEyeVec = oEye;
//tex2D(decal,oUV)*0.07;
//tanEyeVec=float3 (0,1,0);
//tanEyeVec=float3 (1,0,0);
float2 oUVold;
oUVold=oUV;


//height*=tex2D(light,oUV);
//float height2=tex2D(texture2,oUV)-0.5;

oUV+=(1-tex2D(light,oUV))*float2 (0,1)*0.2;


//FIRE
oUV+=height*tanEyeVec.xy;


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


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



//normal*=tex2D (light,oUV*3)*2.2;

//normal*=(tex2D (light,oUV*2));


//normal*=0.5;
 //normal=((tex2D (texture2,oUV)-0.5)+(tex2D (texture,oUV)-0.5));
//float maxx=dot(normal,oLight)+pow (dot(normal,oHalf),20);
float maxx=dot(normal,oLight);
//maxx=pow(maxx,6);
//maxx*=maxx;
//if (dot(normal,oHalf)>0) maxx=1; else maxx=0;
//normal*=depth*1.1;
//normal*=basetexture;
//oHalf+=tex2D(light,oUV);

float mx=max (0,dot(normal,oHalf));

//mx=sin(mx*2);
mx=pow(mx,12);

mx*=3.6;
mx+=1.0;
//basetexture*=1+15*mx*(tex2D (light,oUV*2));
//basetexture*=tex2D (decal,oUV);
basetexture*=(tex2D (decal,oUV));
//basetexture*=tex2D(light,oUV);
mx*=tex2D (decal,oUV).xyzz;


//basetexture*=(1+1*tex2D (light,oUV*7));

//mx=1+(mx-1)*depth;
//oPosition.xy+=4*normal.xy;
//oPosition.w+=normal.z*8;

//oPosition.w-=normal.z*4;

//normal+=(1+0.8*tex2Dproj (light,oPosition))*0.1;
//if (height<0.075*(-alpha2)) mx=0;



float4 ColorGreen=HCOL;
float4 ColorRed=float4 (4,1.0,0,1);
 //ColorGreen=float4 (0.3,0.7,1,1);
 //ColorRed=float4 (0,1.5,4,1);
float4 lit=tex2D (light,oUV);
ColorRed=ColorRed+(ColorGreen-ColorRed)*lit*lit;

OUT.color=basetexture*mx*tex2D(light,oUV)*float4 (1,0.7,0.4,1);


OUT.color=basetexture*mx*tex2D(light,oUV)*ColorRed;


//OUT.color=depth;

//FIRE

//OUT.color=basetexture*mx;;
//
//*mx*float4 (1,0.7,0.5,1);

//OUT.color=tex2D(decal,oUV);


//*(1+0.8*tex2Dproj (light,oPosition));
//*float4 (1,0.7,0.4,1);

//OUT.color=tex2Dproj (light,oPosition);

//OUT.color=tex2Dproj (light,oPosition);
//*float4 (1,0.7,0.4,1);
//OUT.color=basetexture;


//basetexture=float4(0,0,0,1)+(basetexture-float4(0,0,0,1))*max (0,min (1,alpha2+pow(tex2D(decal,oUV)+0.4,18)));
//OUT.color=basetexture;
//OUT.color=height*tanEyeVec.x*float4 (10,0,0,1);
//OUT.color=tanEyeVec.xyzz;
//OUT.color=maxx;
//OUT.color=float4 (0.0,0.0,0.0,0)+(HCOL*(OUT.color-float4 (0.0,0.0,0.0,0)));
//OUT.color*=mx;
//OUT.color=texCUBE (cube,oHalf.xyz);
//OUT.color=texCUBE (cube,oHalf.xyz);
//(tex2D (decal,oUV*11))*(cll4+0.5)*(basetexture)*HCOL2;

//OUT.color=(tex2D (decal,oUV*11))*(cll4+0.5)*HCOL2;

//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;


	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;




}
*/