#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 gLightPositionVec4;
    vec4 gLightDirectionVec4;
    vec4 gLightOriginVec4;
};

struct CustomPerMaterialUniforms
{
    vec4 gImposterDataVec4;
    vec4 gTileBlendScalesVec4;
    vec4 gHueOverlayParamsVec4;
    vec4 gSaturationOverlayParamsVec4;
    vec4 gValueOverlayParamsVec4;
    vec4 gTerrainColour1Vec4;
    vec4 gTerrainColour2Vec4;
};

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

layout(location = 0) in vec4 mkLocalPositionVec4;
layout(location = 1) in vec4 mkTexCoordsVec4;
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;

vec4 _758;
mat3 _759;

void main()
{
    vec4 _710 = mkLocalPositionVec4;
    _710.w = 1.0;
    vec3 _346 = -_327.lUniforms.mpCommonPerMesh.gLightDirectionVec4.xyz;
    float _556 = mkTexCoordsVec4.x - 0.5;
    float _559 = 0.5 - mkTexCoordsVec4.y;
    vec4 _578 = _327.lUniforms.mpCommonPerMesh.gWorldMat4 * vec4(_710.xy - vec2(_556, _559), mkLocalPositionVec4.z, 1.0);
    mat4 _720 = _327.lUniforms.mpCommonPerMesh.gWorldMat4;
    _720[3] = _578;
    vec3 _619 = normalize(_327.lUniforms.mpCommonPerMesh.gWorldMat4[1].xyz);
    vec3 _623 = normalize(cross(_619, _346.xyz));
    vec3 _641 = normalize(mix(normalize(_327.lUniforms.mpPerFrame.gViewMat4[3].xyz - _578.xyz), normalize(cross(_623, _619)), vec3((_327.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x * _327.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x) * _327.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x)));
    mat3 _730 = _759;
    _730[2] = _641;
    mat3 _733 = _730;
    _733[0] = normalize(mix(cross(_619, _641), _623, vec3(_327.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x)));
    mat3 _735 = _733;
    _735[1] = _619;
    vec3 _658 = _735 * vec4(_556, _559, 0.0, 1.0).xyz;
    vec4 _737 = vec4(_658.x, _658.y, _658.z, _758.w);
    _737.w = 1.0;
    mat4 _704 = inverse(_720);
    mat4 _742 = _704;
    _742[0] = normalize(_704[0]);
    mat4 _745 = _742;
    _745[1] = normalize(_704[1]);
    mat4 _748 = _745;
    _748[2] = normalize(_704[2]);
    mat4 _750 = _748;
    _750[3] = vec4(0.0, 0.0, 0.0, 1.0);
    vec4 _521 = _720 * vec4((_750 * _737).xyz, 1.0);
    vec3 _386 = _521.xyz + (_346 * (-2.0));
    Out.mTexCoordsVec4 = vec4(mkTexCoordsVec4.x, mkTexCoordsVec4.y, mkTexCoordsVec4.z, mkTexCoordsVec4.w);
    vec4 _708 = _327.lUniforms.mpPerFrame.gViewProjectionMat4 * vec4(_386.x, _386.y, _386.z, _521.w);
    vec4 _756 = _708;
    _756.z = 0.5 - (max(_708.z, -1.0) * 0.5);
    Out.mScreenSpacePositionVec4 = _756;
    gl_Position = _756;

// 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); 
}


