
// Vk3DVision (http://3dsurroundgaming.com/) - Original Shader 
#version 450

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 CustomPerMaterialUniforms
{
    vec4 gSkyColourVec4;
    vec4 gSkyUpperParamsVec4;
    vec4 gSkyUpperColourVec4;
    vec4 gSkySolarColourVec4;
    vec4 gSkyGradientSpeedVec4;
    vec4 gHorizonColourVec4;
    vec4 gSunColourVec4;
    vec4 gSpaceSunColourVec4;
    vec4 gScatteringParamsVec4;
    vec4 gSunPositionVec4;
    vec4 gFogColourVec4;
    vec4 gFogParamsVec4;
    vec4 gHeightFogParamsVec4;
    vec4 gHeightFogColourVec4;
    vec4 gSpaceHorizonColourVec4;
    vec4 gFogFadeHeightsVec4;
    vec4 gSpaceSkyColourVec4;
    vec4 gSpaceScatteringParamsVec4;
    vec4 gWaterFogColourNearVec4;
    vec4 gWaterFogColourFarVec4;
    vec4 gWaterFogVec4;
    vec4 gSpaceSkyColour1Vec4;
    vec4 gSpaceSkyColour2Vec4;
    vec4 gSpaceSkyColour3Vec4;
    vec4 gMaterialParamsVec4;
    vec4 gaPlanetPositionsVec4[6];
    vec4 gRingParamsVec4;
    vec4 gRingParams2Vec4;
    vec4 gRingColour1Vec4;
    vec4 gRingColour2Vec4;
    vec4 gRainbowParamsVec4;
    vec4 gLightTopColourVec4;
    vec4 gPlanetCloudParamsVec4;
    vec4 gPlanetCloudParams2Vec4;
    vec4 gTileBlendScalesVec4;
    vec4 gTerrainDistancesVec4;
};

struct CommonPerMeshUniforms
{
    vec4 gPlanetPositionVec4;
    mat4 gWorldMat4;
    mat4 gWorldNormalMat4;
    float fdFadeValueDummy;
    vec4 gLightPositionVec4;
    vec4 gLightDirectionVec4;
    vec4 gLightOriginVec4;
    vec4 gScanParamsPosVec4;
    vec4 gScanParamsCfg1Vec4;
    vec4 gScanParamsCfg2Vec4;
    vec4 gScanParamsCfg3Vec4;
    vec4 gScanColourVec4;
    mat4 gaShadowMat4[3];
    vec4 gLightColourVec4;
    vec4 gLightCustomParamsVec4;
    mat4 gWorldMotionMat4;
    mat4 gInverseModelMat4Dummy;
};

struct CustomPerMeshUniforms
{
    vec4 gDummyVec4;
};

struct UniformBuffer
{
    PerFrameUniforms mpPerFrame;
    CustomPerMaterialUniforms mpCustomPerMaterial;
    CommonPerMeshUniforms mpCommonPerMesh;
    CustomPerMeshUniforms mpCustomPerMesh;
};

layout(set = 0, binding = 0, std140) uniform lUniforms_BLK
{
    UniformBuffer lUniforms;
} _121;

layout(location = 0) in vec4 mkLocalPositionVec4;
layout(location = 0) out VertexBlock
{
    vec4 mWorldPositionVec4;
    vec4 mTexCoordsVec4;
    vec4 mWorldNormalVec3_mfDistanceFromPlanet;
} Out;

layout(location = 1) in vec4 mkTexCoordsVec4;
layout(location = 7) in vec4 mkLocalNormalVec4;

void main()
{
    vec4 _270 = _121.lUniforms.mpCommonPerMesh.gWorldMat4 * vec4(mkLocalPositionVec4.xyz, 1.0);
    Out.mWorldPositionVec4 = _270;
    vec3 _152 = normalize(_270.xyz - _121.lUniforms.mpCommonPerMesh.gPlanetPositionVec4.xyz);
    Out.mWorldNormalVec3_mfDistanceFromPlanet = vec4(_152.x, _152.y, _152.z, Out.mWorldNormalVec3_mfDistanceFromPlanet.w);
    Out.mWorldNormalVec3_mfDistanceFromPlanet.w = length(_121.lUniforms.mpPerFrame.gViewPositionVec3 - _121.lUniforms.mpCommonPerMesh.gPlanetPositionVec4.xyz) - _121.lUniforms.mpCommonPerMesh.gPlanetPositionVec4.w;
    Out.mTexCoordsVec4 = mkTexCoordsVec4;
    vec4 _280 = _121.lUniforms.mpPerFrame.gViewMat4 * _270;
    vec4 _330 = _280;
    _330.z = -_280.z;
    float _287 = length(_330.xyz);
    vec3 _292 = _330.xyz / vec3(_287);
    float _297 = _292.z + 1.0;
    vec4 _337 = vec4(_292.x, _292.y, _292.z, _330.w);
    _337.x = _292.x / _297;
    vec4 _341 = _337;
    _341.y = _292.y / _297;
    vec4 _349 = _341;
    _349.z = 1.0 - ((_287 - _121.lUniforms.mpPerFrame.gClipPlanesVec4.x) / (_121.lUniforms.mpPerFrame.gClipPlanesVec4.y - _121.lUniforms.mpPerFrame.gClipPlanesVec4.x));
    vec4 _351 = _349;
    _351.w = 1.0;
    gl_Position = _351;
}

