
// ALL THE SHINY in the CS
#version 450
// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
layout(set = 0, binding = 99, std140) uniform Vk3DParams
{
    vec4 stereo;
    vec4 custom_params;
}
 vk3d_params;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

struct sCB
{
    mat4 VStoWS[2];
    vec4 projSetup;
    vec4 fogColor_Intensity;
    vec4 fogSetup;
    vec4 sunColor_Intensity;
    vec4 sunDir_Power;
    vec4 camPos;
    vec4 skinAlbedoPostMultiply;
    vec4 FrustumCorner01;
    vec4 FrustumCorner23;
    vec4 FrustumCornerZ;
    vec4 InvTargetViewportSize;
    vec4 MinExposure;
    vec4 vVolumeTextureSize;
    mat4 mProj;
    mat4 mInvProj;
    vec4 vClusterSize;
    vec4 vDepthSliceGeomFactor_InvLog;
    vec4 vNear_InvNear_Far_CamFar;
    vec4 vFogVolumeWBias_ResponsiveFactor_FogEdgeThreshold;
    vec4 vFogSubCrop;
    ivec4 iMousePos;
};

layout(set = 0, binding = 52, std140) uniform dyn_CONSTANT_BUFFER_BLOCK_0
{
    sCB CB0;
} _427;

layout(set = 0, binding = 10) uniform sampler2D DepthMinMaxTile8x8;
layout(set = 0, binding = 7) uniform sampler3D VolumetricFogLeft;
layout(set = 0, binding = 3) uniform sampler2D AvgLumMap;
layout(set = 0, binding = 2) uniform sampler2D InputColor;
layout(set = 0, binding = 0) uniform sampler2D depthMap;
layout(set = 0, binding = 1) uniform sampler2D transparencyMap;
layout(set = 0, binding = 16, rgba16f) uniform writeonly image2D Output;
layout(set = 0, binding = 17, r8ui) uniform writeonly uimage2D TAATransparencyThresholdTileTexture;
layout(set = 0, binding = 6) uniform sampler2D GISpecularFactorMap;
layout(set = 0, binding = 5) uniform sampler2D GISpecularLightingMap;
layout(set = 0, binding = 18, r32ui) uniform writeonly uimage2D PrepareSSROutput;

shared float simpleSum[64];

void main()
{
    ivec2 _651 = ivec2(gl_GlobalInvocationID.xy);
    vec2 _658 = (vec2(_651) + vec2(0.5)) * _427.CB0.InvTargetViewportSize.xy;
    float _1017 = _427.CB0.projSetup.y / (textureLod(depthMap, _658, 0.0).x + _427.CB0.projSetup.x);
    vec2 _1034 = _658 * _427.CB0.vFogSubCrop.xy;
    float _1037 = 1.0 - _1034.y;
    vec2 _1704 = _1034;
    _1704.y = _1037;
    float _1090 = _1017 * _427.CB0.vNear_InvNear_Far_CamFar.w;
    float _1834;
    for (;;)
    {
        uvec2 _1272 = uvec2(textureSize(DepthMinMaxTile8x8, 0));
        vec2 _1250 = (_1704 * vec2(_1272)) - vec2(0.5);
        vec2 _1829;
        if (fract(clamp(_1250.x, 0.0, float(_1272.x - 1u))) > 0.949999988079071044921875)
        {
            vec2 _1716 = _1704;
            _1716.x = _1034.x - 3.051757857974735088646411895752e-06;
            _1829 = _1716;
        }
        else
        {
            _1829 = _1704;
        }
        vec2 _1830;
        if (fract(clamp(_1250.y, 0.0, float(_1272.y - 1u))) > 0.949999988079071044921875)
        {
            vec2 _1720 = _1829;
            _1720.y = _1829.y - 3.051757857974735088646411895752e-06;
            _1830 = _1720;
        }
        else
        {
            _1830 = _1829;
        }
        vec4 _1157 = textureGather(DepthMinMaxTile8x8, _1830, 0);
        float _1159 = _1157.x;
        float _1161 = _1157.y;
        float _1164 = _1157.z;
        float _1167 = _1157.w;
        float _1168 = max(max(max(_1159, _1161), _1164), _1167);
        if (!(((_1168 - _1090) / _1168) >= _427.CB0.vFogVolumeWBias_ResponsiveFactor_FogEdgeThreshold.z))
        {
            _1834 = 0.0;
            break;
        }
        uvec2 _1388 = uvec2(textureSize(DepthMinMaxTile8x8, 0));
        vec2 _1366 = (_1704 * vec2(_1388)) - vec2(0.5);
        vec2 _1740 = _1366;
        _1740.x = clamp(_1366.x, 0.0, float(_1388.x - 1u));
        vec2 _1744 = _1740;
        _1744.y = clamp(_1366.y, 0.0, float(_1388.y - 1u));
        vec2 _1328 = fract(_1744);
        float _1343 = _1328.x;
        _1834 = sqrt(mix(mix(float(((_1167 - _1090) / _1167) >= _427.CB0.vFogVolumeWBias_ResponsiveFactor_FogEdgeThreshold.z), float(((_1164 - _1090) / _1164) >= _427.CB0.vFogVolumeWBias_ResponsiveFactor_FogEdgeThreshold.z), _1343), mix(float(((_1159 - _1090) / _1159) >= _427.CB0.vFogVolumeWBias_ResponsiveFactor_FogEdgeThreshold.z), float(((_1161 - _1090) / _1161) >= _427.CB0.vFogVolumeWBias_ResponsiveFactor_FogEdgeThreshold.z), _1343), _1328.y));
        break;
    }
    float _1095 = _1834 * _427.CB0.vFogVolumeWBias_ResponsiveFactor_FogEdgeThreshold.x;
    vec4 _1109 = textureLod(VolumetricFogLeft, vec3(_1034.x, _1037, ((log((-(_1017 * (-_427.CB0.vNear_InvNear_Far_CamFar.w))) * _427.CB0.vNear_InvNear_Far_CamFar.y) * _427.CB0.vDepthSliceGeomFactor_InvLog.y) - _1095) / _427.CB0.vClusterSize.z), 0.0);
    vec4 _710 = textureLod(transparencyMap, _658, 0.0);
    float _719 = max(max(_710.x, _710.y), _710.z);
    float _721 = _710.w;
    float _722 = 1.0 - _721;
    float _1841;
    if (max(_719, _722) > 0.0)
    {
        float _1842;
        if (_722 > 0.0500000007450580596923828125)
        {
            _1842 = 1.0;
        }
        else
        {
            float _1416 = max(0.001000000047497451305389404296875, max(_427.CB0.MinExposure.x, texelFetch(AvgLumMap, ivec2(0), 0).y));
            vec3 _1425 = _710.xyz * (_1416 * (1.0 / (1.0 + (_719 * _1416))));
            _1842 = float(max(max(_1425.x, _1425.y), _1425.z) > 0.0500000007450580596923828125);
        }
        _1841 = _1842;
    }
    else
    {
        _1841 = 0.0;
    }
    float _749 = _1109.w * _721;
    vec3 _755 = _710.xyz;
    vec3 _772 = texelFetch(InputColor, _651, 0).xyz * _749;
    vec4 _793 = vec4(_755 + _772, _721);
    imageStore(Output, _651, vec4(((_1109.xyz * _721) + _755) + _772, _749));
    simpleSum[gl_LocalInvocationIndex] = _1841;
    for (int _1844 = 32; _1844 >= 1; _1844 = _1844 >> 1)
    {
        barrier();
        memoryBarrierShared();
        uint _832 = uint(_1844);
        if (gl_LocalInvocationIndex < _832)
        {
            simpleSum[gl_LocalInvocationIndex] += simpleSum[gl_LocalInvocationIndex + _832];
        }
    }
    barrier();
    memoryBarrierShared();
    if (gl_LocalInvocationIndex == 0u)
    {
        int _1845;
        if (simpleSum[0] == 0.0)
        {
            _1845 = 0;
        }
        else
        {
            _1845 = (simpleSum[0] == 64.0) ? 2 : 1;
        }
        imageStore(TAATransparencyThresholdTileTexture, ivec2(gl_WorkGroupID.xy), uvec4(uint(_1845), 0u, 0u, 0u));
    }
    if (_427.CB0.MinExposure.w == 2.0)
    {
        bool _881 = (gl_LocalInvocationID.x & 1u) == 0u;
        bool _888;
        if (_881)
        {
            _888 = (gl_LocalInvocationID.y & 3u) == 0u;
        }
        else
        {
            _888 = _881;
        }
        if (_888)
        {
            ivec2 _894 = _651 >> ivec2(1);
            ivec2 _1797 = _894;
            _1797.y = _894.y >> 1;
            vec3 _1554 = max(vec3(0.0), (_793.xyz + ((texelFetch(GISpecularFactorMap, _651, 0).xyz * texelFetch(GISpecularLightingMap, _651, 0).xyz) * _721)).xyz);
            float _1556 = _1554.x;
            float _1558 = _1554.y;
            float _1561 = _1554.z;
            int _1567 = max(931135488, (floatBitsToInt(max(max(_1556, _1558), _1561)) & 2139095040));
            float _1572 = uintBitsToFloat(uint(_1567 + 125829120));
            imageStore(PrepareSSROutput, _1797, uvec4(uint((((floatBitsToInt(uintBitsToFloat(uint(floatBitsToInt(_1556) & (-32768))) + _1572) | (floatBitsToInt(uintBitsToFloat(uint(floatBitsToInt(_1558) & (-32768))) + _1572) << 9)) & 262143) | (floatBitsToInt(uintBitsToFloat(uint(floatBitsToInt(_1561) & (-32768))) + _1572) << 18)) | ((_1567 + (-931135488)) << 4)), 0u, 0u, 0u));
        }
    }
    else
    {
        bool _942 = (gl_LocalInvocationID.x & 1u) == 0u;
        bool _949;
        if (_942)
        {
            _949 = (gl_LocalInvocationID.y & 1u) == 0u;
        }
        else
        {
            _949 = _942;
        }
        if (_949)
        {
            vec3 _1464 = max(vec3(0.0), (_793.xyz + ((texelFetch(GISpecularFactorMap, _651, 0).xyz * texelFetch(GISpecularLightingMap, _651, 0).xyz) * _721)).xyz);
            float _1466 = _1464.x;
            float _1468 = _1464.y;
            float _1471 = _1464.z;
            int _1477 = max(931135488, (floatBitsToInt(max(max(_1466, _1468), _1471)) & 2139095040));
            float _1482 = uintBitsToFloat(uint(_1477 + 125829120));
            imageStore(PrepareSSROutput, (_651 >> ivec2(1)) / ivec2(_427.CB0.MinExposure.zw), uvec4(uint((((floatBitsToInt(uintBitsToFloat(uint(floatBitsToInt(_1466) & (-32768))) + _1482) | (floatBitsToInt(uintBitsToFloat(uint(floatBitsToInt(_1468) & (-32768))) + _1482) << 9)) & 262143) | (floatBitsToInt(uintBitsToFloat(uint(floatBitsToInt(_1471) & (-32768))) + _1482) << 18)) | ((_1477 + (-931135488)) << 4)), 0u, 0u, 0u));
        }
    }
}

