#version 450
 
struct PerFrameUniforms
{
    mat4 gViewMat4;
    mat4 gViewProjectionMat4;
    mat4 gCameraMat4;
    vec3 gViewPositionVec3;
    float gfTime;
    vec4 gFrameBufferSizeVec4;
};

struct CommonPerMeshUniforms
{
    vec4 gPlanetPositionVec4;
    mat4 gWorldMat4;
    float gfFadeValue;
    vec4 gaSkinMatrixRowsVec4[225];
    vec4 gaPrevSkinMatrixRowsVec4[225];
};

struct CustomPerMaterialUniforms
{
    vec4 gImposterDataVec4;
    vec4 gTileBlendScalesVec4;
    vec4 gHueOverlayParamsVec4;
    vec4 gSaturationOverlayParamsVec4;
    vec4 gValueOverlayParamsVec4;
    vec4 gTerrainColour1Vec4;
    vec4 gTerrainColour2Vec4;
    vec4 gWaveOneAmplitudeAndPosOffsetV4;
    vec4 gWaveOneFrequencyVec4;
    vec4 gWaveOneFallOffAndSpeedVec4;
    vec4 gWaveTwoAmplitudeVec4;
    vec4 gWaveTwoFrequencyVec4;
    vec4 gWaveTwoFallOffAndSpeedVec4;
};

struct CustomPerMeshUniforms
{
    vec4 gUVScrollStepVec4;
    vec4 gCustomParams01Vec4;
    vec4 gBboxDepthAndClips;
};

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

layout(location = 0) in vec4 mkLocalPositionVec4;
layout(location = 1) in vec4 mkTexCoordsVec4;
layout(location = 6) in vec4 mkWeightsVec4;
layout(location = 5) in vec4 mkJointsVec4;
layout(location = 0) out VertexBlock
{
    vec4 mScreenSpacePositionVec4;
    vec4 mTexCoordsVec4;
} Out;

layout(location = 7) in vec4 mkLocalNormalVec4;
layout(location = 3) in vec4 mkTangentVec4;
layout(location = 8) in vec4 mkColourVec4;

mat4 _2222;

void main()
{
    vec4 _2153 = mkLocalPositionVec4;
    _2153.w = 1.0;
    int _1800 = int(mkJointsVec4.x) * 3;
    mat4 _2156 = _2222;
    _2156[0] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1800];
    mat4 _2158 = _2156;
    _2158[1] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1800 + 1];
    mat4 _2160 = _2158;
    _2160[2] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1800 + 2];
    mat4 _2162 = _2160;
    _2162[3] = vec4(0.0, 0.0, 0.0, 1.0);
    vec4 _1738 = (_2153 * _2162) * mkWeightsVec4.x;
    vec4 _2224;
    if (mkWeightsVec4.y > 0.001000000047497451305389404296875)
    {
        int _1821 = int(mkJointsVec4.y) * 3;
        mat4 _2167 = _2222;
        _2167[0] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1821];
        mat4 _2169 = _2167;
        _2169[1] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1821 + 1];
        mat4 _2171 = _2169;
        _2171[2] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1821 + 2];
        mat4 _2173 = _2171;
        _2173[3] = vec4(0.0, 0.0, 0.0, 1.0);
        _2224 = _1738 + ((_2153 * _2173) * mkWeightsVec4.y);
    }
    else
    {
        _2224 = _1738;
    }
    vec4 _2227;
    if (mkWeightsVec4.z > 0.001000000047497451305389404296875)
    {
        int _1842 = int(mkJointsVec4.z) * 3;
        mat4 _2178 = _2222;
        _2178[0] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1842];
        mat4 _2180 = _2178;
        _2180[1] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1842 + 1];
        mat4 _2182 = _2180;
        _2182[2] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1842 + 2];
        mat4 _2184 = _2182;
        _2184[3] = vec4(0.0, 0.0, 0.0, 1.0);
        _2227 = _2224 + ((_2153 * _2184) * mkWeightsVec4.z);
    }
    else
    {
        _2227 = _2224;
    }
    vec4 _2228;
    if (mkWeightsVec4.w > 0.001000000047497451305389404296875)
    {
        int _1863 = int(mkJointsVec4.w) * 3;
        mat4 _2189 = _2222;
        _2189[0] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1863];
        mat4 _2191 = _2189;
        _2191[1] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1863 + 1];
        mat4 _2193 = _2191;
        _2193[2] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1863 + 2];
        mat4 _2195 = _2193;
        _2195[3] = vec4(0.0, 0.0, 0.0, 1.0);
        _2228 = _2227 + ((_2153 * _2195) * mkWeightsVec4.w);
    }
    else
    {
        _2228 = _2227;
    }
    vec4 _1795 = _2228 / vec4(max(_2228.w, 9.9999999747524270787835121154785e-07));
    vec3 _1572 = _94.lUniforms.mpCommonPerMesh.gWorldMat4[3].xyz - _94.lUniforms.mpCommonPerMesh.gPlanetPositionVec4.xyz;
    float _1584 = ((_94.lUniforms.mpPerFrame.gfTime + _1572.x) + _1572.y) + _1572.z;
    vec3 _1919 = _1795.xyz;
    float _2243;
    if (dot(_94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.xyz, _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.xyz) > 0.0)
    {
        float _2229;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.x > 0.0)
        {
            _2229 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.x;
        }
        else
        {
            _2229 = 0.0;
        }
        float _2230;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.y > 0.0)
        {
            _2230 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.y;
        }
        else
        {
            _2230 = 0.0;
        }
        float _2231;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.z > 0.0)
        {
            _2231 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.z;
        }
        else
        {
            _2231 = 0.0;
        }
        _2243 = dot(vec3(_2229, _2230, _2231), _1919);
    }
    else
    {
        _2243 = 1.0;
    }
    float _2247;
    if (dot(_94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.xyz, _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.xyz) > 0.0)
    {
        float _2236;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.x > 0.0)
        {
            _2236 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.x;
        }
        else
        {
            _2236 = 0.0;
        }
        float _2237;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.y > 0.0)
        {
            _2237 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.y;
        }
        else
        {
            _2237 = 0.0;
        }
        float _2238;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.z > 0.0)
        {
            _2238 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.z;
        }
        else
        {
            _2238 = 0.0;
        }
        _2247 = dot(vec3(_2236, _2237, _2238), _1919);
    }
    else
    {
        _2247 = 1.0;
    }
    vec3 _2053 = _1919 + (((vec3(sin(dot(_94.lUniforms.mpCustomPerMaterial.gWaveOneFrequencyVec4.xyz, _1919) + (_1584 * _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.w))) * _94.lUniforms.mpCustomPerMaterial.gWaveOneAmplitudeAndPosOffsetV4.xyz) * _2243) + ((vec3(sin(dot(_94.lUniforms.mpCustomPerMaterial.gWaveTwoFrequencyVec4.xyz, _1919) + (_1584 * _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.w))) * _94.lUniforms.mpCustomPerMaterial.gWaveTwoAmplitudeVec4.xyz) * _2247));
    Out.mTexCoordsVec4 = vec4(mkTexCoordsVec4.x, mkTexCoordsVec4.y, mkTexCoordsVec4.z, mkTexCoordsVec4.w);
    vec4 _2091 = _94.lUniforms.mpPerFrame.gViewProjectionMat4 * (_94.lUniforms.mpCommonPerMesh.gWorldMat4 * vec4(_2053.x, _2053.y, _2053.z, _1795.w));
    vec4 _2221 = _2091;
    _2221.z = 0.5 - (max(_2091.z, -1.0) * 0.5);
    Out.mScreenSpacePositionVec4 = _2221;
    gl_Position = _2221;

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

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


