#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 
 ///////////////////////////////////////////////////////////////////////////////
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

layout(set = 0, binding = 0, std140) uniform _139_141
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    vec4 _m3;
    vec4 _m4;
    vec4 _m5;
    vec4 _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;
    float _m21;
    float _m22;
    float _m23;
    float _m24;
    uint _m25;
    float _m26;
    float _m27;
    float _m28;
    float _m29[2];
} _141;

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

layout(set = 0, binding = 2) uniform TEXTURE_2D _214;
layout(set = 0, binding = 3) uniform sampler _218;
layout(set = 0, binding = 4) uniform sampler _250;
layout(set = 0, binding = 5) uniform TEXTURE_2D _314;
layout(set = 1, binding = 1, r11f_g11f_b10f) uniform writeonly image3D _441;
layout(set = 1, binding = 2, r11f_g11f_b10f) uniform writeonly image3D _453;
layout(set = 1, binding = 3, r11f_g11f_b10f) uniform readonly image3D _472;
layout(set = 1, binding = 4, r11f_g11f_b10f) uniform readonly image3D _484;

uint _43;
uint _45;
uint _47;
uint _49;
uint _51;
uint _53;
uint _55;
uint _56;
uint _58;
uint _59;
uint _61;
uint _63;
uint _65;
uint _67;
uint _69;
uint _71;
uint _73;
uint _75;
uint _77;

float _16(float _13, float _14, float _15)
{
    return min(_13, min(_14, _15));
}

float _27(vec4 _26)
{
    float _99 = _26.y;
    float _103 = _26.z;
    float _107 = _26.w;
    return min(_26.x, _16(_99, _103, _107));
}

float _32(float _30, vec4 _31)
{
    float _115 = _31.y;
    float _118 = _31.z;
    float _121 = _31.w;
    float _125 = _30;
    float _127 = _31.x;
    float _130 = _16(_115, _118, _121);
    return _16(_125, _127, _130);
}

float _21(float _19, float _20)
{
    return min(_19, _20);
}

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

float _39(inout float _37, bool _38)
{
    if (_38)
    {
        _37 += (float(_37 < _141._m7) * _141._m8);
    }
    float _158 = _37;
    return _141._m0.w / (_10(_158) + _141._m0.z);
}

void main()
{
    _43 = 2147483648u;
    _45 = 1073741824u;
    _47 = 0u;
    _49 = 268435456u;
    _51 = 536870912u;
    _53 = 805306368u;
    _55 = 1073741824u;
    _56 = 1342177280u;
    _58 = 0u;
    _59 = 16777216u;
    _61 = 33554432u;
    _63 = 50331648u;
    _65 = 67108864u;
    _67 = 83886080u;
    _69 = 100663296u;
    _71 = 117440512u;
    _73 = 134217728u;
    _75 = 150994944u;
    _77 = 167772160u;
    vec3 _169 = _141._m3.xyz;
    ivec3 _177 = ivec3(GlobalInvocationID);
    float _183 = 0.119999997317790985107421875;
    float _185 = _141._m4.y;
    vec2 _191 = vec2(vec2(_177.xy) + vec2(0.5)) / _169.xy;
    float _205 = 0.0;
    float _206 = 0.0;
    if (_141._m4.x == 0.0)
    {
        vec4 _232 = TEXTURE_GATHER1(SAMPLER_2D(_214, _218), _191 + (vec2(-0.5, 0.5) * _141._m5.zw));
        _206 = _27(_232);
        float _245 = _206;
        vec4 _247 = TEXTURE_GATHER1(SAMPLER_2D(_214, _218), _191 + (vec2(0.5, -0.5) * _141._m5.zw));
        _206 = _32(_245, _247);
        float _275 = _206;
        float _277 = TEXTURE_LOD(SAMPLER_2D(_214, _250), vec4(_191 + (vec2(1.0) * _141._m5.zw), 0.0, 0.0).xy, vec4(_191 + (vec2(1.0) * _141._m5.zw), 0.0, 0.0).w).x;
        _206 = _21(_275, _277);
        float _306 = _206;
        float _308 = TEXTURE_LOD(SAMPLER_2D(_214, _250), vec4(_191 + (vec2(-1.0) * _141._m5.zw), 0.0, 0.0).xy, vec4(_191 + (vec2(-1.0) * _141._m5.zw), 0.0, 0.0).w).x;
        _206 = _21(_306, _308);
        _206 = 1.0 - _206;
    }
    else
    {
        vec4 _326 = TEXTURE_GATHER1(SAMPLER_2D(_314, _218), _191 + (vec2(-0.5, 0.5) * _141._m6.zw));
        _206 = _27(_326);
        float _338 = _206;
        vec4 _340 = TEXTURE_GATHER1(SAMPLER_2D(_314, _218), _191 + (vec2(0.5, -0.5) * _141._m6.zw));
        _206 = _32(_338, _340);
        float _366 = _206;
        float _368 = TEXTURE_LOD(SAMPLER_2D(_314, _250), vec4(_191 + (vec2(1.0) * _141._m6.zw), 0.0, 0.0).xy, vec4(_191 + (vec2(1.0) * _141._m6.zw), 0.0, 0.0).w).x;
        _206 = _21(_366, _368);
        float _395 = _206;
        float _397 = TEXTURE_LOD(SAMPLER_2D(_314, _250), vec4(_191 + (vec2(-1.0) * _141._m6.zw), 0.0, 0.0).xy, vec4(_191 + (vec2(-1.0) * _141._m6.zw), 0.0, 0.0).w).x;
        _206 = _21(_395, _397);
        _206 = 1.0 - _206;
    }
    float _403 = _206;
    bool _405 = false;
    float _406 = _39(_403, _405);
    _205 = _406;
    float _407 = pow(max(0.0, _205 - _183) / (_185 - _183), 0.5);
    int _418 = int(_407 * _169.z) + 1;
    _418 += 2;
    _418 = min(int(_169.z), _418);
    vec3 _434 = vec3(0.0);
    float _436 = 0.0;
    float _437 = 0.0;
    float _438 = 1.0;
    imageStore(_441, ivec3(_177.xy, 0), vec4(_434, 0.0));
    imageStore(_453, ivec3(_177.xy, 0), vec4(_438, 0.0, 0.0, 0.0));
    for (int _462 = 1; _462 <= _418; _462++)
    {
        vec3 _471 = imageLoad(_472, ivec3(_177.xy, _462 - 1)).xyz;
        vec2 _483 = imageLoad(_484, ivec3(_177.xy, _462 - 1)).xy;
        float _495 = _483.x;
        float _498 = _483.y;
        _434 += (_471 * _438);
        _436 += _495;
        _437 += _498;
        float _515 = exp(-_436);
        _438 = _10(_515);
        float _517 = _437 / float(_462);
        imageStore(_441, ivec3(_177.xy, _462), vec4(_434, 0.0));
        imageStore(_453, ivec3(_177.xy, _462), vec4(_438, _517, 0.0, 0.0));
    }
}

