//HUD VS 2.
// Vk3DVision (http://3dsurroundgaming.com/) - Original Shader
#version 450
#extension GL_EXT_nonuniform_qualifier : require

struct FlrInput
{
    vec4 position;
    vec4 color;
    vec2 UV0;
    vec2 UV1;
};

struct FlrOutput
{
    vec4 position;
    vec4 UV0;
    vec2 UV1;
    vec4 color;
    vec4 sdfParameters;
    vec4 colorOutline;
};

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

layout(set = 0, binding = 0, std140) uniform PerInstance
{
    mat4 projMatrix;
    mat4 viewProjMatrix;
    mat4 worldViewProjMatrix;
    vec4 sdfParsContour;
    vec4 sdfParsContourOutline;
    vec4 colorText;
    vec4 colorOutline;
    vec4 posOffset;
} _50;

layout(set = 0, binding = 99, std430) buffer DebugBuffer
{
    uint debugBuffer[];
} _204;

layout(set = 2, binding = 0) uniform texture2D globalTextures[];
layout(set = 2, binding = 0) uniform textureCube globalCubeTextures[];
layout(set = 2, binding = 0) uniform texture3D global3DTextures[];
layout(set = 1, binding = 0) uniform sampler linearClampSampler;
layout(set = 1, binding = 1) uniform sampler linearRepeatSampler;
layout(set = 1, binding = 2) uniform sampler nearestClampSampler;
layout(set = 1, binding = 3) uniform sampler nearestRepeatSampler;
layout(set = 1, binding = 4) uniform sampler shadowSampler;

layout(location = 0) in vec4 inPosition;
layout(location = 3) in vec4 inColor;
layout(location = 1) in vec2 inUV0;
layout(location = 2) in vec2 inUV1;
layout(location = 0) out vec4 outUV0;
layout(location = 1) out vec2 outUV1;
layout(location = 2) out vec4 outColor;
layout(location = 3) out vec4 outSdfParameters;
layout(location = 4) out vec4 outColorOutline;

vec3 gammaToLinear(vec3 color)
{
    return pow(clamp(color, vec3(0.0), vec3(1.0)), vec3(2.2000000476837158203125));
}

FlrOutput flrMain(FlrInput flrInput)
{
    vec4 inputPos = flrInput.position;
    float thickness = flrInput.UV1.x;
    float smoothing = _50.sdfParsContour.y;
    float thicknessOutline = _50.sdfParsContourOutline.x;
    float smoothingOutline = _50.sdfParsContourOutline.y;
    thickness = clamp(thickness, 0.0, 1.0);
    float sdf1 = 1.0 - thickness;
    float sdf2 = clamp(sdf1 + smoothing, 0.0, 1.0);
    float sdf3 = 1.0 - thicknessOutline;
    float sdf4 = clamp(sdf3 + smoothingOutline, 0.0, 1.0);
    FlrOutput flrOutput;
    flrOutput.sdfParameters = vec4(sdf1, sdf2, sdf3, sdf4);
    flrOutput.colorOutline = _50.colorOutline;
    vec3 _100 = inputPos.xyz * _50.posOffset.w;
    inputPos = vec4(_100.x, _100.y, _100.z, inputPos.w);
    inputPos.w = 1.0;
    flrOutput.position = _50.viewProjMatrix * inputPos;
	
	if (flrOutput.position.w==1 || flrOutput.position.w>50) {
        flrOutput.position.x += vk3d_params.stereo.x * (flrOutput.position.w - vk3d_params.stereo.y);
    } else {
	    flrOutput.position.x += vk3d_params.stereo.x * flrOutput.position.w * vk3d_params.custom_params.z;
    }
	
    vec3 param = flrInput.color.xyz;
    vec3 _115 = gammaToLinear(param);
    flrOutput.color = vec4(_115.x, _115.y, _115.z, flrOutput.color.w);
    flrOutput.color.w = flrInput.color.w;
    flrOutput.UV0 = vec4(flrInput.UV0.x, flrInput.UV0.y, flrOutput.UV0.z, flrOutput.UV0.w);
    flrOutput.UV0.z = 1.0;
    flrOutput.UV0.w = flrInput.position.w;
    flrOutput.UV1 = flrInput.UV1;
    return flrOutput;
}

void main()
{
    FlrInput flrInput;
    flrInput.position = inPosition;
    flrInput.color = inColor;
    flrInput.UV0 = inUV0;
    flrInput.UV1 = inUV1;
    FlrInput param = flrInput;
    FlrOutput flrOutput = flrMain(param);
    outUV0 = flrOutput.UV0;
    outUV1 = flrOutput.UV1;
    outColor = flrOutput.color;
    outSdfParameters = flrOutput.sdfParameters;
    outColorOutline = flrOutput.colorOutline;
    gl_Position = flrOutput.position;
}


