
#version 460
 #extension GL_EXT_multiview : enable
// Vk3DVision SinglePass
///////////////////////////////////////////////////////////////////////////////

#define STEREO 1

#define VIEW gl_ViewIndex

// 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(early_fragment_tests) in;
// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
 
struct Vk3DStereo
{
	vec4 stereo;
	vec4 custom_params;
};
layout(set = 0, binding = 20, std140) uniform Vk3DParams
{
	Vk3DStereo vk3d_params[2];
};


   

layout(set = 0, binding = 0, std140) uniform _213_215
{
    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;
    float _m21;
    float _m22;
    float _m23;
    float _m24;
    float _m25;
    float _m26;
    float _m27;
    float _m28;
    float _m29;
    float _m30;
    float _m31;
    float _m32;
    float _m33;
    float _m34;
    float _m35;
    float _m36;
    float _m37;
    float _m38;
    uint _m39;
    float _m40;
    float _m41;
    float _m42;
    float _m43;
    float _m44;
    float _m45;
    float _m46;
    float _m47;
    float _m48;
    float _m49;
    float _m50;
    float _m51;
    float _m52[1];
} _215;

layout(set = 2, binding = 0, std140) uniform _286_288
{
    vec4 _m0;
    vec4 _m1;
    float _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;
    uint _m15;
    uint _m16;
    uint _m17;
    float _m18;
    float _m19[3];
} _288;

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

layout(set = 1, binding = 0, std140) uniform _902_904
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    int _m3;
    uint _m4;
    float _m5[2];
} _904;

layout(push_constant, std430) uniform _893_895
{
    int _m0;
} _895;

layout(set = 1, binding = 1) uniform texture2D _423;
layout(set = 0, binding = 6) uniform sampler _427;
layout(set = 3, binding = 0) uniform texture2D _516[34816];
layout(set = 0, binding = 7) uniform sampler _538;
layout(set = 0, binding = 8) uniform texture3D _675;
layout(set = 0, binding = 9) uniform sampler _677;
layout(set = 0, binding = 10) uniform texture3D _696;
layout(set = 0, binding = 11) uniform texture3D _796;
layout(set = 0, binding = 12) uniform texture2D _862;
layout(set = 0, binding = 13) uniform sampler _864;

layout(location = 17, component = 3) in float _327;
layout(location = 18, component = 0) in float _329;
layout(location = 19, component = 0) in float _335;
layout(location = 19, component = 1) in float _337;
layout(location = 19, component = 2) in float _339;
layout(location = 19, component = 3) in float _343;
layout(location = 20, component = 0) in float _345;
layout(location = 20, component = 1) in float _347;
layout(location = 20, component = 2) in float _359;
layout(location = 0, component = 0) out vec4 _593;
layout(location = 1, component = 0) out vec4 _831;
layout(location = 2, component = 0) out vec4 _832;
layout(location = 10, component = 0) in vec4 _905;
layout(location = 11, component = 0) in vec4 _906;
layout(location = 12, component = 0) in vec4 _907;
layout(location = 18, component = 1) in float _908;
layout(location = 18, component = 2) in float _909;
layout(location = 18, component = 3) in float _910;
uint _53;
uint _55;
uint _57;
uint _59;
uint _61;
uint _63;
uint _65;
uint _66;
uint _68;
uint _69;
uint _71;
uint _73;
uint _75;
uint _77;
uint _79;
uint _81;
uint _83;
uint _85;
uint _87;

vec2 _24(mat2 _22, vec2 _23)
{
    return _22 * _23;
}

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

float _45(inout float _43, bool _44)
{
    if (_44)
    {
        _43 += (float(_43 < _215._m21) * _215._m22);
    }
    float _233 = _43;
    return _215._m0.w / (_10(_233) + _215._m0.z);
}

uint _15(float _14)
{
    return floatBitsToUint(_14);
}

vec3 _50(vec2 _49)
{
    return (vec3(_215._m23, _215._m24, _215._m25) + (vec3(_215._m26, _215._m27, _215._m28) * _49.x)) + (vec3(_215._m29, _215._m30, _215._m31) * _49.y);
}

float _27(float _26)
{
    float _104 = (((-0.15658299624919891357421875) * abs(_26)) + 1.57079637050628662109375) * sqrt(1.0 - abs(_26));
    float _118;
    if (_26 >= 0.0)
    {
        _118 = _104;
    }
    else
    {
        _118 = 3.1415927410125732421875 - _104;
    }
    return _118;
}

float _30(float _29)
{
    float _132;
    if (_29 < 1.0)
    {
        _132 = _29;
    }
    else
    {
        _132 = 1.0 / _29;
    }
    float _129 = _132;
    float _140 = _129 * _129;
    float _144 = 0.087292902171611785888671875;
    _144 = (-0.3018949925899505615234375) + (_144 * _140);
    _144 = 1.0 + (_144 * _140);
    _144 *= _129;
    float _160;
    if (_29 < 1.0)
    {
        _160 = _144;
    }
    else
    {
        _160 = 1.57079637050628662109375 - _144;
    }
    return _160;
}

float _33(float _32)
{
    float _173 = abs(_32);
    float _170 = _30(_173);
    float _177;
    if (_32 < 0.0)
    {
        _177 = -_170;
    }
    else
    {
        _177 = _170;
    }
    return _177;
}

float _38(float _36, float _37)
{
    float _191 = _36 / _37;
    float _187 = _33(_191);
    if (_37 < 0.0)
    {
        _187 += ((_36 >= 0.0) ? 3.1415927410125732421875 : (-3.1415927410125732421875));
    }
    return _187;
}

void main()
{
    _53 = 2147483648u;
    _55 = 1073741824u;
    _57 = 0u;
    _59 = 268435456u;
    _61 = 536870912u;
    _63 = 805306368u;
    _65 = 1073741824u;
    _66 = 1342177280u;
    _68 = 0u;
    _69 = 16777216u;
    _71 = 33554432u;
    _73 = 50331648u;
    _75 = 67108864u;
    _77 = 83886080u;
    _79 = 100663296u;
    _81 = 117440512u;
    _83 = 134217728u;
    _85 = 150994944u;
    _87 = 167772160u;
    vec3 _282 = vec3(1.0, 0.0, 0.0);
    float _284 = _288._m9 * 0.01745329238474369049072265625;
    float _294 = sin(_284);
    float _297 = cos(_284);
    mat2 _300 = mat2(vec2(vec2(_297, -_294)), vec2(vec2(_294, _297)));
    mat2 _315 = _300;
    vec2 _317 = _282.xy;
    vec2 _320 = _24(_315, _317);
    _282 = vec3(_320.x, _320.y, _282.z);
    _282 = normalize(_282);
    vec2 _325 = vec2(_327, _329);
    vec3 _332 = vec3(0.0);
    vec3 _334 = vec3(0.0);
    _332 = normalize(vec3(_335, _337, _339));
    _334 = normalize(vec3(_343, _345, _347));
    vec3 _351 = _332;
    vec3 _353 = _334;
    vec3 _355 = normalize(cross(_351, _353) * _359);
    mat3 _365 = mat3(vec3(_353), vec3(_355), vec3(_351));
    vec3 _382 = normalize(_365[1]);
    vec3 _387 = normalize(cross(_334, _382));
    float _392 = dot(_387, _282);
    float _396 = dot(_334, _282);
    vec3 _400 = vec3(_396, _392, 0.0);
    float _404 = (_329 * 0.5) + 0.5;
    _404 *= ((_404 * _404) * _404);
    _400 = mix(_400, vec3(0.0), vec3(_404));
    vec2 _420 = (textureLod(sampler2D(_423, _427), vec4(_325 * _288._m1.xy, 0.0, 0.0).xy, vec4(_325 * _288._m1.xy, 0.0, 0.0).w).yx * 0.5) + vec2(0.5);
    float _455 = dot(_420, vec2(0.5));
    float _459 = fract((_215._m50 * _288._m10) + _455) * _288._m11;
    float _474 = fract(((_215._m50 * _288._m10) + 0.5) + _455) * _288._m11;
    vec2 _487 = vec2(_288._m12, _288._m13);
    vec2 _495 = _487 * _215._m50;
    vec2 _500 = _325 + _495;
    vec2 _504 = _400.xy;
    if (_288._m14 < 1.0)
    {
        _504 = (texture(sampler2D(_516[_288._m15], _427), _500).xy * 2.0) - vec2(1.0);
    }
    vec3 _532 = texture(sampler2D(_516[_288._m16], _538), _500 + (_504 * _459)).xyz;
    vec3 _548 = texture(sampler2D(_516[_288._m16], _538), _500 + (_504 * _474)).xyz;
    float _562 = _288._m11 * 0.5;
    float _573 = abs(_562 - _459) / _562;
    float _566 = _10(_573);
    vec3 _575 = mix(_532, _548, vec3(_566));
    float _581 = texture(sampler2D(_516[_288._m17], _427), _500).x;
    vec3 _600 = (_575 * _288._m18) * _581;
    _593 = vec4(_600.x, _600.y, _600.z, _593.w);
    _593.w = _581;
    vec2 _606 = vec4(gl_FragCoord.xy, 1.0 - gl_FragCoord.z, gl_FragCoord.w).xy * _215._m16.xy;
    float _636 = vec4(gl_FragCoord.xy, 1.0 - gl_FragCoord.z, gl_FragCoord.w).z;
    bool _638 = false;
    float _639 = _45(_636, _638);
    float _624 = _639;
    vec2 _640 = _606 + vec2(0.0);
    float _644 = 0.119999997317790985107421875;
    float _646 = _215._m17.y;
    float _649 = _215._m18.z + 1.0;
    float _653 = pow(max(0.0, _624 - _644) / (_646 - _644), 0.5);
    float _663 = (0.5 / _649) + (_653 * (1.0 - (1.0 / _649)));
    _640.x -= vk3d_params[VIEW].stereo.x * 0.5;
    vec3 _672 = textureLod(sampler3D(_675, _677), vec4(_640, _663, 0.0).xyz, vec4(_640, _663, 0.0).w).xyz;
    vec2 _695 = textureLod(sampler3D(_696, _677), vec4(_640, _663, 0.0).xyz, vec4(_640, _663, 0.0).w).xy;
    float _714 = _695.x;
    float _717 = _695.y;
    float _723 = _215._m51;
    uint _721 = _15(_723);
    bool _727 = (_721 & 2u) != 0u;
    _672 *= float(_727);
    _714 = _727 ? _714 : 1.0;
    vec3 _738 = vec3(0.0);
    if ((_721 & 1u) != 0u)
    {
        vec3 _744 = vec3(_215._m32, _215._m33, _215._m34);
        vec3 _755 = _50(_606);
        vec4 _759 = vec4(0.0);
        vec3 _761 = normalize(_755);
        float _764 = _761.z;
        _759.x = clamp(_27(_764) / 3.1415927410125732421875, 0.00390625, 0.99609375);
        float _773 = _761.y;
        float _776 = _761.x;
        _759.y = _38(_773, _776) / 6.283185482025146484375;
        _759.z = sqrt(_624 * _215._m19.w);
        _759.z = clamp(_759.z, 0.015625, 0.984375);
        _738 = textureLod(sampler3D(_796, _538), _759.xyz, _759.w).xyz;
        _738 *= _717;
    }
    vec3 _816 = ((_593.xyz + _738) * _714) + _672;
    _593 = vec4(_816.x, _816.y, _816.z, _593.w);
    float _819 = _593.w;
    _593.w = _10(_819);
    vec3 _828 = _593.xyz * _593.w;
    _593 = vec4(_828.x, _828.y, _828.z, _593.w);
    _831 = vec4(0.0);
    _832 = vec4(0.0);
    float _833 = _215._m20.w;
    if (!(_833 == 0.0))
    {
        vec2 _841 = vec4(gl_FragCoord.xy, 1.0 - gl_FragCoord.z, gl_FragCoord.w).xy * _215._m16.xy;
        bool _857 = ((1.0 - gl_FragCoord.z) - 0.0) < (1.0 - textureLod(sampler2D(_862, _864), vec4(_841, 0.0, 0.0).xy, vec4(_841, 0.0, 0.0).w).x);
        _831 = _593 * float(!_857);
        _593 *= float(_857);
        _832 = vec4(_593.w);
    }
}

