#version 450
 #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 = 10, std140) uniform Vk3DParams
{
	Vk3DStereo vk3d_params[2];
};

layout(set = 0, binding = 0, std140) uniform _114_116
{
    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;
} _116;

layout(set = 2, binding = 0, std140) uniform _151_153
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    vec4 _m3;
    vec4 _m4;
} _153;

layout(set = 1, binding = 0, std140) uniform _256_258
{
    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;
    vec4 _m21;
    vec4 _m22;
    vec4 _m23;
    vec4 _m24;
    vec4 _m25;
    vec4 _m26;
    vec4 _m27;
    vec4 _m28;
    vec4 _m29;
    vec4 _m30;
    vec4 _m31;
    vec4 _m32;
} _258;

layout(set = 0, binding = 1, std430) restrict readonly buffer _422_424
{
    vec4 _m0[];
} _424;

layout(push_constant, std430) uniform _418_420
{
    int _m0;
    int _m1;
} _420;

layout(set = 2, binding = 1) uniform SAMPLER_2D _93;
layout(set = 1, binding = 1) uniform SAMPLER_2D _171;
layout(set = 2, binding = 2) uniform SAMPLER_2D _251;

layout(location = 2) in vec4 _96;
layout(location = 0) out vec4 _163;
layout(location = 8) in vec4 _166;
layout(location = 9) in vec4 _173;
layout(location = 7) in vec4 _253;
layout(location = 3) in vec4 _376;
layout(location = 4) in vec4 _387;

float _30(uvec2 _28, uint _29)
{
    uvec2 _49 = _28 & uvec2(3u);
    return float(((((2068378560u * (1u - (_49.x >> uint(1)))) + (1500172770u * (_49.x >> uint(1)))) >> ((_49.y + ((_49.x & 1u) << uint(2))) << uint(2))) + _29) & 15u) / 16.0;
}

void _10(float _9)
{
    if (_9 < 0.0)
    {
        discard;
    }
}

float _21(vec4 _19, vec4 _20)
{
    return dot(_19, _20);
}

float _14(float _13)
{
    return clamp(_13, 0.0, 1.0);
}

void main()
{
    float _89 = SAMPLE_TEXTURE1(_93, vec4(_96.zw, 0.0, -2.0).xy, vec4(_96.zw, 0.0, -2.0).w).x;
    int _126;
    if (dot(_116._m13.zw, vec2(1.0)) > 0.0)
    {
        _126 = int(_116._m14.x) & 15;
    }
    else
    {
        _126 = 0;
    }
    uint _113 = uint(_126);
    uvec2 _145 = uvec2(gl_FragCoord.xy);
    uint _146 = _113;
    float _140 = _30(_145, _146);
    float _160 = (_89 - (_140 * _153._m2.w)) - 0.0039215688593685626983642578125;
    _10(_160);
    _163 = vec4(0.0);
    float _165 = _166.w;
    vec4 _170 = SAMPLE_TEXTURE(_171, _173.xy);
    vec3 _182 = _170.xyz - vec3(0.5);
    _170 = vec4(_182.x, _182.y, _182.z, _170.w);
    if (_153._m3.x > 0.5)
    {
        float _191 = _165;
        float _193 = _191;
        _10(_193);
    }
    vec2 _197 = gl_FragCoord.xy * _116._m15.xy;
    _197.y = 1.0 - _197.y;
    vec4 _208 = vec4((_197.x * 2.0) - 1.0, (_197.y * 2.0) - 1.0, gl_FragCoord.z, 1.0);
    vec3 _223;
    _223.x = dot(_208, _116._m16);
    _223.y = dot(_208, _116._m17);
    _223.z = dot(_208, _116._m18);
    _223 /= vec3(dot(_208, _116._m19));
    float _250 = SAMPLE_TEXTURE(_251, _253.xy * vec2(_258._m32.w)).y;
    vec4 _275 = vec4(_258._m30.xyz, 1.0);
    vec4 _276 = _258._m1;
    vec3 _266;
    _266.x = _21(_275, _276);
    vec4 _288 = vec4(_258._m30.xyz, 1.0);
    vec4 _289 = _258._m2;
    _266.y = _21(_288, _289);
    vec4 _301 = vec4(_258._m30.xyz, 1.0);
    vec4 _302 = _258._m3;
    _266.z = _21(_301, _302);
    vec3 _307 = _266 - _223;
    float _311 = (_250 * _153._m4.x) + (1.0 - _153._m4.x);
    float _321 = length(_307) * _311;
    vec2 _326 = vec2(6.666666507720947265625, 10.0);
    float _330 = _321 - _258._m31.w;
    float _341 = _330 * _326.x;
    float _336 = _14(_341);
    float _348 = _330 * _326.y;
    float _343 = _14(_348);
    float _358 = (1.0 - _343) * _250;
    vec3 _350 = _258._m32.xyz * _14(_358);
    float _361 = _336;
    float _368 = ceil(_361 - 0.001000000047497451305389404296875);
    float _363 = _14(_368);
    float _373 = _363 - 9.9999997473787516355514526367188e-05;
    _10(_373);
    vec2 _375 = ((_376.xy / vec2(_376.w)) * 0.5) + vec2(0.5);
    vec2 _386 = ((_387.xy / vec2(_387.w)) * 0.5) + vec2(0.5);
    _375.y = 1.0 - _375.y;
    _386.y = 1.0 - _386.y;
    vec2 _405 = _116._m20.xy;
    _163 = vec4((_375 - _386) * _405, 0.0, 1.0);
}

