
// 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;
    uint s8;
    uint s9;
    uint s10;
    uint s11;
    uint s12;
    uint s13;
    uint s14;
    uint s15;
    uint s16;
    uint s17;
    uint s18;
    uint s19;
};

struct S_MATERIAL_INSTANCE
{
    float c0;
    float c1;
    float c2;
    float c3;
    float c4;
    float c5;
    float c6;
    float c7;
    float c8;
    float c9;
    float c10;
    float c11;
    float c12;
    float c13;
    float c14;
    float c15;
    float c16;
    float c17;
    float c18;
    float c19;
    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;
} _1330;

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

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

layout(location = 8) in vec4 in_uv0;
layout(location = 9) in vec4 in_uv1;
layout(location = 23) out float interp_instanceID;

vec3 _8395;

void main()
{
    int _1320 = gl_InstanceIndex + gl_DrawIDARB;
    int _1321 = readFirstInvocationARB(_1320);
    uint _3331 = uint(gl_VertexIndex);
    uint _3334 = _3331 + _1330.g_cbMainArray._aMain[_1321]._Indices._uiPositionOffset;
    uint _3354 = _3331 + _1330.g_cbMainArray._aMain[_1321]._Indices._uiNormalOffset;
    int _3383 = g_rbTBNs_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3354]._iNormal & 1023;
    int _3386 = (g_rbTBNs_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3354]._iNormal >> 10) & 1023;
    int _3389 = (g_rbTBNs_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiNormalsBufferIndex].g_rbTBNs[_3354]._iNormal >> 20) & 1023;
    int _8382;
    if (_3383 > 512)
    {
        _8382 = _3383 | (-1024);
    }
    else
    {
        _8382 = _3383;
    }
    int _8384;
    if (_3386 > 512)
    {
        _8384 = _3386 | (-1024);
    }
    else
    {
        _8384 = _3386;
    }
    int _8386;
    if (_3389 > 512)
    {
        _8386 = _3389 | (-1024);
    }
    else
    {
        _8386 = _3389;
    }
    float _3432 = float(_8382);
    float _3435 = float(_8384);
    float _3438 = float(_8386);
    vec3 _3439 = vec3(_3432, _3435, _3438);
    vec3 _3442 = _3439 * vec3(0.001956947147846221923828125);
    vec4 _3575 = vec4(g_rbVertices_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiPositionsBufferIndex].g_rbVertices[_3334].x, g_rbVertices_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiPositionsBufferIndex].g_rbVertices[_3334].y, g_rbVertices_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiPositionsBufferIndex].g_rbVertices[_3334].z, 1.0);
    vec4 _3576 = g_rbObjects_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiObjectIndex].g_rbObjects[0]._mModel * _3575;
    vec3 _3577 = _3576.xyz;
    mat3 _3734 = mat3(g_rbObjects_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiObjectIndex].g_rbObjects[0]._mModel[0].xyz, g_rbObjects_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiObjectIndex].g_rbObjects[0]._mModel[1].xyz, g_rbObjects_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiObjectIndex].g_rbObjects[0]._mModel[2].xyz);
    vec3 _3737 = _3734 * _3442;
    float _3978 = cos(2.0);
    float _3980 = sin(2.0);
    vec2 _3992 = in_uv1.zw - vec2(0.5);
    vec3 _8326 = _8395;
    _8326.y = (textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiMaterialIndex].g_rbMaterials[0].s0], (((_3992 * mat2(vec2(_3978, _3980), vec2(-_3980, _3978))) + vec2(0.5)) * vec2(1.25, 3.0)) + vec2(-0.300000011920928955078125, 0.0900000035762786865234375), 0.0) * vec4(1.0, 0.9215819835662841796875, 0.982250988483428955078125, 1.0)).x;
    vec3 _4036 = vec3(g_rbMaterialInstances_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiMaterialInstanceIndex].g_rbMaterialInstances[0].c0);
    vec3 _4039 = mod(_4036, vec3(2.0));
    vec3 _4043 = _8326 * _4039;
    float _4046 = cos(-6.28318500518798828125);
    float _4048 = sin(-6.28318500518798828125);
    vec3 _8335 = _8395;
    _8335.y = (textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiMaterialIndex].g_rbMaterials[0].s0], (((_3992 * mat2(vec2(_4046, _4048), vec2(-_4048, _4046))) + vec2(0.5)) * vec2(1.2999999523162841796875)) + vec2(-0.48500001430511474609375, -0.2800000011920928955078125), 0.0) * vec4(1.0, 0.9215819835662841796875, 0.982250988483428955078125, 1.0)).y;
    vec3 _4105 = _4036 * vec3(0.100000001490116119384765625);
    vec3 _4108 = floor(_4105);
    vec3 _4112 = mod(_4108, vec3(2.0));
    vec3 _4116 = _8335 * _4112;
    vec3 _4120 = vec3(1.0) - _4043;
    vec3 _4123 = vec3(1.0) - _4116;
    vec3 _4124 = _4120 * _4123;
    float _4129 = cos(-0.5);
    float _4131 = sin(-0.5);
    vec3 _8344 = _8395;
    _8344.y = (textureLod(g_rb2DTextures[g_rbMaterials_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiMaterialIndex].g_rbMaterials[0].s0], (((_3992 * mat2(vec2(_4129, _4131), vec2(-_4131, _4129))) + vec2(0.5)) * vec2(1.5, 0.75)) + vec2(-0.660000026226043701171875, 0.100000001490116119384765625), 0.0) * vec4(1.0, 0.9215819835662841796875, 0.982250988483428955078125, 1.0)).z;
    vec3 _4188 = _4036 * vec3(0.00999999977648258209228515625);
    vec3 _4191 = floor(_4188);
    vec3 _4195 = mod(_4191, vec3(2.0));
    vec3 _4199 = _8344 * _4195;
    vec3 _4206 = vec3(1.0) - _4199;
    vec3 _4207 = _4124 * _4206;
    vec3 _4209 = vec3(1.0) - _4207;
    float _4211 = _4209.y;
    float _4216 = _4211 - 0.949999988079071044921875;
    float _4221 = _4216 * 19.9959964752197265625;
    float _4222 = clamp(_4221, 0.0, 1.0);
    float _4223 = mix(0.0, 1.0, _4222);
    float _4231 = _4211 - 0.88999998569488525390625;
    float _4236 = _4231 * 99.90019989013671875;
    float _4237 = clamp(_4236, 0.0, 1.0);
    float _4238 = mix(0.0, 1.0, _4237);
    vec3 _4243 = vec3(_4238);
    vec3 _4244 = mix(vec3(0.0), vec3(-0.011610000394284725189208984375), _4243);
    vec3 _4249 = vec3(_4223);
    vec3 _4250 = mix(_4244, vec3(-0.03869999945163726806640625), _4249);
    vec3 _4256 = _4250 * _3737;
    vec3 _4264 = vec3(g_rbMaterialInstances_Buffer[_1330.g_cbMainArray._aMain[_1321]._Indices._uiMaterialInstanceIndex].g_rbMaterialInstances[0].c13);
    vec3 _4265 = mix(vec3(0.0), _4256, _4264);
    vec3 _4288 = _3577 + _4265;
    float _4353 = _4288.x;
    float _4354 = _4288.y;
    float _4355 = _4288.z;
    vec4 _4356 = vec4(_4353, _4354, _4355, 1.0);
    vec4 _4357 = _1674.g_cbPass._EyeData._mCurrentFrameMatrices[0]._mView * _4356;
    vec4 _4373 = _1674.g_cbPass._EyeData._mCurrentFrameMatrices[0]._mViewJitteredProj * _4356;
    vec4 _8392;
    if (_1674.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _4388 = _4373.w;
        vec4 _8393;
        if ((_4373.z / _4388) > 1.0)
        {
            vec4 _8394;
            if (_4357.z > _1674.g_cbPass._fNearPlane)
            {
                vec4 _8357 = _4373;
                _8357.z = _4388;
                _8394 = _8357;
            }
            else
            {
                _8394 = _4373;
            }
            _8393 = _8394;
        }
        else
        {
            _8393 = _4373;
        }
        _8392 = _8393;
    }
    else
    {
        _8392 = _4373;
    }
    interp_instanceID = float(_1320) + 0.5;
    float _3217 = _4357.x;
    float _3218 = _4357.y;
    float _3219 = _4357.z;
    vec4 _3220 = vec4(_3217, _3218, _3219, 1.0);
    float _3221 = dot(_1674.g_cbPass._vfVsClippingPlane[0], _3220);
    float _3222 = -_3221;
    gl_ClipDistance[0] = _3222;
    gl_Position = _8392;
}

