
// 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;
    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[];
} _161;

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

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

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 _797 = gl_InstanceIndex + gl_DrawIDARB;
    int _798 = readFirstInvocationARB(_797);
    uint _2687 = uint(gl_VertexIndex);
    uint _2690 = _2687 + _807.g_cbMainArray._aMain[_798]._Indices._uiPositionOffset;
    vec4 _2703 = vec4(g_rbVertices_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiPositionsBufferIndex].g_rbVertices[_2690].x, g_rbVertices_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiPositionsBufferIndex].g_rbVertices[_2690].y, g_rbVertices_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiPositionsBufferIndex].g_rbVertices[_2690].z, 1.0);
    uint _2710 = _2687 + _807.g_cbMainArray._aMain[_798]._Indices._uiNormalOffset;
    int _2729 = g_rbNormals_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiNormalsBufferIndex].g_rbNormals[_2710] & 1023;
    int _2732 = (g_rbNormals_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiNormalsBufferIndex].g_rbNormals[_2710] >> 10) & 1023;
    int _2735 = (g_rbNormals_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiNormalsBufferIndex].g_rbNormals[_2710] >> 20) & 1023;
    int _7160;
    if (_2729 > 512)
    {
        _7160 = _2729 | (-1024);
    }
    else
    {
        _7160 = _2729;
    }
    int _7162;
    if (_2732 > 512)
    {
        _7162 = _2732 | (-1024);
    }
    else
    {
        _7162 = _2732;
    }
    int _7164;
    if (_2735 > 512)
    {
        _7164 = _2735 | (-1024);
    }
    else
    {
        _7164 = _2735;
    }
    float _2778 = float(_7160);
    float _2781 = float(_7162);
    float _2784 = float(_7164);
    vec3 _2785 = vec3(_2778, _2781, _2784);
    vec3 _2788 = _2785 * vec3(0.001956947147846221923828125);
    vec3 _2802 = _2703.xyz;
    vec2 _3072 = vec2(g_rbMaterials_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiMaterialIndex].g_rbMaterials[0].c0, 0.0);
    vec2 _3073 = in_uv0 + _3072;
    vec4 _3074 = textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiMaterialIndex].g_rbMaterials[0].s0], _3073, 0.0);
    float _3078 = _3074.x;
    float _3088 = _3078 * 0.999989986419677734375;
    float _3089 = clamp(_3088, 0.0, 1.0);
    float _3090 = mix(-1.0, 1.0, _3089);
    vec3 _3092 = vec3(_3090);
    vec3 _3095 = _2788 * _3092;
    float _3108 = in_color.x * 0.999989986419677734375;
    float _3109 = clamp(_3108, 0.0, 1.0);
    float _3110 = mix(0.100000001490116119384765625, 1.0, _3109);
    vec3 _3112 = vec3(_3110);
    vec3 _3115 = _3095 * _3112;
    vec3 _3119 = _3115 * vec3(0.01899999938905239105224609375);
    float _3132 = g_rbMaterials_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiMaterialIndex].g_rbMaterials[0].c1 * 0.999989986419677734375;
    float _3133 = clamp(_3132, 0.0, 1.0);
    float _3134 = mix(0.0, 1.0, _3133);
    vec3 _3136 = vec3(_3134);
    vec3 _3139 = _3119 * _3136;
    float _3152 = g_rbMaterials_Buffer[_807.g_cbMainArray._aMain[_798]._Indices._uiMaterialIndex].g_rbMaterials[0].c2 * 0.999989986419677734375;
    float _3153 = clamp(_3152, 0.0, 1.0);
    float _3154 = mix(0.0, 1.0, _3153);
    vec3 _3159 = _3115 * vec3(0.0199999995529651641845703125);
    vec3 _3164 = vec3(_3154);
    vec3 _3165 = mix(_3159, _3139, _3164);
    vec3 _3189 = _2802 + _3165;
    float _3315 = _3189.x;
    float _3316 = _3189.y;
    float _3317 = _3189.z;
    vec4 _3318 = vec4(_3315, _3316, _3317, 1.0);
    vec4 _3319 = _161.g_rbMatrices[_807.g_cbMainArray._aMain[_798]._Indices._uiMatricesIndex]._mModelView * _3318;
    vec4 _3338 = _161.g_rbMatrices[_807.g_cbMainArray._aMain[_798]._Indices._uiMatricesIndex]._mModelViewProj * _3318;
    vec4 _7170;
    if (_1020.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _3372 = _3338.w;
        vec4 _7171;
        if ((_3338.z / _3372) > 1.0)
        {
            vec4 _7172;
            if (_3319.z > _1020.g_cbPass._fNearPlane)
            {
                vec4 _7151 = _3338;
                _7151.z = _3372;
                _7172 = _7151;
            }
            else
            {
                _7172 = _3338;
            }
            _7171 = _7172;
        }
        else
        {
            _7171 = _3338;
        }
        _7170 = _7171;
    }
    else
    {
        _7170 = _3338;
    }
    interp_instanceID = float(_797) + 0.5;
    float _2574 = _3319.x;
    float _2575 = _3319.y;
    float _2576 = _3319.z;
    vec4 _2577 = vec4(_2574, _2575, _2576, 1.0);
    float _2578 = dot(_1020.g_cbPass._vfVsClippingPlane[0], _2577);
    float _2579 = -_2578;
    gl_ClipDistance[0] = _2579;
    interp_vfVsNormal = mat3(_161.g_rbMatrices[_807.g_cbMainArray._aMain[_798]._Indices._uiMatricesIndex]._mModelView[0].xyz, _161.g_rbMatrices[_807.g_cbMainArray._aMain[_798]._Indices._uiMatricesIndex]._mModelView[1].xyz, _161.g_rbMatrices[_807.g_cbMainArray._aMain[_798]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _2788;
    gl_Position = _7170;
}

