// DAMN FOG
#version 460
 #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 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 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, comp)
	#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 
 ///////////////////////////////////////////////////////////////////////////////

// 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];
};

#extension GL_KHR_shader_subgroup_basic : require
#extension GL_KHR_shader_subgroup_shuffle : require
#extension GL_KHR_shader_subgroup_ballot : require
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;

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

layout(set = 0, binding = 0, std140) uniform _300_302
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    float _m3;
    float _m4;
    float _m5;
    float _m6;
    float _m7;
    float _m8;
    float _m9;
    float _m10;
    float _m11;
    float _m12;
    float _m13;
    float _m14;
    float _m15;
    float _m16;
    float _m17;
    float _m18;
    float _m19;
    float _m20;
    uint _m21;
    float _m22;
    float _m23;
    float _m24;
    float _m25[2];
} _302;

layout(set = 0, binding = 1, std140) uniform _771_773
{
    vec4 _m0[64];
} _773;

layout(set = 0, binding = 2) uniform TEXTURE_2D _272;
layout(set = 0, binding = 3) uniform sampler _276;
layout(set = 1, binding = 1) uniform TEXTURE_2D _283;
layout(set = 1, binding = 2, r32f) uniform writeonly IMAGE_2D _492;
layout(set = 1, binding = 3, r16f) uniform writeonly IMAGE_2D _499;
layout(set = 1, binding = 4, r16f) uniform writeonly IMAGE_2D _510;
layout(set = 1, binding = 5, r32f) uniform writeonly IMAGE_2D _728;
layout(set = 1, binding = 6, r32f) uniform writeonly IMAGE_2D _750;
layout(set = 1, binding = 7, r32f) uniform writeonly IMAGE_2D _760;

uint _57;
uint _59;
uint _61;
uint _63;
uint _65;
uint _67;
uint _69;
uint _70;
uint _72;
uint _73;
uint _75;
uint _77;
uint _79;
uint _81;
uint _83;
uint _85;
uint _87;
uint _89;
uint _91;
shared uint _435[64];
shared uint _440[64];

bool _54(float _53)
{
    return (_53 == 0.0) ? true : false;
}

vec4 _11(vec4 _10)
{
    return clamp(_10, vec4(0.0), vec4(1.0));
}

float _33(float _30, float _31, float _32)
{
    return min(_30, min(_31, _32));
}

float _49(vec4 _48)
{
    float _153 = _48.y;
    float _156 = _48.z;
    float _159 = _48.w;
    return min(_48.x, _33(_153, _156, _159));
}

float _28(float _25, float _26, float _27)
{
    return max(_25, max(_26, _27));
}

float _46(vec4 _45)
{
    float _135 = _45.y;
    float _139 = _45.z;
    float _143 = _45.w;
    return max(_45.x, _28(_135, _139, _143));
}

float _42(float _40, float _41)
{
    return min(_40, _41);
}

float _38(float _36, float _37)
{
    return max(_36, _37);
}

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

float _17(uint _16)
{
    return uintBitsToFloat(_16);
}

void main()
{
    _57 = 2147483648u;
    _59 = 1073741824u;
    _61 = 0u;
    _63 = 268435456u;
    _65 = 536870912u;
    _67 = 805306368u;
    _69 = 1073741824u;
    _70 = 1342177280u;
    _72 = 0u;
    _73 = 16777216u;
    _75 = 33554432u;
    _77 = 50331648u;
    _79 = 67108864u;
    _81 = 83886080u;
    _83 = 100663296u;
    _85 = 117440512u;
    _87 = 134217728u;
    _89 = 150994944u;
    _91 = 167772160u;
    uint _173 = gl_SubgroupID;
    uint _177 = gl_SubgroupSize;
    uint _180 = gl_SubgroupInvocationID;
    uint _183 = 256u / _177;
    uint _187 = uint(floor(sqrt(float(_183))));
    uint _193 = _183 / _187;
    uint _197 = 16u / _187;
    uint _201 = 16u / _193;
    ivec2 _207 = (ivec2(int(_173 % _187), int(_173 / _187)) * ivec2(int(_197), int(_201))) + ivec2(int(_180 % _197), int(_180 / _197));
    ivec2 _233 = (ivec2(WorkGroupID.xy) * ivec2(16)) + _207;
    vec2 _248 = ((vec2(_233) * 2.0) * _255._m0.xy) + (vec2(0.5) * _255._m0.xy);
    
    // FIX
    vec4 _269 = TEXTURE_GATHER1(SAMPLER_2D(_272, _276), _248);
    _269.x = 0; 
    vec4 _282 = TEXTURE_GATHER1(SAMPLER_2D(_283, _276), _248);
    float _289 = _282.x;
    float _294;
    if (_54(_289) == true)
    {
        _294 = _269.x - _302._m4;
    }
    else
    {
        _294 = _269.x;
    }
    _269.x = _294;
    float _313 = _282.y;
    float _318;
    if (_54(_313) == true)
    {
        _318 = _269.y - _302._m4;
    }
    else
    {
        _318 = _269.y;
    }
    _269.y = _318;
    float _331 = _282.z;
    float _336;
    if (_54(_331) == true)
    {
        _336 = _269.z - _302._m4;
    }
    else
    {
        _336 = _269.z;
    }
    _269.z = _336;
    float _349 = _282.w;
    float _354;
    if (_54(_349) == true)
    {
        _354 = _269.w - _302._m4;
    }
    else
    {
        _354 = _269.w;
    }
    _269.w = _354;
    vec4 _368 = _269;
    vec4 _371 = _11(_368);
    float _367 = _49(_371);
    vec4 _374 = _269;
    vec4 _377 = _11(_374);
    float _373 = _46(_377);
    float _379 = 0.0;
    float _380 = 0.0;
    if (_177 >= 16u)
    {
        float _387 = _367;
        float _389 = subgroupShuffleXor(_367, 1u);
        _379 = _42(_387, _389);
        float _393 = _373;
        float _395 = subgroupShuffleXor(_373, 1u);
        _380 = _38(_393, _395);
        float _400 = _379;
        float _402 = subgroupShuffleXor(_379, 8u);
        _379 = _42(_400, _402);
        float _406 = _380;
        float _408 = subgroupShuffleXor(_380, 8u);
        _380 = _38(_406, _408);
    }
    else
    {
        uint _411 = uint(_207.x) / 2u;
        uint _417 = uint(_207.y) / 2u;
        uint _422 = _411 + (_417 * 8u);
        if (gl_LocalInvocationIndex < 64u)
        {
            _435[gl_LocalInvocationIndex] = 4294967295u;
            _440[gl_LocalInvocationIndex] = 0u;
        }
        groupMemoryBarrier();
        barrier();
        uint _445 = 1u;
        uint _446 = 0u;
        bool _454 = ((uint(_207.x) + _446) % _445) == 0u;
        bool _465;
        if (_454)
        {
            _465 = ((uint(_207.y) + _446) % _445) == 0u;
        }
        else
        {
            _465 = _454;
        }
        if (_465)
        {
            float _470 = _367;
            uint _473 = atomicMin(_435[_422], _22(_470));
            float _476 = _373;
            uint _479 = atomicMax(_440[_422], _22(_476));
        }
        groupMemoryBarrier();
        barrier();
        uint _481 = _435[_422];
        _379 = _17(_481);
        uint _486 = _440[_422];
        _380 = _17(_486);
        groupMemoryBarrier();
        barrier();
    }
    IMAGE_STORE(_492, _233, vec4(_367));
    IMAGE_STORE(_499, _233, vec4(_367));
    if ((_180 & 9u) == 0u)
    {
        IMAGE_STORE(_510, _233 / ivec2(2), vec4(_379));
    }
    float _518 = 0.0;
    float _519 = 0.0;
    if (_177 >= 32u)
    {
        float _527 = _379;
        float _529 = subgroupShuffleXor(_379, 2u);
        _518 = _42(_527, _529);
        float _533 = _380;
        float _535 = subgroupShuffleXor(_380, 2u);
        _519 = _38(_533, _535);
        float _539 = _518;
        float _541 = subgroupShuffleXor(_518, 16u);
        _518 = _42(_539, _541);
        float _545 = _519;
        float _547 = subgroupShuffleXor(_519, 16u);
        _519 = _38(_545, _547);
    }
    else
    {
        uint _550 = uint(_207.x) / 4u;
        uint _556 = uint(_207.y) / 4u;
        uint _561 = _550 + (_556 * 4u);
        if (gl_LocalInvocationIndex < 16u)
        {
            _435[gl_LocalInvocationIndex] = 4294967295u;
            _440[gl_LocalInvocationIndex] = 0u;
        }
        groupMemoryBarrier();
        barrier();
        uint _574 = 2u;
        uint _575 = 1u;
        bool _583 = ((uint(_207.x) + _575) % _574) == 0u;
        bool _594;
        if (_583)
        {
            _594 = ((uint(_207.y) + _575) % _574) == 0u;
        }
        else
        {
            _594 = _583;
        }
        if (_594)
        {
            float _599 = _379;
            uint _602 = atomicMin(_435[_561], _22(_599));
            float _605 = _380;
            uint _608 = atomicMax(_440[_561], _22(_605));
        }
        groupMemoryBarrier();
        barrier();
        uint _610 = _435[_561];
        _518 = _17(_610);
        uint _615 = _440[_561];
        _519 = _17(_615);
        groupMemoryBarrier();
        barrier();
    }
    float _619 = 0.0;
    float _620 = 0.0;
    if (_177 >= 64u)
    {
        float _627 = _518;
        float _629 = subgroupShuffleXor(_518, 4u);
        _619 = _42(_627, _629);
        float _633 = _519;
        float _635 = subgroupShuffleXor(_519, 4u);
        _620 = _38(_633, _635);
        float _639 = _619;
        float _641 = subgroupBroadcast(_619, 32u);
        _619 = _42(_639, _641);
        float _645 = _620;
        float _647 = subgroupBroadcast(_620, 32u);
        _620 = _38(_645, _647);
    }
    else
    {
        uint _650 = uint(_207.x) / 8u;
        uint _655 = uint(_207.y) / 8u;
        uint _660 = _650 + (_655 * 2u);
        if (gl_LocalInvocationIndex < 4u)
        {
            _435[gl_LocalInvocationIndex] = 4294967295u;
            _440[gl_LocalInvocationIndex] = 0u;
        }
        groupMemoryBarrier();
        barrier();
        uint _673 = 4u;
        uint _674 = 2u;
        bool _682 = ((uint(_207.x) + _674) % _673) == 0u;
        bool _693;
        if (_682)
        {
            _693 = ((uint(_207.y) + _674) % _673) == 0u;
        }
        else
        {
            _693 = _682;
        }
        if (_693)
        {
            float _698 = _518;
            uint _701 = atomicMin(_435[_660], _22(_698));
            float _704 = _519;
            uint _707 = atomicMax(_440[_660], _22(_704));
        }
        groupMemoryBarrier();
        barrier();
        uint _709 = _435[_660];
        _619 = _17(_709);
        uint _714 = _440[_660];
        _620 = _17(_714);
        groupMemoryBarrier();
        barrier();
    }
    if (gl_LocalInvocationIndex == 0u)
    {
        _435[0] = 4294967295u;
        _440[0] = 0u;
    }
    groupMemoryBarrier();
    barrier();
    if (_180 == 0u)
    {
        IMAGE_STORE(_728, _233 / ivec2(8), vec4(_619));
        float _737 = _619;
        uint _740 = atomicMin(_435[0], _22(_737));
        float _742 = _620;
        uint _745 = atomicMax(_440[0], _22(_742));
    }
    groupMemoryBarrier();
    barrier();
    if (gl_LocalInvocationIndex == 0u)
    {
        uint _755 = _440[0];
        IMAGE_STORE(_750, _233 / ivec2(16), vec4(_17(_755)));
        uint _765 = _435[0];
        IMAGE_STORE(_760, _233 / ivec2(16), vec4(_17(_765)));
    }
}








