#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 CommonPerMeshUniforms
{
    vec4 gPlanetPositionVec4;
    mat4 gWorldMat4;
    mat4 gWorldNormalMat4;
    float gfFadeValue;
    vec4 gLightColourVec4;
    vec4 gLightCustomParamsVec4;
    mat4 gWorldMotionMat4;
    mat4 gInverseModelMat4;
    vec4 gUserDataVec4;
};

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

layout(set = 1, binding = 2) uniform sampler2D gFadeNoiseMap;
layout(set = 1, binding = 3) uniform sampler2D gBufferMap;
layout(set = 1, binding = 0) uniform sampler2D gDiffuseMap;
layout(set = 1, binding = 1) uniform sampler2D gMasksMap;

layout(location = 0) in VertexBlock
{
    vec4 mTexCoordsVec4;
    vec4 mWorldPositionVec3_mfSpare;
    vec3 mTangentSpaceNormalVec3;
    vec4 mScreenSpacePositionVec4;
    flat vec3 mfFadeValueForInstance_mfLodIndex_mfShearMotionLength;
} In;

layout(location = 0) out vec4 out_color0;
layout(location = 1) out vec4 out_color1;
layout(location = 2) out vec4 out_color2;
layout(location = 3) out vec4 out_color3;

vec4 _1687;
vec3 _1698;

void main()
{
    if (In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x < 1.0)
    {
        vec3 _1038 = floor(In.mWorldPositionVec3_mfSpare.xyz);
        vec3 _1040 = fract(In.mWorldPositionVec3_mfSpare.xyz);
        vec4 _1060 = textureLod(gFadeNoiseMap, (_1038.xy + (vec2(37.0, 17.0) * _1038.z)) + ((_1040 * _1040) * (vec3(3.0) - (_1040 * 2.0))).xy, 0.0);
        float _1061 = _1060.x;
        if (In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x < 0.0)
        {
            if ((1.0 - _1061) > (In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x + 2.0))
            {
                discard;
            }
        }
        else
        {
            if (_1061 > In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x)
            {
                discard;
            }
        }
    }
    vec2 _1102 = ((In.mScreenSpacePositionVec4.xy / vec2(In.mScreenSpacePositionVec4.w)) * 0.5) + vec2(0.5);
    vec2 _1205 = (_1102 * 2.0) - vec2(1.0);
    vec4 _1620 = vec4(_1205.x, _1205.y, _1687.z, _1687.w);
    _1620.z = (((_578.lUniforms.mpPerFrame.gClipPlanesVec4.x * _578.lUniforms.mpPerFrame.gClipPlanesVec4.y) / (texture(gBufferMap, vec2(_1102.x, 1.0 - _1102.y)).x * _578.lUniforms.mpPerFrame.gClipPlanesVec4.y)) - _578.lUniforms.mpPerFrame.gClipPlanesVec4.x) / (_578.lUniforms.mpPerFrame.gClipPlanesVec4.y - _578.lUniforms.mpPerFrame.gClipPlanesVec4.x);

// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
_1620.x -= vk3d_params.stereo.x * (1 - vk3d_params.stereo.y * _1620.z * 10); 
    vec4 _1622 = _1620;
    _1622.w = 1.0;
    vec4 _1215 = _578.lUniforms.mpPerFrame.gInverseViewProjectionMat4 * _1622;
    vec3 _1131 = (_578.lUniforms.mpCommonPerMesh.gInverseModelMat4 * vec4((_1215.xyz / vec3(_1215.w)).xyz + _578.lUniforms.mpPerFrame.gViewPositionVec3, 1.0)).xyz + vec3(0.5);
    float _1134 = 1.0 - _1131.y;
    vec3 _1626 = _1131;
    _1626.y = _1134;
    float _1137 = _1131.x;
    bool _1138 = _1137 < 0.0;
    bool _1145;
    if (!_1138)
    {
        _1145 = _1137 >= 1.0;
    }
    else
    {
        _1145 = _1138;
    }
    bool _1152;
    if (!_1145)
    {
        _1152 = _1134 < 0.0;
    }
    else
    {
        _1152 = _1145;
    }
    bool _1159;
    if (!_1152)
    {
        _1159 = _1134 >= 1.0;
    }
    else
    {
        _1159 = _1152;
    }
    bool _1166;
    if (!_1159)
    {
        _1166 = _1131.z < 0.0;
    }
    else
    {
        _1166 = _1159;
    }
    bool _1173;
    if (!_1166)
    {
        _1173 = _1131.z >= 1.0;
    }
    else
    {
        _1173 = _1166;
    }
    if (_1173)
    {
        discard;
    }
    vec4 _701 = texture(gDiffuseMap, _1626.xy);
    vec4 _707 = texture(gMasksMap, _1626.xy);
    float _710 = _707.z;
    int _1258 = int(_578.lUniforms.mpCommonPerMesh.gUserDataVec4.x);
    float _1261 = float(_1258 & 255) * 0.0039215688593685626983642578125;
    float _1267 = float((_1258 >> 8) & 255) * 0.0039215688593685626983642578125;
    int _1269 = int(_578.lUniforms.mpCommonPerMesh.gUserDataVec4.y);
    float _1272 = float(_1269 & 255) * 0.0039215688593685626983642578125;
    float _1278 = float((_1269 >> 8) & 255) * 0.0039215688593685626983642578125;
    int _1280 = int(_578.lUniforms.mpCommonPerMesh.gUserDataVec4.z);
    float _1283 = float(_1280 & 255) * 0.0039215688593685626983642578125;
    float _1289 = float((_1280 >> 8) & 255) * 0.0039215688593685626983642578125;
    float _1313 = (_1267 < 0.0) ? (-1.0) : 1.0;
    float _1316 = _1267 * _1313;
    float _1689;
    if (_1316 > 1.0)
    {
        _1689 = pow(_1316, 2.400000095367431640625);
    }
    else
    {
        float _1690;
        if (_1316 > 0.0)
        {
            _1690 = pow(_1316, 2.2000000476837158203125);
        }
        else
        {
            _1690 = _1316;
        }
        _1689 = _1690;
    }
    vec3 _1648 = _1698;
    _1648.x = _1689 * _1313;
    float _1339 = (_1278 < 0.0) ? (-1.0) : 1.0;
    float _1342 = _1278 * _1339;
    float _1701;
    if (_1342 > 1.0)
    {
        _1701 = pow(_1342, 2.400000095367431640625);
    }
    else
    {
        float _1702;
        if (_1342 > 0.0)
        {
            _1702 = pow(_1342, 2.2000000476837158203125);
        }
        else
        {
            _1702 = _1342;
        }
        _1701 = _1702;
    }
    vec3 _1651 = _1648;
    _1651.y = _1701 * _1339;
    float _1365 = (_1289 < 0.0) ? (-1.0) : 1.0;
    float _1368 = _1289 * _1365;
    float _1705;
    if (_1368 > 1.0)
    {
        _1705 = pow(_1368, 2.400000095367431640625);
    }
    else
    {
        float _1706;
        if (_1368 > 0.0)
        {
            _1706 = pow(_1368, 2.2000000476837158203125);
        }
        else
        {
            _1706 = _1368;
        }
        _1705 = _1706;
    }
    vec3 _1654 = _1651;
    _1654.z = _1705 * _1365;
    float _1409 = (_1261 < 0.0) ? (-1.0) : 1.0;
    float _1412 = _1261 * _1409;
    float _1715;
    if (_1412 > 1.0)
    {
        _1715 = pow(_1412, 2.400000095367431640625);
    }
    else
    {
        float _1716;
        if (_1412 > 0.0)
        {
            _1716 = pow(_1412, 2.2000000476837158203125);
        }
        else
        {
            _1716 = _1412;
        }
        _1715 = _1716;
    }
    vec3 _1657 = _1698;
    _1657.x = _1715 * _1409;
    float _1435 = (_1272 < 0.0) ? (-1.0) : 1.0;
    float _1438 = _1272 * _1435;
    float _1732;
    if (_1438 > 1.0)
    {
        _1732 = pow(_1438, 2.400000095367431640625);
    }
    else
    {
        float _1733;
        if (_1438 > 0.0)
        {
            _1733 = pow(_1438, 2.2000000476837158203125);
        }
        else
        {
            _1733 = _1438;
        }
        _1732 = _1733;
    }
    vec3 _1660 = _1657;
    _1660.y = _1732 * _1435;
    float _1461 = (_1283 < 0.0) ? (-1.0) : 1.0;
    float _1464 = _1283 * _1461;
    float _1736;
    if (_1464 > 1.0)
    {
        _1736 = pow(_1464, 2.400000095367431640625);
    }
    else
    {
        float _1737;
        if (_1464 > 0.0)
        {
            _1737 = pow(_1464, 2.2000000476837158203125);
        }
        else
        {
            _1737 = _1464;
        }
        _1736 = _1737;
    }
    vec3 _1663 = _1660;
    _1663.z = _1736 * _1461;
    vec4 _1758;
    if (_710 > 0.25)
    {
        vec4 _1759;
        if (_710 < 0.75)
        {
            vec3 _763 = _701.xyz * _1663;
            _1759 = vec4(_763.x, _763.y, _763.z, _701.w);
        }
        else
        {
            vec3 _770 = _701.xyz * _1654;
            _1759 = vec4(_770.x, _770.y, _770.z, _701.w);
        }
        _1758 = _1759;
    }
    else
    {
        _1758 = _701;
    }
    float _777 = _1758.w * _578.lUniforms.mpCustomPerMaterial.gMaterialColourVec4.w;
    vec4 _1666 = _1758;
    _1666.w = _777;
    if (_777 < 9.9999997473787516355514526367188e-05)
    {
        discard;
    }
    vec4 _1671 = _1687;
    _1671.x = 0.0;
    vec4 _1673 = _1671;
    _1673.y = sqrt(_578.lUniforms.mpCustomPerMaterial.gMaterialParamsVec4.x * 0.5);
    vec4 _1675 = _1673;
    _1675.z = clamp(_578.lUniforms.mpCustomPerMaterial.gMaterialParamsVec4.z, 0.0, 1.0);
    vec4 _1677 = _1675;
    _1677.w = 0.0;
    out_color0 = _1666;
    out_color1 = vec4(0.0);
    out_color2 = vec4(0.0);
    out_color3 = _1677;
}


