

#include "/lib/shadow_param.glsl"
#include "/lib/uniforms.glsl"

#include "/lib/taa/res_params.glsl"
uniform mat4 gbufferModelViewInverse;
varying vec4 lmtexcoord;
varying vec4 color;
varying vec3 normalMat;
flat varying float emissive;
flat varying float translucent;

attribute vec4 mc_Entity;

//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////

vec3 viewToWorld(vec3 viewPos)
{
    return (gbufferModelViewInverse * vec4(viewPos, 0.0)).xyz;
}

#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec4 toClipSpace3(vec3 viewSpacePosition)
{
    return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition), -viewSpacePosition.z);
}
void main()
{
    lmtexcoord.xyzw = vec4(gl_MultiTexCoord0.xy, (gl_MultiTexCoord1.xy * recip));
#ifdef COMPLEX_NORMALS
    normalMat = viewToWorld(normalize(gl_NormalMatrix * gl_Normal));
#else
    normalMat = gl_Normal;
#endif
    color = gl_Color;
    emissive = 0.0;
    int entityCheck = int(mc_Entity.x);

    // Emissive Check
    emissive = (entityCheck == 1 || lmtexcoord.z > 0.94) ? 1.0 : 0.0;

    if (mc_Entity.x == 1)
    {
        lmtexcoord.z *= 2.0;
    }
    vec3 position = mat3(gl_ModelViewMatrix) * gl_Vertex.xyz + gl_ModelViewMatrix[3].xyz;

#if defined ENTITY && defined NO_ENTITY_TAA
    gl_Position = toClipSpace3(position);

#else
    gl_Position = taaFunc(toClipSpace3(position), frameCounter, viewResolution);
#endif
}
