// SOME GLASS
#version 450
 #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 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 
 ///////////////////////////////////////////////////////////////////////////////
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
// 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 = 1, binding = 0, std140) uniform _53_55
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
} _55;

layout(set = 0, binding = 0, std140) uniform _73_75
{
    vec4 _m0;
} _75;

layout(push_constant, std430) uniform _364_366
{
    int _m0;
    int _m1;
} _366;

layout(set = 1, binding = 1) uniform SAMPLER_2D _91;
layout(set = 1, binding = 2, rgba8) uniform writeonly IMAGE_2D _359;

float _16(vec3 _15)
{
    return dot(_15, vec3(0.2125999927520751953125, 0.715200006961822509765625, 0.072200000286102294921875));
}

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

void main()
{
    ivec3 _35 = ivec3(GlobalInvocationID);
    vec2 _44 = (vec2(_35.xy) + vec2(0.5)) * _55._m0.zw;
    vec2 _63;
    if (_55._m1.y != 0.0)
    {
        _63 = _75._m0.xy;
    }
    else
    {
        _63 = vec2(1.0);
    }
    vec2 _62 = _63;
    vec2 _82 = _44 * _62;
    vec4 _87 = TEXTURE_LOD(_91, vec4(_82, 0.0, 0.0).xy, vec4(_82, 0.0, 0.0).w);
    vec4 _105 = TEXTURE_LOD(_91, vec4(_82 + ((_62 * _55._m2.zw) * vec2(0.86000001430511474609375, 0.5)), 0.0, 0.0).xy, vec4(_82 + ((_62 * _55._m2.zw) * vec2(0.86000001430511474609375, 0.5)), 0.0, 0.0).w);
    vec4 _135 = TEXTURE_LOD(_91, vec4(_82 + ((_62 * _55._m2.zw) * vec2(-0.5, 0.86000001430511474609375)), 0.0, 0.0).xy, vec4(_82 + ((_62 * _55._m2.zw) * vec2(-0.5, 0.86000001430511474609375)), 0.0, 0.0).w);
    vec4 _164 = TEXTURE_LOD(_91, vec4(_82 + ((_62 * _55._m2.zw) * vec2(-0.86000001430511474609375, -0.5)), 0.0, 0.0).xy, vec4(_82 + ((_62 * _55._m2.zw) * vec2(-0.86000001430511474609375, -0.5)), 0.0, 0.0).w);
    vec4 _193 = TEXTURE_LOD(_91, vec4(_82 + ((_62 * _55._m2.zw) * vec2(0.5, -0.86000001430511474609375)), 0.0, 0.0).xy, vec4(_82 + ((_62 * _55._m2.zw) * vec2(0.5, -0.86000001430511474609375)), 0.0, 0.0).w);
    vec3 _239 = max(((((_87.xyz + _105.xyz) + _135.xyz) + _164.xyz) + _193.xyz) * 0.20000000298023223876953125, vec3(0.0));
    vec4 _221;
    _221 = vec4(_239.x, _239.y, _239.z, _221.w);
    _221.w = max(((((_87.w + _105.w) + _135.w) + _164.w) + _193.w) * 0.20000000298023223876953125, 0.0);
    if (_55._m1.x == 1.0)
    {
        vec3 _266 = _87.xyz;
        float _265 = _16(_266) + 9.9999999747524270787835121154785e-07;
        vec3 _273 = _105.xyz;
        float _272 = _16(_273) + 9.9999999747524270787835121154785e-07;
        vec3 _279 = _135.xyz;
        float _278 = _16(_279) + 9.9999999747524270787835121154785e-07;
        vec3 _285 = _164.xyz;
        float _284 = _16(_285) + 9.9999999747524270787835121154785e-07;
        vec3 _291 = _193.xyz;
        float _290 = _16(_291) + 9.9999999747524270787835121154785e-07;
        _265 = min(_55._m1.z, max(((((_265 + _272) + _278) + _284) + _290) * 0.20000000298023223876953125, 0.0));
        vec3 _318 = vec3(((_265 * _55._m1.w) != 0.0) ? 1.0 : _265);
        _221 = vec4(_318.x, _318.y, _318.z, _221.w);
    }
    if (_55._m1.x == 2.0)
    {
        vec3 _328 = _221.xyz;
        float _327 = _16(_328);
        float _336 = _327 - _55._m1.w;
        vec3 _341 = _221.xyz * smoothstep(0.0, 1.0, _10(_336));
        _221 = vec4(_341.x, _341.y, _341.z, _221.w);
    }
    if (_55._m1.x == 3.0)
    {
        _221 = vec4(_87.xyz.x, _87.xyz.y, _87.xyz.z, _221.w);
        _221.w = _87.w;
    }
    IMAGE_STORE(_359, _35.xy, _221);
}

