// no fog version of tcGen.inc

uniform	vec2	u_tgen;
uniform	vec3	u_parmtc;
uniform	vec3	u_tcGenVectorS;
uniform	vec3	u_tcGenVectorT;
uniform	float	u_tcModParms[29];	// TR_MAX_TEXMODS * 6 + TR_MAX_TEXMODS + 1

#define	TCGEN_TEXTURE			1.0
#define	TCGEN_LIGHTMAP			2.0
#define	TCGEN_ENVIRONMENT_MAPPED	3.0
#define	TCGEN_FIRERISEENV_MAPPED	4.0
#define	TCGEN_VECTOR			6.0

#define	GLSL_TMOD_NONE			0.0
#define	GLSL_TMOD_TURBULENT		1.0
#define	GLSL_TMOD_MATRIX		2.0
#define	GLSL_TMOD_SWAP			3.0

void tcGen (out vec2 st, in vec3 glVertex)
{
	int tcOffs = 0;
	// texGen:
	st = vec2(0.0);		// TCGEN_BAD (default) shut up compiler :(
	if (u_tgen.x == TCGEN_TEXTURE)
		st = attr_texCoords;
	if (u_tgen.x == TCGEN_LIGHTMAP)
		st = attr_lightCoords;
	if (u_tgen.x == TCGEN_ENVIRONMENT_MAPPED)
	{	// u_parmtc = backEnd.or.viewOrigin
		vec3 viewer = normalize(u_parmtc - glVertex);
		float d = dot(attr_Normal, viewer);
		vec3 reflected = attr_Normal * 2.0 * d - viewer;
		st = 0.5 + reflected.yz * 0.5;
	}
	if (u_tgen.x == TCGEN_FIRERISEENV_MAPPED)
	{	// u_parmtc = normalize(-backEnd.currentEntity->e.fireRiseDir)
		float d = dot(attr_Normal, u_parmtc);
		vec3 reflected = attr_Normal * 2.0 * d - u_parmtc;
		st = 0.5 + reflected.yz * vec2(0.5, -0.5);
	}
	if (u_tgen.x == TCGEN_VECTOR)
		st = vec2( dot(glVertex, u_tcGenVectorS), dot(glVertex, u_tcGenVectorT) );

	// texMod:
	// unroll texMod loop (#define TR_MAX_TEXMODS 4)
	// for stupid NVidia GLSL compiler (new Detonator + old cards like 9600GT/8500GT)
	include tcMod.inc
	include tcMod.inc
	include tcMod.inc
	include tcMod.inc
}
