
// 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_SPEEDTREE_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];
    uint _uiPadding[2];
    vec4 _vTreeRotation;
    vec4 _vWindGlobal;
    vec4 _vWindVector;
    vec4 _vWindBranchAdherences;
    vec4 _vWindBranch;
    vec4 _vWindBranchTwitch;
    vec4 _vWindBranchWhipTurbulences;
    vec4 _vWindFrondRipple;
    vec4 _vWindLeaf1Ripple;
    vec4 _vWindLeaf1Tumble;
    vec4 _vWindLeaf1Twitch;
    vec4 _vWindLeaf2Ripple;
    vec4 _vWindLeaf2Tumble;
    vec4 _vWindLeaf2Twitch;
    vec4 _vAnchorAllTime;
    vec4 _vRollingBranch;
    vec4 _vRollingLeafOffset;
    vec4 _vRollingNoise;
    uint _uiLOD;
    uint _uiSmooth;
    float _fLocalExposureCompensation;
    float _fLocalExposureCompensationEV100;
    vec4 _vWindGlobalLast;
    vec4 _vWindBranchLast;
    vec4 _vWindFrondRippleLast;
    vec4 _vWindLeaf1RippleLast;
    vec4 _vWindLeaf1TumbleLast;
    vec4 _vWindLeaf1TwitchLast;
    vec4 _vWindLeaf2RippleLast;
    vec4 _vWindLeaf2TumbleLast;
    vec4 _vAnchorAllTimeLast;
};

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

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

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

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

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

layout(location = 8) in vec2 in_uv0;
layout(location = 10) in vec4 in_lodPosition;
layout(location = 11) in vec4 in_windBranchData;
layout(location = 12) in vec4 in_windExtraDataFlag;
layout(location = 13) in vec4 in_LeafAnchorHint;
layout(location = 23) out float interp_instanceID;

void main()
{
    int _3214 = gl_InstanceIndex + gl_DrawIDARB;
    int _3215 = readFirstInvocationARB(_3214);
    uint _5109 = uint(gl_VertexIndex);
    uint _5112 = _5109 + _3224.g_cbMainArray._aMain[_3215]._Indices._uiPositionOffset;
    vec4 _5125 = vec4(g_rbVertices_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiPositionsBufferIndex].g_rbVertices[_5112].x, g_rbVertices_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiPositionsBufferIndex].g_rbVertices[_5112].y, g_rbVertices_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiPositionsBufferIndex].g_rbVertices[_5112].z, 1.0);
    vec3 _5310 = _5125.xyz;
    vec3 _5641 = vec3(g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    vec3 _5642 = mix(in_lodPosition.xyz, _5310, _5641);
    vec2 _5827 = _5642.xy;
    vec2 _5828 = _5827 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.x;
    vec2 _5930 = vec2(g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.zw);
    vec2 _5931 = _5828 - _5930;
    vec2 _5932 = _5931 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
    float _5954 = 5.0 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
    vec2 _5980 = cos(_5932);
    float _5982 = _5980.x;
    float _5984 = _5980.y;
    float _5985 = _5982 + _5984;
    float _5961 = _5932.x;
    float _5962 = 3.1415927410125732421875 * _5961;
    float _5964 = _5962 * _5954;
    float _5966 = _5932.y;
    float _5968 = _5966 * _5954;
    float _5969 = _5964 + _5968;
    float _5972 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * _5985;
    float _5973 = _5969 + _5972;
    float _5974 = sin(_5973);
    float _5975 = abs(_5974);
    float _5942 = _5975 * _5975;
    float _5945 = _5942 * _5942;
    float _5836 = mix(g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.y, 1.0, _5945);
    float _5840 = _5836 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
    float _5998 = length(_5642);
    float _6009 = max(_5642.y - (0.25 / g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z), 0.0) * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z;
    float _9951;
    if (_6009 != 0.0)
    {
        _9951 = pow(abs(_6009), g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.w);
    }
    else
    {
        _9951 = _6009;
    }
    float _6023 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x * 0.800000011920928955078125;
    vec4 _6024 = vec4(g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x, _6023, 0.0, 0.0);
    vec4 _6080 = _6024 + vec4(0.5);
    vec4 _6081 = fract(_6080);
    vec4 _6082 = _6081 * 2.0;
    vec4 _6084 = _6082 - vec4(1.0);
    vec4 _6085 = abs(_6084);
    vec4 _6089 = _6085 * _6085;
    vec4 _6091 = _6085 * 2.0;
    vec4 _6093 = vec4(3.0) - _6091;
    vec4 _6094 = _6089 * _6093;
    vec4 _6075 = _6094 - vec4(0.5);
    vec4 _6076 = _6075 * 2.0;
    float _6027 = _6076.x;
    float _6029 = _6076.y;
    float _6032 = _6029 * _6029;
    float _6033 = _6027 + _6032;
    float _6037 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.y * _6033;
    float _6042 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchAdherences.x / g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z;
    float _6045 = _6042 * _5840;
    float _6047 = _6037 + _6045;
    float _6050 = _6047 * _9951;
    vec2 _6054 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xz * _6050;
    vec2 _6056 = _5642.xz;
    vec2 _6057 = _6056 + _6054;
    vec3 _6059 = vec3(_6057.x, _5642.y, _6057.y);
    vec3 _6064 = normalize(_6059);
    vec3 _6066 = _6064 * _5998;
    vec3 _5855 = _6066 - _5642;
    vec3 _6254 = vec3(in_windBranchData.y);
    vec3 _6255 = _6254 * vec3(0.0625, -1.0, 16.0);
    vec3 _6256 = fract(_6255);
    vec3 _6258 = _6256.xzy;
    vec3 _6259 = _6258 * 2.0;
    vec3 _6260 = _6259 - vec3(1.0);
    vec3 _6230 = _6260 * in_windBranchData.x;
    float _6329 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x + in_windBranchData.y;
    float _6332 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y;
    float _6334 = _6332 + in_windBranchData.y;
    float _6336 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y * 0.5;
    float _6340 = _6336 * _6329;
    vec4 _6341 = vec4(_6329, _6334, _6340, 0.0);
    vec4 _6480 = _6341 + vec4(0.5);
    vec4 _6481 = fract(_6480);
    vec4 _6482 = _6481 * 2.0;
    vec4 _6484 = _6482 - vec4(1.0);
    vec4 _6485 = abs(_6484);
    vec4 _6489 = _6485 * _6485;
    vec4 _6491 = _6485 * 2.0;
    vec4 _6493 = vec4(3.0) - _6491;
    vec4 _6494 = _6489 * _6493;
    vec4 _6475 = _6494 - vec4(0.5);
    vec4 _6476 = _6475 * 2.0;
    float _6366 = _6476.x;
    float _6368 = _6476.y;
    float _6370 = _6476.z;
    float _6371 = _6368 * _6370;
    bool _6374 = _6371 < 0.0;
    float _9959;
    if (_6374)
    {
        _9959 = -_6371;
    }
    else
    {
        _9959 = _6371;
    }
    float _9974 = _6374 ? (-1.0) : 1.0;
    float _6384 = mix(_6371, _9974, _9959);
    float _6388 = mix(_6384, _9974, _9959);
    float _6391 = _6388 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x;
    float _6394 = 1.0 - g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.w;
    float _6395 = _6391 * _6394;
    float _6398 = 1.0 - g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x;
    float _6399 = _6366 * _6398;
    float _6400 = _6395 + _6399;
    vec3 _6245 = _6230 * _6400;
    vec3 _6247 = _6245 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.y;
    vec3 _6249 = _5642 + _6247;
    vec3 _5876 = _6249 - _5642;
    vec3 _5887 = _5855 + _5876;
    vec3 _5895 = _5642 + _5887;
    float _6558 = _5895.x;
    float _6559 = _5895.y;
    float _6560 = _5895.z;
    vec4 _6561 = vec4(_6558, _6559, _6560, 1.0);
    vec4 _6562 = _426.g_rbMatrices[_3224.g_cbMainArray._aMain[_3215]._Indices._uiMatricesIndex]._mModelView * _6561;
    vec4 _6581 = _426.g_rbMatrices[_3224.g_cbMainArray._aMain[_3215]._Indices._uiMatricesIndex]._mModelViewProj * _6561;
    vec4 _9970;
    if (_3471.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _6615 = _6581.w;
        vec4 _9971;
        if ((_6581.z / _6615) > 1.0)
        {
            vec4 _9972;
            if (_6562.z > _3471.g_cbPass._fNearPlane)
            {
                vec4 _9941 = _6581;
                _9941.z = _6615;
                _9972 = _9941;
            }
            else
            {
                _9972 = _6581;
            }
            _9971 = _9972;
        }
        else
        {
            _9971 = _6581;
        }
        _9970 = _9971;
    }
    else
    {
        _9970 = _6581;
    }
    interp_instanceID = float(_3214) + 0.5;
    float _4992 = _6562.x;
    float _4993 = _6562.y;
    float _4994 = _6562.z;
    vec4 _4995 = vec4(_4992, _4993, _4994, 1.0);
    float _4996 = dot(_3471.g_cbPass._vfVsClippingPlane[0], _4995);
    float _4997 = -_4996;
    gl_ClipDistance[0] = _4997;
    gl_Position = _9970;
}

