<Shader>
	<VertexShader>
		<Code>
			#version 120
			varying vec2 Texcoord;
			varying vec3 Normal;
			varying vec3 LightDir;
			varying vec3 ViewDir;
	
			uniform mat4 Jen_ModelViewProjectionMatrix;
			uniform vec3 Jen_ViewPos;
			uniform vec3 Jen_LightPos;
			
			attribute vec3 PositionAttr;
			attribute vec3 NormalAttr;
			
			void main( void )
			{
				Texcoord = NormalAttr.xz * NormalAttr.y;
				Normal = NormalAttr;
				Normal.xz = Normal.xz * (1.0-Normal.y);
				
				LightDir = Jen_LightPos - PositionAttr;
				ViewDir = Jen_ViewPos - PositionAttr;
				
				gl_Position = Jen_ModelViewProjectionMatrix * vec4(PositionAttr, 1.0);
			}
		</Code>
	</VertexShader>
	
	<FragmentShader>
		<Code>
			#version 120
			uniform sampler2D NormalMap;

			varying vec2 Texcoord;
			varying vec3 Normal;
			varying vec3 LightDir;
			varying vec3 ViewDir;
	
			void main( void )
			{
				float LightLength = length(LightDir);
				vec3 nViewDir = normalize(ViewDir);
				vec3 nLightDir = LightDir/LightLength;
				vec4 Sample = texture2D(NormalMap, Texcoord);//mix(texture2D(NormalMap, Texcoord), vec4(0.0,0.0,1.0,1.0), min(length(ViewDir)*0.01,1.0));

   				vec3 rNormal = normalize( mat3(vec3(0.0,0.0,1.0),vec3(1.0,0.0,0.0), Normal) * (Sample.xyz*2.0 - 1.0));
				rNormal = mix(Normal, rNormal, Normal.y);
   
				float fRDotV = clamp(dot(reflect(-nLightDir, rNormal), nViewDir),0.0, 1.0);
				float fresnel = 1.0 - clamp(abs(dot(nViewDir,rNormal)), 0.1, 0.9);
				
				float Ndotl = max(dot(rNormal,nLightDir),0.0);
				float Spec = mix(pow(fRDotV, 20.0)*2.85+pow(fRDotV, 400.0)*2.85,0.0,min(LightLength*0.014,1.0));
				float Diff = mix(Ndotl,mix(Ndotl*0.28,0.0,min(LightLength*0.01,1.0)),min(LightLength*0.02,1.0));
				vec3 color = abs(normalize(ViewDir))* Sample.w *(0.07 + Spec*fresnel + Diff);
			
				//vec3(0.33,0.0,1.0);
				
				gl_FragColor = vec4(color,1.0);
			}
		</Code> 
	</FragmentShader>
</Shader>
