#version 450
 
invariant gl_Position;

struct PerFrameUniforms
{
    mat4 gViewMat4;
    mat4 gViewProjectionMat4;
    mat4 gCameraMat4;
    mat4 gCameraNoHeadTrackingMat4;
    mat4 gPrevViewProjectionMat4;
    mat4 gThisToPrevViewProjectionMat4;
    mat4 gInverseViewMat4;
    mat4 gInverseProjectionMat4;
    mat4 gInverseProjectionSCMat4;
    mat4 gInverseViewProjectionMat4;
    vec4 gInverseWorldUpMatVec4[3];
    vec3 gViewPositionVec3;
    float gfTime;
    vec3 gVREyeInfoVec3;
    float gfPrevTime;
    vec4 gClipPlanesVec4;
    vec4 gMBlurSettingsVec4;
    vec3 gDeJitterVec3;
    int giFrameIndex;
    vec4 gTaaSettingsVec4;
    vec4 gTessSettingsVec4;
    vec4 gShellsSettingsVec4;
    vec4 gFrameBufferSizeVec4;
    vec4 gFoVValuesVec4;
    vec4 gShadowSizeVec4;
    vec3 gShadowProjScaleVec3;
    int giDisableAmbientAllowed;
    vec4 gShadowFadeParamVec4;
};

struct CommonPerMeshUniforms
{
    vec4 gPlanetPositionVec4;
    mat4 gWorldMat4;
    mat4 gWorldNormalMat4;
    float fdFadeValueDummy;
    vec4 gLightPositionVec4;
    vec4 gLightDirectionVec4;
    vec4 gLightOriginVec4;
};

struct CustomPerMaterialUniforms
{
    vec4 gImposterDataVec4;
    vec4 gTileBlendScalesVec4;
    vec4 gHueOverlayParamsVec4;
    vec4 gSaturationOverlayParamsVec4;
    vec4 gValueOverlayParamsVec4;
    vec4 gTerrainColour1Vec4;
    vec4 gTerrainColour2Vec4;
    vec4 gMaterialParamsVec4;
    vec4 gMaterialColourVec4;
    vec4 gMaterialSFXVec4;
    vec4 gMaterialSFXColVec4;
    vec4 gSunPositionVec4;
};

struct CustomPerMeshUniforms
{
    vec4 gUVScrollStepVec4;
    vec4 gCustomParams01Vec4;
    vec4 gCustomParams02Vec4;
    vec4 gObjectColourVec4;
};

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

layout(location = 0) in vec4 mkLocalPositionVec4;
layout(location = 7) in vec4 mkLocalNormalVec4;
layout(location = 3) in vec4 mkTangentVec4;
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 = 0) out VertexBlock
{
    vec4 mTexCoordsVec4;
    vec4 mWorldPositionVec3_mfSpare;
    flat vec3 mfFadeValueForInstance_mfLodIndex_mfShearMotionLength;
} Out;

layout(location = 14) in vec4 mkTransformMat4R5;
layout(location = 13) in vec4 mkTransformMat4R4;
layout(location = 1) in vec4 mkTexCoordsVec4;

mat4 _1075;
vec4 _1076;
mat3 _1077;

void main()
{
    mat4 _979 = _1075;
    _979[0] = mkTransformMat4R0;
    mat4 _981 = _979;
    _981[1] = mkTransformMat4R1;
    mat4 _983 = _981;
    _983[2] = mkTransformMat4R2;
    mat4 _985 = _983;
    _985[3] = mkTransformMat4R3;
    Out.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x = mkTransformMat4R0.w;
    mat4 _988 = _985;
    _988[0].w = 0.0;
    mat4 _990 = _988;
    _990[1].w = 0.0;
    mat4 _992 = _990;
    _992[2].w = 0.0;
    mat4 _994 = _992;
    _994[3].w = 1.0;
    Out.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.y = mkTransformMat4R4.w;
    float _762 = mkTexCoordsVec4.x - 0.5;
    float _765 = 0.5 - mkTexCoordsVec4.y;
    float _773 = _762 * length(_468.lUniforms.mpCommonPerMesh.gWorldMat4[0].xyz);
    vec2 _1001 = vec2(_762, _765);
    _1001.x = _773;
    float _781 = _765 * length(_468.lUniforms.mpCommonPerMesh.gWorldMat4[1].xyz);
    vec2 _1005 = _1001;
    _1005.y = _781;
    vec4 _785 = _468.lUniforms.mpCommonPerMesh.gWorldMat4 * mkLocalPositionVec4;
    vec4 _806 = _994 * vec4(_785.xy - _1005, _785.z, 1.0);
    mat4 _1010 = _994;
    _1010[3] = _806;
    vec3 _873 = vec3(_468.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x);
    vec3 _876 = normalize(mix((_990[1].xyz - (_988[0].xyz * mkTransformMat4R5.x)) - (_992[2].xyz * mkTransformMat4R5.y), _468.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4[1].xyz, _873));
    vec3 _889 = normalize(mix(normalize(_468.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4[3].xyz - _806.xyz), _468.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4[2].xyz, vec3((_468.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x * _468.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x) * _468.lUniforms.mpCustomPerMesh.gCustomParams01Vec4.x)));
    mat3 _1027 = _1077;
    _1027[2] = _889;
    mat3 _1030 = _1027;
    _1030[0] = normalize(mix(cross(_876, _889), _468.lUniforms.mpPerFrame.gCameraNoHeadTrackingMat4[0].xyz, _873));
    mat3 _1032 = _1030;
    _1032[1] = _876;
    vec3 _906 = _1032 * vec4(_773, _781, 0.0, 1.0).xyz;
    vec4 _1034 = vec4(_906.x, _906.y, _906.z, _1076.w);
    _1034.w = 1.0;
    mat4 _973 = inverse(_1010);
    mat4 _1039 = _973;
    _1039[0] = normalize(_973[0]);
    mat4 _1042 = _1039;
    _1042[1] = normalize(_973[1]);
    mat4 _1045 = _1042;
    _1045[2] = normalize(_973[2]);
    mat4 _1047 = _1045;
    _1047[3] = vec4(0.0, 0.0, 0.0, 1.0);
    vec4 _949 = _1047 * _1034;
    float _723 = _949.x;
    float _724 = _949.y;
    float _725 = _949.z;
    vec4 _726 = vec4(_723, _724, _725, 1.0);
    vec4 _727 = _1010 * _726;
    Out.mWorldPositionVec3_mfSpare = vec4(0.0);
    Out.mWorldPositionVec3_mfSpare = vec4(_727.x, _727.y, _727.z, Out.mWorldPositionVec3_mfSpare.w);
    Out.mWorldPositionVec3_mfSpare = vec4(_727.x, _727.y, _727.z, Out.mWorldPositionVec3_mfSpare.w);
    vec3 _532 = normalize(_994[3].xyz - _468.lUniforms.mpCommonPerMesh.gPlanetPositionVec4.xyz) * _468.lUniforms.mpCommonPerMesh.gPlanetPositionVec4.w;
    vec2 _549 = (_532.xz + (mkLocalPositionVec4.xz - vec2(_762, 0.0))).xy * vec2(0.125);
    float _562 = ((_549.x + _532.y) + _549.y) * 10.0;
    vec4 _1066 = vec4(mkTexCoordsVec4.x, mkTexCoordsVec4.y, mkTexCoordsVec4.x, mkTexCoordsVec4.y);
    _1066.x = (mkTexCoordsVec4.x / _468.lUniforms.mpCustomPerMesh.gUVScrollStepVec4.z) + (floor(mod(_562, _468.lUniforms.mpCustomPerMesh.gUVScrollStepVec4.z)) / _468.lUniforms.mpCustomPerMesh.gUVScrollStepVec4.z);
    vec4 _1069 = _1066;
    _1069.y = (mkTexCoordsVec4.y / _468.lUniforms.mpCustomPerMesh.gUVScrollStepVec4.w) + (floor(mod(_562, _468.lUniforms.mpCustomPerMesh.gUVScrollStepVec4.w)) / _468.lUniforms.mpCustomPerMesh.gUVScrollStepVec4.w);
    Out.mTexCoordsVec4 = _1069;
    vec4 _977 = _468.lUniforms.mpPerFrame.gViewProjectionMat4 * _727;

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

    Out.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.z = 0.0;
    gl_Position = _977;

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


