
// 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 CustomPerMeshUniforms
{
    vec4 gDoFParamsVec4;
    vec4 gHDRParamsVec4;
    vec4 gHBAOParamsVec4;
    vec4 gThresholdParamsVec4;
    vec4 gBlurParamsVec4;
    vec4 gColourLUTParamsVec4;
    vec4 gColourLUTStrengthsVec4;
    vec4 gSharpenStrength;
    vec4 gTextureSizeMipLevelVec4;
    vec4 gSkyUpperParamsVec4;
    vec4 gLightShaftColourBottomVec4;
    vec4 gLightShaftColourTopVec4;
    vec4 gHDRParams2Vec4;
};

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 UniformBuffer
{
    PerFrameUniforms mpPerFrame;
    CustomPerMeshUniforms mpCustomPerMesh;
    CommonPerMeshUniforms mpCommonPerMesh;
};

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

layout(set = 1, binding = 0) uniform sampler2D gBufferMap;
layout(set = 1, binding = 1) uniform sampler2D gBuffer1Map;
layout(set = 1, binding = 2) uniform sampler2D gBuffer3Map;

layout(location = 0) in VertexBlock
{
    vec2 mTexCoordsVec2;
} In;

layout(location = 0) out vec4 out_color0;

vec4 _1017;

void main()
{
    vec2 _1020;
    bool _1021;
    for (;;)
    {
        vec4 _847 = texture(gBufferMap, In.mTexCoordsVec2);
        vec4 _851 = texture(gBuffer1Map, In.mTexCoordsVec2);
        if (_847.x < 1.0)
        {
            _1021 = false;
            _1020 = _847.xy * 0.5;
            break;
        }
        vec2 _897 = (vec2(In.mTexCoordsVec2.x, 1.0 - In.mTexCoordsVec2.y) * 2.0) - vec2(1.0);
        vec4 _996 = vec4(_897.x, _897.y, _1017.z, _1017.w);
        _996.z = (((_387.lUniforms.mpPerFrame.gClipPlanesVec4.x * _387.lUniforms.mpPerFrame.gClipPlanesVec4.y) / (_851.x * _387.lUniforms.mpPerFrame.gClipPlanesVec4.y)) - _387.lUniforms.mpPerFrame.gClipPlanesVec4.x) / (_387.lUniforms.mpPerFrame.gClipPlanesVec4.y - _387.lUniforms.mpPerFrame.gClipPlanesVec4.x);
        vec4 _998 = _996;
        _998.w = 1.0;
        vec4 _907 = _387.lUniforms.mpPerFrame.gInverseViewProjectionMat4 * _998;
        vec3 _919 = (_907.xyz / vec3(_907.w)).xyz + _387.lUniforms.mpPerFrame.gViewPositionVec3;
        vec4 _1001 = vec4(_919.x, _919.y, _919.z, _1017.w);
        _1001.w = 1.0;
        vec4 _802 = _387.lUniforms.mpPerFrame.gPrevViewProjectionMat4 * _1001;
        vec4 _1004 = _802;
        _1004.y = -_802.y;
        vec2 _823 = (((_1004.xyz / vec3(_802.w)).xy * 0.5) + vec2(0.5)) - In.mTexCoordsVec2;
        vec2 _1008 = _823;
        _1008.y = -_823.y;
        vec2 _955 = _1008 * 16.0;
        vec2 _986 = vec2(_955.x, -_955.y);
        float _958 = length(_986);
        vec2 _963 = _986 / vec2(max(1.0, _958));
        vec2 _1019;
        if (_958 > 0.0)
        {
            _1019 = _963 / vec2(sqrt(length(_963)));
        }
        else
        {
            _1019 = _963;
        }
        _1021 = _847.y > 0.75;
        _1020 = min(vec2(0.996078431606292724609375), (_1019 * 0.4980392158031463623046875) + vec2(0.5)) * 0.5;
        break;
    }
    bool _1022;
    if (!_1021)
    {
        _1022 = (int(texture(gBuffer3Map, In.mTexCoordsVec2).x * 255.0) & 128) != 0;
    }
    else
    {
        _1022 = _1021;
    }
    out_color0 = vec4(_1020 * 2.0, (_1022 ? 0.5 : 0.0) + 0.25, 1.0);
}

