<?xml version="1.0" encoding="UTF-8" ?>
<shader>
	<fragment><![CDATA[
		#version 150
		
		const vec4 terrain_Color = vec4(0.3, 0.8, 0.1, 1.0);
		const float terrain_GridSize = 0.1;

		smooth in vec2 frag_Texture;

		out vec4 frag_Color;

		void main()
		{
			vec2 f = fract(frag_Texture);
			float u = sin(f.x) + 1.0 / 2.0;
			float v = sin(f.y) + 1.0 / 2.0;
			float c = mix(0.7, 1.0, (u + v) / 2.0);
			
			if (f.x < terrain_GridSize || (1.0 - f.x) < terrain_GridSize ||
				f.y < terrain_GridSize || (1.0 - f.y) < terrain_GridSize)
			{
				c *= 0.9;
			}
			
			frag_Color = vec4(terrain_Color.rgb * c, terrain_Color.a);
		}
	]]></fragment>
	<vertex><![CDATA[
		#version 150

		uniform mat4 terrain_Projection;
		uniform mat4 terrain_View;
		uniform mat4 terrain_World;
		
		uniform vec3 terrain_CameraPosition;
		uniform float terrain_CurveFactor;

		in vec3 terrain_Position;
		in vec2 terrain_Texture;
		
		smooth out vec2 frag_Texture;
		
		void main()
		{
			vec4 p = terrain_View * terrain_World * vec4(terrain_Position, 1.0);
			
			if (terrain_CurveFactor > 0)
			{
				float z = (p.z + terrain_CurveFactor) / terrain_CurveFactor;
				p.y -= z * z;
			}
			
			gl_Position = terrain_Projection * p;
			
			frag_Texture = terrain_Texture;
		}
	]]></vertex>
</shader>
