
// 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_TBN
{
    int _iNormal;
    int _iTangent;
};

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;
    uint s0;
    uint s1;
    uint s2;
    uint s3;
    uint s4;
    uint s5;
    uint s6;
    uint s7;
    uint s8;
    uint s9;
    uint s10;
    uint s11;
};

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

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_rbTBNs_Layout
{
    S_TBN g_rbTBNs[];
} g_rbTBNs_Buffer[];

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

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

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

layout(location = 13) in vec3 in_vfMsBindPoseNormal;
layout(location = 8) in vec4 in_uv0;
layout(location = 9) in vec2 in_uv1;
layout(location = 8) out vec4 interp_uv0;
layout(location = 9) out vec2 interp_uv1;
layout(location = 21) out vec3 interp_vfVsPosition;
layout(location = 14) out vec3 interp_vfVsTangent;
layout(location = 15) out vec3 interp_vfVsBinormal;
layout(location = 13) out vec3 interp_vfVsNormal;
layout(location = 23) out float interp_instanceID;

vec3 _8247;

void main()
{
    int _1171 = gl_InstanceIndex + gl_DrawIDARB;
    int _1172 = readFirstInvocationARB(_1171);
    uint _3104 = uint(gl_VertexIndex);
    uint _3107 = _3104 + _1181.g_cbMainArray._aMain[_1172]._Indices._uiPositionOffset;
    vec4 _3120 = vec4(g_rbVertices_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiPositionsBufferIndex].g_rbVertices[_3107].x, g_rbVertices_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiPositionsBufferIndex].g_rbVertices[_3107].y, g_rbVertices_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiPositionsBufferIndex].g_rbVertices[_3107].z, 1.0);
    uint _3127 = _3104 + _1181.g_cbMainArray._aMain[_1172]._Indices._uiNormalOffset;
    int _3156 = g_rbTBNs_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3127]._iNormal & 1023;
    int _3159 = (g_rbTBNs_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3127]._iNormal >> 10) & 1023;
    int _3162 = (g_rbTBNs_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3127]._iNormal >> 20) & 1023;
    int _8225;
    if (_3156 > 512)
    {
        _8225 = _3156 | (-1024);
    }
    else
    {
        _8225 = _3156;
    }
    int _8227;
    if (_3159 > 512)
    {
        _8227 = _3159 | (-1024);
    }
    else
    {
        _8227 = _3159;
    }
    int _8229;
    if (_3162 > 512)
    {
        _8229 = _3162 | (-1024);
    }
    else
    {
        _8229 = _3162;
    }
    vec3 _3215 = vec3(float(_8225), float(_8227), float(_8229)) * vec3(0.001956947147846221923828125);
    int _3224 = g_rbTBNs_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3127]._iTangent & 1023;
    int _3227 = (g_rbTBNs_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3127]._iTangent >> 10) & 1023;
    int _3230 = (g_rbTBNs_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3127]._iTangent >> 20) & 1023;
    int _8231;
    if (_3224 > 512)
    {
        _8231 = _3224 | (-1024);
    }
    else
    {
        _8231 = _3224;
    }
    int _8233;
    if (_3227 > 512)
    {
        _8233 = _3227 | (-1024);
    }
    else
    {
        _8233 = _3227;
    }
    int _8235;
    if (_3230 > 512)
    {
        _8235 = _3230 | (-1024);
    }
    else
    {
        _8235 = _3230;
    }
    float _3288 = float((g_rbTBNs_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3127]._iTangent >> 30) != 0);
    vec3 _3305 = _3120.xyz;
    vec3 _3419 = vec4(vec3(float(_8231), float(_8233), float(_8235)) * vec3(0.001956947147846221923828125), _3288).xyz;
    vec4 _3728 = textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMaterialIndex].g_rbMaterials[0].s3], in_uv1, 0.0);
    vec3 _3732 = _3728.xxx;
    vec3 _8185 = _8247;
    _8185.y = abs(((((((textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMaterialIndex].g_rbMaterials[0].s2], in_uv0.xy, 0.0) * vec4(0.952941000461578369140625, 0.811765015125274658203125, 1.0, 1.0)) + vec4(0.047058999538421630859375, 0.074510000646114349365234375, 0.0, 0.0)) * 2.0) - vec4(1.0)) * 0.5) + vec4(0.5)).xyz - vec3(0.5, 0.5, 1.0)).x;
    vec3 _3801 = vec3(1.0) - _8185;
    vec3 _3805 = _3801 * _3801;
    vec3 _3807 = vec3(1.0) - _3805;
    float _3810 = _3728.x;
    float _3815 = _3810 - 0.706767022609710693359375;
    float _3820 = _3815 * 3.4101412296295166015625;
    float _3821 = clamp(_3820, 0.0, 1.0);
    float _3822 = mix(1.0, 0.0, _3821);
    vec3 _3824 = vec3(_3822);
    vec3 _3833 = _3807 * _3824;
    float _3835 = _3833.y;
    vec3 _3839 = vec3(_3835);
    vec3 _3840 = mix(vec3(1.0), vec3(0.254339993000030517578125), _3839);
    vec3 _3844 = _3732 * _3840;
    float _3852 = _3844.y;
    vec3 _3858 = vec3(g_rbMaterials_Buffer[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMaterialIndex].g_rbMaterials[0].c0);
    vec3 _3859 = mix(vec3(0.0), vec3(1.0), _3858);
    float _3871 = _3859.y;
    vec3 _3875 = vec3(_3871);
    vec3 _3876 = mix(vec3(-0.07739900052547454833984375, -0.07739900052547454833984375, 0.0), vec3(0.692071020603179931640625, 0.692071020603179931640625, 0.0), _3875);
    float _3878 = _3876.y;
    float _3883 = _3852 - _3878;
    float _3885 = max(0.1500000059604644775390625, 9.9999997473787516355514526367188e-05);
    float _3886 = _3883 / _3885;
    float _3887 = clamp(_3886, 0.0, 1.0);
    float _3888 = mix(1.0, 0.0, _3887);
    vec3 _3893 = vec3(_3888);
    vec3 _3894 = mix(vec3(1.0), vec3(0.0), _3893);
    float _3896 = _3894.y;
    vec3 _3900 = vec3(_3896);
    vec3 _3901 = mix(vec3(0.0, 0.0, -0.00386999989859759807586669921875), vec3(0.0), _3900);
    vec3 _3905 = in_vfMsBindPoseNormal * _3901;
    vec3 _3929 = _3305 + _3905;
    float _4055 = _3929.x;
    float _4056 = _3929.y;
    float _4057 = _3929.z;
    vec4 _4058 = vec4(_4055, _4056, _4057, 1.0);
    vec4 _4059 = _165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView * _4058;
    vec4 _4078 = _165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelViewProj * _4058;
    vec4 _8244;
    if (_1442.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _4112 = _4078.w;
        vec4 _8245;
        if ((_4078.z / _4112) > 1.0)
        {
            vec4 _8246;
            if (_4059.z > _1442.g_cbPass._fNearPlane)
            {
                vec4 _8211 = _4078;
                _8211.z = _4112;
                _8246 = _8211;
            }
            else
            {
                _8246 = _4078;
            }
            _8245 = _8246;
        }
        else
        {
            _8245 = _4078;
        }
        _8244 = _8245;
    }
    else
    {
        _8244 = _4078;
    }
    interp_instanceID = float(_1171) + 0.5;
    float _2991 = _4059.x;
    float _2992 = _4059.y;
    float _2993 = _4059.z;
    vec4 _2994 = vec4(_2991, _2992, _2993, 1.0);
    float _2995 = dot(_1442.g_cbPass._vfVsClippingPlane[0], _2994);
    float _2996 = -_2995;
    gl_ClipDistance[0] = _2996;
    interp_uv0 = in_uv0;
    interp_uv1 = in_uv1;
    interp_vfVsPosition = _4059.xyz;
    interp_vfVsTangent = mat3(_165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView[0].xyz, _165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView[1].xyz, _165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _3419;
    interp_vfVsBinormal = mat3(_165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView[0].xyz, _165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView[1].xyz, _165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView[2].xyz) * (cross(_3215, _3419) * ((_3288 != 0.0) ? (-1.0) : 1.0));
    interp_vfVsNormal = mat3(_165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView[0].xyz, _165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView[1].xyz, _165.g_rbMatrices[_1181.g_cbMainArray._aMain[_1172]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _3215;
    gl_Position = _8244;
}

