// FLARES FIX
#version 450
 #extension GL_EXT_multiview : enable
// Vk3DVision SinglePass
///////////////////////////////////////////////////////////////////////////////

#define STEREO 1


#define VIEW gl_WorkGroupID.z / (gl_NumWorkGroups.z /2)
#define NumWorkGroups uvec3(gl_NumWorkGroups.x, gl_NumWorkGroups.y, gl_NumWorkGroups.z / 2)
#define WorkGroupID uvec3(gl_WorkGroupID.x, gl_WorkGroupID.y, (gl_WorkGroupID.z < (gl_WorkGroupID.z + 1) / 2 ? gl_WorkGroupID.z : gl_WorkGroupID.z - (gl_WorkGroupID.z + 1) / 2))
#define GlobalInvocationID uvec3(WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID)

// Stereo and Mono Texture Sampling
#if(STEREO == 1)
	#define SAMPLER_2D sampler2DArray
	#define USAMPLER_2D usampler2DArray
	#define ISAMPLER_2D isampler2DArray
	#define IMAGE_2D image2DArray
	#define UIMAGE_2D uimage2DArray
	#define UTEXTURE_2D utexture2DArray
	#define TEXTURE_2D texture2DArray
	#define SAMPLE_TEXTURE(Sampler, uv) texture(Sampler, vec3(uv, VIEW))
	#define SAMPLE_TEXTURE1(Sampler, uv, bias) texture(Sampler, vec3(uv, VIEW), bias)
	#define IMAGE_LOAD(Image2D, pos) imageLoad(Image2D, ivec3(pos, VIEW))
	#define IMAGE_STORE(Image2D, pos, result) imageStore(Image2D, ivec3(pos, VIEW), result)
	#define TEXEL_FETCH(Sampler, uv, lod) texelFetch(Sampler, ivec3(uv, VIEW), lod)
	#define TEXEL_FETCH_OFFSET(Sampler, uv, lod, offset) texelFetchOffset(Sampler, ivec3(uv, VIEW), lod, offset)
	#define TEXTURE_LOD(Sampler, uv, lod) textureLod(Sampler, vec3(uv, VIEW), lod)
	#define TEXTURE_LOD_OFFSET(Sampler, uv, lod, offset) textureLodOffset(Sampler, vec3(uv, VIEW), lod, offset)
	#define TEXTURE_GATHER(Sampler, uv, comp) textureGather(Sampler, vec3(uv, VIEW), comp)
	#define TEXTURE_GATHER1(Sampler, uv) textureGather(Sampler, vec3(uv, VIEW))
	#define TEXTURE_GATHER_OFFSET(Sampler, uv, offset, comp) textureGatherOffset(Sampler, vec3(uv, VIEW), offset, comp)
	#define TEXTURE_GATHER_OFFSETS(Sampler, uv, offset) textureGatherOffsets(Sampler, vec3(uv, VIEW), offset)
	#define TEXTURE_GATHER_OFFSETS1(Sampler, uv, offset, comp) textureGatherOffsets(Sampler, vec3(uv, VIEW), offset, comp)
	#define TEXTURE_SIZE(Sampler, lod) textureSize(Sampler, lod).xy
	#define TEXTURE_GRAD(Sampler, P, dPdx, dPdy) textureGrad(Sampler, vec3(P, VIEW), dPdx, dPdy)
#else
	#define SAMPLER_2D sampler2D
	#define USAMPLER_2D usampler2D
	#define ISAMPLER_2D isampler2D
	#define IMAGE_2D image2D
	#define UIMAGE_2D uimage2D
	#define UTEXTURE_2D utexture2D
	#define TEXTURE_2D texture2D
	#define SAMPLE_TEXTURE(Sampler, uv) texture(Sampler, uv)
	#define SAMPLE_TEXTURE1(Sampler, uv, bias) texture(Sampler, uv, bias)
	#define IMAGE_LOAD(Image2D, pos) imageLoad(Image2D, pos)
	#define IMAGE_STORE(Image2D, pos, result) imageStore(Image2D, pos, result)
	#define TEXEL_FETCH(Sampler, uv, lod) texelFetch(Sampler, uv, lod)
	#define TEXEL_FETCH_OFFSET(Sampler, uv, lod, offset) texelFetchOffset(Sampler, uv, lod, offset)
	#define TEXTURE_LOD(Sampler, uv, lod) textureLod(Sampler, uv, lod)
	#define TEXTURE_LOD_OFFSET(Sampler, uv, lod, offset) textureLodOffset(Sampler, uv, lod, offset)
	#define TEXTURE_GATHER(Sampler, uv, comp) textureGather(Sampler, uv, comp)
	#define TEXTURE_GATHER1(Sampler, uv, comp) textureGather(Sampler, uv)
	#define TEXTURE_GATHER_OFFSET(Sampler, uv, offset, comp) textureGatherOffset(Sampler, uv, offset, comp)
	#define TEXTURE_GATHER_OFFSETS(Sampler, uv, offset) textureGatherOffsets(Sampler, uv, offset)
	#define TEXTURE_GATHER_OFFSETS1(Sampler, uv, offset, comp) textureGatherOffsets(Sampler, uv, offset, comp)
	#define TEXTURE_SIZE(Sampler, lod) textureSize(Sampler, lod)
	#define TEXTURE_GRAD(Sampler, P, dPdx, dPdy) textureGrad(Sampler, P, dPdx, dPdy)
#endif 
 ///////////////////////////////////////////////////////////////////////////////
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

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


   
layout(set = 1, binding = 0, std140) uniform _292_294
{
    vec4 _m0;
} _294;

layout(set = 0, binding = 0, std140) uniform _427_429
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    vec4 _m3;
    vec4 _m4;
    vec4 _m5;
    vec4 _m6;
    vec4 _m7;
    vec4 _m8;
    vec4 _m9;
    vec4 _m10;
    vec4 _m11;
    vec4 _m12;
    vec4 _m13;
    vec4 _m14;
    vec4 _m15;
    vec4 _m16;
    vec4 _m17;
    vec4 _m18;
    vec4 _m19;
    vec4 _m20;
} _429;

layout(push_constant, std430) uniform _1043_1045
{
    int _m0;
    int _m1;
} _1045;

layout(set = 0, binding = 1) uniform SAMPLER_2D _362;
layout(set = 1, binding = 1) uniform TEXTURE_2D _382;
layout(set = 0, binding = 2) uniform sampler _386;
layout(set = 0, binding = 3) uniform SAMPLER_2D _404;
layout(set = 1, binding = 2) uniform TEXTURE_2D _563;
layout(set = 1, binding = 3) uniform SAMPLER_2D _584;
layout(set = 1, binding = 4) uniform TEXTURE_2D _610;
layout(set = 1, binding = 5, r11f_g11f_b10f) uniform IMAGE_2D _644;
layout(set = 0, binding = 4) uniform sampler3D _776;
layout(set = 0, binding = 5) uniform sampler3D _797;
layout(set = 0, binding = 6) uniform sampler3D _919;
layout(set = 1, binding = 6, r11f_g11f_b10f) uniform writeonly IMAGE_2D _1034;
layout(set = 1, binding = 1) uniform SAMPLER_2D _1046;
layout(set = 1, binding = 2) uniform SAMPLER_2D _1047;
layout(set = 1, binding = 4) uniform SAMPLER_2D _1048;

shared float _357[64];
shared float _379[64];

vec2 _16(vec2 _15)
{
    return clamp(_15, vec2(0.0), vec2(1.0));
}

uint _51(inout uint _50)
{
    _50 = ((_50 & 5u) << uint(1)) | ((_50 & 10u) >> uint(1));
    _50 = ((_50 & 3u) << uint(2)) | ((_50 & 12u) >> uint(2));
    return _50;
}

float _63(uvec2 _61, uint _62)
{
    uvec2 _241 = _61 % uvec2(3u);
    uint _245 = ((_241.x + (_241.y * 3u)) + _62) % 9u;
    float _257;
    if (_245 == 0u)
    {
        _257 = 0.0;
    }
    else
    {
        _257 = float((2168608311u >> ((_245 - 1u) << uint(2))) & 15u) / 9.0;
    }
    return _257;
}

vec2 _56(uint _54, uint _55)
{
    float _221 = 1.0 / float(_54);
    uint _233 = _55 + 1u;
    uint _234 = _51(_233);
    return vec2(float(_55 + 1u) * _221, float(_234) / 16.0);
}

uint _21(float _20)
{
    return floatBitsToUint(_20);
}

float _46(float _42, vec4 _43, float _44, bool _45)
{
    float _183 = _43.w / (_42 + _43.z);
    return _183 * _44;
}

float _24(float _23)
{
    float _81 = (((-0.15658299624919891357421875) * abs(_23)) + 1.57079637050628662109375) * sqrt(1.0 - abs(_23));
    float _93;
    if (_23 >= 0.0)
    {
        _93 = _81;
    }
    else
    {
        _93 = 3.1415927410125732421875 - _81;
    }
    return _93;
}

float _27(float _26)
{
    float _107;
    if (_26 < 1.0)
    {
        _107 = _26;
    }
    else
    {
        _107 = 1.0 / _26;
    }
    float _106 = _107;
    float _117 = _106 * _106;
    float _121 = 0.087292902171611785888671875;
    _121 = (-0.3018949925899505615234375) + (_121 * _117);
    _121 = 1.0 + (_121 * _117);
    _121 *= _106;
    float _135;
    if (_26 < 1.0)
    {
        _135 = _121;
    }
    else
    {
        _135 = 1.57079637050628662109375 - _121;
    }
    return _135;
}

float _30(float _29)
{
    float _150 = abs(_29);
    float _147 = _27(_150);
    float _152;
    if (_29 < 0.0)
    {
        _152 = -_147;
    }
    else
    {
        _152 = _147;
    }
    return _152;
}

float _35(float _33, float _34)
{
    float _168 = _33 / _34;
    float _164 = _30(_168);
    if (_34 < 0.0)
    {
        _164 += ((_33 >= 0.0) ? 3.1415927410125732421875 : (-3.1415927410125732421875));
    }
    return _164;
}

float _10(float _9)
{
    return clamp(_9, 0.0, 1.0);
}

void main()
{
    ivec3 _278 = ivec3(GlobalInvocationID);
    vec2 _284 = (vec2(_278.xy) + vec2(0.5)) * _294._m0.zw;
    vec2 _301 = vec2(_278.xy) * _294._m0.zw;
    // Actual FIX
    _301.x -= vk3d_params[VIEW].stereo.x * 0.5; 
    uint _309 = uint((int(gl_LocalInvocationID.x) / 2) + ((int(gl_LocalInvocationID.y) / 2) * 8));
    vec2 _324 = (vec2(GlobalInvocationID.xy - gl_LocalInvocationID.xy) - vec2(2.0)) + (vec2(gl_LocalInvocationID.xy) * vec2(2.0));
    _324 *= _294._m0.zw;
    uint _344 = uint(int(gl_LocalInvocationID.x) + (int(gl_LocalInvocationID.y) * 8));
    _357[_344] = 1.0 - TEXTURE_LOD(_362, vec4(_324, 0.0, 0.0).xy, vec4(_324, 0.0, 0.0).w).x;
    _379[_344] = TEXTURE_LOD(SAMPLER_2D(_382, _386), vec4(_324, 0.0, 0.0).xy, vec4(_324, 0.0, 0.0).w).x;
    memoryBarrier();
    barrier();
    float _403 = TEXTURE_LOD(_404, vec4(_284, 0.0, 0.0).xy, vec4(_284, 0.0, 0.0).w).x;
    vec4 _418 = vec4(0.0, 0.0, 0.0, 1.0);
    if (_403 < 1.0)
    {
        vec2 _424 = vec2(1.0);
        float _426 = _429._m0.x;
        if (_426 > 0.0)
        {
            float _437 = _403;
            vec2 _439 = vec2(0.0);
            for (uint _441 = 0u; _441 < 4u; _441++)
            {
                for (uint _450 = 0u; _450 < 4u; _450++)
                {
                    uint _458 = (_309 + _450) + (_441 * 8u);
                    float _466 = _357[_458] - _437;
                    float _472 = exp(((-_466) * _466) * 1000000.0);
                    _439 += vec2(_379[_458] * _472, _472);
                }
            }
            vec2 _493 = _429._m0.zw;
            vec2 _505 = pow(vec2(_439.x / _439.y), _493);
            _424 = _16(_505);
            bool _507 = (dot(_429._m1.zw, vec2(1.0)) > 0.0) ? true : false;
            if (_507)
            {
                uint _520;
                if (_507 == true)
                {
                    uint _529 = uint(_429._m2.x) % 9u;
                    uint _530 = _51(_529);
                    _520 = _530;
                }
                else
                {
                    _520 = 0u;
                }
                uint _519 = _520;
                uvec2 _537 = uvec2(_278.xy);
                uint _538 = _519;
                float _533 = (_63(_537, _538) - 0.5) * 0.19607843458652496337890625;
                vec2 _547 = _424 * 2.0;
                vec2 _544 = _16(_547);
                vec2 _554 = _424 + (_544 * _533);
                _424 = _16(_554);
            }
        }
        float _556 = _429._m3.x;
        vec3 _562 = TEXTURE_LOD(SAMPLER_2D(_563, _386), vec4(_284, 0.0, 0.0).xy, vec4(_284, 0.0, 0.0).w).xyz;
        if (_556 > 0.0)
        {
            vec3 _583 = TEXTURE_LOD(_584, vec4(_284 + (_294._m0.zw * 0.25), 0.0, 0.0).xy, vec4(_284 + (_294._m0.zw * 0.25), 0.0, 0.0).w).xyz;
            float _609 = TEXTURE_LOD(SAMPLER_2D(_610, _386), vec4(_284, 0.0, 0.0).xy, vec4(_284, 0.0, 0.0).w).x;
            _562 = mix(_562, _583, vec3(_609));
        }
        _418 = vec4(_562 * _424.y, _424.x);
    }
    vec3 _641 = IMAGE_LOAD(_644, _278.xy).xyz;
    vec3 _650;
    if (_403 == 1.0)
    {
        _650 = vec3(0.0);
    }
    else
    {
        _650 = _418.xyz + (_641 * _418.w);
    }
    _641 = _650;
    uvec2 _665 = uvec2(_278.xy) & uvec2(3u);
    vec2 _672;
    if (dot(_429._m1.zw, vec2(1.0)) > 0.0)
    {
        uint _694 = 16u;
        uint _695 = ((_665.x + (_665.y * 4u)) + uint(int(_429._m2.x))) & 7u;
        _672 = (_56(_694, _695) * 2.0) - vec2(1.0);
    }
    else
    {
        _672 = vec2(0.0);
    }
    vec2 _671 = _672;
    _671 = (_671 + vec2(0.5)) / _429._m4.xy;
    vec4 _710 = vec4(0.0);
    float _712 = 1.0;
    float _715 = _429._m5.w;
    uint _713 = _21(_715);
    if ((_713 & 6u) != 0u)
    {
        vec2 _725 = _301 + _671;
        vec3 _729 = _429._m4.xyz;
        float _733 = 0.100000001490116119384765625;
        float _735 = _429._m6.y;
        float _739 = _429._m4.z;
        float _742 = 0.0;
        float _745 = _403;
        vec4 _747 = _429._m7;
        float _750 = 1.0;
        bool _751 = false;
        float _743 = _46(_745, _747, _750, _751);
        _742 = pow((_743 - _733) / (_735 - _733), 0.5);
        _742 = (_742 * (_739 - 1.0)) / _739;
        vec4 _767 = vec4(_725, _742, 0.0);
        vec3 _793 = textureLod(_776, vec4(_767.xyz, 0.0).xyz, vec4(_767.xyz, 0.0).w).xyz;
        _710 = vec4(_793.x, _793.y, _793.z, _710.w);
        vec2 _796 = textureLod(_797, vec4(_767.xyz, 0.0).xyz, vec4(_767.xyz, 0.0).w).xy;
        _710.w = _796.x;
        _712 = _796.y;
    }
    if ((_713 & 2u) != 0u)
    {
        vec4 _825 = vec4(0.0);
        vec3 _826 = _429._m8.xyz;
        float _831 = _403;
        vec4 _833 = _429._m7;
        float _836 = 1.0;
        bool _837 = false;
        float _830 = _46(_831, _833, _836, _837);
        vec3 _839 = mix(_429._m9.xyz, _429._m10.xyz, vec3(_301.x * _429._m11.z));
        vec3 _856 = mix(_429._m12.xyz, _429._m13.xyz, vec3(_301.x * _429._m11.z));
        vec3 _872 = mix(_856, _839, vec3(1.0 - (_301.y * _429._m11.w)));
        vec4 _883 = vec4(0.0);
        vec3 _884 = normalize(_872);
        float _887 = _884.z;
        _883.x = clamp(_24(_887) / 3.1415927410125732421875, 0.00390625, 0.99609375);
        float _896 = _884.y;
        float _899 = _884.x;
        _883.y = _35(_896, _899) / 6.283185482025146484375;
        _883.z = sqrt(_830 * _429._m14.w);
        _883.z = clamp(_883.z, 0.015625, 0.984375);
        vec3 _926 = textureLod(_919, _883.xyz, _883.w).xyz;
        _825 = vec4(_926.x, _926.y, _926.z, _825.w);
        float _929 = _429._m15.w;
        if (_929 > 0.0)
        {
            float _937 = _429._m16.x * 1.57079637050628662109375;
            float _942 = _429._m17.x * 3.1415927410125732421875;
            vec3 _947 = vec3(sin(_937) * cos(_942), sin(_937) * sin(_942), cos(_937));
            float _961 = dot(normalize(_872), _947);
            vec3 _972;
            if (_429._m19.x > 0.0)
            {
                _972 = vec3(1.0);
            }
            else
            {
                _972 = _429._m20.xyz;
            }
            vec3 _966 = _972 * (10.0 * _429._m18.x);
            float _991 = _961;
            float _1000 = pow(_10(_991), 10000.0) * float(_403 == 1.0);
            vec3 _1005 = _825.xyz + ((_966 * (_929 * 10.0)) * _10(_1000));
            _825 = vec4(_1005.x, _1005.y, _1005.z, _825.w);
        }
        _641 += (_825.xyz * _712);
    }
    if ((_713 & 4u) != 0u)
    {
        _641 = (_641 * _710.w) + _710.xyz;
    }
    IMAGE_STORE(_644, _278.xy, vec4(_641, 1.0));
    IMAGE_STORE(_1034, _278.xy, vec4(_641, 1.0));
}

