// More blending of CS textures
#version 450
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;

struct VOLUMETRIC_LIGHTING_CONSTANT_BUFFER
{
    vec4 _vfAmbientColor;
    vec4 _vfSunDirVS;
    float _fPreviousFrameExposureCompensation;
    float _fToneMapInverseToneMapExposure;
    float _fProjPenumbraLerpFactor;
    int _iBlurLighting;
    ivec4 _viPack3DTo2D_Info;
    vec4 _vfClampedFragmentStorageInfos;
    float _fUpsamplingFactor;
    float _fTemporalExponentialSmoothingFactor;
    float _fDummy0;
    float _fDummy1;
    uint _uDebugFlags;
    int _iUseBlueNoise;
    int _bSub3DTexelMotionCorrection;
    int _iHandleGI;
    ivec4 _viBlueNoisePerSliceDelta[64];
    vec4 _fClusterCellSizeEstimate[64];
};

struct VOLUMETRIC_COMMON_CONSTANT_BUFFER
{
    mat4 _mProj;
    mat4 _mInvProj;
    mat4 _mPrevProj;
    mat4 _mLastViewInv;
    mat4 _mCurrViewInv;
    mat4 _mCurrPosToPrevPosVS;
    float _fDepthSliceGeomFactor;
    float _fDepthSliceGeomFactorInvLog;
    uint _uViewportWidth;
    uint _uViewportHeight;
    vec4 _vfMaxUVCoord;
    vec4 _vfRcpUVCropScale;
    vec4 _vfRescaleUVToPreviousFrame;
    ivec4 _viClusterSize;
    vec4 _vfInvClusterSize;
    ivec4 _viCBClusterSize;
    float _fNear;
    float _fInvNear;
    float _fFar;
    float _fCamFar;
    int _iFrameIndex;
    int _iNeedFlushTAA;
    uint _uSceneZoneID;
    uint _uPadding0;
    vec4 _afStereoEyeDelta;
    uint _uEye;
    uint _uDummy0;
    uint _uDummy1;
    uint _uDummy2;
};

layout(set = 0, binding = 27, std430) readonly buffer stc_AtomicCounter_Layout
{
    int AtomicCounter[];
} _311;

layout(set = 0, binding = 53, std140) uniform dyn_CONSTANT_BUFFER_BLOCK_1
{
    VOLUMETRIC_LIGHTING_CONSTANT_BUFFER g_cbLighting;
} _333;

layout(set = 0, binding = 52, std140) uniform dyn_CONSTANT_BUFFER_BLOCK_0
{
    VOLUMETRIC_COMMON_CONSTANT_BUFFER g_cbCommon;
} _426;

layout(set = 0, binding = 2) uniform usampler2D ClampEventPixelList;
layout(set = 0, binding = 1) uniform sampler2D InTexPreviousValueBlendFactor;
layout(set = 0, binding = 0) uniform sampler2D InTexScatterValueNoAA;
layout(set = 0, binding = 16, r32ui) uniform writeonly uimage3D OutPatchedTex;

ivec3 _899;

void main()
{
    for (;;)
    {
        int _306 = int(gl_GlobalInvocationID.x);
        if (_306 >= _311.AtomicCounter[0])
        {
            break;
        }
        int _535 = int(_333.g_cbLighting._vfClampedFragmentStorageInfos.x * float(_306));
        uint _348 = uint(int(texelFetch(ClampEventPixelList, ivec2(_306 - (floatBitsToInt(_333.g_cbLighting._vfClampedFragmentStorageInfos.y) * _535), _535), 0).x));
        int _549 = int(_348 & 511u);
        ivec3 _834 = _899;
        _834.x = _549;
        int _554 = int((_348 >> uint(9)) & 511u);
        ivec3 _836 = _834;
        _836.y = _554;
        int _559 = int((_348 >> uint(18)) & 63u);
        ivec3 _838 = _836;
        _838.z = _559;
        float _586 = uintBitsToFloat(uint(_333.g_cbLighting._viPack3DTo2D_Info.x));
        int _598 = int(float(_559) * _586);
        ivec2 _619 = ivec2(((_559 - (_598 * _333.g_cbLighting._viPack3DTo2D_Info.y)) * _333.g_cbLighting._viPack3DTo2D_Info.z) + _549, (_598 * _333.g_cbLighting._viPack3DTo2D_Info.w) + _554);
        vec4 _379 = texelFetch(InTexPreviousValueBlendFactor, _619, 0);
        vec3 _901;
        vec3 _902;
        _902 = vec3(-3.4028234663852885981170418348452e+38);
        _901 = vec3(3.4028234663852885981170418348452e+38);
        vec3 _909;
        vec3 _911;
        for (int _900 = -1; _900 <= 1; _902 = _911, _901 = _909, _900++)
        {
            _911 = _902;
            _909 = _901;
            vec3 _908;
            vec3 _910;
            for (int _903 = -1; _903 <= 1; _903++, _911 = _910, _909 = _908)
            {
                _910 = _911;
                _908 = _909;
                vec3 _915;
                vec3 _916;
                for (int _905 = -1; _905 <= 1; _910 = _916, _908 = _915, _905++)
                {
                    ivec3 _433 = clamp(_838 + ivec3(_905, _903, _900), ivec3(0), _426.g_cbCommon._viCBClusterSize.xyz - ivec3(1));
                    int _640 = _433.z;
                    int _644 = int(float(_640) * _586);
                    vec4 _444 = texelFetch(InTexScatterValueNoAA, ivec2(((_640 - (_644 * _333.g_cbLighting._viPack3DTo2D_Info.y)) * _333.g_cbLighting._viPack3DTo2D_Info.z) + _433.x, (_644 * _333.g_cbLighting._viPack3DTo2D_Info.w) + _433.y), 0);
                    vec3 _445 = _444.xyz;
                    if (_444.x < 65408.0)
                    {
                        _916 = max(_445, _910)*2;
                        _915 = min(_445, _908);
                    }
                    else
                    {
                        _916 = _910*2;
                        _915 = _908;
                    }
                }
            }
        }
        vec3 _468 = clamp(_379.xyz, _901, _902);
        if (!(max(max(abs(_379.x - _468.x), abs(_379.y - _468.y)), abs(_379.z - _468.z)) >= max(0.001000000047497451305389404296875, unpackHalf2x16((_348 >> uint(25)) << uint(8)).x * 4.9999998736893758177757263183594e-05)))
        {
            break;
        }
        if (_901.x == 3.4028234663852885981170418348452e+38)
        {
            break;
        }
        vec3 _748 = max(vec3(0.0), mix(_468, texelFetch(InTexScatterValueNoAA, _619, 0).xyz, vec3(_379.w)));
        float _750 = _748.x;
        float _752 = _748.y;
        float _755 = _748.z;
        int _761 = max(931135488, (floatBitsToInt(max(max(_750, _752), _755)) & 2139095040));
        float _766 = uintBitsToFloat(uint(_761 + 125829120));
        imageStore(OutPatchedTex, _838, uvec4(uint((((floatBitsToInt(uintBitsToFloat(uint(floatBitsToInt(_750) & (-32768))) + _766) | (floatBitsToInt(uintBitsToFloat(uint(floatBitsToInt(_752) & (-32768))) + _766) << 9)) & 262143) | (floatBitsToInt(uintBitsToFloat(uint(floatBitsToInt(_755) & (-32768))) + _766) << 18)) | ((_761 + (-931135488)) << 4)), 0u, 0u, 0u));
        break;
    }
}


