
// 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 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_MESH_OBJECT
{
    mat4 _mModel;
    mat4 _mModelLast;
    mat4 _mInvModel;
    mat4 _mInvModelLast;
    vec4 _vDiversityOffset;
    uint _uiSceneZoneIndex;
    uint _uiNeighborSceneZoneIndex;
    uint _uiDisplayFlags;
    uint _uiPackedLocalExposureCompensation;
    vec4 _vPortalDirAndDistance;
    int _iPickingID[2];
    float _fLocalExposureCompensation;
    float _fLocalExposureCompensationEV100;
};

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

struct S_MATERIAL_INSTANCE
{
    float c0;
    float c1;
    float c2;
    float c3;
    float _fGloubiboulga;
};

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 = 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;
} _1213;

layout(set = 1, binding = 33, std430) readonly buffer g_rbObjects_Layout
{
    S_MESH_OBJECT g_rbObjects[];
} g_rbObjects_Buffer[];

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

layout(set = 1, binding = 35, std430) readonly buffer g_rbMaterialInstances_Layout
{
    S_MATERIAL_INSTANCE g_rbMaterialInstances[];
} g_rbMaterialInstances_Buffer[];

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

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

layout(location = 8) in vec2 in_uv0;
layout(location = 23) out float interp_instanceID;

vec3 _7716;

void main()
{
    int _1203 = gl_InstanceIndex + gl_DrawIDARB;
    int _1204 = readFirstInvocationARB(_1203);
    uint _3106 = uint(gl_VertexIndex);
    uint _3109 = _3106 + _1213.g_cbMainArray._aMain[_1204]._Indices._uiPositionOffset;
    uint _3129 = _3106 + _1213.g_cbMainArray._aMain[_1204]._Indices._uiNormalOffset;
    int _3158 = g_rbTBNs_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3129]._iNormal & 1023;
    int _3161 = (g_rbTBNs_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3129]._iNormal >> 10) & 1023;
    int _3164 = (g_rbTBNs_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3129]._iNormal >> 20) & 1023;
    int _7703;
    if (_3158 > 512)
    {
        _7703 = _3158 | (-1024);
    }
    else
    {
        _7703 = _3158;
    }
    int _7705;
    if (_3161 > 512)
    {
        _7705 = _3161 | (-1024);
    }
    else
    {
        _7705 = _3161;
    }
    int _7707;
    if (_3164 > 512)
    {
        _7707 = _3164 | (-1024);
    }
    else
    {
        _7707 = _3164;
    }
    float _3207 = float(_7703);
    float _3210 = float(_7705);
    float _3213 = float(_7707);
    vec3 _3214 = vec3(_3207, _3210, _3213);
    vec3 _3217 = _3214 * vec3(0.001956947147846221923828125);
    vec4 _3340 = vec4(g_rbVertices_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiPositionsBufferIndex].g_rbVertices[_3109].x, g_rbVertices_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiPositionsBufferIndex].g_rbVertices[_3109].y, g_rbVertices_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiPositionsBufferIndex].g_rbVertices[_3109].z, 1.0);
    vec4 _3341 = g_rbObjects_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiObjectIndex].g_rbObjects[0]._mModel * _3340;
    vec3 _3342 = _3341.xyz;
    mat3 _3499 = mat3(g_rbObjects_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiObjectIndex].g_rbObjects[0]._mModel[0].xyz, g_rbObjects_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiObjectIndex].g_rbObjects[0]._mModel[1].xyz, g_rbObjects_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiObjectIndex].g_rbObjects[0]._mModel[2].xyz);
    vec3 _3502 = _3499 * _3217;
    vec3 _7601 = _7716;
    _7601.x = -0.004999999888241291046142578125;
    vec3 _7604 = _7601;
    _7604.y = -0.004999999888241291046142578125;
    vec3 _7607 = _7604;
    _7607.z = -0.004999999888241291046142578125;
    vec3 _7610 = _7716;
    _7610.x = textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiMaterialIndex].g_rbMaterials[0].s2], (in_uv0 * vec2(0.699999988079071044921875, 1.4965989589691162109375)) + vec2(0.039999999105930328369140625, -0.680000007152557373046875), 0.0).x;
    vec3 _7618 = _7716;
    _7618.x = g_rbMaterialInstances_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiMaterialInstanceIndex].g_rbMaterialInstances[0].c0;
    vec3 _7620 = _7618;
    _7620.y = g_rbMaterialInstances_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiMaterialInstanceIndex].g_rbMaterialInstances[0].c0;
    vec3 _7622 = _7620;
    _7622.z = g_rbMaterialInstances_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiMaterialInstanceIndex].g_rbMaterialInstances[0].c0;
    vec3 _3725 = _7622 * vec3(0.00999999977648258209228515625, 0.100000001490116119384765625, 1.0);
    vec3 _7625 = _7716;
    _7625.x = _3725.x;
    vec3 _7628 = _7625;
    _7628.y = _3725.y;
    vec3 _7631 = _7628;
    _7631.z = _3725.z;
    vec3 _3736 = round(_7631);
    vec3 _7634 = _7716;
    _7634.x = _3736.x;
    vec3 _7637 = _7634;
    _7637.y = _3736.y;
    vec3 _7640 = _7637;
    _7640.z = _3736.z;
    vec3 _3754 = _7637 * vec3(10.0, 10.0, 1.0);
    vec3 _7649 = vec3(0.0);
    _7649.y = _3754.x;
    vec3 _7652 = _7649;
    _7652.z = _3754.y;
    vec3 _3763 = _7640 - _7652;
    float _3765 = _3763.x;
    vec3 _3769 = vec3(_3765);
    vec3 _3770 = mix(vec3(0.0), _7610, _3769);
    vec3 _3774 = clamp(_3770, vec3(0.0), vec3(1.0));
    float _3777 = cos(0.21371400356292724609375);
    float _3779 = sin(0.21371400356292724609375);
    vec3 _7656 = _7716;
    _7656.x = textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiMaterialIndex].g_rbMaterials[0].s2], ((in_uv0 * mat2(vec2(_3777, _3779), vec2(-_3779, _3777))) * vec2(3.0, 2.0)) + vec2(-0.78911602497100830078125, -0.0272109992802143096923828125), 0.0).y;
    float _3823 = _3763.y;
    vec3 _3827 = vec3(_3823);
    vec3 _3828 = mix(vec3(0.0), _7656, _3827);
    vec3 _3832 = clamp(_3828, vec3(0.0), vec3(1.0));
    vec3 _3836 = vec3(1.0) - _3774;
    vec3 _3839 = vec3(1.0) - _3832;
    vec3 _3840 = _3836 * _3839;
    vec3 _3842 = vec3(1.0) - _3840;
    vec3 _3846 = clamp(_3842, vec3(0.0), vec3(1.0));
    vec3 _7666 = _7716;
    _7666.x = textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiMaterialIndex].g_rbMaterials[0].s2], in_uv0, 0.0).z;
    float _3873 = _3763.z;
    vec3 _3877 = vec3(_3873);
    vec3 _3878 = mix(vec3(0.0), _7666, _3877);
    vec3 _3882 = clamp(_3878, vec3(0.0), vec3(1.0));
    vec3 _3886 = vec3(1.0) - _3846;
    vec3 _3889 = vec3(1.0) - _3882;
    vec3 _3890 = _3886 * _3889;
    vec3 _3892 = vec3(1.0) - _3890;
    vec3 _3896 = clamp(_3892, vec3(0.0), vec3(1.0));
    vec3 _3904 = vec3(g_rbMaterialInstances_Buffer[_1213.g_cbMainArray._aMain[_1204]._Indices._uiMaterialInstanceIndex].g_rbMaterialInstances[0].c1);
    vec3 _3905 = mix(vec3(0.0), _3896, _3904);
    float _3907 = _3905.x;
    float _3912 = _3907 - 0.6541349887847900390625;
    float _3917 = _3912 * 2.891217708587646484375;
    float _3918 = clamp(_3917, 0.0, 1.0);
    float _3919 = mix(0.0, 1.0, _3918);
    vec3 _3932 = vec3(_3919);
    vec3 _3933 = mix(vec3(0.0), _7607, _3932);
    vec3 _3939 = _3933 * _3502;
    vec3 _3962 = _3342 + _3939;
    float _4027 = _3962.x;
    float _4028 = _3962.y;
    float _4029 = _3962.z;
    vec4 _4030 = vec4(_4027, _4028, _4029, 1.0);
    vec4 _4031 = _1441.g_cbPass._EyeData._mCurrentFrameMatrices[0]._mView * _4030;
    vec4 _4047 = _1441.g_cbPass._EyeData._mCurrentFrameMatrices[0]._mViewJitteredProj * _4030;
    vec4 _7713;
    if (_1441.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _4062 = _4047.w;
        vec4 _7714;
        if ((_4047.z / _4062) > 1.0)
        {
            vec4 _7715;
            if (_4031.z > _1441.g_cbPass._fNearPlane)
            {
                vec4 _7683 = _4047;
                _7683.z = _4062;
                _7715 = _7683;
            }
            else
            {
                _7715 = _4047;
            }
            _7714 = _7715;
        }
        else
        {
            _7714 = _4047;
        }
        _7713 = _7714;
    }
    else
    {
        _7713 = _4047;
    }
    interp_instanceID = float(_1203) + 0.5;
    float _2992 = _4031.x;
    float _2993 = _4031.y;
    float _2994 = _4031.z;
    vec4 _2995 = vec4(_2992, _2993, _2994, 1.0);
    float _2996 = dot(_1441.g_cbPass._vfVsClippingPlane[0], _2995);
    float _2997 = -_2996;
    gl_ClipDistance[0] = _2997;
    gl_Position = _7713;
}

