#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 vertexstscalebias;
    vec4 vertexxyzscale;
    vec4 vertexxyzbias;
    vec4 globalvieworigin;
} freqLow_vertexUniforms;

layout(set = 0, binding = 0, std140) uniform freqHigh_vertexUniforms_ubo
{
    vec4 mvpmatrixx;
    vec4 mvpmatrixy;
    vec4 mvpmatrixz;
    vec4 mvpmatrixw;
    vec4 modelmatrixx;
    vec4 modelmatrixy;
    vec4 modelmatrixz;
    vec4 mvpmatrixdeterminantsign;
} freqHigh_vertexUniforms;

layout(location = 2) out vec4 vofi_TexCoord0;
layout(location = 1) in vec2 in_TexCoord;
layout(location = 12) in vec2 in_VmtrTC;
layout(location = 0) in vec4 in_Position;
layout(location = 2) in vec3 in_PackedTnputs;
layout(location = 3) out vec4 vofi_TexCoord1;
layout(location = 4) out vec4 vofi_TexCoord2;
layout(location = 5) out vec4 vofi_TexCoord3;
layout(location = 13) in vec4 in_VmtrSB;
layout(location = 7) out vec4 vofi_TexCoord5;
layout(location = 6) out vec4 vofi_TexCoord4;

uint asuint(float x)
{
    return floatBitsToUint(x);
}

vec4 unpackR8G8B8A8(uint value)
{
    return vec4(float((value >> uint(24)) & 255u), float((value >> uint(16)) & 255u), float((value >> uint(8)) & 255u), float(value & 255u)) / vec4(255.0);
}

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

float dot3(vec3 a, vec4 b)
{
    return dot(a, b.xyz);
}

void main()
{
    vofi_TexCoord0 = ((in_TexCoord * freqLow_vertexUniforms.vertexstscalebias.xy) + freqLow_vertexUniforms.vertexstscalebias.zw).xyxy;
    vec2 _102 = (in_VmtrTC * freqLow_vertexUniforms.vertexstscalebias.xy) + freqLow_vertexUniforms.vertexstscalebias.zw;
    vofi_TexCoord0 = vec4(vofi_TexCoord0.x, vofi_TexCoord0.y, _102.x, _102.y);
    vec4 localPosition = (in_Position * freqLow_vertexUniforms.vertexxyzscale) + freqLow_vertexUniforms.vertexxyzbias;
    float param = in_PackedTnputs.x;
    uint param_1 = asuint(param);
    vec4 localNormal = (unpackR8G8B8A8(param_1).wzyx * 2.0) - vec4(1.0);
    float param_2 = in_PackedTnputs.y;
    uint param_3 = asuint(param_2);
    vec4 unpacked_tangent = unpackR8G8B8A8(param_3).wzyx;
    vec3 _148 = (unpacked_tangent.xyz * 2.0) - vec3(1.0);
    vec4 localTangent;
    localTangent = vec4(_148.x, _148.y, _148.z, localTangent.w);
    localTangent.w = (floor((unpacked_tangent.w * 255.100006103515625) / 128.0) * 2.0) - 1.0;
    vec4 param_4 = localPosition;
    vec4 param_5 = freqHigh_vertexUniforms.mvpmatrixx;
    gl_Position.x = dot4(param_4, param_5);
    vec4 param_6 = localPosition;
    vec4 param_7 = freqHigh_vertexUniforms.mvpmatrixy;
    gl_Position.y = dot4(param_6, param_7);
    vec4 param_8 = localPosition;
    vec4 param_9 = freqHigh_vertexUniforms.mvpmatrixz;
    gl_Position.z = dot4(param_8, param_9);
    vec4 param_10 = localPosition;
    vec4 param_11 = freqHigh_vertexUniforms.mvpmatrixw;
    gl_Position.w = dot4(param_10, param_11);
    vec3 param_12 = localNormal.xyz;
    vec4 param_13 = freqHigh_vertexUniforms.modelmatrixx;
    vofi_TexCoord1.x = dot3(param_12, param_13);
    vec3 param_14 = localNormal.xyz;
    vec4 param_15 = freqHigh_vertexUniforms.modelmatrixy;
    vofi_TexCoord1.y = dot3(param_14, param_15);
    vec3 param_16 = localNormal.xyz;
    vec4 param_17 = freqHigh_vertexUniforms.modelmatrixz;
    vofi_TexCoord1.z = dot3(param_16, param_17);
    vec3 param_18 = localTangent.xyz;
    vec4 param_19 = freqHigh_vertexUniforms.modelmatrixx;
    vofi_TexCoord2.x = dot3(param_18, param_19);
    vec3 param_20 = localTangent.xyz;
    vec4 param_21 = freqHigh_vertexUniforms.modelmatrixy;
    vofi_TexCoord2.y = dot3(param_20, param_21);
    vec3 param_22 = localTangent.xyz;
    vec4 param_23 = freqHigh_vertexUniforms.modelmatrixz;
    vofi_TexCoord2.z = dot3(param_22, param_23);
    vofi_TexCoord2.w = localTangent.w * (-freqHigh_vertexUniforms.mvpmatrixdeterminantsign.x);
    vofi_TexCoord3 = in_VmtrSB;
    vofi_TexCoord5 = vofi_TexCoord3 / vec4(2048.0);
    float param_24 = in_PackedTnputs.z;
    uint param_25 = asuint(param_24);
    vec4 vtxCol = unpackR8G8B8A8(param_25).wzyx;
    vec3 _284 = vtxCol.xyz * (vtxCol.w * 16.0);
    vtxCol = vec4(_284.x, _284.y, _284.z, vtxCol.w);
    vofi_TexCoord3 = vec4(vofi_TexCoord3.x, vofi_TexCoord3.y, vtxCol.xy.x, vtxCol.xy.y);
    vofi_TexCoord1.w = vtxCol.z;
    vec4 param_26 = localPosition;
    vec4 param_27 = freqHigh_vertexUniforms.modelmatrixx;
    vec4 globalPosition;
    globalPosition.x = dot4(param_26, param_27);
    vec4 param_28 = localPosition;
    vec4 param_29 = freqHigh_vertexUniforms.modelmatrixy;
    globalPosition.y = dot4(param_28, param_29);
    vec4 param_30 = localPosition;
    vec4 param_31 = freqHigh_vertexUniforms.modelmatrixz;
    globalPosition.z = dot4(param_30, param_31);
    globalPosition.w = 1.0;
    vofi_TexCoord4 = globalPosition - freqLow_vertexUniforms.globalvieworigin;
    gl_Position.y = -gl_Position.y;

// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
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);
}
}





