#define	GLSL_SWT_NONE		0.0
#define	GLSL_SWT_GGGR		1.0
#define	GLSL_SWT_BRBG		2.0
#define	GLSL_SWT_AGAR_NM	3.0
#define	GLSL_SWT_NONE_NM	4.0

vec4 Swizzle(in vec4 t, in float swizzle)
{
	if (swizzle == GLSL_SWT_NONE)
		return t;

	if (swizzle == GLSL_SWT_GGGR)
		return vec4(t.a, t.g, 1.0, 1.0);

	if (swizzle == GLSL_SWT_BRBG)
		return vec4(t.g, t.a, t.r, 1.0);

	if (swizzle == GLSL_SWT_AGAR_NM)
	{
		vec2 nm = vec2(t.a, t.g) * 2.0 - 1.0;
		return vec4(nm, sqrt(1.0 - clamp(dot(nm, nm), 0.0, 1.0)), t.r);
	}

	// GLSL_SWT_NONE_NM
	return t * vec4(2.0, 2.0, 2.0, 1.0) - vec4(1.0, 1.0, 1.0, 0.0);
}

vec4 Texture(in sampler2D map, in vec2 texCoord, in float swizzle)
{
	return Swizzle(texture(map, texCoord), swizzle);
}

vec4 TextureLod(in sampler2D map, in vec2 texCoord, float lod, in float swizzle)
{
	return Swizzle(textureLod(map, texCoord, lod), swizzle);
}
