

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

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

attribute vec4 mc_Entity;

uniform sampler2D gaux3;

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()
{

    float skysize = 1.0;

#if CLOUD_QUALITY == 3
    skysize = 1.0;
#endif

#if CLOUD_QUALITY == 2
    skysize = 0.75;
#endif

#if CLOUD_QUALITY == 1
    skysize = 0.5;
#endif
    color = gl_Color;

    vec3 viewVector = (gl_ModelViewMatrix * gl_Vertex).xyz;

    np3 = (viewToWorld(viewVector));

    vec3 position = mat3(gl_ModelViewMatrix) * gl_Vertex.xyz + gl_ModelViewMatrix[3].xyz;

    gl_Position = taaFunc(toClipSpace3(position), frameCounter, viewResolution);

    gl_Position.xy = gl_Position.xy * skysize + skysize * gl_Position.w - gl_Position.w;
}
