#version 400

uniform sampler2D gBufferMap;
uniform int mapType;

smooth in vec2 VS_TexCoord;

layout(location = 0) out vec4 colorOut;


vec3 spheremapDec(vec2 enc)
{
  vec3 ret = vec3(enc * 2.0f, 0.0f) + vec3(-1.0f, -1.0f, 1.0f);
  float l = dot(ret.xy, -ret.xy) + 1.0f;
  ret.z = l;
  ret.xy *= sqrt(l);
  return ret.xyz * 2.0f + vec3(0.0f, 0.0f, -1.0f);
}

void main()
{
	switch(mapType)
	{
		case 0:
		{
			vec3 N = spheremapDec(texture(gBufferMap, VS_TexCoord).xy);
			colorOut = vec4(N, 1.0);
			break;
		}
		case 1:
		case 2:
		case 3:
		{
			colorOut = texture(gBufferMap, VS_TexCoord);
			break;
		}

	}
}	

