// DECALS
#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 _122_124
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    vec4 _m3;
} _124;

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

layout(set = 1, binding = 0, std140) uniform _233_235
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
} _235;

layout(push_constant, std430) uniform _258_260
{
    int _m0;
    int _m1;
} _260;

layout(set = 2, binding = 1) uniform SAMPLER_2D _179;
layout(set = 2, binding = 2) uniform SAMPLER_2D _223;
layout(set = 0, binding = 1) uniform SAMPLER_2D _261;

layout(location = 2) in vec4 _133;
layout(location = 0) in vec4 _211;
layout(location = 0) out vec4 _246;

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

float _17(float _16)
{
    return _16 * ((_16 * ((_16 * 0.305306017398834228515625) + 0.6821711063385009765625)) + 0.01252287812530994415283203125);
}

vec3 _23(vec3 _22)
{
    float _67 = _22.x;
    vec3 _66;
    _66.x = _17(_67);
    float _74 = _22.y;
    _66.y = _17(_74);
    float _80 = _22.z;
    _66.z = _17(_80);
    return _66;
}

vec4 _29(vec4 _28)
{
    vec3 _90 = _28.xyz;
    vec4 _89 = vec4(_23(_90), 1.0);
    float _98 = _28.w;
    _89.w = _17(_98);
    return _89;
}

vec4 _39(SAMPLER_2D _37, vec2 _38)
{
    vec4 _107 = SAMPLE_TEXTURE(_37, _38);
    vec4 _111 = _107;
    _107 = _29(_111);
    return _107;
}

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

void main()
{
    vec2 _117 = gl_FragCoord.xy * _124._m3.zw;
    _117 = vec2(0);
   // _117.x += vk3d_params[VIEW].stereo.x*0.5;
    
    float _132 = length(_133.xy - vec2(0.5)) * 2.0;
    float _142 = _145._m1.x;
    float _153 = 1.0 - _132;
    float _150 = _14(_153);
    float _160 = 1.0 - (_132 / _142);
    float _155 = _14(_160);
    float _162 = _150 * _150;
    float _166 = _155 * _155;
    float _170 = _162 * _162;
    float _174 = _166 * _166;
    vec2 _180 = _133.xy;
    vec4 _178 = _39(_179, _180);
    vec4 _184 = (_145._m2 * _145._m1.y) * _178.x;
    vec4 _194 = (_145._m3 * _145._m1.z) * _178.y;
    vec4 _203 = ((_194 * _170) + (_184 * _174)) * _211;
    float _214 = 3.9215687138494104146957397460938e-05;
    float _220 = _203.w - _214;
    _10(_220);
    vec2 _228 = _117 * vec2(1.0, 0.60000002384185791015625);
    vec4 _222 = _39(_223, _228);
    vec3 _242 = _222.xyz + vec3(_145._m4.x * _235._m2.x);
    _222 = vec4(_242.x, _242.y, _242.z, _222.w);
    _246 = _222 * _203;
    vec3 _255 = _246.xyz * _246.w;
    _246 = vec4(_255.x, _255.y, _255.z, _246.w);
}



