#version 120

#define IDLE_HANDS //Makes your hands sway back and forth in 1st person, like they do in 3rd person
#define RAINBOW_ENCHANTMENTS //If enabled, the enchantment glint will be rainbow instead of the default purple color

uniform float frameTimeCounter;
uniform mat4 gbufferModelViewInverse;
uniform vec3 actualCameraPosition;

varying vec2 lmcoord;
varying vec2 texcoord;
#ifdef RAINBOW_ENCHANTMENTS
	varying vec3 rainbowPos;
#endif
varying vec3 vPosView;
varying vec4 tint;

void main() {
	vPosView = (gl_ModelViewMatrix * gl_Vertex).xyz;

	if (gl_ProjectionMatrix[2][2] > -0.5) {
		#ifdef IDLE_HANDS
			vPosView.xy += sin(frameTimeCounter * vec2(1.6, 1.2)) * (sign(gl_ModelViewMatrix[3][0] + 0.3125) * 0.015625);
		#endif
		#ifdef RAINBOW_ENCHANTMENTS
			rainbowPos = vPosView * 2.0;
		#endif
	}
	#ifdef RAINBOW_ENCHANTMENTS
		else {
			rainbowPos = mat3(gbufferModelViewInverse) * vPosView + actualCameraPosition + vec3(0.5); //center of noisetex pixels should align to the edges of blocks.
		}
	#endif
	gl_Position = gl_ProjectionMatrix * vec4(vPosView, 1.0);

	texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
	lmcoord  = (gl_TextureMatrix[1] * gl_MultiTexCoord1).xy;
	//bug fix: in 1.17 these numbers are *vastly* outside their intended range,
	//and also they don't seem to change with the *actual* light level.
	//this fix is not necessary in the main edition of QOL,
	//since that doesn't use lmcoord in gbuffers_armor_glint.
	lmcoord  = clamp(lmcoord, vec2(1.0 / 32.0), vec2(31.0 / 32.0));
	tint  =  gl_Color;
}