#version 110
#define float4 vec4
#define float3 vec3
#define float2 vec2
#define oUV gl_TexCoord[0]
#define tex3D texture3D
#define tex2D texture2D
#define tex1D texture1D
varying vec4 Color;

varying vec3 normal;

				uniform sampler2D texture2d_1;
				uniform sampler2D texture2d_2;
				uniform sampler2D texture2d_3;
				uniform sampler2D texture2d_blob;
				//uniform sampler2D texture2d_2;

				uniform samplerCube texture2d_cube;

	uniform float PosY;
	uniform float ttime;
varying vec3 position;
varying vec4 positionProj;
varying vec4 normalB;



void main (void) 
{


//float4 TheNormal=(nnormal.xyzz+float4 (1.0))*0.5;
//TheNormal.w=shadow;

//if (sin (position.z*5.0)*sin(position.y*5.0)<-0.5) discard;

vec3 Normal= (normal);

float dott=dot(normal.xyz,vec3 (1.0,0.0,0.0));
dott=clamp (dott,0.0,1.0);
dott=pow(dott,5.0);
dott=1.0+dott*1.4;



//Normal.x*=Normal.x*(Normal.x*Normal.x);
//Normal.y*=Normal.y*(Normal.y*Normal.y);
//Normal.z*=Normal.z*(Normal.z*Normal.z);
Normal=normalize (Normal);
vec4 Norm=(Normal.xyzz+float4 (1.0))*0.5;

vec4 res=vec4 (0.8)*dott*vec4 (0.7,0.6,0.3,0.2);
res=res+ (Norm.xyzz-res)*0.2;
res*=vec4 (0.7,0.8,0.9,1.0)*0.6;


res=vec4 (1.0);
dott=dot(normal.xyz,vec3 (0.0,0.0,1.0));
dott=clamp (dott,0.0,1.0);
dott=pow(dott,5.0);
dott=0.3+dott*3.0;
res*=dott*vec4 (0.5,1.0,1.0,1.0);





dott=dot(normalize (normal.xyz),vec3 (0.0,-0.6,-0.5));
dott=clamp (abs(dott),0.0,1.0);
dott=0.1+6.5*pow(dott,3.0);
res=dott*0.54*vec4 (0.7,0.5,0.4,1.0);




//float ft=texture2D (texture2d_1,position.xz*3.5).x;

//res*=0.5;
//res=vec4 (0.0);
//res=vec4 (0.2);
float PosL=PosY;
//res=res+ (Norm.yzxz-res)*0.07;
//res=vec4(0.3);
//res*=1.0+0.2*texture2D (texture2d_1,position.zy*0.04+vec2 (0.5));
float fff=tex2D (texture2d_1,position.xz*0.004+ttime*0.003).x;
 fff*=tex2D (texture2d_1,position.xz*0.010-ttime*0.002).x;

 fff=pow (fff*2.7,13.0);
//res*=vec4 (0.5,0.9,1.0,1.0)*5.5*tex2D (texture2d_blob,vec2 (0.95,0.5)*0.49+positionProj.st*vec2 (0.0009,0.0009));
res*=0.7+0.9*vec4 (fff);
res*=0.2+1.0*vec4 (0.5,1.0,1.1,1.0)*0.7;
//res=res+ (Norm.yzxz-res)*0.07;
res*=0.9;
//res*=1.0+121.3*pow(texture (texture2d_cube,normalB.xyz).x,6.0);

res*=1.0+0.8*pow( 1.7*tex2D (texture2d_1,position.xz*0.002).x,8.0)*vec4 (0.6,0.9,1.0,0.0);
res*=1.0+0.3*pow( 1.7*tex2D (texture2d_1,position.xz*0.004+vec2(ttime*0.01)).x,8.0)*vec4 (0.4,0.4,0.4,0.0);
//res*=pow( PosY*tex2D (texture2d_1,position.zy*0.06).x,8.0);

//discard;
res+=0.2*(tex2D (texture2d_3,position.zy*0.45+vec2 (0.0))-vec4 (0.5));
res+=0.2*(Color-vec4 (0.5));
float thew=1.0;
if (Color.x>0.9)
{
	res+=vec4 (1.0,0.9,0.6,1.0);
	thew=0.0;
}

//res=v;
//res*=0.8;
//res=vec4 (0.5);
gl_FragData[1]=res;
gl_FragData[0]=Norm;
gl_FragData[0].w=thew;
//Diffuse+float4 (0.5);
//gl_FragData[1]=float4 (0.3,0.3,0.3,0.3);

}














