// UI & Rocket Launcher
#version 450

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

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

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

layout(location = 0) in vec4 in_Position;
layout(location = 2) out vec4 vofi_TexCoord0;
layout(location = 1) in vec2 in_TexCoord;
layout(location = 0) out vec4 vofi_Color;
layout(location = 3) in vec4 in_Color;

float _56;

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

float SRGBlinear(float value)
{
    if (value <= 0.040449999272823333740234375)
    {
        return value / 12.9200000762939453125;
    }
    else
    {
        return pow((value / 1.05499994754791259765625) + 0.0521326996386051177978515625, 2.400000095367431640625);
    }
}

vec3 SRGBlinear(vec3 sRGB)
{
    float param = sRGB.x;
    vec3 outLinear;
    outLinear.x = SRGBlinear(param);
    float param_1 = sRGB.y;
    outLinear.y = SRGBlinear(param_1);
    float param_2 = sRGB.z;
    outLinear.z = SRGBlinear(param_2);
    return outLinear;
}

vec4 SRGBlinear(vec4 sRGBA)
{
    vec3 param = sRGBA.xyz;
    vec4 outLinear = vec4(SRGBlinear(param), 1.0);
    float param_1 = sRGBA.w;
    outLinear.w = SRGBlinear(param_1);
    return outLinear;
}

vec4 DeGamma(vec4 color)
{
    vec4 param = color;
    return SRGBlinear(param);
}

void main()
{
    vec4 param = in_Position;
    vec4 param_1 = freqHigh_vertexUniforms.mvpmatrixx;
    gl_Position.x = dot4(param, param_1);
    vec4 param_2 = in_Position;
    vec4 param_3 = freqHigh_vertexUniforms.mvpmatrixy;
    gl_Position.y = dot4(param_2, param_3);
    vec4 param_4 = in_Position;
    vec4 param_5 = freqHigh_vertexUniforms.mvpmatrixz;
    gl_Position.z = dot4(param_4, param_5);
    vec4 param_6 = in_Position;
    vec4 param_7 = freqHigh_vertexUniforms.mvpmatrixw;
    gl_Position.w = dot4(param_6, param_7);
    vec3 viewDir = gl_Position.xyz - freqLow_vertexUniforms.globalvieworigin.xyz;
    float viewDistance = length(viewDir);
    vofi_TexCoord0 = vec4(in_TexCoord.x, in_TexCoord.y, viewDistance, 0.0);
    vec4 _176;
    if (freqHigh_vertexUniforms.fontfxdegamma.x > 0.0)
    {
        vec4 param_8 = in_Color;
        _176 = DeGamma(param_8);
    }
    else
    {
        _176 = in_Color;
    }
    vofi_Color = _176;
    gl_Position.y = -gl_Position.y;
if (gl_Position.w > 10.0) // Select UI vs Game
    {
    	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);
		}
    }
    else
    if (vk3d_params.custom_params.y != 0)
    {
        if ((gl_Position.x < -1.9 || gl_Position.x > 1.9) || (gl_Position.y < -1.9 || gl_Position.y > 1.9))
            gl_Position.x += vk3d_params.stereo.x * vk3d_params.custom_params.x;
        else
            gl_Position.x -= vk3d_params.stereo.x * (gl_Position.w - vk3d_params.stereo.y) * vk3d_params.custom_params.y;
    }
    else
        gl_Position.x += vk3d_params.stereo.x * vk3d_params.custom_params.x;
}



