#version 450
// haloing living ship
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;
    flat mat3 mUpMatrixMat3;
    vec3 mTangentMatRow1Vec3;
    vec3 mTangentMatRow2Vec3;
    vec3 mTangentMatRow3Vec3;
    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 _2038;
mat3 _2048;

void main()
{
    Out.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.y = 0.0;
    Out.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x = _113.lUniforms.mpCommonPerMesh.gfFadeValue;
    int _1836 = int(mkJointsVec4.x) * 3;
    mat4 _1981 = _2038;
    _1981[0] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1836];
    mat4 _1983 = _1981;
    _1983[1] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1836 + 1];
    mat4 _1985 = _1983;
    _1985[2] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1836 + 2];
    mat4 _1987 = _1985;
    _1987[3] = vec4(0.0, 0.0, 0.0, 1.0);
    mat4 _1749 = _1987 * mkWeightsVec4.x;
    mat4 _2040;
    if (mkWeightsVec4.y > 0.001000000047497451305389404296875)
    {
        int _1857 = int(mkJointsVec4.y) * 3;
        mat4 _1992 = _2038;
        _1992[0] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1857];
        mat4 _1994 = _1992;
        _1994[1] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1857 + 1];
        mat4 _1996 = _1994;
        _1996[2] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1857 + 2];
        mat4 _1998 = _1996;
        _1998[3] = vec4(0.0, 0.0, 0.0, 1.0);
        mat4 _1762 = _1998 * mkWeightsVec4.y;
        _2040 = mat4(_1749[0] + _1762[0], _1749[1] + _1762[1], _1749[2] + _1762[2], _1749[3] + _1762[3]);
    }
    else
    {
        _2040 = _1749;
    }
    mat4 _2043;
    if (mkWeightsVec4.z > 0.001000000047497451305389404296875)
    {
        int _1878 = int(mkJointsVec4.z) * 3;
        mat4 _2003 = _2038;
        _2003[0] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1878];
        mat4 _2005 = _2003;
        _2005[1] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1878 + 1];
        mat4 _2007 = _2005;
        _2007[2] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1878 + 2];
        mat4 _2009 = _2007;
        _2009[3] = vec4(0.0, 0.0, 0.0, 1.0);
        mat4 _1789 = _2009 * mkWeightsVec4.z;
        _2043 = mat4(_2040[0] + _1789[0], _2040[1] + _1789[1], _2040[2] + _1789[2], _2040[3] + _1789[3]);
    }
    else
    {
        _2043 = _2040;
    }
    mat4 _2044;
    if (mkWeightsVec4.w > 0.001000000047497451305389404296875)
    {
        int _1899 = abs(int(mkJointsVec4.w)) * 3;
        mat4 _2014 = _2038;
        _2014[0] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1899];
        mat4 _2016 = _2014;
        _2016[1] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1899 + 1];
        mat4 _2018 = _2016;
        _2018[2] = _113.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1899 + 2];
        mat4 _2020 = _2018;
        _2020[3] = vec4(0.0, 0.0, 0.0, 1.0);
        mat4 _1817 = _2020 * mkWeightsVec4.w;
        _2044 = mat4(_2043[0] + _1817[0], _2043[1] + _1817[1], _2043[2] + _1817[2], _2043[3] + _1817[3]);
    }
    else
    {
        _2044 = _2043;
    }
    mat3 _2023 = _2048;
    _2023[0] = _2044[0].xyz;
    mat3 _2026 = _2023;
    _2026[1] = _2044[1].xyz;
    mat3 _2029 = _2026;
    _2029[2] = _2044[2].xyz;
    vec4 _1936 = mkLocalPositionVec4 * _2044;
    Out.mWorldPositionVec3_mfSpare = vec4(0.0);
    vec4 _1955 = _113.lUniforms.mpCommonPerMesh.gWorldMat4 * (_1936 / vec4(max(_1936.w, 9.9999999747524270787835121154785e-07)));
    vec3 _1557 = normalize((_113.lUniforms.mpCommonPerMesh.gWorldNormalMat4 * vec4(normalize(mkLocalNormalVec4.xyz) * _2029, 1.0)).xyz);
    Out.mWorldPositionVec3_mfSpare = vec4(_1955.x, _1955.y, _1955.z, Out.mWorldPositionVec3_mfSpare.w);
    Out.mWorldPositionVec3_mfSpare = vec4(_1955.x, _1955.y, _1955.z, Out.mWorldPositionVec3_mfSpare.w);
    vec3 _1973 = (_113.lUniforms.mpCommonPerMesh.gWorldNormalMat4 * vec4(normalize(mkTangentVec4.xyz) * _2029, 1.0)).xyz;
    Out.mTangentMatRow1Vec3 = normalize(_1973);
    Out.mTangentMatRow2Vec3 = normalize(cross(_1557, _1973) * ((mkTangentVec4.w > 0.00999999977648258209228515625) ? 1.0 : (-1.0)));
    Out.mTangentMatRow3Vec3 = normalize(_1557);
    mat3 _2032 = _2048;
    _2032[0] = _113.lUniforms.mpPerFrame.gInverseWorldUpMatVec4[0].xyz;
    mat3 _2034 = _2032;
    _2034[1] = _113.lUniforms.mpPerFrame.gInverseWorldUpMatVec4[1].xyz;
    mat3 _2036 = _2034;
    _2036[2] = _113.lUniforms.mpPerFrame.gInverseWorldUpMatVec4[2].xyz;
    Out.mUpMatrixMat3 = _2036;
    Out.mColourVec4 = mkColourVec4;
    Out.mTexCoordsVec4 = vec4(mkTexCoordsVec4.x, mkTexCoordsVec4.y, mkTexCoordsVec4.x, mkTexCoordsVec4.y);
    vec4 _1977 = _113.lUniforms.mpPerFrame.gViewProjectionMat4 * _1955;
    
    _1977.x += vk3d_params.stereo.x * (_1977.w - vk3d_params.stereo.y); 
    
    Out.mScreenSpacePositionVec4 = _1977;
    Out.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.z = 0.0;
    gl_Position = _1977;

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


