// FLARES + DLC FIX
#version 460
 #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 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(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 = 20, std140) uniform Vk3DParams
{
	Vk3DStereo vk3d_params[2];
};


   

layout(set = 0, binding = 0, std140) uniform _254_256
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    vec4 _m3;
    vec4 _m4;
    vec4 _m5;
    vec4 _m6;
    vec4 _m7;
    vec4 _m8;
    float _m9;
    float _m10;
    float _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;
    uint _m27;
    float _m28;
    float _m29;
    float _m30;
    float _m31;
    float _m32;
    float _m33;
    float _m34;
    float _m35;
    float _m36;
    float _m37;
    float _m38;
    float _m39[2];
} _256;

layout(set = 1, binding = 0, std140) uniform _374_376
{
    vec4 _m0;
    vec4 _m1;
    vec4 _m2;
    uint _m3;
    float _m4[3];
} _376;

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

layout(set = 0, binding = 2) uniform TEXTURE_2D _408;
layout(set = 0, binding = 3) uniform sampler _412;
layout(set = 1, binding = 1, r11f_g11f_b10f) uniform IMAGE_2D _447;
layout(set = 1, binding = 2) uniform TEXTURE_2D _493;
layout(set = 0, binding = 4) uniform sampler _495;
layout(set = 1, binding = 3) uniform TEXTURE_2D _529;
layout(set = 0, binding = 5) uniform sampler _531;
layout(set = 0, binding = 6) uniform texture3D _611;
layout(set = 0, binding = 7) uniform sampler _613;
layout(set = 0, binding = 8) uniform texture3D _632;
layout(set = 0, binding = 9) uniform texture3D _731;
layout(set = 1, binding = 4, r11f_g11f_b10f) uniform writeonly IMAGE_2D _819;

uint _63;
uint _65;
uint _67;
uint _69;
uint _71;
uint _73;
uint _75;
uint _76;
uint _78;
uint _79;
uint _81;
uint _83;
uint _85;
uint _87;
uint _89;
uint _91;
uint _93;
uint _95;
uint _97;
shared float _849[64];
shared float _850[64];

float _18(float _17)
{
    float _112;
    if (_17 <= 0.040449999272823333740234375)
    {
        _112 = _17 / 12.9200000762939453125;
    }
    else
    {
        _112 = pow((_17 / 1.05499994754791259765625) + 0.0521326996386051177978515625, 2.400000095367431640625);
    }
    return _112;
}

vec3 _24(vec3 _23)
{
    float _129 = _23.x;
    float _133 = _23.y;
    float _138 = _23.z;
    return vec3(_18(_129), _18(_133), _18(_138));
}

uint _55(inout uint _54)
{
    _54 = (((_54 & 4u) >> uint(2)) | ((_54 & 1u) << uint(2))) | (_54 & 2u);
    return _54;
}

vec2 _60(uint _58, uint _59)
{
    uint _336 = _59 & 7u;
    uint _342 = _336;
    uint _344 = _55(_342);
    return (vec2(float(_336), float(_344)) * 1.0) / vec2(float(_58));
}

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

float _45(inout float _43, bool _44)
{
    if (_44)
    {
        _43 += (float(_43 < _256._m9) * _256._m10);
    }
    float _274 = _43;
    return _256._m0.w / (_10(_274) + _256._m0.z);
}

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

vec3 _50(vec2 _49)
{
    return (vec3(_256._m11, _256._m12, _256._m13) + (vec3(_256._m14, _256._m15, _256._m16) * _49.x)) + (vec3(_256._m17, _256._m18, _256._m19) * _49.y);
}

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

float _30(float _29)
{
    float _174;
    if (_29 < 1.0)
    {
        _174 = _29;
    }
    else
    {
        _174 = 1.0 / _29;
    }
    float _171 = _174;
    float _182 = _171 * _171;
    float _186 = 0.087292902171611785888671875;
    _186 = (-0.3018949925899505615234375) + (_186 * _182);
    _186 = 1.0 + (_186 * _182);
    _186 *= _171;
    float _202;
    if (_29 < 1.0)
    {
        _202 = _186;
    }
    else
    {
        _202 = 1.57079637050628662109375 - _186;
    }
    return _202;
}

float _33(float _32)
{
    float _215 = abs(_32);
    float _212 = _30(_215);
    float _219;
    if (_32 < 0.0)
    {
        _219 = -_212;
    }
    else
    {
        _219 = _212;
    }
    return _219;
}

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

void main()
{
    _63 = 2147483648u;
    _65 = 1073741824u;
    _67 = 0u;
    _69 = 268435456u;
    _71 = 536870912u;
    _73 = 805306368u;
    _75 = 1073741824u;
    _76 = 1342177280u;
    _78 = 0u;
    _79 = 16777216u;
    _81 = 33554432u;
    _83 = 50331648u;
    _85 = 67108864u;
    _87 = 83886080u;
    _89 = 100663296u;
    _91 = 117440512u;
    _93 = 134217728u;
    _95 = 150994944u;
    _97 = 167772160u;
    ivec3 _356 = ivec3(GlobalInvocationID);
    vec2 _363 = vec2(_356.xy) + vec2(0.5);
    vec2 _371 = _363 * _376._m0.zw;
    vec2 _382 = vec2(_356.xy) * _376._m0.zw;
    uint _390 = uint((int(gl_LocalInvocationID.x) / 2) + ((int(gl_LocalInvocationID.y) / 2) * 8));
    float _405 = 1.0 - TEXTURE_LOD(SAMPLER_2D(_408, _412), vec4(_371, 0.0, 0.0).xy, vec4(_371, 0.0, 0.0).w).x;
    bool _429 = false;
    _429 = (_376._m3 & 1u) != 0u;
    vec3 _437 = vec3(0.0);
    if (_429 || (_405 < 1.0))
    {
        _437 = IMAGE_LOAD(_447, _356.xy).xyz;
    }
    if (!_429)
    {
        vec3 _457 = vec3(0.0);
        if ((_376._m3 & 2u) != 0u)
        {
            float _464 = _376._m1.w;
            float _468 = _256._m31 / _464;
            vec2 _474 = _371;
            _474.x = 0.5 + (_468 * (_371.x - 0.5));
            vec2 _483 = vec2(0.0, _376._m0.w);
            vec2 _487 = vec2(_483.y / _464, 0.0);
            _457 = TEXTURE_GRAD(SAMPLER_2D(_493, _495), _474, _487, _483).xyz;
            vec3 _503 = _457;
            _457 = _24(_503);
        }
        else
        {
            _457 = _376._m2.xyz;
        }
        _437 = mix(_437, _457, bvec3(_405 == 1.0));
    }
    vec2 _517 = vec2(0.0);
    if (dot(_256._m3.zw, vec2(1.0)) > 0.0)
    {
        int _528 = int(TEXEL_FETCH(SAMPLER_2D(_529, _531), (_356.xy * ivec2(4)) & ivec2(511), 0).x * 16.0);
        uint _555 = 8u;
        uint _556 = uint(_528 + int(_256._m4.x));
        _517 = _60(_555, _556) + vec2(0.0625);
        _517 -= vec2(0.5);
        _517 /= _256._m5.xy;
    }
    float _571 = _405;
    bool _573 = false;
    float _574 = _45(_571, _573);
    float _570 = _574;
    vec2 _575 = _382 + _517;
    float _579 = 0.119999997317790985107421875;
    float _581 = _256._m6.y;
    float _585 = _256._m5.z + 1.0;
    float _589 = pow(max(0.0, _570 - _579) / (_581 - _579), 0.5);
    float _599 = (0.5 / _585) + (_589 * (1.0 - (1.0 / _585)));
    
    //if (VIEW == 1)
    _575.x -=vk3d_params[VIEW].stereo.x*0.5;
    
    vec3 _608 = textureLod(sampler3D(_611, _613), vec4(_575, _599, 0.0).xyz, vec4(_575, _599, 0.0).w).xyz;
    vec2 _631 = textureLod(sampler3D(_632, _613), vec4(_575, _599, 0.0).xyz, vec4(_575, _599, 0.0).w).xy;
    
    
    float _650 = _631.x;
    float _653 = _631.y;
    float _658 = _256._m32;
    uint _656 = _15(_658);
    bool _662 = (_656 & 2u) != 0u;
    _608 *= float(_662);
    _650 = _662 ? _650 : 1.0;
    vec3 _673 = vec3(0.0);
    if ((_656 & 1u) != 0u)
    {
        vec3 _679 = vec3(_256._m20, _256._m21, _256._m22);
        vec3 _690 = _50(_382);
        vec4 _694 = vec4(0.0);
        vec3 _696 = normalize(_690);
        float _699 = _696.z;
        _694.x = clamp(_27(_699) / 3.1415927410125732421875, 0.00390625, 0.99609375);
        float _708 = _696.y;
        float _711 = _696.x;
        _694.y = _38(_708, _711) / 6.283185482025146484375;
        _694.z = sqrt(_570 * _256._m7.w);
        _694.z = clamp(_694.z, 0.015625, 0.984375);
        _673 = textureLod(sampler3D(_731, _531), _694.xyz, _694.w).xyz;
        if ((_256._m33 > 0.0) && (_405 >= 1.0))
        {
            vec3 _750 = vec3(_256._m34, _256._m35, _256._m36);
            float _761 = dot(normalize(_690), _750);
            vec3 _776;
            if (_256._m38 > 0.0)
            {
                _776 = vec3(1.0);
            }
            else
            {
                _776 = _256._m8.xyz;
            }
            vec3 _766 = _776 * (10.0 * _256._m37);
            float _791 = _761;
            float _796 = pow(_10(_791), 10000.0);
            _673 += ((_766 * (_256._m33 * 10.0)) * _10(_796));
        }
        _673 *= _653;
    }
    _437 = ((_437 + _673) * _650) + _608;
    IMAGE_STORE(_447, _356.xy, vec4(_437, 1.0));
    IMAGE_STORE(_819, _356.xy, vec4(_437, 1.0));
}







