#version 450
// unknown 1
struct PerFrameUniforms
{
    mat4 gViewMat4;
    mat4 gViewProjectionMat4;
    mat4 gCameraMat4;
    mat4 gCameraNoHeadTrackingMat4;
    mat4 gPrevViewProjectionMat4;
    mat4 gThisToPrevViewProjectionMat4;
    mat4 gInverseViewMat4;
    mat4 gInverseProjectionMat4;
    mat4 gInverseProjectionSCMat4;
    mat4 gInverseViewProjectionMat4;
    vec4 gInverseWorldUpMatVec4[3];
    vec3 gViewPositionVec3;
    float gfTime;
    vec3 gVREyeInfoVec3;
    float gfPrevTime;
    vec4 gClipPlanesVec4;
    vec4 gMBlurSettingsVec4;
    vec3 gDeJitterVec3;
    int giFrameIndex;
    vec4 gTaaSettingsVec4;
    vec4 gTessSettingsVec4;
    vec4 gShellsSettingsVec4;
    vec4 gFrameBufferSizeVec4;
    vec4 gFoVValuesVec4;
    vec4 gShadowSizeVec4;
    vec3 gShadowProjScaleVec3;
    int giDisableAmbientAllowed;
    vec4 gShadowFadeParamVec4;
};

struct CustomPerMeshUniforms
{
    vec4 gDoFParamsVec4;
    vec4 gHDRParamsVec4;
    vec4 gHBAOParamsVec4;
    vec4 gThresholdParamsVec4;
    vec4 gBlurParamsVec4;
    vec4 gColourLUTParamsVec4;
    vec4 gColourLUTStrengthsVec4;
    vec4 gSharpenStrength;
    vec4 gTextureSizeMipLevelVec4;
    vec4 gSkyUpperParamsVec4;
    vec4 gLightShaftColourBottomVec4;
    vec4 gLightShaftColourTopVec4;
    vec4 gHDRParams2Vec4;
};

struct CommonPerMeshUniforms
{
    vec4 gPlanetPositionVec4;
    mat4 gWorldMat4;
    mat4 gWorldNormalMat4;
    float fdFadeValueDummy;
    vec4 gLightPositionVec4;
    vec4 gLightDirectionVec4;
    vec4 gLightOriginVec4;
    vec4 gScanParamsPosVec4;
    vec4 gScanParamsCfg1Vec4;
    vec4 gScanParamsCfg2Vec4;
    vec4 gScanParamsCfg3Vec4;
    vec4 gScanColourVec4;
    mat4 gaShadowMat4[3];
    vec4 gLightColourVec4;
    vec4 gLightCustomParamsVec4;
    mat4 gWorldMotionMat4;
    mat4 gInverseModelMat4Dummy;
};

struct UniformBuffer
{
    PerFrameUniforms mpPerFrame;
    CustomPerMeshUniforms mpCustomPerMesh;
    CommonPerMeshUniforms mpCommonPerMesh;
};

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

layout(set = 0, binding = 0, std140) uniform lUniforms_BLK
{
    UniformBuffer lUniforms;
} _387;

layout(set = 1, binding = 0) uniform sampler2D gBufferMap;
layout(set = 1, binding = 1) uniform sampler2D gBuffer1Map;
layout(set = 1, binding = 2) uniform sampler2D gBuffer3Map;

layout(location = 0) in VertexBlock
{
    vec2 mTexCoordsVec2;
} In;

layout(location = 0) out vec4 out_color0;

vec4 _1015;

void main()
{
    vec2 _1018;
    bool _1019;
    for (;;)
    {
        vec4 _845 = texture(gBufferMap, In.mTexCoordsVec2);
        vec4 _849 = texture(gBuffer1Map, In.mTexCoordsVec2);
        if (_845.x < 1.0)
        {
            _1019 = false;
            _1018 = _845.xy * 0.5;
            break;
        }
        vec2 _895 = (vec2(In.mTexCoordsVec2.x, 1.0 - In.mTexCoordsVec2.y) * 2.0) - vec2(1.0);
        vec4 _994 = vec4(_895.x, _895.y, _1015.z, _1015.w);
        _994.z = (((_387.lUniforms.mpPerFrame.gClipPlanesVec4.x * _387.lUniforms.mpPerFrame.gClipPlanesVec4.y) / (_849.x * _387.lUniforms.mpPerFrame.gClipPlanesVec4.y)) - _387.lUniforms.mpPerFrame.gClipPlanesVec4.x) / (_387.lUniforms.mpPerFrame.gClipPlanesVec4.y - _387.lUniforms.mpPerFrame.gClipPlanesVec4.x);
        
        _994.x -= vk3d_params.stereo.x * (1 - vk3d_params.stereo.y * _994.z * 10);
        
        vec4 _996 = _994;
        _996.w = 1.0;
        vec4 _905 = _387.lUniforms.mpPerFrame.gInverseViewProjectionMat4 * _996;
        vec3 _917 = (_905.xyz / vec3(_905.w)).xyz + _387.lUniforms.mpPerFrame.gViewPositionVec3;
        vec4 _999 = vec4(_917.x, _917.y, _917.z, _1015.w);
        
        _999.x -= vk3d_params.stereo.x * (1 - vk3d_params.stereo.y * _999.z * 10);
        
        _999.w = 1.0;
        vec4 _800 = _387.lUniforms.mpPerFrame.gPrevViewProjectionMat4 * _999;
        vec4 _1002 = _800;
        _1002.y = -_800.y;
        vec2 _821 = (((_1002.xyz / vec3(_800.w)).xy * 0.5) + vec2(0.5)) - In.mTexCoordsVec2;
        vec2 _1006 = _821;
        _1006.y = -_821.y;
        vec2 _953 = _1006 * 16.0;
        vec2 _984 = vec2(_953.x, -_953.y);
        float _956 = length(_984);
        vec2 _961 = _984 / vec2(max(1.0, _956));
        vec2 _1017;
        if (_956 > 0.0)
        {
            _1017 = _961 / vec2(sqrt(length(_961)));
        }
        else
        {
            _1017 = _961;
        }
        _1019 = _845.y > 0.75;
        _1018 = min(vec2(0.996078431606292724609375), (_1017 * 0.4980392158031463623046875) + vec2(0.5)) * 0.5;
        break;
    }
    bool _1020;
    if (!_1019)
    {
        _1020 = (int(texture(gBuffer3Map, In.mTexCoordsVec2).x * 255.0) & 128) != 0;
    }
    else
    {
        _1020 = _1019;
    }
    out_color0 = vec4(_1018 * 2.0, _1020 ? 0.5 : 0.0, 1.0);
}


