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

struct CommonPerMeshUniforms
{
    vec4 gPlanetPositionVec4;
    mat4 gWorldMat4;
    float fdFadeValueDummy;
    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;
} _406;

layout(location = 0) in vec4 mkLocalPositionVec4;
layout(location = 9) in vec4 mkTransformMat4R0;
layout(location = 10) in vec4 mkTransformMat4R1;
layout(location = 11) in vec4 mkTransformMat4R2;
layout(location = 12) in vec4 mkTransformMat4R3;
layout(location = 14) in vec4 mkTransformMat4R5;
layout(location = 0) out VertexBlock
{
    vec4 mScreenSpacePositionVec4;
    vec4 mTexCoordsVec4;
    vec3 mPixelZandW_mfFadeValueForInstance;
} Out;

layout(location = 1) in vec4 mkTexCoordsVec4;
layout(location = 7) in vec4 mkLocalNormalVec4;
layout(location = 3) in vec4 mkTangentVec4;
layout(location = 8) in vec4 mkColourVec4;
layout(location = 13) in vec4 mkTransformMat4R4;

mat4 _900;
vec4 _901;
mat3 _902;

void main()
{
    vec4 _822 = mkLocalPositionVec4;
    _822.w = 1.0;
    mat4 _824 = _900;
    _824[0] = mkTransformMat4R0;
    mat4 _826 = _824;
    _826[1] = mkTransformMat4R1;
    mat4 _828 = _826;
    _828[2] = mkTransformMat4R2;
    mat4 _830 = _828;
    _830[3] = mkTransformMat4R3;
    Out.mPixelZandW_mfFadeValueForInstance.z = mkTransformMat4R0.w;
    mat4 _833 = _830;
    _833[0].w = 0.0;
    mat4 _835 = _833;
    _835[1].w = 0.0;
    mat4 _837 = _835;
    _837[2].w = 0.0;
    mat4 _839 = _837;
    _839[3].w = 1.0;
    vec3 _415 = -_406.lUniforms.mpCommonPerMesh.gLightDirectionVec4.xyz;
    float _625 = mkTexCoordsVec4.x - 0.5;
    float _628 = 0.5 - mkTexCoordsVec4.y;
    float _636 = _625 * length(_406.lUniforms.mpCommonPerMesh.gWorldMat4[0].xyz);
    vec2 _848 = vec2(_625, _628);
    _848.x = _636;
    float _644 = _628 * length(_406.lUniforms.mpCommonPerMesh.gWorldMat4[1].xyz);
    vec2 _852 = _848;
    _852.y = _644;
    vec4 _648 = _406.lUniforms.mpCommonPerMesh.gWorldMat4 * _822;
    vec4 _669 = _839 * vec4(_648.xy - _852, _648.z, 1.0);
    mat4 _857 = _839;
    _857[3] = _669;
    vec3 _710 = normalize(_835[1].xyz);
    vec3 _714 = normalize(cross(_710, _415.xyz));
    vec3 _732 = normalize(mix(normalize(_406.lUniforms.mpPerFrame.gViewMat4[3].xyz - _669.xyz), normalize(cross(_714, _710)), vec3((_406.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x * _406.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x) * _406.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x)));
    mat3 _867 = _902;
    _867[2] = _732;
    mat3 _870 = _867;
    _870[0] = normalize(mix(cross(_710, _732), _714, vec3(_406.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x)));
    mat3 _872 = _870;
    _872[1] = _710;
    vec3 _749 = _872 * vec4(_636, _644, 0.0, 1.0).xyz;
    vec4 _874 = vec4(_749.x, _749.y, _749.z, _901.w);
    _874.w = 1.0;
    mat4 _816 = inverse(_857);
    mat4 _879 = _816;
    _879[0] = normalize(_816[0]);
    mat4 _882 = _879;
    _882[1] = normalize(_816[1]);
    mat4 _885 = _882;
    _885[2] = normalize(_816[2]);
    mat4 _887 = _885;
    _887[3] = vec4(0.0, 0.0, 0.0, 1.0);
    vec4 _590 = _857 * vec4((_887 * _874).xyz, 1.0);
    vec3 _455 = _590.xyz + (_415 * (-2.0));
    Out.mTexCoordsVec4 = vec4(mkTexCoordsVec4.x, mkTexCoordsVec4.y, mkTexCoordsVec4.z, mkTexCoordsVec4.w);
    vec4 _820 = _406.lUniforms.mpPerFrame.gViewProjectionMat4 * vec4(_455.x, _455.y, _455.z, _590.w);
    vec4 _898 = _820;
    _898.z = 0.5 - (max(_820.z, -1.0) * 0.5);
    Out.mScreenSpacePositionVec4 = _898;
    gl_Position = _898;

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


