#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;

mat4 _2221;

void main()
{
    vec4 _2152 = mkLocalPositionVec4;
    _2152.w = 1.0;
    int _1799 = int(mkJointsVec4.x) * 3;
    mat4 _2155 = _2221;
    _2155[0] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1799];
    mat4 _2157 = _2155;
    _2157[1] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1799 + 1];
    mat4 _2159 = _2157;
    _2159[2] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1799 + 2];
    mat4 _2161 = _2159;
    _2161[3] = vec4(0.0, 0.0, 0.0, 1.0);
    vec4 _1737 = (_2152 * _2161) * mkWeightsVec4.x;
    vec4 _2223;
    if (mkWeightsVec4.y > 0.001000000047497451305389404296875)
    {
        int _1820 = int(mkJointsVec4.y) * 3;
        mat4 _2166 = _2221;
        _2166[0] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1820];
        mat4 _2168 = _2166;
        _2168[1] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1820 + 1];
        mat4 _2170 = _2168;
        _2170[2] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1820 + 2];
        mat4 _2172 = _2170;
        _2172[3] = vec4(0.0, 0.0, 0.0, 1.0);
        _2223 = _1737 + ((_2152 * _2172) * mkWeightsVec4.y);
    }
    else
    {
        _2223 = _1737;
    }
    vec4 _2226;
    if (mkWeightsVec4.z > 0.001000000047497451305389404296875)
    {
        int _1841 = int(mkJointsVec4.z) * 3;
        mat4 _2177 = _2221;
        _2177[0] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1841];
        mat4 _2179 = _2177;
        _2179[1] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1841 + 1];
        mat4 _2181 = _2179;
        _2181[2] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1841 + 2];
        mat4 _2183 = _2181;
        _2183[3] = vec4(0.0, 0.0, 0.0, 1.0);
        _2226 = _2223 + ((_2152 * _2183) * mkWeightsVec4.z);
    }
    else
    {
        _2226 = _2223;
    }
    vec4 _2227;
    if (mkWeightsVec4.w > 0.001000000047497451305389404296875)
    {
        int _1862 = int(mkJointsVec4.w) * 3;
        mat4 _2188 = _2221;
        _2188[0] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1862];
        mat4 _2190 = _2188;
        _2190[1] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1862 + 1];
        mat4 _2192 = _2190;
        _2192[2] = _94.lUniforms.mpCommonPerMesh.gaSkinMatrixRowsVec4[_1862 + 2];
        mat4 _2194 = _2192;
        _2194[3] = vec4(0.0, 0.0, 0.0, 1.0);
        _2227 = _2226 + ((_2152 * _2194) * mkWeightsVec4.w);
    }
    else
    {
        _2227 = _2226;
    }
    vec4 _1794 = _2227 / vec4(max(_2227.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 _1918 = _1794.xyz;
    float _2242;
    if (dot(_94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.xyz, _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.xyz) > 0.0)
    {
        float _2228;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.x > 0.0)
        {
            _2228 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.x;
        }
        else
        {
            _2228 = 0.0;
        }
        float _2229;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.y > 0.0)
        {
            _2229 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.y;
        }
        else
        {
            _2229 = 0.0;
        }
        float _2230;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.z > 0.0)
        {
            _2230 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.z;
        }
        else
        {
            _2230 = 0.0;
        }
        _2242 = dot(vec3(_2228, _2229, _2230), _1918);
    }
    else
    {
        _2242 = 1.0;
    }
    float _2246;
    if (dot(_94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.xyz, _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.xyz) > 0.0)
    {
        float _2235;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.x > 0.0)
        {
            _2235 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.x;
        }
        else
        {
            _2235 = 0.0;
        }
        float _2236;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.y > 0.0)
        {
            _2236 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.y;
        }
        else
        {
            _2236 = 0.0;
        }
        float _2237;
        if (_94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.z > 0.0)
        {
            _2237 = 1.0 / _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.z;
        }
        else
        {
            _2237 = 0.0;
        }
        _2246 = dot(vec3(_2235, _2236, _2237), _1918);
    }
    else
    {
        _2246 = 1.0;
    }
    vec3 _2052 = _1918 + (((vec3(sin(dot(_94.lUniforms.mpCustomPerMaterial.gWaveOneFrequencyVec4.xyz, _1918) + (_1584 * _94.lUniforms.mpCustomPerMaterial.gWaveOneFallOffAndSpeedVec4.w))) * _94.lUniforms.mpCustomPerMaterial.gWaveOneAmplitudeAndPosOffsetV4.xyz) * _2242) + ((vec3(sin(dot(_94.lUniforms.mpCustomPerMaterial.gWaveTwoFrequencyVec4.xyz, _1918) + (_1584 * _94.lUniforms.mpCustomPerMaterial.gWaveTwoFallOffAndSpeedVec4.w))) * _94.lUniforms.mpCustomPerMaterial.gWaveTwoAmplitudeVec4.xyz) * _2246));
    Out.mTexCoordsVec4 = vec4(mkTexCoordsVec4.x, mkTexCoordsVec4.y, mkTexCoordsVec4.z, mkTexCoordsVec4.w);
    vec4 _2090 = _94.lUniforms.mpPerFrame.gViewProjectionMat4 * (_94.lUniforms.mpCommonPerMesh.gWorldMat4 * vec4(_2052.x, _2052.y, _2052.z, _1794.w));
    vec4 _2220 = _2090;
    _2220.z = 0.5 - (max(_2090.z, -1.0) * 0.5);
    Out.mScreenSpacePositionVec4 = _2220;
    gl_Position = _2220;
	
// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
//gl_Position.x += vk3d_params.stereo.x * (gl_Position.w - vk3d_params.stereo.y); 
}


