// Weapon Effects
#version 460

struct particleubermaterial_t
{
    vec4 particleUberParms1;
    vec4 particleUberParms2;
    vec4 particleUberParms3;
    uvec4 tilingPacked;
    vec4 particleFade_emissive_pad;
    uvec4 scaleBias01;
    uvec4 scaleBias23;
};


// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
layout(set = 0, binding = 155, std140) uniform Vk3DParams
{
    vec4 stereo;
    vec4 custom_params;
} vk3d_params;

layout(set = 2, binding = 0, std140) uniform _surfaceUniforms_ubo
{
    vec4 particleuberparms1;
    vec4 particleuberparms2;
    vec4 particleuberparms3;
    vec4 tiling;
    vec4 tiling2;
    vec4 particlefade;
    vec4 emissive;
    vec4 transmapscalebias;
    vec4 transmapscalebias1;
    vec4 transmapscalebias2;
    vec4 transmapidx;
} _surfaceUniforms;

layout(set = 1, binding = 0, std140) uniform _instanceUniforms_ubo
{
    vec4 modelmatrixx;
    vec4 modelmatrixy;
    vec4 modelmatrixz;
    vec4 modelmatrixw;
    vec4 particlestscalebias;
    vec4 particlecolorscale;
    vec4 particlecolorbias;
} _instanceUniforms;

layout(set = 0, binding = 0, std140) uniform _viewUniforms_ubo
{
    vec4 viewprojectionmatrixx;
    vec4 viewprojectionmatrixy;
    vec4 viewprojectionmatrixz;
    vec4 viewprojectionmatrixw;
    vec4 fragmentpositiontoviewtexture;
    vec4 projectionmatrixz;
    vec4 clusteredlighting;
    vec4 particleatlasparms;
    vec4 usebindlesstextures;
    vec4 particlemult;
    vec4 fogparms;
    vec4 lightscatteringres;
    vec4 lightscatteringparms;
    vec4 globalvieworigin;
    vec4 frustumvectl;
    vec4 frustumvectr;
    vec4 resolutionscale;
    vec4 frustumvecbl;
    vec4 frustumvecbr;
    vec4 znearfar;
    vec4 watervolumeviewparms;
} _viewUniforms;

layout(set = 0, binding = 2, std430) restrict readonly buffer clusterlightsid_b
{
    uint clusterlightsid[];
} _673;

layout(set = 0, binding = 3, std140) uniform lightparms1_ubo
{
    vec4 lightparms1[4096];
} _678;

layout(set = 0, binding = 4, std140) uniform lightparms2_ubo
{
    vec4 lightparms2[4096];
} _682;

layout(set = 0, binding = 5, std140) uniform lightparms3_ubo
{
    vec4 lightparms3[4096];
} _686;

layout(push_constant, std430) uniform PushConstants
{
    int lodLevel;
    int modelIndex;
} pushConstants;

layout(set = 3, binding = 0) uniform texture2D globalTextures[65536];
layout(set = 0, binding = 6) uniform samplerCubeArray samp_envprobesmaparray;
layout(set = 0, binding = 7) uniform sampler2D samp_particleslightatlasmap;
layout(set = 0, binding = 8) uniform sampler samp_loosealbedosampler;
layout(set = 0, binding = 9) uniform sampler2D samp_viewdepthmap;
layout(set = 0, binding = 10) uniform sampler3D samp_finallightscatteringpacked0map;
layout(set = 0, binding = 11) uniform sampler3D samp_finallightscatteringpacked1map;
layout(set = 0, binding = 12) uniform sampler3D samp_skylightinglutmap;
layout(set = 0, binding = 13) uniform sampler2D samp_watergbufferdepthmap;
layout(set = 2, binding = 1) uniform sampler2D samp_transmap;

layout(location = 0) in vec4 in_Position;
layout(location = 12) out vec4 vofi_TexCoord10;
layout(location = 2) in vec4 in_Normal;
layout(location = 9) in vec4 in_Tangent;
layout(location = 2) out vec4 vofi_TexCoord0;
layout(location = 1) in vec2 in_TexCoord;
layout(location = 4) in vec2 in_TexCoord1;
layout(location = 3) out vec4 vofi_TexCoord1;
layout(location = 4) out vec4 vofi_TexCoord2;
layout(location = 12) in vec2 in_VmtrTC;
layout(location = 13) in uvec4 in_Materials;
layout(location = 10) out vec4 vofi_TexCoord8;
layout(location = 11) out vec4 vofi_TexCoord9;
layout(location = 0) out vec4 vofi_Color;
layout(location = 3) in vec4 in_Color;
layout(location = 6) out vec4 vofi_TexCoord4;
layout(location = 7) out vec4 vofi_TexCoord5;
layout(location = 9) out vec4 vofi_TexCoord7;

float _81;

mat4 MatrixMul(mat4 m1, mat4 m2)
{
    return m1 * m2;
}

float dot4(vec4 a, vec4 b)
{
    return dot(a, b);
}

float saturate(float v)
{
    return clamp(v, 0.0, 1.0);
}

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

vec3 SRGBlinear(vec3 sRGB)
{
    float param = sRGB.x;
    vec3 outLinear;
    outLinear.x = SRGBlinear(param);
    float param_1 = sRGB.y;
    outLinear.y = SRGBlinear(param_1);
    float param_2 = sRGB.z;
    outLinear.z = SRGBlinear(param_2);
    return outLinear;
}

vec4 SRGBlinear(vec4 sRGBA)
{
    vec3 param = sRGBA.xyz;
    vec4 outLinear = vec4(SRGBlinear(param), 1.0);
    float param_1 = sRGBA.w;
    outLinear.w = SRGBlinear(param_1);
    return outLinear;
}

vec4 DeGamma(vec4 color)
{
    vec4 param = color;
    return SRGBlinear(param);
}

uint asuint(float x)
{
    return floatBitsToUint(x);
}

void main()
{
    particleubermaterial_t mtl;
    mtl.particleUberParms1 = _surfaceUniforms.particleuberparms1;
    mtl.particleUberParms2 = _surfaceUniforms.particleuberparms2;
    mtl.particleUberParms3 = _surfaceUniforms.particleuberparms3;
    vec4 tiling = _surfaceUniforms.tiling;
    vec4 tiling2 = _surfaceUniforms.tiling2;
    mtl.particleFade_emissive_pad = vec4(_surfaceUniforms.particlefade.xy, _surfaceUniforms.emissive.x, 0.0);
    float modeUnlitParticle = 0.0;
    float modeLitParticle = 1.0;
    float modeSmokeParticle = 2.0;
    float modeLitSmokeParticle = 3.0;
    float modeFluidParticle = 4.0;
    float modeLitFluidParticle = 5.0;
    float uberMode = mtl.particleUberParms1.x;
    mat4 modelMatrix = mat4(vec4(_instanceUniforms.modelmatrixx), vec4(_instanceUniforms.modelmatrixy), vec4(_instanceUniforms.modelmatrixz), vec4(_instanceUniforms.modelmatrixw));
    mat4 viewProjectionMatrix = mat4(vec4(_viewUniforms.viewprojectionmatrixx), vec4(_viewUniforms.viewprojectionmatrixy), vec4(_viewUniforms.viewprojectionmatrixz), vec4(_viewUniforms.viewprojectionmatrixw));
    mat4 param = modelMatrix;
    mat4 param_1 = viewProjectionMatrix;
    mat4 mvpMatrixT = MatrixMul(param, param_1);
    vec4 mvpMatrixX = mvpMatrixT[0];
    vec4 mvpMatrixY = mvpMatrixT[1];
    vec4 mvpMatrixZ = mvpMatrixT[2];
    vec4 mvpMatrixW = mvpMatrixT[3];
    vec4 param_2 = in_Position;
    vec4 param_3 = mvpMatrixX;
    gl_Position.x = dot4(param_2, param_3);
    vec4 param_4 = in_Position;
    vec4 param_5 = mvpMatrixY;
    gl_Position.y = dot4(param_4, param_5);
    vec4 param_6 = in_Position;
    vec4 param_7 = mvpMatrixZ;
    gl_Position.z = dot4(param_6, param_7);
    vec4 param_8 = in_Position;
    vec4 param_9 = mvpMatrixW;
    gl_Position.w = dot4(param_8, param_9);
    vofi_TexCoord10.x = mvpMatrixX.w;
    vofi_TexCoord10.y = mvpMatrixY.w;
    vofi_TexCoord10.z = mvpMatrixZ.w;
    vofi_TexCoord10.w = mvpMatrixW.w;
    vec4 param_10 = vec4(in_Position.xyz, 1.0);
    vec4 param_11 = _instanceUniforms.modelmatrixx;
    vec3 worldPos;
    worldPos.x = dot4(param_10, param_11);
    vec4 param_12 = vec4(in_Position.xyz, 1.0);
    vec4 param_13 = _instanceUniforms.modelmatrixy;
    worldPos.y = dot4(param_12, param_13);
    vec4 param_14 = vec4(in_Position.xyz, 1.0);
    vec4 param_15 = _instanceUniforms.modelmatrixz;
    worldPos.z = dot4(param_14, param_15);
    float emissiveMult = (in_Normal.x * 10.0) + 1.0;
    float alphaMul = (in_Normal.y * 10.0) + 1.0;
    float randSeed = in_Normal.z;
    float alphaFade = in_Normal.w;
    float eyeDist = gl_Position.w;
    bool facingCamera = in_Tangent.y > 0.0;
    float frameFrac = in_Tangent.z;
    float depthAlphaMul = in_Tangent.w;
    vec2 _397 = (in_TexCoord * _instanceUniforms.particlestscalebias.x) + vec2(_instanceUniforms.particlestscalebias.y);
    vofi_TexCoord0 = vec4(_397.x, _397.y, vofi_TexCoord0.z, vofi_TexCoord0.w);
    vec2 _408 = (in_TexCoord1 * _instanceUniforms.particlestscalebias.x) + vec2(_instanceUniforms.particlestscalebias.y);
    vofi_TexCoord0 = vec4(vofi_TexCoord0.x, vofi_TexCoord0.y, _408.x, _408.y);
    vofi_TexCoord1.x = emissiveMult;
    vofi_TexCoord1.y = depthAlphaMul;
    vofi_TexCoord1.z = frameFrac;
    vofi_TexCoord1.w = alphaFade;
    vofi_TexCoord2 = vec4(worldPos.x, worldPos.y, worldPos.z, vofi_TexCoord2.w);
    float timeVal = in_VmtrTC.y;
    vofi_TexCoord2.w = timeVal;
    vec4 normalTmp;
    normalTmp.x = (float(in_Materials.x & 255u) / 127.5) - 1.0;
    normalTmp.y = (float((in_Materials.x >> uint(8)) & 255u) / 127.5) - 1.0;
    normalTmp.z = (float(in_Materials.y & 255u) / 127.5) - 1.0;
    normalTmp.w = 0.0;
    vec4 tangentTmp;
    tangentTmp.x = (float((in_Materials.y >> uint(8)) & 255u) / 127.5) - 1.0;
    tangentTmp.y = (float(in_Materials.z & 255u) / 127.5) - 1.0;
    tangentTmp.z = (float((in_Materials.z >> uint(8)) & 255u) / 127.5) - 1.0;
    tangentTmp.w = 0.0;
    vofi_TexCoord8.x = dot(normalTmp, _instanceUniforms.modelmatrixx);
    vofi_TexCoord8.y = dot(normalTmp, _instanceUniforms.modelmatrixy);
    vofi_TexCoord8.z = dot(normalTmp, _instanceUniforms.modelmatrixz);
    vofi_TexCoord9.x = dot(tangentTmp, _instanceUniforms.modelmatrixx);
    vofi_TexCoord9.y = dot(tangentTmp, _instanceUniforms.modelmatrixy);
    vofi_TexCoord9.z = dot(tangentTmp, _instanceUniforms.modelmatrixz);
    float fadeNear = mtl.particleFade_emissive_pad.x;
    float fadeFar = mtl.particleFade_emissive_pad.y;
    float rcpNearFadeDist = 1.0 / max(0.001000000047497451305389404296875, fadeFar - fadeNear);
    float param_16 = (eyeDist - fadeNear) * rcpNearFadeDist;
    float particleFade = saturate(param_16);
    vec4 param_17 = in_Color;
    vofi_Color = DeGamma(param_17);
    vofi_Color.w *= particleFade;
    float param_18 = in_VmtrTC.x;
    uint tc_atlas_i = asuint(param_18);
    float rcp_short = 3.0517578125e-05;
    vec2 tc_atlas = vec2(float(tc_atlas_i & 65535u) * rcp_short, float(tc_atlas_i >> uint(16)) * rcp_short);
    float atlasY = 1.0 - tc_atlas.y;
    vofi_TexCoord4 = vec4(tc_atlas.x, atlasY, alphaMul, 0.0);
    vec2 uv;
    switch (gl_VertexIndex & 3)
    {
        case 0:
        {
            uv = vec2(0.0);
            break;
        }
        case 1:
        {
            uv = vec2(1.0, 0.0);
            break;
        }
        case 2:
        {
            uv = vec2(0.0, 1.0);
            break;
        }
        default:
        {
            uv = vec2(1.0);
            break;
        }
    }
    if ((uberMode == modeSmokeParticle) || (uberMode == modeLitSmokeParticle))
    {
        float scaleAdjust = in_Normal.x * 2.0;
        vec4 randOffset = fract(vec4(randSeed * 321.0, 0.0, randSeed * 129.0, 0.0));
        vofi_TexCoord5 = ((uv.xyxy - vec4(0.5)) * (tiling * scaleAdjust)) + fract((tiling2 * (timeVal + randSeed)) + randOffset);
        vofi_TexCoord7 = vec4(uv.x, uv.y, vofi_TexCoord7.z, vofi_TexCoord7.w);
    }
    else
    {
        if ((uberMode == modeFluidParticle) || (uberMode == modeLitFluidParticle))
        {
            vofi_TexCoord7 = vec4(worldPos.x, worldPos.y, worldPos.z, vofi_TexCoord7.w);
        }
    }
    gl_Position.y = -gl_Position.y;

// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
    if(vk3d_params.custom_params.z != 0)
    {
        if (gl_Position.w > vk3d_params.custom_params.z)
            gl_Position.x += vk3d_params.stereo.x * (gl_Position.w - vk3d_params.stereo.y); 
        else
            gl_Position.x += vk3d_params.stereo.x * (gl_Position.w - vk3d_params.custom_params.w) *0.75;
    }
    else
    {
        gl_Position.x += vk3d_params.stereo.x * (gl_Position.w - vk3d_params.stereo.y); 
    }
}


