#version 450
// haloing living ship 2
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 gfFadeValue;
    vec4 gaSkinMatrixRowsVec4[225];
    vec4 gaPrevSkinMatrixRowsVec4[225];
    vec4 gLightPositionVec4;
    vec4 gLightDirectionVec4;
    vec4 gLightOriginVec4;
    vec4 gScanParamsPosVec4;
    vec4 gScanParamsCfg1Vec4;
    vec4 gScanParamsCfg2Vec4;
    vec4 gScanParamsCfg3Vec4;
    vec4 gScanColourVec4;
    mat4 gaShadowMat4[3];
    vec4 gLightColourVec4;
    vec4 gLightCustomParamsVec4;
    mat4 gWorldMotionMat4;
    mat4 gInverseModelMat4Dummy;
};

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;
    vec4 gAverageColour1Vec4;
    vec4 gAverageColour2Vec4;
    vec4 gRecolour1Vec4;
    vec4 gRecolour2Vec4;
    vec4 gSkyColourVec4;
    vec4 gHorizonColourVec4;
    vec4 gSunColourVec4;
    vec4 gWaterFogColourNearVec4;
    vec4 gWaterFogColourFarVec4;
    vec4 gWaterFogVec4;
    vec4 gHeightFogParamsVec4;
    vec4 gHeightFogColourVec4;
    vec4 gSpaceHorizonColourVec4;
    vec4 gFogColourVec4;
    vec4 gFogParamsVec4;
    vec4 gScatteringParamsVec4;
    vec4 gFogFadeHeightsVec4;
    vec4 gSpaceScatteringParamsVec4;
    vec4 gSkyUpperColourVec4;
    vec4 gLightTopColourVec4;
};

struct CustomPerMeshUniforms
{
    vec4 gUVScrollStepVec4;
    vec4 gCustomParams01Vec4;
    vec4 gCustomParams02Vec4;
    vec4 gObjectColourVec4;
};

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;
} _113;

layout(location = 0) in vec4 mkLocalPositionVec4;
layout(location = 7) in vec4 mkLocalNormalVec4;
layout(location = 3) in vec4 mkTangentVec4;
layout(location = 0) out VertexBlock
{
    vec4 mTexCoordsVec4;
    vec4 mWorldPositionVec3_mfSpare;
    vec4 mColourVec4;
    vec3 mTangentSpaceNormalVec3;
    flat mat3 mUpMatrixMat3;
    vec4 mScreenSpacePositionVec4;
    flat vec3 mfFadeValueForInstance_mfLodIndex_mfShearMotionLength;
} Out;

layout(location = 6) in vec4 mkWeightsVec4;
layout(location = 5) in vec4 mkJointsVec4;
layout(location = 8) in vec4 mkColourVec4;
layout(location = 1) in vec4 mkTexCoordsVec4;

mat4 _2014;
mat3 _2024;

void main()
{
    Out.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.y = 0.0;
    Out.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x = _113.lUniforms.mpCommonPerMesh.gfFadeValue;
    int _1818 = int(mkJointsVec4.x) * 3;
    mat4 _1954 = _2014;
    _1954[0] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1818];
    mat4 _1956 = _1954;
    _1956[1] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1818 + 1];
    mat4 _1958 = _1956;
    _1958[2] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1818 + 2];
    mat4 _1960 = _1958;
    _1960[3] = vec4(0.0, 0.0, 0.0, 1.0);
    mat4 _1731 = _1960 * mkWeightsVec4.x;
    mat4 _2016;
    if (mkWeightsVec4.y > 0.001000000047497451305389404296875)
    {
        int _1839 = int(mkJointsVec4.y) * 3;
        mat4 _1965 = _2014;
        _1965[0] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1839];
        mat4 _1967 = _1965;
        _1967[1] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1839 + 1];
        mat4 _1969 = _1967;
        _1969[2] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1839 + 2];
        mat4 _1971 = _1969;
        _1971[3] = vec4(0.0, 0.0, 0.0, 1.0);
        mat4 _1744 = _1971 * mkWeightsVec4.y;
        _2016 = mat4(_1731[0] + _1744[0], _1731[1] + _1744[1], _1731[2] + _1744[2], _1731[3] + _1744[3]);
    }
    else
    {
        _2016 = _1731;
    }
    mat4 _2019;
    if (mkWeightsVec4.z > 0.001000000047497451305389404296875)
    {
        int _1860 = int(mkJointsVec4.z) * 3;
        mat4 _1976 = _2014;
        _1976[0] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1860];
        mat4 _1978 = _1976;
        _1978[1] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1860 + 1];
        mat4 _1980 = _1978;
        _1980[2] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1860 + 2];
        mat4 _1982 = _1980;
        _1982[3] = vec4(0.0, 0.0, 0.0, 1.0);
        mat4 _1771 = _1982 * mkWeightsVec4.z;
        _2019 = mat4(_2016[0] + _1771[0], _2016[1] + _1771[1], _2016[2] + _1771[2], _2016[3] + _1771[3]);
    }
    else
    {
        _2019 = _2016;
    }
    mat4 _2020;
    if (mkWeightsVec4.w > 0.001000000047497451305389404296875)
    {
        int _1881 = abs(int(mkJointsVec4.w)) * 3;
        mat4 _1987 = _2014;
        _1987[0] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1881];
        mat4 _1989 = _1987;
        _1989[1] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1881 + 1];
        mat4 _1991 = _1989;
        _1991[2] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1881 + 2];
        mat4 _1993 = _1991;
        _1993[3] = vec4(0.0, 0.0, 0.0, 1.0);
        mat4 _1799 = _1993 * mkWeightsVec4.w;
        _2020 = mat4(_2019[0] + _1799[0], _2019[1] + _1799[1], _2019[2] + _1799[2], _2019[3] + _1799[3]);
    }
    else
    {
        _2020 = _2019;
    }
    mat3 _1996 = _2024;
    _1996[0] = _2020[0].xyz;
    mat3 _1999 = _1996;
    _1999[1] = _2020[1].xyz;
    mat3 _2002 = _1999;
    _2002[2] = _2020[2].xyz;
    vec4 _1918 = mkLocalPositionVec4 * _2020;
    Out.mWorldPositionVec3_mfSpare = vec4(0.0);
    vec4 _1937 = _113.lUniforms.mpCommonPerMesh.gWorldMat4 * (_1918 / vec4(max(_1918.w, 9.9999999747524270787835121154785e-07)));
    Out.mWorldPositionVec3_mfSpare = vec4(_1937.x, _1937.y, _1937.z, Out.mWorldPositionVec3_mfSpare.w);
    Out.mWorldPositionVec3_mfSpare = vec4(_1937.x, _1937.y, _1937.z, Out.mWorldPositionVec3_mfSpare.w);
    Out.mTangentSpaceNormalVec3 = normalize((_113.lUniforms.mpCommonPerMesh.gWorldNormalMat4 * vec4(normalize(mkLocalNormalVec4.xyz) * _2002, 1.0)).xyz);
    mat3 _2005 = _2024;
    _2005[0] = _113.lUniforms.mpPerFrame.gInverseWorldUpMatVec4[0].xyz;
    mat3 _2007 = _2005;
    _2007[1] = _113.lUniforms.mpPerFrame.gInverseWorldUpMatVec4[1].xyz;
    mat3 _2009 = _2007;
    _2009[2] = _113.lUniforms.mpPerFrame.gInverseWorldUpMatVec4[2].xyz;
    Out.mUpMatrixMat3 = _2009;
    Out.mColourVec4 = mkColourVec4;
    Out.mTexCoordsVec4 = vec4(mkTexCoordsVec4.x, mkTexCoordsVec4.y, mkTexCoordsVec4.x, mkTexCoordsVec4.y) + (_113.lUniforms.mpCustomPerMesh.gUVScrollStepVec4 * _113.lUniforms.mpPerFrame.gfTime);
    vec4 _1950 = _113.lUniforms.mpPerFrame.gViewProjectionMat4 * _1937;
    
    _1950.x += vk3d_params.stereo.x * (_1950.w - vk3d_params.stereo.y); 
    
    Out.mScreenSpacePositionVec4 = _1950;
    Out.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.z = 0.0;
    vec4 _2012 = _1950;
    _2012.z = _1950.z + 9.9999999747524270787835121154785e-07;
    gl_Position = _2012;

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


