#version 150
attribute vec3 pos;
attribute vec2 tc; 
attribute vec3 normal; 
varying vec3 n; 
varying vec2 tex;
flat out vec2 fTex; 
flat out vec3 fNormal;
varying float z; 
varying float y; 
varying vec3 opos; 
varying vec3 ipos; 
uniform mat4 viewproj; 
uniform mat4 view;
uniform float time; 

void main()
{	
	tex = tc*1.0;//(pos.xy+1.0)/2.0;
	fTex = tc*1.0;
	gl_Position = viewproj*vec4(pos.x*128.0, .15*pow(pos.z*0.50, 2.0), pos.y*128.0*4.0, 1.0);
	gl_Position = viewproj*vec4(pos.x*128.0, pos.z, pos.y*128.0*4.0, 1.0);
	gl_Position = viewproj*vec4(pos.xyz, 1.0);

	vec3 adjPos = vec3(pos.x*2.0, 8.0*pow(pos.y, 0.3500), pos.z);
	adjPos = pos.xyz;
	adjPos.x *= 2.0;
	adjPos.y = 250.0*(pow(pos.y, 0.25));
	adjPos.y = pos.y;
	//vec3 adjPos = vec3(pos.x*2.0, 150.0*pow(pos.y, .500), pos.z);
	gl_Position = viewproj*vec4(adjPos, 1.0);

	z = pos.z;
	y = adjPos.y; 
	opos = (view*vec4(adjPos.xyz, 1.0)).xyz;
	ipos = adjPos.xyz;
	n = normalize(normal);
	fNormal = n;
}	

//FRAGMENT
//#version 150
flat in vec2 fTex;
flat in vec3 fNormal; 
uniform sampler2D Texture0; 
uniform sampler2D Texture1; 
uniform float time; 
uniform mat3 nview;
uniform mat4 tview;
uniform vec3 eyePos;
float rand(vec2 co)
{
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

void main()
{  
	gl_FragColor = vec4(.220);
	gl_FragColor = mix(gl_FragColor, vec4(.82), min(1.0, -z/600));

	gl_FragColor.rgb = n;
	gl_FragColor = vec4(tex, 0, 0);
	gl_FragColor = vec4(normalize(.5+.5*n), 0);
	//gl_FragColor = vec4(.5+.5*normalize((fNormal)), 0);
	//gl_FragColor = vec4(gl_Position);

	if (tex.x>.7475 && tex.x<.7525 )
	//if (tex.x>.2475 && tex.x<.2525 )
		gl_FragColor = vec4(1.0,y/120.0,0,0);

	//gl_FragColor = vec4(fTex, 0.0, 1.0);
	return; 
	vec4 p = gl_FragCoord; 
	vec4 pdx = dFdx(gl_FragCoord);
	vec4 pdy = dFdy(gl_FragCoord);
	//pdy.w = pdx.w = 1.0;
	p.z = p.z/p.w;
	pdx.z = pdx.z/pdy.w;
	pdy.z = pdy.z/pdy.w;
	vec3 v1 = normalize(p.xyz-(pdx.xyz));
	vec3 v2 = normalize(p.xyz-(pdy.xyz));
	vec3 sn = normalize(cross(v1, v2));

	gl_FragColor = vec4(sn, 1.0);
}
