#version 450

struct PerFrameUniforms
{
    mat4 gViewMat4;
    mat4 gViewProjectionMat4;
    mat4 gCameraMat4;
    mat4 gCameraNoHeadTrackingMat4;
    mat4 gPrevViewProjectionMat4;
    mat4 gThisToPrevViewProjectionMat4;
    mat4 gInverseViewMat4;
    mat4 gInverseProjectionMat4;
    mat4 gInverseProjectionSCMat4;
    mat4 gInverseViewProjectionMat4;
    vec4 gInverseWorldUpMatVec4[3];
    vec3 gViewPositionVec3;
    float gfTime;
    vec3 gVREyeInfoVec3;
    float gfPrevTime;
    vec4 gClipPlanesVec4;
    vec4 gMBlurSettingsVec4;
    vec3 gDeJitterVec3;
    int giFrameIndex;
    vec4 gTaaSettingsVec4;
    vec4 gTessSettingsVec4;
    vec4 gShellsSettingsVec4;
    vec4 gFrameBufferSizeVec4;
    vec4 gFoVValuesVec4;
    vec4 gShadowSizeVec4;
    vec3 gShadowProjScaleVec3;
    int giDisableAmbientAllowed;
    vec4 gShadowFadeParamVec4;
};

struct CommonPerMeshUniforms
{
    vec4 gPlanetPositionVec4;
    mat4 gWorldMat4;
    mat4 gWorldNormalMat4;
    float fdFadeValueDummy;
    vec4 gaParticleCornersVec4[4];
    vec4 gaParticlePositionsVec4[32];
    vec4 gaParticleSizeAndRotationsVec4[32];
    vec4 gaParticleNormalsVec4[32];
    vec4 gaParticleColoursVec4[32];
    vec4 gLightPositionVec4;
    vec4 gLightDirectionVec4;
    vec4 gLightOriginVec4;
    vec4 gLightColourVec4;
    vec4 gLightCustomParamsVec4;
    mat4 gWorldMotionMat4;
    mat4 gInverseModelMat4Dummy;
    vec4 gUserDataVec4;
};

struct CustomPerMaterialUniforms
{
    vec4 gImposterDataVec4;
    vec4 gTileBlendScalesVec4;
    vec4 gHueOverlayParamsVec4;
    vec4 gSaturationOverlayParamsVec4;
    vec4 gValueOverlayParamsVec4;
    vec4 gTerrainColour1Vec4;
    vec4 gTerrainColour2Vec4;
    vec4 gMaterialParamsVec4;
    vec4 gMaterialColourVec4;
    vec4 gMaterialSFXVec4;
    vec4 gMaterialSFXColVec4;
    vec4 gSunPositionVec4;
};

struct CustomPerMeshUniforms
{
    vec4 gUVScrollStepVec4;
    vec4 gCustomParams01Vec4;
    vec4 gHeavyAirFadeOutVec4;
    vec4 gMultiTextureVec4;
};

struct UniformBuffer
{
    PerFrameUniforms mpPerFrame;
    CommonPerMeshUniforms mpCommonPerMesh;
    CustomPerMaterialUniforms mpCustomPerMaterial;
    CustomPerMeshUniforms mpCustomPerMesh;
};


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

layout(set = 0, binding = 0, std140) uniform lUniforms_BLK
{
    UniformBuffer lUniforms;
} _153;

layout(location = 4) in float mkfParticleId;
layout(location = 2) in float mkfParticleCornerId;
layout(location = 1) in vec2 mkTexCoordsVec4;
layout(location = 0) out VertexBlock
{
    vec4 mColourVec4;
    vec4 mTexCoordsVec4;
    vec4 mScreenSpacePositionVec4;
    vec3 mWorldNormalVec3;
} Out;

layout(location = 0) in vec3 mkLocalPositionVec3;

vec3 _1541;

void main()
{
    int _350 = int(mkfParticleId);
    vec4 _1501 = mkTexCoordsVec4.xyxy;
    _1501.x = (mkTexCoordsVec4.x / _153.lUniforms.mpCustomPerMesh.gMultiTextureVec4.x) + (mod(mkfParticleId, _153.lUniforms.mpCustomPerMesh.gMultiTextureVec4.x) / _153.lUniforms.mpCustomPerMesh.gMultiTextureVec4.x);
    Out.mTexCoordsVec4 = _1501;
    vec3 _1063 = vec3(_153.lUniforms.mpCommonPerMesh.gaParticleSizeAndRotationsVec4[_350].z, _153.lUniforms.mpCommonPerMesh.gaParticleSizeAndRotationsVec4[_350].w, _153.lUniforms.mpCommonPerMesh.gaParticlePositionsVec4[_350].w);
    vec4 _1071 = _153.lUniforms.mpPerFrame.gViewProjectionMat4 * vec4(_153.lUniforms.mpCommonPerMesh.gaParticleSizeAndRotationsVec4[_350].z, _153.lUniforms.mpCommonPerMesh.gaParticleSizeAndRotationsVec4[_350].w, _153.lUniforms.mpCommonPerMesh.gaParticlePositionsVec4[_350].w, 0.0);
    float _1077 = atan(_1071.x, _1071.y);
    float _1079 = sin(_1077);
    float _1081 = cos(_1077);
    mat4 _1534;
    if (_153.lUniforms.mpPerFrame.gFoVValuesVec4.z == 2.0)
    {
        vec3 _1102 = _153.lUniforms.mpCommonPerMesh.gaParticlePositionsVec4[_350].xyz - _153.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4[3].xyz;
        vec3 _1114 = normalize(_1102 - (_153.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4[1].xyz * dot(_153.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4[1].xyz, _1102)));
        float _1119 = dot(_1114, _153.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4[2].xyz);
        float _1129 = cos(asin(_1119)) * sign(dot(_1114, _153.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4[0].xyz));
        _1534 = _153.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4 * mat4(vec4(_1119, 0.0, -_1129, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(_1129, 0.0, _1119, 0.0), vec4(0.0, 0.0, 0.0, 1.0));
    }
    else
    {
        _1534 = _153.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4;
    }
    mat4 _1512 = _1534;
    _1512[3] = vec4(0.0, 0.0, 0.0, 1.0);
    mat4 _1514 = _1512;
    _1514[0].w = 0.0;
    mat4 _1516 = _1514;
    _1516[1].w = 0.0;
    mat4 _1518 = _1516;
    _1518[2].w = 0.0;
    vec3 _1163 = (_1518 * (mat4(vec4(_1081, -_1079, 0.0, 0.0), vec4(_1079, _1081, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)) * vec4(_153.lUniforms.mpCommonPerMesh.gaParticleCornersVec4[int(mkfParticleCornerId)].xyz * (_153.lUniforms.mpCommonPerMesh.gaParticleSizeAndRotationsVec4[_350].x * sqrt(dot(_153.lUniforms.mpCommonPerMesh.gWorldMat4[0].xyz, _153.lUniforms.mpCommonPerMesh.gWorldMat4[0].xyz))), 1.0))).xyz;
    vec4 _1169 = vec4(_1163 + _153.lUniforms.mpCommonPerMesh.gaParticlePositionsVec4[_350].xyz, 1.0);
    vec4 _1535;
    if (length(_1063) >= length(((_153.lUniforms.mpCommonPerMesh.gaParticlePositionsVec4[_350].xyz + _1063) + _1163) - _153.lUniforms.mpCommonPerMesh.gaParticlePositionsVec4[_350].xyz))
    {
        _1535 = vec4(_1169.xyz - _1063, 0.0);
    }
    else
    {
        _1535 = _1169;
    }
    Out.mColourVec4 = _153.lUniforms.mpCommonPerMesh.gaParticleColoursVec4[_350];
    float _1241 = (Out.mColourVec4.x < 0.0) ? (-1.0) : 1.0;
    float _1244 = Out.mColourVec4.x * _1241;
    float _1536;
    if (_1244 > 1.0)
    {
        _1536 = pow(_1244, 2.400000095367431640625);
    }
    else
    {
        float _1537;
        if (_1244 > 0.0)
        {
            _1537 = pow(_1244, 2.2000000476837158203125);
        }
        else
        {
            _1537 = _1244;
        }
        _1536 = _1537;
    }
    vec3 _1521 = _1541;
    _1521.x = _1536 * _1241;
    float _1267 = (Out.mColourVec4.y < 0.0) ? (-1.0) : 1.0;
    float _1270 = Out.mColourVec4.y * _1267;
    float _1543;
    if (_1270 > 1.0)
    {
        _1543 = pow(_1270, 2.400000095367431640625);
    }
    else
    {
        float _1544;
        if (_1270 > 0.0)
        {
            _1544 = pow(_1270, 2.2000000476837158203125);
        }
        else
        {
            _1544 = _1270;
        }
        _1543 = _1544;
    }
    vec3 _1524 = _1521;
    _1524.y = _1543 * _1267;
    float _1293 = (Out.mColourVec4.z < 0.0) ? (-1.0) : 1.0;
    float _1296 = Out.mColourVec4.z * _1293;
    float _1547;
    if (_1296 > 1.0)
    {
        _1547 = pow(_1296, 2.400000095367431640625);
    }
    else
    {
        float _1548;
        if (_1296 > 0.0)
        {
            _1548 = pow(_1296, 2.2000000476837158203125);
        }
        else
        {
            _1548 = _1296;
        }
        _1547 = _1548;
    }
    vec3 _1527 = _1524;
    _1527.z = _1547 * _1293;
    Out.mColourVec4 = vec4(_1527.x, _1527.y, _1527.z, Out.mColourVec4.w);
    Out.mColourVec4.w *= _1535.w;
    Out.mColourVec4.w = min(Out.mColourVec4.w, 1.0);
    vec4 _1530 = _1535;
    _1530.w = 1.0;
    Out.mWorldNormalVec3 = normalize(_1530.xyz - (_153.lUniforms.mpCommonPerMesh.gaParticlePositionsVec4[_350].xyz - (_153.lUniforms.mpPerFrame.gCameraMat4[2].xyz * _153.lUniforms.mpCommonPerMesh.gaParticleSizeAndRotationsVec4[_350].x)));
    vec4 _940 = _153.lUniforms.mpPerFrame.gViewProjectionMat4 * _1530;
    vec2 _950 = _940.xy - (_153.lUniforms.mpPerFrame.gDeJitterVec3.xy * _940.w);
    vec4 _952 = vec4(_950.x, _950.y, _940.z, _940.w);

// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
_952.x += vk3d_params.stereo.x * (_952.w - vk3d_params.stereo.y); 

    Out.mScreenSpacePositionVec4 = _952;
    gl_Position = _952;
}


