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

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 = 13) in vec4 mkTransformMat4R4;

mat4 _953;
mat3 _954;
vec4 _955;

void main()
{
    vec4 _878 = mkLocalPositionVec4;
    _878.w = 1.0;
    mat4 _880 = _953;
    _880[0] = mkTransformMat4R0;
    mat4 _882 = _880;
    _882[1] = mkTransformMat4R1;
    mat4 _884 = _882;
    _884[2] = mkTransformMat4R2;
    mat4 _886 = _884;
    _886[3] = mkTransformMat4R3;
    Out.mPixelZandW_mfFadeValueForInstance.z = mkTransformMat4R0.w;
    mat4 _889 = _886;
    _889[0].w = 0.0;
    mat4 _891 = _889;
    _891[1].w = 0.0;
    mat4 _893 = _891;
    _893[2].w = 0.0;
    mat4 _895 = _893;
    _895[3].w = 1.0;
    mat4 _625 = _895 * _417.lUniforms.mpCommonPerMesh.gWorldMat4;
    vec3 _683 = _625[3].xyz;
    vec3 _686 = _625[1].xyz;
    vec3 _690 = normalize(_686);
    vec3 _694 = normalize(cross(_690, (-_417.lUniforms.mpCommonPerMesh.gLightDirectionVec4.xyz).xyz));
    vec3 _712 = normalize(mix(normalize(_417.lUniforms.mpPerFrame.gViewMat4[3].xyz - _683), normalize(cross(_694, _690)), vec3((_417.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x * _417.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x) * _417.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x)));
    mat3 _908 = _954;
    _908[2] = _712;
    mat3 _911 = _908;
    _911[0] = normalize(mix(cross(_690, _712), _694, vec3(_417.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x)));
    mat3 _913 = _911;
    _913[1] = _690;
    vec3 _729 = _913 * _878.xyz;
    vec4 _915 = vec4(_729.x, _729.y, _729.z, _955.w);
    _915.w = 1.0;
    vec4 _735 = _625[0];
    vec4 _740 = _625[2];
    vec3 _791 = ((_915.xyz * vec3(length(_735), length(_686), length(_740))).xyz + _683).xyz + (((_735.xyz * mkTransformMat4R5.x) + (_740.xyz * mkTransformMat4R5.y)) * mkLocalPositionVec4.y);
    vec3 _802 = _791.xyz - _417.lUniforms.mpCommonPerMesh.gPlanetPositionVec4.xyz;
    vec3 _823 = normalize(_417.lUniforms.mpPerFrame.gCameraMat4[3].xyz - _417.lUniforms.mpCommonPerMesh.gLightPositionVec4.xyz);
    vec3 _825 = normalize(_893[2].xyz);
    float _834 = acos(clamp(dot(-_823, _825), -1.0, 1.0)) * 57.295780181884765625;
    float _956;
    if (dot(normalize(cross(_825, _823)), _802 / vec3(length(_802))) >= 0.0)
    {
        _956 = 360.0 - _834;
    }
    else
    {
        _956 = _834;
    }
    float _864 = ((1.0 - mkTexCoordsVec4.x) * _417.lUniforms.mpCustomPerMaterial.gImposterDataVec4.y) + (floor((_956 * 0.00277799996547400951385498046875) * _417.lUniforms.mpCustomPerMaterial.gImposterDataVec4.x) * _417.lUniforms.mpCustomPerMaterial.gImposterDataVec4.y);
    vec4 _941 = vec4(mkTexCoordsVec4.x, mkTexCoordsVec4.y, mkTexCoordsVec4.z, mkTexCoordsVec4.w);
    _941.x = _864;
    vec2 _872 = vec2(_864, 1.0 - mkTexCoordsVec4.y);
    Out.mTexCoordsVec4 = vec4(_872.x, _872.y, _941.z, _941.w);
    vec4 _876 = _417.lUniforms.mpPerFrame.gViewProjectionMat4 * vec4(_791.x, _791.y, _791.z, _915.w);
    float _524 = _876.z;
    Out.mPixelZandW_mfFadeValueForInstance.x = (0.5 - (_524 * 0.5)) - ((_417.lUniforms.mpCustomPerMesh.gBboxDepthAndClips.z + (_417.lUniforms.mpCustomPerMesh.gBboxDepthAndClips.x / (_417.lUniforms.mpCustomPerMesh.gBboxDepthAndClips.w - _417.lUniforms.mpCustomPerMesh.gBboxDepthAndClips.z))) * 0.5);
    Out.mPixelZandW_mfFadeValueForInstance.y = _876.w;
    vec4 _951 = _876;
    _951.z = 0.5 - (max(_524, -1.0) * 0.5);
    Out.mScreenSpacePositionVec4 = _951;
    gl_Position = _951;

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


