
// Vk3DVision (http://3dsurroundgaming.com/) - Original Shader
#version 450
#extension GL_EXT_nonuniform_qualifier : require
#extension GL_ARB_shader_draw_parameters : require
#extension GL_ARB_shader_ballot : require

out float gl_ClipDistance[1];

invariant gl_Position;

struct S_MATRICES
{
    mat4 _mModelViewProj;
    mat4 _mModelViewProjPrevious;
    mat4 _mModelView;
    mat4 _mInvModelView;
};

struct unaligned_float3
{
    float x;
    float y;
    float z;
};

struct S_INDICES
{
    uint _uiObjectIndex;
    uint _uiMaterialIndex;
    uint _uiMaterialInstanceIndex;
    uint _uiLastFrameMaterialIndex;
    uint _uiLastFrameMaterialInstanceIndex;
    uint _uiPositionsBufferIndex;
    uint _uiPrevPositionsBufferIndex;
    uint _uiNormalsBufferIndex;
    uint _uiPositionOffset;
    uint _uiPrevPositionOffset;
    uint _uiNormalOffset;
    uint _uiMatricesIndex;
};

struct S_MAIN_DEFAULT
{
    S_INDICES _Indices;
};

struct S_MAIN_DEFAULT_ARRAY
{
    S_MAIN_DEFAULT _aMain[32];
};

struct S_MATERIAL
{
    vec4 _vErrorColor;
    float _fDepthBias;
    float _fDummy0;
    float _fDummy1;
    float _fDummy2;
    float c0;
    float c1;
    float c2;
    float c3;
    float c4;
    float c5;
    float c6;
    float c7;
    float c8;
    float c9;
    float c10;
    float c11;
    uint s0;
    uint s1;
    uint s2;
    uint s3;
};

struct S_PASS_MATRICES
{
    mat4 _mViewJitteredProj;
    mat4 _mViewProj;
    mat4 _mView;
    mat4 _mInvView;
    mat4 _mJitteredProj;
};

struct S_EYE_DATA
{
    S_PASS_MATRICES _mCurrentFrameMatrices[2];
    S_PASS_MATRICES _mPreviousFrameMatrices[2];
    mat4 _mJitteredProjection[2];
    mat4 _mNoJitterProjection[2];
    mat4 _mInvViewJitteredProj[2];
    vec4 _vWorldSpaceCameraVector[2];
    vec4 _vWorldSpaceCameraPosition[2];
    vec4 _vFrameBufferScale;
    vec4 _vFrameBufferViewportSize;
    vec4 _vFrameBufferOneOnViewportSize;
    vec4 _vViewportSize;
    vec4 _vFogSubCrop;
    uint _uiAlignment0;
    uint _uiAlignment1;
    float _vCameraJitterDeltaX;
    float _vCameraJitterDeltaY;
    vec4 _vfRcpFVolumetricFogDepthTileSize;
};

struct S_CASCADED_SHADOW
{
    mat4 _mCascadeMatrix[2][8];
    mat4 _mViewSpaceToStaticShadowMapSpace[2];
    vec4 _vfCascadeShadowAttenuation;
    vec4 _vfShadowCascadeTextureTexelSize;
    vec4 _vfStaticShadowBlurRadius;
    vec4 _vfCascadeLinearZProjFactors[8];
    vec4 _vfCascadeParams[8];
};

struct S_CLUSTER_LIGHT_SETUP
{
    S_CASCADED_SHADOW _CascadedShadow;
    vec4 _vfSkinUVParamsAndNormalBias;
    vec4 _vfShadowTextureTexelSize;
    vec4 _vfDummy_SkinFresnelF0AndF90;
    uint _uiCascadedUsed;
    float _fSSSWidth;
    float _fOffsetBias;
    float _fDummy;
};

struct S_CLUSTER_INFO
{
    mat4 _mViewToClusterView[2];
    mat4 _mClusterProjMatrix;
    mat4 _mClusterInvProjMatrix;
    vec4 _vfLeftEyeToCombinedEyeVsDeltaXZ;
    uint _uiFinestMipWidth;
    uint _uiFinestMipHeight;
    uint _uiFinestMipDepth;
    uint _uiFinestMipWidthHeight;
    float _fZSliceGeomFactor;
    float _fRcpLogZSliceGeomFactor;
    float _fDummy0;
    float _fDummy1;
    float _fNearP;
    float _fInvNearP;
    float _fFarP;
    float _fClusterCoincidentWithCamera;
};

struct S_PASS
{
    S_EYE_DATA _EyeData;
    vec4 _avFrustumCorners[4];
    vec4 _vTime;
    vec4 _cFogColor;
    vec4 _vFogSetup;
    vec4 _cSunColor;
    vec4 _vSunDir;
    vec4 _vProjectionSetup;
    vec4 _vProjectionCoeff;
    vec4 _vOutputColor;
    vec4 _vfVsClippingPlane[2];
    S_CLUSTER_LIGHT_SETUP _LightSetup;
    S_CLUSTER_INFO _ClusterInfo;
    float _fIBLIntensity;
    float _fGIIntensity;
    float _fAmbiantOcclusionDirectIntensity;
    float _fAmbiantOcclusionIndirectIntensity;
    float _fNormalSign;
    int _iFogType;
    float _fSelfOcclusionDebugRatio;
    float _fEmissive;
    int _iEnableSkinSSSSS;
    int _iUseHairOpaquePrepass;
    float _fLocalSceneExposure;
    uint _uiDebugMode;
    uint _sFlags;
    float _fTAADropsSharpness;
    uint _uNeoScaleX;
    uint _uNeoScaleY;
    uint _uiDirectOverdrawFilter;
    float _fCoderTest0;
    float _fCoderTest1;
    float _fCoderTest2;
    uint _uiBakeOutput;
    float _fDefaultAmbientIntensity;
    float _fDefaultLightingIntensity;
    uint _uiOutputColor;
    float _fAARotation;
    float _fClampDirectSpecular;
    float _fNearPlane;
    float _fFarPlane;
    float _fNDFFilteringScreenSpaceVariance;
    float _fNDFFilteringThreshold;
    float _fNDFFilteringScreenSpaceVariance_EyeShader;
    float _fNDFFilteringThreshold_EyeShader;
    float _fSurfaceGradientTextureFiltering;
    float _fZero;
    uint _uDepthClamp;
    uint _uiLightDebugMode;
    vec4 _vfFragCoordToDepthTexFactor;
    vec4 _vfFragCoordToDepthTexFactor_HalfRes;
    uint _uHdr;
    uint _uiDrawMayaSwatch;
    float _fEyeRoughnessBias;
    float _fDummy1;
};

layout(set = 1, binding = 24, std430) readonly buffer stc_g_rbMatrices_Layout
{
    S_MATRICES g_rbMatrices[];
} _176;

layout(set = 1, binding = 39, std430) readonly buffer g_rbVertices_Layout
{
    unaligned_float3 g_rbVertices[];
} g_rbVertices_Buffer[];

layout(set = 1, binding = 40, std430) readonly buffer g_rbNormals_Layout
{
    int g_rbNormals[];
} g_rbNormals_Buffer[];

layout(set = 0, binding = 52, std140) uniform dyn_CONSTANT_BUFFER_BLOCK_CB_S_MAIN_ARRAY_BINDING
{
    S_MAIN_DEFAULT_ARRAY g_cbMainArray;
} _858;

layout(set = 1, binding = 34, std430) readonly buffer g_rbMaterials_Layout
{
    S_MATERIAL g_rbMaterials[];
} g_rbMaterials_Buffer[];

layout(set = 2, binding = 53, std140) uniform dyn_CONSTANT_BUFFER_BLOCK_CB_S_PASS_BINDING
{
    S_PASS g_cbPass;
} _1090;

layout(set = 1, binding = 12) uniform sampler2D g_rb2DTextures[];

layout(location = 3) in vec4 in_color;
layout(location = 8) in vec2 in_uv0;
layout(location = 13) out vec3 interp_vfVsNormal;
layout(location = 23) out float interp_instanceID;

void main()
{
    int _848 = gl_InstanceIndex + gl_DrawIDARB;
    int _849 = readFirstInvocationARB(_848);
    uint _3124 = uint(gl_VertexIndex);
    uint _3127 = _3124 + _858.g_cbMainArray._aMain[_849]._Indices._uiPositionOffset;
    vec4 _3140 = vec4(g_rbVertices_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiPositionsBufferIndex].g_rbVertices[_3127].x, g_rbVertices_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiPositionsBufferIndex].g_rbVertices[_3127].y, g_rbVertices_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiPositionsBufferIndex].g_rbVertices[_3127].z, 1.0);
    uint _3147 = _3124 + _858.g_cbMainArray._aMain[_849]._Indices._uiNormalOffset;
    int _3166 = g_rbNormals_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiNormalsBufferIndex].g_rbNormals[_3147] & 1023;
    int _3169 = (g_rbNormals_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiNormalsBufferIndex].g_rbNormals[_3147] >> 10) & 1023;
    int _3172 = (g_rbNormals_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiNormalsBufferIndex].g_rbNormals[_3147] >> 20) & 1023;
    int _8273;
    if (_3166 > 512)
    {
        _8273 = _3166 | (-1024);
    }
    else
    {
        _8273 = _3166;
    }
    int _8275;
    if (_3169 > 512)
    {
        _8275 = _3169 | (-1024);
    }
    else
    {
        _8275 = _3169;
    }
    int _8277;
    if (_3172 > 512)
    {
        _8277 = _3172 | (-1024);
    }
    else
    {
        _8277 = _3172;
    }
    float _3215 = float(_8273);
    float _3218 = float(_8275);
    float _3221 = float(_8277);
    vec3 _3222 = vec3(_3215, _3218, _3221);
    vec3 _3225 = _3222 * vec3(0.001956947147846221923828125);
    vec3 _3239 = _3140.xyz;
    vec2 _3509 = vec2(g_rbMaterials_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiMaterialIndex].g_rbMaterials[0].c0, 0.0);
    vec2 _3510 = in_uv0 + _3509;
    vec4 _3511 = textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiMaterialIndex].g_rbMaterials[0].s0], _3510, 0.0);
    float _3513 = _3511.x;
    float _3523 = _3513 * 0.999989986419677734375;
    float _3524 = clamp(_3523, 0.0, 1.0);
    float _3525 = mix(-0.60000002384185791015625, 1.0, _3524);
    vec3 _3527 = vec3(_3525);
    vec3 _3530 = _3225 * _3527;
    float _3543 = in_color.x * 0.999989986419677734375;
    float _3544 = clamp(_3543, 0.0, 1.0);
    float _3545 = mix(0.100000001490116119384765625, 1.0, _3544);
    vec3 _3547 = vec3(_3545);
    vec3 _3550 = _3530 * _3547;
    vec3 _3554 = _3550 * vec3(0.01899999938905239105224609375);
    float _3567 = g_rbMaterials_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiMaterialIndex].g_rbMaterials[0].c1 * 0.999989986419677734375;
    float _3568 = clamp(_3567, 0.0, 1.0);
    float _3569 = mix(0.0, 1.0, _3568);
    vec3 _3571 = vec3(_3569);
    vec3 _3574 = _3554 * _3571;
    float _3587 = g_rbMaterials_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiMaterialIndex].g_rbMaterials[0].c2 * 0.999989986419677734375;
    float _3588 = clamp(_3587, 0.0, 1.0);
    float _3589 = mix(0.0, 1.0, _3588);
    vec3 _3594 = _3550 * vec3(0.0199999995529651641845703125);
    vec3 _3599 = vec3(_3589);
    vec3 _3600 = mix(_3594, _3574, _3599);
    vec3 _3624 = _3239 + _3600;
    float _3750 = _3624.x;
    float _3751 = _3624.y;
    float _3752 = _3624.z;
    vec4 _3753 = vec4(_3750, _3751, _3752, 1.0);
    vec4 _3754 = _176.g_rbMatrices[_858.g_cbMainArray._aMain[_849]._Indices._uiMatricesIndex]._mModelView * _3753;
    vec4 _3773 = _176.g_rbMatrices[_858.g_cbMainArray._aMain[_849]._Indices._uiMatricesIndex]._mModelViewProj * _3753;
    float _3814 = g_rbMaterials_Buffer[_858.g_cbMainArray._aMain[_849]._Indices._uiMaterialIndex].g_rbMaterials[0]._fDepthBias * 9.9999999747524270787835121154785e-07;
    float _3820 = _3754.z;
    float _3829 = _3773.z * (1.0 + ((-_1090.g_cbPass._fFarPlane) * (_3814 / (_3820 + _3814))));
    vec4 _8258 = _3773;
    _8258.z = _3829;
    vec4 _8283;
    if (_1090.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _3844 = _3773.w;
        vec4 _8284;
        if ((_3829 / _3844) > 1.0)
        {
            vec4 _8285;
            if (_3820 > _1090.g_cbPass._fNearPlane)
            {
                vec4 _8264 = _8258;
                _8264.z = _3844;
                _8285 = _8264;
            }
            else
            {
                _8285 = _8258;
            }
            _8284 = _8285;
        }
        else
        {
            _8284 = _8258;
        }
        _8283 = _8284;
    }
    else
    {
        _8283 = _8258;
    }
    interp_instanceID = float(_848) + 0.5;
    float _3011 = _3754.x;
    float _3012 = _3754.y;
    vec4 _3014 = vec4(_3011, _3012, _3820, 1.0);
    float _3015 = dot(_1090.g_cbPass._vfVsClippingPlane[0], _3014);
    float _3016 = -_3015;
    gl_ClipDistance[0] = _3016;
    interp_vfVsNormal = mat3(_176.g_rbMatrices[_858.g_cbMainArray._aMain[_849]._Indices._uiMatricesIndex]._mModelView[0].xyz, _176.g_rbMatrices[_858.g_cbMainArray._aMain[_849]._Indices._uiMatricesIndex]._mModelView[1].xyz, _176.g_rbMatrices[_858.g_cbMainArray._aMain[_849]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _3225;
    gl_Position = _8283;
}

