<shader>{
	"name":"HeightmapEditor",
	"ubo":[ "UBOTransform" ],
	"options": { "modelMatrix":true },
	"uniforms":[
		{ "name":"u_tex01", "type":"sampler2D" },
		{ "name":"u_texScale", "type":"vec2" },
		{ "name":"u_worldMouse", "type":"vec2" }	
	]
}<\shader>
	
<materials>[
	{ "name":"HeightmapEditor",
		"uniforms":[ 
			{ "name":"u_texScale",		"value":[1,1] },
			{ "name":"u_worldMouse",	"value":[2,2] }
		]
	}
]<\materials>			{ "name":"u_tex01",			"value":"tex01", "type":"tex" },
	
<vertex>
	#version 300 es
	layout(location=0) in vec3 a_position;
	layout(location=2) in vec2 a_uv;

	uniform UBOTransform{
		mat4 	projViewMatrix;
		vec3	cameraPos;
		float	globalTime;
		vec2	screenSize;
	};

	uniform mat4 u_modelMatrix;
	uniform vec2 u_texScale;
	uniform sampler2D u_tex01;

	out vec2 v_uv;
	out vec3 v_worldPos;

	vec3 heightMap(float h, vec3 pos, vec2 uv, sampler2D tex){
		pos.y = (texture(u_tex01, a_uv).r * 2.0 - 1.0) * h;
		return pos;
	}

	void main(void){
		v_uv		= a_uv * u_texScale;
		vec3 pos	= heightMap(2.0, a_position, v_uv, u_tex01);
		v_worldPos	= (u_modelMatrix * vec4(pos,1.0)).xyz;

		gl_Position	= projViewMatrix * u_modelMatrix * vec4(v_worldPos, 1.0);
	}
<\vertex>

<fragment>
	#version 300 es
	precision mediump float;
	
	in vec2 v_uv;
	in vec3 v_worldPos;
	
	uniform sampler2D u_tex01;
	uniform vec2 u_worldMouse;

	layout(location=0) out vec4 oFragColor;
	layout(location=1) out vec4 oUVColor;

	void main(void){
		vec3 c = vec3(0.0, 0.0, 0.0);

		if(u_worldMouse.x != 0.0 && u_worldMouse.y != 0.0){
			if(length(v_worldPos.xz - u_worldMouse) < 0.2){
				c.g = 0.1;
			}
		}

		oFragColor	= vec4(texture( u_tex01, v_uv ).rgb + c, 1.0);
		oUVColor	= vec4(v_uv,0.0,1.0); //vec4(1.0, 0.0, 0.0, 1.0);
	}
<\fragment>