// GUN 1
#version 450


// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
layout(set = 0, binding = 30, std140) uniform Vk3DParams
{
    vec4 stereo;
    vec4 custom_params;
} vk3d_params;

layout(set = 0, binding = 1, std140) uniform freqLow_vertexUniforms_ubo
{
    vec4 vertexxyzscale;
    vec4 vertexxyzbias;
    vec4 vertexstscalebias;
} freqLow_vertexUniforms;

layout(set = 0, binding = 0, std140) uniform freqHigh_vertexUniforms_ubo
{
    vec4 hardwareskinning;
    vec4 mvpmatrixx;
    vec4 mvpmatrixy;
    vec4 mvpmatrixz;
    vec4 mvpmatrixw;
    vec4 mvpmatrixnojitterx;
    vec4 mvpmatrixnojittery;
    vec4 mvpmatrixnojitterz;
    vec4 mvpmatrixnojitterw;
    vec4 mvpmatrixlastx;
    vec4 mvpmatrixlasty;
    vec4 mvpmatrixlastz;
    vec4 mvpmatrixlastw;
} freqHigh_vertexUniforms;

layout(set = 0, binding = 2, std140) uniform matrices_ubo
{
    vec4 matrices[768];
} _139;

layout(set = 0, binding = 3, std140) uniform matricesprevious_ubo
{
    vec4 matricesprevious[768];
} _549;

layout(location = 0) in vec4 in_Position;
layout(location = 9) in vec4 in_Tangent;
layout(location = 2) in vec4 in_Normal;
layout(location = 3) in vec4 in_Color;
layout(location = 3) out vec4 vofi_TexCoord1;
layout(location = 1) in vec2 in_TexCoord;
layout(location = 2) out vec4 vofi_TexCoord0;
layout(location = 4) out vec4 vofi_TexCoord2;

float dot4(vec4 a, vec4 b)
{
    return dot(a, b);
}

void main()
{
    vec4 localPosition = (in_Position * freqLow_vertexUniforms.vertexxyzscale) + freqLow_vertexUniforms.vertexxyzbias;
    if (freqHigh_vertexUniforms.hardwareskinning.x != 0.0)
    {
        vec4 tempPosition = localPosition;
        vec4 matX = vec4(0.0);
        vec4 matY = vec4(0.0);
        vec4 matZ = vec4(0.0);
        float hiweight = in_Tangent.w * 255.100006103515625;
        vec4 weights;
        weights.y = hiweight - (floor(hiweight / 128.0) * 128.0);
        float packedWeights = in_Normal.w * 255.100006103515625;
        weights.z = floor(packedWeights / 16.0);
        weights.w = packedWeights - (weights.z * 16.0);
        weights.y *= 0.00393700785934925079345703125;
        weights.z *= 0.02222222276031970977783203125;
        weights.w *= 0.01666666753590106964111328125;
        weights.x = 1.0 - ((weights.y + weights.z) + weights.w);
        uvec4 indices = uvec4(in_Color * 255.0);
        for (uint i = 0u; i < 4u; i++)
        {
            matX += (_139.matrices[(indices[i] * 3u) + 0u] * weights[i]);
        }
        for (uint i_1 = 0u; i_1 < 4u; i_1++)
        {
            matY += (_139.matrices[(indices[i_1] * 3u) + 1u] * weights[i_1]);
        }
        for (uint i_2 = 0u; i_2 < 4u; i_2++)
        {
            matZ += (_139.matrices[(indices[i_2] * 3u) + 2u] * weights[i_2]);
        }
        vec4 param = tempPosition;
        vec4 param_1 = matX;
        localPosition.x = dot4(param, param_1);
        vec4 param_2 = tempPosition;
        vec4 param_3 = matY;
        localPosition.y = dot4(param_2, param_3);
        vec4 param_4 = tempPosition;
        vec4 param_5 = matZ;
        localPosition.z = dot4(param_4, param_5);
        localPosition.w = 1.0;
    }
    vec4 param_6 = localPosition;
    vec4 param_7 = freqHigh_vertexUniforms.mvpmatrixx;
    gl_Position.x = dot4(param_6, param_7);
    vec4 param_8 = localPosition;
    vec4 param_9 = freqHigh_vertexUniforms.mvpmatrixy;
    gl_Position.y = dot4(param_8, param_9);
    vec4 param_10 = localPosition;
    vec4 param_11 = freqHigh_vertexUniforms.mvpmatrixz;
    gl_Position.z = dot4(param_10, param_11);
    vec4 param_12 = localPosition;
    vec4 param_13 = freqHigh_vertexUniforms.mvpmatrixw;
    gl_Position.w = dot4(param_12, param_13);
    vofi_TexCoord1 = gl_Position;
    vec4 texcoord0 = vec4(0.0);
    texcoord0 = ((in_TexCoord * freqLow_vertexUniforms.vertexstscalebias.xy) + freqLow_vertexUniforms.vertexstscalebias.zw).xyxy;
    vofi_TexCoord0 = texcoord0;
    vec4 localPosition_1 = (in_Position * freqLow_vertexUniforms.vertexxyzscale) + freqLow_vertexUniforms.vertexxyzbias;
    if (freqHigh_vertexUniforms.hardwareskinning.x != 0.0)
    {
        vec4 tempPosition_1 = localPosition_1;
        vec4 matX_1 = vec4(0.0);
        vec4 matY_1 = vec4(0.0);
        vec4 matZ_1 = vec4(0.0);
        float hiweight_1 = in_Tangent.w * 255.100006103515625;
        vec4 weights_1;
        weights_1.y = hiweight_1 - (floor(hiweight_1 / 128.0) * 128.0);
        float packedWeights_1 = in_Normal.w * 255.100006103515625;
        weights_1.z = floor(packedWeights_1 / 16.0);
        weights_1.w = packedWeights_1 - (weights_1.z * 16.0);
        weights_1.y *= 0.00393700785934925079345703125;
        weights_1.z *= 0.02222222276031970977783203125;
        weights_1.w *= 0.01666666753590106964111328125;
        weights_1.x = 1.0 - ((weights_1.y + weights_1.z) + weights_1.w);
        uvec4 indices_1 = uvec4(in_Color * 255.0);
        for (uint i_3 = 0u; i_3 < 4u; i_3++)
        {
            matX_1 += (_139.matrices[(indices_1[i_3] * 3u) + 0u] * weights_1[i_3]);
        }
        for (uint i_4 = 0u; i_4 < 4u; i_4++)
        {
            matY_1 += (_139.matrices[(indices_1[i_4] * 3u) + 1u] * weights_1[i_4]);
        }
        for (uint i_5 = 0u; i_5 < 4u; i_5++)
        {
            matZ_1 += (_139.matrices[(indices_1[i_5] * 3u) + 2u] * weights_1[i_5]);
        }
        vec4 param_14 = tempPosition_1;
        vec4 param_15 = matX_1;
        localPosition_1.x = dot4(param_14, param_15);
        vec4 param_16 = tempPosition_1;
        vec4 param_17 = matY_1;
        localPosition_1.y = dot4(param_16, param_17);
        vec4 param_18 = tempPosition_1;
        vec4 param_19 = matZ_1;
        localPosition_1.z = dot4(param_18, param_19);
        localPosition_1.w = 1.0;
    }
    vec4 param_20 = localPosition_1;
    vec4 param_21 = freqHigh_vertexUniforms.mvpmatrixnojitterx;
    vec4 posNoJitter;
    posNoJitter.x = dot4(param_20, param_21);
    vec4 param_22 = localPosition_1;
    vec4 param_23 = freqHigh_vertexUniforms.mvpmatrixnojittery;
    posNoJitter.y = dot4(param_22, param_23);
    vec4 param_24 = localPosition_1;
    vec4 param_25 = freqHigh_vertexUniforms.mvpmatrixnojitterz;
    posNoJitter.z = dot4(param_24, param_25);
    vec4 param_26 = localPosition_1;
    vec4 param_27 = freqHigh_vertexUniforms.mvpmatrixnojitterw;
    posNoJitter.w = dot4(param_26, param_27);
    vofi_TexCoord1 = posNoJitter;
    vec4 localPosition_2 = (in_Position * freqLow_vertexUniforms.vertexxyzscale) + freqLow_vertexUniforms.vertexxyzbias;
    if (freqHigh_vertexUniforms.hardwareskinning.x != 0.0)
    {
        vec4 tempPosition_2 = localPosition_2;
        vec4 matX_2 = vec4(0.0);
        vec4 matY_2 = vec4(0.0);
        vec4 matZ_2 = vec4(0.0);
        float hiweight_2 = in_Tangent.w * 255.100006103515625;
        vec4 weights_2;
        weights_2.y = hiweight_2 - (floor(hiweight_2 / 128.0) * 128.0);
        float packedWeights_2 = in_Normal.w * 255.100006103515625;
        weights_2.z = floor(packedWeights_2 / 16.0);
        weights_2.w = packedWeights_2 - (weights_2.z * 16.0);
        weights_2.y *= 0.00393700785934925079345703125;
        weights_2.z *= 0.02222222276031970977783203125;
        weights_2.w *= 0.01666666753590106964111328125;
        weights_2.x = 1.0 - ((weights_2.y + weights_2.z) + weights_2.w);
        uvec4 indices_2 = uvec4(in_Color * 255.0);
        for (uint i_6 = 0u; i_6 < 4u; i_6++)
        {
            matX_2 += (_549.matricesprevious[(indices_2[i_6] * 3u) + 0u] * weights_2[i_6]);
        }
        for (uint i_7 = 0u; i_7 < 4u; i_7++)
        {
            matY_2 += (_549.matricesprevious[(indices_2[i_7] * 3u) + 1u] * weights_2[i_7]);
        }
        for (uint i_8 = 0u; i_8 < 4u; i_8++)
        {
            matZ_2 += (_549.matricesprevious[(indices_2[i_8] * 3u) + 2u] * weights_2[i_8]);
        }
        vec4 param_28 = tempPosition_2;
        vec4 param_29 = matX_2;
        localPosition_2.x = dot4(param_28, param_29);
        vec4 param_30 = tempPosition_2;
        vec4 param_31 = matY_2;
        localPosition_2.y = dot4(param_30, param_31);
        vec4 param_32 = tempPosition_2;
        vec4 param_33 = matZ_2;
        localPosition_2.z = dot4(param_32, param_33);
        localPosition_2.w = 1.0;
    }
    vec4 param_34 = localPosition_2;
    vec4 param_35 = freqHigh_vertexUniforms.mvpmatrixlastx;
    vec4 posLast;
    posLast.x = dot4(param_34, param_35);
    vec4 param_36 = localPosition_2;
    vec4 param_37 = freqHigh_vertexUniforms.mvpmatrixlasty;
    posLast.y = dot4(param_36, param_37);
    vec4 param_38 = localPosition_2;
    vec4 param_39 = freqHigh_vertexUniforms.mvpmatrixlastz;
    posLast.z = dot4(param_38, param_39);
    vec4 param_40 = localPosition_2;
    vec4 param_41 = freqHigh_vertexUniforms.mvpmatrixlastw;
    posLast.w = dot4(param_40, param_41);
    vofi_TexCoord2 = posLast;
    gl_Position.y = -gl_Position.y;

if (vk3d_params.custom_params.z != 0)
{
    if(gl_Position.w > vk3d_params.custom_params.z)
        gl_Position.x += vk3d_params.stereo.x * (gl_Position.w - vk3d_params.stereo.y);
    else
        gl_Position.x += vk3d_params.stereo.x * (gl_Position.w - vk3d_params.stereo.y * 0.65) * 0.75;
}
else
{
    gl_Position.x += vk3d_params.stereo.x * (gl_Position.w - vk3d_params.stereo.y);
}
}


