#version 450
// decals
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;
};

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

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;

//Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
layout(set = 0, binding = 45, std140) uniform Vk3DParams
{
    vec4 stereo;
    vec4 custom_params;
} vk3d_params;

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 _1695;
vec3 _1706;

void main()
{
    if (In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x < 1.0)
    {
        vec3 _1042 = floor(In.mWorldPositionVec3_mfSpare.xyz);
        vec3 _1044 = fract(In.mWorldPositionVec3_mfSpare.xyz);
        vec4 _1064 = textureLod(gFadeNoiseMap, (_1042.xy + (vec2(37.0, 17.0) * _1042.z)) + ((_1044 * _1044) * (vec3(3.0) - (_1044 * 2.0))).xy, 0.0);
        float _1065 = _1064.x;
        if (In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x < 0.0)
        {
            if ((1.0 - _1065) > (In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x + 2.0))
            {
                discard;
            }
        }
        else
        {
            if (_1065 > In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x)
            {
                discard;
            }
        }
    }
    vec2 _1106 = ((In.mScreenSpacePositionVec4.xy / vec2(In.mScreenSpacePositionVec4.w)) * 0.5) + vec2(0.5);
    vec2 _1209 = (_1106 * 2.0) - vec2(1.0);
    vec4 _1628 = vec4(_1209.x, _1209.y, _1695.z, _1695.w);
    _1628.z = (((_582.lUniforms.mpPerFrame.gClipPlanesVec4.x * _582.lUniforms.mpPerFrame.gClipPlanesVec4.y) / (texture(gBufferMap, vec2(_1106.x, 1.0 - _1106.y)).x * _582.lUniforms.mpPerFrame.gClipPlanesVec4.y)) - _582.lUniforms.mpPerFrame.gClipPlanesVec4.x) / (_582.lUniforms.mpPerFrame.gClipPlanesVec4.y - _582.lUniforms.mpPerFrame.gClipPlanesVec4.x);
    
    _1628.x -= vk3d_params.stereo.x * (1 - vk3d_params.stereo.y * _1628.z * 10);
    
    vec4 _1630 = _1628;
    _1630.w = 1.0;
    vec4 _1219 = _582.lUniforms.mpPerFrame.gInverseViewProjectionMat4 * _1630;
    vec3 _1135 = (_582.lUniforms.mpCommonPerMesh.gInverseModelMat4 * vec4((_1219.xyz / vec3(_1219.w)).xyz + _582.lUniforms.mpPerFrame.gViewPositionVec3, 1.0)).xyz + vec3(0.5);
    float _1138 = 1.0 - _1135.y;
    vec3 _1634 = _1135;
    _1634.y = _1138;
    float _1141 = _1135.x;
    bool _1142 = _1141 < 0.0;
    bool _1149;
    if (!_1142)
    {
        _1149 = _1141 >= 1.0;
    }
    else
    {
        _1149 = _1142;
    }
    bool _1156;
    if (!_1149)
    {
        _1156 = _1138 < 0.0;
    }
    else
    {
        _1156 = _1149;
    }
    bool _1163;
    if (!_1156)
    {
        _1163 = _1138 >= 1.0;
    }
    else
    {
        _1163 = _1156;
    }
    bool _1170;
    if (!_1163)
    {
        _1170 = _1135.z < 0.0;
    }
    else
    {
        _1170 = _1163;
    }
    bool _1177;
    if (!_1170)
    {
        _1177 = _1135.z >= 1.0;
    }
    else
    {
        _1177 = _1170;
    }
    if (_1177)
    {
        discard;
    }
    vec4 _705 = texture(gDiffuseMap, _1634.xy);
    vec4 _711 = texture(gMasksMap, _1634.xy);
    float _714 = _711.z;
    int _1262 = int(_582.lUniforms.mpCommonPerMesh.gUserDataVec4.x);
    float _1265 = float(_1262 & 255) * 0.0039215688593685626983642578125;
    float _1271 = float((_1262 >> 8) & 255) * 0.0039215688593685626983642578125;
    int _1273 = int(_582.lUniforms.mpCommonPerMesh.gUserDataVec4.y);
    float _1276 = float(_1273 & 255) * 0.0039215688593685626983642578125;
    float _1282 = float((_1273 >> 8) & 255) * 0.0039215688593685626983642578125;
    int _1284 = int(_582.lUniforms.mpCommonPerMesh.gUserDataVec4.z);
    float _1287 = float(_1284 & 255) * 0.0039215688593685626983642578125;
    float _1293 = float((_1284 >> 8) & 255) * 0.0039215688593685626983642578125;
    float _1317 = (_1271 < 0.0) ? (-1.0) : 1.0;
    float _1320 = _1271 * _1317;
    float _1697;
    if (_1320 > 1.0)
    {
        _1697 = pow(_1320, 2.400000095367431640625);
    }
    else
    {
        float _1698;
        if (_1320 > 0.0)
        {
            _1698 = pow(_1320, 2.2000000476837158203125);
        }
        else
        {
            _1698 = _1320;
        }
        _1697 = _1698;
    }
    vec3 _1656 = _1706;
    _1656.x = _1697 * _1317;
    float _1343 = (_1282 < 0.0) ? (-1.0) : 1.0;
    float _1346 = _1282 * _1343;
    float _1709;
    if (_1346 > 1.0)
    {
        _1709 = pow(_1346, 2.400000095367431640625);
    }
    else
    {
        float _1710;
        if (_1346 > 0.0)
        {
            _1710 = pow(_1346, 2.2000000476837158203125);
        }
        else
        {
            _1710 = _1346;
        }
        _1709 = _1710;
    }
    vec3 _1659 = _1656;
    _1659.y = _1709 * _1343;
    float _1369 = (_1293 < 0.0) ? (-1.0) : 1.0;
    float _1372 = _1293 * _1369;
    float _1713;
    if (_1372 > 1.0)
    {
        _1713 = pow(_1372, 2.400000095367431640625);
    }
    else
    {
        float _1714;
        if (_1372 > 0.0)
        {
            _1714 = pow(_1372, 2.2000000476837158203125);
        }
        else
        {
            _1714 = _1372;
        }
        _1713 = _1714;
    }
    vec3 _1662 = _1659;
    _1662.z = _1713 * _1369;
    float _1413 = (_1265 < 0.0) ? (-1.0) : 1.0;
    float _1416 = _1265 * _1413;
    float _1723;
    if (_1416 > 1.0)
    {
        _1723 = pow(_1416, 2.400000095367431640625);
    }
    else
    {
        float _1724;
        if (_1416 > 0.0)
        {
            _1724 = pow(_1416, 2.2000000476837158203125);
        }
        else
        {
            _1724 = _1416;
        }
        _1723 = _1724;
    }
    vec3 _1665 = _1706;
    _1665.x = _1723 * _1413;
    float _1439 = (_1276 < 0.0) ? (-1.0) : 1.0;
    float _1442 = _1276 * _1439;
    float _1740;
    if (_1442 > 1.0)
    {
        _1740 = pow(_1442, 2.400000095367431640625);
    }
    else
    {
        float _1741;
        if (_1442 > 0.0)
        {
            _1741 = pow(_1442, 2.2000000476837158203125);
        }
        else
        {
            _1741 = _1442;
        }
        _1740 = _1741;
    }
    vec3 _1668 = _1665;
    _1668.y = _1740 * _1439;
    float _1465 = (_1287 < 0.0) ? (-1.0) : 1.0;
    float _1468 = _1287 * _1465;
    float _1744;
    if (_1468 > 1.0)
    {
        _1744 = pow(_1468, 2.400000095367431640625);
    }
    else
    {
        float _1745;
        if (_1468 > 0.0)
        {
            _1745 = pow(_1468, 2.2000000476837158203125);
        }
        else
        {
            _1745 = _1468;
        }
        _1744 = _1745;
    }
    vec3 _1671 = _1668;
    _1671.z = _1744 * _1465;
    vec4 _1766;
    if (_714 > 0.25)
    {
        vec4 _1767;
        if (_714 < 0.75)
        {
            vec3 _767 = _705.xyz * _1671;
            _1767 = vec4(_767.x, _767.y, _767.z, _705.w);
        }
        else
        {
            vec3 _774 = _705.xyz * _1662;
            _1767 = vec4(_774.x, _774.y, _774.z, _705.w);
        }
        _1766 = _1767;
    }
    else
    {
        _1766 = _705;
    }
    float _781 = _1766.w * _582.lUniforms.mpCustomPerMaterial.gMaterialColourVec4.w;
    vec4 _1674 = _1766;
    _1674.w = _781;
    if (_781 < 9.9999997473787516355514526367188e-05)
    {
        discard;
    }
    vec4 _1679 = _1695;
    _1679.x = 0.0;
    vec4 _1681 = _1679;
    _1681.y = sqrt(_582.lUniforms.mpCustomPerMaterial.gMaterialParamsVec4.x * 0.5);
    vec4 _1683 = _1681;
    _1683.z = clamp(_582.lUniforms.mpCustomPerMaterial.gMaterialParamsVec4.z, 0.0, 1.0);
    vec4 _1685 = _1683;
    _1685.w = 0.0;
    out_color0 = _1674;
    out_color1 = vec4(0.0);
    out_color2 = vec4(0.0);
    out_color3 = _1685;
}


