#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 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 
 ///////////////////////////////////////////////////////////////////////////////


// 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 _102_104
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    vec4 _m3;
    vec4 _m4;
    vec4 _m5;
    vec4 _m6;
    vec4 _m7;
    vec4 _m8;
    vec4 _m9;
    vec4 _m10;
    vec4 _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;
    float _m25;
    float _m26;
    float _m27;
    float _m28;
    float _m29;
    uint _m30;
    float _m31;
    float _m32;
    float _m33;
    float _m34;
    float _m35;
    float _m36;
    float _m37;
    float _m38;
    float _m39;
    float _m40;
    float _m41;
    float _m42;
    float _m43;
    float _m44;
    float _m45;
    float _m46;
    float _m47[1];
} _104;

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

layout(set = 1, binding = 0, std140) uniform _516_518
{
    float _m0;
    float _m1[3];
} _518;

layout(set = 0, binding = 7) uniform TEXTURE_2D _238;
layout(set = 0, binding = 2) uniform sampler _242;
layout(set = 0, binding = 8) uniform TEXTURE_2D _284;
layout(set = 0, binding = 9) uniform sampler _286;
layout(set = 0, binding = 3) uniform texture3D _510;
layout(set = 0, binding = 4) uniform sampler _511;
layout(set = 0, binding = 5) uniform texture3D _512;
layout(set = 0, binding = 6) uniform sampler _513;
layout(set = 1, binding = 1) uniform TEXTURE_2D _514;

layout(location = 2, component = 0) in vec4 _275;
layout(location = 3, component = 0) in vec4 _279;
layout(location = 0, component = 0) out vec4 _471;
layout(location = 1, component = 0) out vec4 _484;
layout(location = 4, component = 0) in vec4 _485;
uint _42;
uint _44;
uint _46;
uint _48;
uint _50;
uint _52;
uint _54;
uint _55;
uint _57;
uint _58;
uint _60;
uint _62;
uint _64;
uint _66;
uint _68;
uint _70;
uint _72;
uint _74;
uint _76;

void _20(float _19)
{
    if (_19 < 0.0)
    {
        discard;
    }
}

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

float _27(inout float _25, bool _26)
{
    if (_26)
    {
        _25 += (float(_25 < _104._m12) * _104._m13);
    }
    float _122 = _25;
    return _104._m0.w / (_10(_122) + _104._m0.z);
}

vec2 _33(vec2 _32)
{
    return (vec2(1.0) - abs(_32.yx)) * vec2((_32.x >= 0.0) ? 1.0 : (-1.0), (_32.y >= 0.0) ? 1.0 : (-1.0));
}

vec2 _38(inout vec3 _36, bool _37)
{
    _36 /= vec3((abs(_36.x) + abs(_36.y)) + abs(_36.z));
    vec2 _167;
    if (_36.z >= 0.0)
    {
        _167 = _36.xy;
    }
    else
    {
        vec2 _173 = _36.xy;
        _167 = _33(_173);
    }
    _36 = vec3(_167.x, _167.y, _36.z);
    if (_37)
    {
        vec2 _188 = (_36.xy * 0.5) + vec2(0.5);
        _36 = vec3(_188.x, _188.y, _36.z);
    }
    return _36.xy;
}

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

void main()
{
    _42 = 2147483648u;
    _44 = 1073741824u;
    _46 = 0u;
    _48 = 268435456u;
    _50 = 536870912u;
    _52 = 805306368u;
    _54 = 1073741824u;
    _55 = 1342177280u;
    _57 = 0u;
    _58 = 16777216u;
    _60 = 33554432u;
    _62 = 50331648u;
    _64 = 67108864u;
    _66 = 83886080u;
    _68 = 100663296u;
    _70 = 117440512u;
    _72 = 134217728u;
    _74 = 150994944u;
    _76 = 167772160u;
    vec2 _195 = _104._m3.zw;
    vec2 _201 = vec4(gl_FragCoord.xy, 1.0 - gl_FragCoord.z, gl_FragCoord.w).xy * _195;
    vec2 _218 = vec2(_201.x / _104._m42, _201.y);
    vec2 _228 = _218 * _104._m11.xy;
    float _235 = 1.0 - TEXTURE_LOD(SAMPLER_2D(_238, _242), vec4(_228, 0.0, 0.0).xy, vec4(_228, 0.0, 0.0).w).x;
    float _264 = _235 - (1.0 - gl_FragCoord.z);
    _20(_264);
    float _271 = 1.0 - gl_FragCoord.z;
    bool _272 = false;
    float _273 = _27(_271, _272);
    float _266 = _273;
    vec3 _274 = _275.xyz;
    vec3 _278 = normalize(_279.xyz);
    vec2 _304 = (SAMPLE_TEXTURE(SAMPLER_2D(_284, _286), (_274.xy * (_104._m43 / 100.0)) * 4.0).xy * 2.0) - vec2(1.0);
    vec3 _283;
    _283 = vec3(_304.x, _304.y, _283.z);
    float _319 = (1.0 - (_283.x * _283.x)) - (_283.y * _283.y);
    _283.z = sqrt(_10(_319));
    _283 = mix(vec3(0.0, 0.0, 1.0), _283, vec3(_104._m44));
    float _335 = _266 / 1024.0;
    _278 = mix(_278, _283, vec3(_10(_335)));
    vec3 _339 = vec3(0.0);
    vec2 _341 = _274.xy * _104._m45;
    vec2 _374 = (SAMPLE_TEXTURE(SAMPLER_2D(_284, _286), ((_341 / vec2(2.0)) + (((vec2(_104._m46) * 0.0) * 0.0500000007450580596923828125) * _104._m45)) + (_278.xy * 0.02500000037252902984619140625)).xy * 2.0) - vec2(1.0);
    _339 = vec3(_374.x, _374.y, _339.z);
    vec2 _403 = _339.xy + ((SAMPLE_TEXTURE(SAMPLER_2D(_284, _286), ((_341 / vec2(4.0)) + (((vec2(_104._m46) * 0.0) * 0.0500000007450580596923828125) * _104._m45)) + (_278.xy * 0.02500000037252902984619140625)).xy * 2.0) - vec2(1.0));
    _339 = vec3(_403.x, _403.y, _339.z);
    vec2 _424 = _339.xy + ((SAMPLE_TEXTURE(SAMPLER_2D(_284, _286), (_341 / vec2(8.0)) + (_278.xy * 0.02500000037252902984619140625)).xy * 2.0) - vec2(1.0));
    _339 = vec3(_424.x, _424.y, _339.z);
    vec2 _433 = _339.xy * (0.333000004291534423828125 * _104._m44);
    _339 = vec3(_433.x, _433.y, _339.z);
    float _448 = (1.0 - (_339.x * _339.x)) - (_339.y * _339.y);
    _339.z = sqrt(_10(_448));
    vec2 _456 = _278.xy + _339.xy;
    _278 = vec3(_456.x, _456.y, _278.z);
    _278 = normalize(_278);
    float _461 = float(_275.w >= 0.5);
    float _466 = 1.0 - (2.0 * _461);
    vec3 _476 = _278 * _466;
    bool _477 = true;
    vec2 _478 = _38(_476, _477);
    _471 = vec4(_478.x, _478.y, _471.z, _471.w);
    _471 = vec4(_471.x, _471.y, vec2(0.0).x, vec2(0.0).y);
    _484 = vec4(_485.xyz.x, _485.xyz.y, _485.xyz.z, _484.w);
    vec3 _495 = _484.xyz / vec3(16.0);
    vec3 _497 = sqrt(_16(_495));
    _484 = vec4(_497.x, _497.y, _497.z, _484.w);
    _484.w = _461;
}





