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

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

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 _1388;

void main()
{
    if (In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x < 1.0)
    {
        vec3 _992 = floor(In.mWorldPositionVec3_mfSpare.xyz);
        vec3 _994 = fract(In.mWorldPositionVec3_mfSpare.xyz);
        vec4 _1014 = textureLod(gFadeNoiseMap, (_992.xy + (vec2(37.0, 17.0) * _992.z)) + ((_994 * _994) * (vec3(3.0) - (_994 * 2.0))).xy, 0.0);
        float _1015 = _1014.x;
        if (In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x < 0.0)
        {
            if ((1.0 - _1015) > (In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x + 2.0))
            {
                discard;
            }
        }
        else
        {
            if (_1015 > In.mfFadeValueForInstance_mfLodIndex_mfShearMotionLength.x)
            {
                discard;
            }
        }
    }
    vec2 _1056 = ((In.mScreenSpacePositionVec4.xy / vec2(In.mScreenSpacePositionVec4.w)) * 0.5) + vec2(0.5);
    vec2 _1159 = (_1056 * 2.0) - vec2(1.0);
    vec4 _1353 = vec4(_1159.x, _1159.y, _1388.z, _1388.w);
    _1353.z = (((_509.lUniforms.mpPerFrame.gClipPlanesVec4.x * _509.lUniforms.mpPerFrame.gClipPlanesVec4.y) / (texture(gBufferMap, vec2(_1056.x, 1.0 - _1056.y)).x * _509.lUniforms.mpPerFrame.gClipPlanesVec4.y)) - _509.lUniforms.mpPerFrame.gClipPlanesVec4.x) / (_509.lUniforms.mpPerFrame.gClipPlanesVec4.y - _509.lUniforms.mpPerFrame.gClipPlanesVec4.x);
    
    _1353.x-=vk3d_params.stereo.x*(1-vk3d_params.stereo.y * _1353.z * 10);
    
    vec4 _1355 = _1353;
    _1355.w = 1.0;
    vec4 _1169 = _509.lUniforms.mpPerFrame.gInverseViewProjectionMat4 * _1355;
    vec3 _1085 = (_509.lUniforms.mpCommonPerMesh.gInverseModelMat4 * vec4((_1169.xyz / vec3(_1169.w)).xyz + _509.lUniforms.mpPerFrame.gViewPositionVec3, 1.0)).xyz + vec3(0.5);
    float _1088 = 1.0 - _1085.y;
    vec3 _1359 = _1085;
    _1359.y = _1088;
    float _1091 = _1085.x;
    bool _1092 = _1091 < 0.0;
    bool _1099;
    if (!_1092)
    {
        _1099 = _1091 >= 1.0;
    }
    else
    {
        _1099 = _1092;
    }
    bool _1106;
    if (!_1099)
    {
        _1106 = _1088 < 0.0;
    }
    else
    {
        _1106 = _1099;
    }
    bool _1113;
    if (!_1106)
    {
        _1113 = _1088 >= 1.0;
    }
    else
    {
        _1113 = _1106;
    }
    bool _1120;
    if (!_1113)
    {
        _1120 = _1085.z < 0.0;
    }
    else
    {
        _1120 = _1113;
    }
    bool _1127;
    if (!_1120)
    {
        _1127 = _1085.z >= 1.0;
    }
    else
    {
        _1127 = _1120;
    }
    if (_1127)
    {
        discard;
    }
    vec4 _633 = texture(gDiffuseMap, _1359.xy);
    float _639 = _633.w * _509.lUniforms.mpCustomPerMaterial.gMaterialColourVec4.w;
    if (_639 < 9.9999997473787516355514526367188e-05)
    {
        discard;
    }
    vec4 _1373 = _1388;
    _1373.x = 0.0;
    vec4 _1375 = _1373;
    _1375.y = sqrt(_509.lUniforms.mpCustomPerMaterial.gMaterialParamsVec4.x * 0.5);
    vec4 _1377 = _1375;
    _1377.z = clamp(_509.lUniforms.mpCustomPerMaterial.gMaterialParamsVec4.z, 0.0, 1.0);
    vec4 _1379 = _1377;
    _1379.w = 0.0;
    out_color0 = vec4(_633.xyz, _639);
    out_color1 = vec4(0.0);
    out_color2 = vec4(0.0);
    out_color3 = _1379;
}


