// More Smoke
#version 450
 #extension GL_EXT_multiview : enable
#define VIEW gl_ViewIndex


// 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 = 1, binding = 0, std140) uniform _instanceUniforms_ubo
{
    vec4 modelmatrixx;
    vec4 modelmatrixy;
    vec4 modelmatrixz;
    vec4 particlestscalebias;
    vec4 modelmatrixw;
    vec4 ambientinstanceparms;
    vec4 staticmodel;
    vec4 instanceirradiancescale;
    vec4 particleshadowdisable;
    vec4 particletranslucencyscale;
} _instanceUniforms;

layout(set = 0, binding = 0, std140) uniform _viewUniforms_ubo
{
    vec4 viewprojectionmatrixx;
    vec4 viewprojectionmatrixy;
    vec4 viewprojectionmatrixz;
    vec4 viewprojectionmatrixw;
    vec4 ambientviewparms;
    vec4 globalvieworigin;
    vec4 projectionmatrixz;
    vec4 clusteredlighting;
    vec4 envirradiancescale;
    vec4 sungoboscaleoffset;
    vec4 parallellightslicescale;
    vec4 nummultisamples;
    vec4 randomint;
    vec4 shadowatlasresolution;
} _viewUniforms;

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

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

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

layout(set = 0, binding = 7, std140) uniform lightparms3_ubo
{
    vec4 lightparms3[3072];
} _804;

layout(set = 0, binding = 9, std140) uniform shadowsparmsubo_ubo
{
    vec4 shadowsparmsubo[4095];
} _812;

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

layout(set = 0, binding = 1) uniform sampler3D samp_ambientatlas;
layout(set = 0, binding = 2) uniform sampler3D samp_ambientshatlas;
layout(set = 0, binding = 8) uniform sampler2D samp_lightsatlasmap;
layout(set = 0, binding = 10) uniform sampler2DShadow samp_shadowatlasdepthcomparemap;
layout(set = 2, binding = 1) uniform sampler2D samp_transmap;

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

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

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

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

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

void main()
{
    float param = in_VmtrTC.x;
    uint tc_atlas_i = asuint(param);
    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);
    vec2 atlasTilePos = tc_atlas;
    gl_Position = vec4((atlasTilePos * 2.0) - vec2(1.0), vec2(0.0, 1.0));
    vec4 param_1 = vec4(in_Position.xyz, 1.0);
    vec4 param_2 = _instanceUniforms.modelmatrixx;
    vec3 worldPos;
    worldPos.x = dot4(param_1, param_2);
    vec4 param_3 = vec4(in_Position.xyz, 1.0);
    vec4 param_4 = _instanceUniforms.modelmatrixy;
    worldPos.y = dot4(param_3, param_4);
    vec4 param_5 = vec4(in_Position.xyz, 1.0);
    vec4 param_6 = _instanceUniforms.modelmatrixz;
    worldPos.z = dot4(param_5, param_6);
    float emmissiveMul = (in_Normal.x * 10.0) + 1.0;
    float alphaMul = (in_Normal.y * 10.0) + 1.0;
    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;
    float particle_curvature = in_Tangent.x;
    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_TexCoord3.x = dot(normalTmp, _instanceUniforms.modelmatrixx);
    vofi_TexCoord3.y = dot(normalTmp, _instanceUniforms.modelmatrixy);
    vofi_TexCoord3.z = dot(normalTmp, _instanceUniforms.modelmatrixz);
    vofi_TexCoord5.x = dot(tangentTmp, _instanceUniforms.modelmatrixx);
    vofi_TexCoord5.y = dot(tangentTmp, _instanceUniforms.modelmatrixy);
    vofi_TexCoord5.z = dot(tangentTmp, _instanceUniforms.modelmatrixz);
    vec2 _286 = (in_TexCoord * _instanceUniforms.particlestscalebias.x) + vec2(_instanceUniforms.particlestscalebias.y);
    vofi_TexCoord0 = vec4(_286.x, _286.y, vofi_TexCoord0.z, vofi_TexCoord0.w);
    vec2 _297 = (in_TexCoord1 * _instanceUniforms.particlestscalebias.x) + vec2(_instanceUniforms.particlestscalebias.y);
    vofi_TexCoord0 = vec4(vofi_TexCoord0.x, vofi_TexCoord0.y, _297.x, _297.y);
    vofi_TexCoord2 = vec4(worldPos, 0.0);
    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_7 = modelMatrix;
    mat4 param_8 = viewProjectionMatrix;
    mat4 mvpMatrixT = MatrixMul(param_7, param_8);
    vec4 mvpMatrixX = mvpMatrixT[0];
    vec4 mvpMatrixY = mvpMatrixT[1];
    vec4 mvpMatrixZ = mvpMatrixT[2];
    vec4 mvpMatrixW = mvpMatrixT[3];
    vofi_TexCoord4 = vec4(dot(vec4(in_Position.xyz, 1.0), mvpMatrixX), dot(vec4(in_Position.xyz, 1.0), mvpMatrixY), dot(vec4(in_Position.xyz, 1.0), mvpMatrixZ), dot(vec4(in_Position.xyz, 1.0), mvpMatrixW));
    vofi_TexCoord8 = vec4(0.0);
    vofi_TexCoord9 = vec4(0.0);
    vofi_TexCoord10 = vec4(0.0);
    float validAmbientMap = float(_viewUniforms.ambientviewparms.x > 0.0);
    float modelAmbientScale = _viewUniforms.ambientviewparms.x * _instanceUniforms.ambientinstanceparms.x;
    bool _441 = _viewUniforms.ambientviewparms.y > 0.0;
    bool _448;
    if (!_441)
    {
        _448 = _viewUniforms.ambientviewparms.z > 0.0;
    }
    else
    {
        _448 = _441;
    }
    bool _455;
    if (!_448)
    {
        _455 = _viewUniforms.ambientviewparms.w > 0.0;
    }
    else
    {
        _455 = _448;
    }
    float useForcedColor = float(_455);
    vec3 L1 = vec3(0.579999983310699462890625) * _viewUniforms.ambientviewparms.yzw;
    vofi_TexCoord8 = vec4(_viewUniforms.ambientviewparms.y, _viewUniforms.ambientviewparms.z, _viewUniforms.ambientviewparms.w, L1.x);
    vofi_TexCoord9 = vec4(L1.y, L1.z, L1.x, L1.y);
    vofi_TexCoord10 = vec4(L1.z, L1.x, L1.y, L1.z);
    if ((validAmbientMap > 0.0) && (useForcedColor <= 0.0))
    {
        float AMBIENT_MIN_WORLD = -4096.0;
        float AMBIENT_MAX_WORLD = 4096.0;
        float ambientAtlasWidth = 256.0;
        float ambientAtlasHeight = 256.0;
        float ambientAtlasDepth = 6.0;
        float ambientSHAtlasWidth = 256.0;
        float ambientSHAtlasHeight = 256.0;
        float ambientSHAtlasDepth = 24.0;
        vec3 atlasSHPixelSize = vec3(1.0 / ambientSHAtlasWidth, 1.0 / ambientSHAtlasHeight, 1.0 / ambientSHAtlasDepth);
        vec3 atlasSHCubeSize = vec3(2.0 / ambientSHAtlasWidth, 2.0 / ambientSHAtlasHeight, 2.0 / ambientSHAtlasDepth);
        vec3 atlasPixelSize = vec3(1.0 / ambientAtlasWidth, 1.0 / ambientAtlasHeight, 1.0 / ambientAtlasDepth);
        float leafWidth = 1.0 / (AMBIENT_MAX_WORLD - AMBIENT_MIN_WORLD);
        vec3 param_9 = (worldPos - vec3(AMBIENT_MIN_WORLD)) * leafWidth;
        vec3 normSamplePoint = saturate(param_9);
        vec4 atlasSample = vec4(0.0);
        uvec3 octantIndices = uvec3(0u);
        for (uint i = 0u; i < 13u; i++)
        {
            vec3 atlasQuadrant = vec3(0.5) + floor(vec3(2.0) * normSamplePoint);
            vec4 atlasTC = vec4(atlasPixelSize * (vec3(octantIndices) + atlasQuadrant), 0.0);
            atlasSample = textureLod(samp_ambientatlas, atlasTC.xyz, atlasTC.w);
            normSamplePoint = fract(normSamplePoint * vec3(2.0));
            octantIndices = uvec3(atlasSample.zyx * vec3(255.0));
            if (atlasSample.w > 0.0)
            {
                break;
            }
        }
        uint ambientSHHashKey = (((uint(atlasSample.w * 255.0) << uint(24)) | (uint(atlasSample.z * 255.0) << uint(16))) | (uint(atlasSample.y * 255.0) << uint(8))) | uint(atlasSample.x * 255.0);
        uvec3 ambientSHKey = uvec3((ambientSHHashKey >> uint(19)) & 4095u, (ambientSHHashKey >> uint(7)) & 4095u, ambientSHHashKey & 127u);
        vec3 shQuadrant = vec3(2.0) * ((normSamplePoint * vec3(0.5)) + vec3(0.25));
        vec4 shTC = vec4(atlasSHPixelSize * (vec3(ambientSHKey) + shQuadrant), 0.0);
        vec4 sampleSHR = textureLod(samp_ambientshatlas, vec4(shTC.xy, shTC.z + (atlasSHCubeSize.z * 0.0), 0.0).xyz, vec4(shTC.xy, shTC.z + (atlasSHCubeSize.z * 0.0), 0.0).w) * modelAmbientScale;
        vec4 sampleSHG = textureLod(samp_ambientshatlas, vec4(shTC.xy, shTC.z + (atlasSHCubeSize.z * 1.0), 0.0).xyz, vec4(shTC.xy, shTC.z + (atlasSHCubeSize.z * 1.0), 0.0).w) * modelAmbientScale;
        vec4 sampleSHB = textureLod(samp_ambientshatlas, vec4(shTC.xy, shTC.z + (atlasSHCubeSize.z * 2.0), 0.0).xyz, vec4(shTC.xy, shTC.z + (atlasSHCubeSize.z * 2.0), 0.0).w) * modelAmbientScale;
        vofi_TexCoord8 = vec4(sampleSHR.x, sampleSHG.x, sampleSHB.x, sampleSHR.y);
        vofi_TexCoord9 = vec4(sampleSHG.y, sampleSHB.y, sampleSHR.z, sampleSHG.z);
        vofi_TexCoord10 = vec4(sampleSHB.z, sampleSHR.w, sampleSHG.w, sampleSHB.w);
    }
    gl_Position.y = -gl_Position.y;

// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
//gl_Position.x += vk3d_params[VIEW].stereo.x * (gl_Position.w - vk3d_params[VIEW].stereo.y);
}


