
// 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_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 = 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;
} _3339;

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

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 = 8) out vec2 interp_uv0;
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;

float _11936;

void main()
{
    int _3329 = gl_InstanceIndex + gl_DrawIDARB;
    int _3330 = readFirstInvocationARB(_3329);
    uint _5223 = uint(gl_VertexIndex);
    uint _5226 = _5223 + _3339.g_cbMainArray._aMain[_3330]._Indices._uiPositionOffset;
    vec4 _5239 = vec4(g_rbVertices_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiPositionsBufferIndex].g_rbVertices[_5226].x, g_rbVertices_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiPositionsBufferIndex].g_rbVertices[_5226].y, g_rbVertices_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiPositionsBufferIndex].g_rbVertices[_5226].z, 1.0);
    uint _5246 = _5223 + _3339.g_cbMainArray._aMain[_3330]._Indices._uiNormalOffset;
    int _5275 = g_rbTBNs_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5246]._iNormal & 1023;
    int _5278 = (g_rbTBNs_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5246]._iNormal >> 10) & 1023;
    int _5281 = (g_rbTBNs_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5246]._iNormal >> 20) & 1023;
    int _11937;
    if (_5275 > 512)
    {
        _11937 = _5275 | (-1024);
    }
    else
    {
        _11937 = _5275;
    }
    int _11939;
    if (_5278 > 512)
    {
        _11939 = _5278 | (-1024);
    }
    else
    {
        _11939 = _5278;
    }
    int _11941;
    if (_5281 > 512)
    {
        _11941 = _5281 | (-1024);
    }
    else
    {
        _11941 = _5281;
    }
    vec3 _5334 = vec3(float(_11937), float(_11939), float(_11941)) * vec3(0.001956947147846221923828125);
    int _5343 = g_rbTBNs_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5246]._iTangent & 1023;
    int _5346 = (g_rbTBNs_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5246]._iTangent >> 10) & 1023;
    int _5349 = (g_rbTBNs_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5246]._iTangent >> 20) & 1023;
    int _11943;
    if (_5343 > 512)
    {
        _11943 = _5343 | (-1024);
    }
    else
    {
        _11943 = _5343;
    }
    int _11945;
    if (_5346 > 512)
    {
        _11945 = _5346 | (-1024);
    }
    else
    {
        _11945 = _5346;
    }
    int _11947;
    if (_5349 > 512)
    {
        _11947 = _5349 | (-1024);
    }
    else
    {
        _11947 = _5349;
    }
    float _5407 = float((g_rbTBNs_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5246]._iTangent >> 30) != 0);
    vec3 _5424 = _5239.xyz;
    vec3 _5538 = vec4(vec3(float(_11943), float(_11945), float(_11947)) * vec3(0.001956947147846221923828125), _5407).xyz;
    float _5747 = (((100.0 * in_LeafAnchorHint.x) + in_LeafAnchorHint.y) + in_lodPosition.x) + in_lodPosition.y;
    bool _6022 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 6u;
    bool _6024 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 8u;
    bool _6027 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 9u;
    bool _6028 = (_6022 || _6024) || _6027;
    bool _6032 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 3u;
    bool _6041 = ((_6032 || _6022) || _6024) || _6027;
    bool _6044 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 2u;
    bool _6047 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 5u;
    bool _6050 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 7u;
    float _11958;
    if (true && _6032)
    {
        vec2 _6376 = ((_5239.xy * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.x) - vec2(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.zw)) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
        float _6398 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
        vec2 _6424 = cos(_6376);
        float _6419 = abs(sin((((3.1415927410125732421875 * _6376.x) * _6398) + (_6376.y * _6398)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_6424.x + _6424.y))));
        float _6386 = _6419 * _6419;
        float _6069 = mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.y, 1.0, _6386 * _6386);
        float _11959;
        if (_6028)
        {
            _11959 = _6069 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
        }
        else
        {
            _11959 = _6069;
        }
        _11958 = _11959;
    }
    else
    {
        _11958 = 0.0;
    }
    vec3 _11991;
    if (true && (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD != 0u))
    {
        float _6453 = max(g_rbVertices_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiPositionsBufferIndex].g_rbVertices[_5226].y - (0.25 / g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z), 0.0) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z;
        float _11960;
        if (_6453 != 0.0)
        {
            _11960 = pow(abs(_6453), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.w);
        }
        else
        {
            _11960 = _6453;
        }
        vec4 _6529 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x, g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x * 0.800000011920928955078125, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _6520 = (((_6529 * _6529) * (vec4(3.0) - (_6529 * 2.0))) - vec4(0.5)) * 2.0;
        float _6473 = _6520.y;
        vec2 _6501 = _5239.xz + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xz * (((g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.y * (_6520.x + (_6473 * _6473))) + ((g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchAdherences.x / g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z) * _11958)) * _11960));
        _11991 = (normalize(vec3(_6501.x, _5239.y, _6501.y)) * length(_5424)) - _5424;
    }
    else
    {
        _11991 = vec3(0.0);
    }
    vec3 _11996;
    if (true && (((_6041 || _6044) || _6047) || _6050))
    {
        float _6773 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x + in_windBranchData.y;
        vec4 _6929 = abs((fract(vec4(_6773, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y) + in_windBranchData.y, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y * 0.5) * _6773, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _6920 = (((_6929 * _6929) * (vec4(3.0) - (_6929 * 2.0))) - vec4(0.5)) * 2.0;
        float _6815 = _6920.y * _6920.z;
        bool _6818 = _6815 < 0.0;
        float _11978;
        if (_6818)
        {
            _11978 = -_6815;
        }
        else
        {
            _11978 = _6815;
        }
        float _12040 = _6818 ? (-1.0) : 1.0;
        _11996 = (_5424 + (((((fract(vec3(in_windBranchData.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * in_windBranchData.x) * (((mix(mix(_6815, _12040, _11978), _12040, _11978) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x) * (1.0 - g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.w)) + (_6920.x * (1.0 - g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x)))) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.y)) - _5424;
    }
    else
    {
        _11996 = vec3(0.0);
    }
    vec3 _12002;
    if (_6032 && true)
    {
        vec3 _6163 = _5239.xyz;
        vec3 _12003;
        if ((false || (in_LeafAnchorHint.w > 1.0)) && _6041)
        {
            vec3 _12004;
            if (in_windExtraDataFlag.w > 0.0)
            {
                vec2 _8026 = (vec3(g_rbVertices_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiPositionsBufferIndex].g_rbVertices[_5226].x, -g_rbVertices_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiPositionsBufferIndex].g_rbVertices[_5226].z, _11936).xy - vec2(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.zw)) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
                float _8048 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _8074 = cos(_8026);
                float _8069 = abs(sin((((3.1415927410125732421875 * _8026.x) * _8048) + (_8026.y * _8048)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_8074.x + _8074.y))));
                float _8036 = _8069 * _8069;
                float _8039 = _8036 * _8036;
                float _7948 = _6028 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0;
                vec4 _8134 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Ripple.x + _5747, 0.0, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec3 _8163 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _7978 = in_windExtraDataFlag.x * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _8039), _7948);
                vec3 _8198 = fract((_6163 + vec3(_5747)) * 30.299999237060546875);
                float _8206 = (_8198.x + _8198.y) + _8198.z;
                vec4 _8344 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x + _8206, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x * 0.75) - _8206, _11936, _11936) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8335 = (((_8344 * _8344) * (vec4(3.0) - (_8344 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _8226 = (_5424 + ((_5334 * (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Ripple.y * ((((_8134 * _8134) * (vec4(3.0) - (_8134 * 2.0))) - vec4(0.5)) * 2.0).x)) * (in_windExtraDataFlag.x * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.x, 1.0, _8039), _7948)))) - _6163;
                float _8230 = _8335.x;
                float _8232 = _8335.y;
                float _8241 = (_7978 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.z) * (_8230 + (_8232 * _8232));
                float _8358 = sin(_8241);
                float _8361 = cos(_8241);
                float _8365 = 1.0 - _8361;
                float _8368 = _8163.x;
                float _8369 = _8365 * _8368;
                float _8381 = _8163.y;
                float _8382 = _8369 * _8381;
                float _8386 = _8163.z;
                float _8387 = _8358 * _8386;
                float _8395 = _8369 * _8386;
                float _8400 = _8358 * _8381;
                float _8418 = _8365 * _8381;
                float _8431 = _8418 * _8386;
                float _8436 = _8358 * _8368;
                vec3 _8247 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8163);
                float _8252 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8163), -1.0, 1.0);
                vec3 _11867 = _8247;
                _11867.y = _8247.y + _8252;
                vec3 _8259 = normalize(_11867);
                float _8276 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.z + _8206;
                vec4 _8529 = abs((fract(vec4(_8276 + (_5747 * _5747), (0.87000000476837158203125 * _8276) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8520 = (((_8529 * _8529) * (vec4(3.0) - (_8529 * 2.0))) - vec4(0.5)) * 2.0;
                float _8498 = _8520.y;
                float _8293 = _7978 * (((acos(_8252) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.w) + ((_8232 - (_8230 * _8230)) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.y)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.x * pow(clamp((((_8520.x * _8498) * _8498) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.y)));
                float _8543 = sin(_8293);
                float _8546 = cos(_8293);
                float _8550 = 1.0 - _8546;
                float _8553 = _8259.x;
                float _8554 = _8550 * _8553;
                float _8566 = _8259.y;
                float _8567 = _8554 * _8566;
                float _8571 = _8259.z;
                float _8572 = _8543 * _8571;
                float _8580 = _8554 * _8571;
                float _8585 = _8543 * _8566;
                float _8603 = _8550 * _8566;
                float _8616 = _8603 * _8571;
                float _8621 = _8543 * _8553;
                _12004 = ((((mat3(vec3((_8369 * _8368) + _8361, _8382 - _8387, _8395 + _8400), vec3(_8382 + _8387, (_8418 * _8381) + _8361, _8431 - _8436), vec3(_8395 - _8400, _8431 + _8436, ((_8365 * _8386) * _8386) + _8361)) * mat3(vec3((_8554 * _8553) + _8546, _8567 - _8572, _8580 + _8585), vec3(_8567 + _8572, (_8603 * _8566) + _8546, _8616 - _8621), vec3(_8580 - _8585, _8616 + _8621, ((_8550 * _8571) * _8571) + _8546))) * _8226) * length(_8226)) + _6163) - _5424;
            }
            else
            {
                vec2 _7235 = (vec3(g_rbVertices_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiPositionsBufferIndex].g_rbVertices[_5226].x, -g_rbVertices_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiPositionsBufferIndex].g_rbVertices[_5226].z, _11936).xy - vec2(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.zw)) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
                float _7257 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _7283 = cos(_7235);
                float _7278 = abs(sin((((3.1415927410125732421875 * _7235.x) * _7257) + (_7235.y * _7257)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_7283.x + _7283.y))));
                float _7245 = _7278 * _7278;
                float _7248 = _7245 * _7245;
                float _7157 = _6028 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0;
                vec4 _7343 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Ripple.x + _5747, 0.0, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec3 _7372 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _7187 = in_windExtraDataFlag.x * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _7248), _7157);
                vec3 _7407 = fract((_6163 + vec3(_5747)) * 30.299999237060546875);
                float _7415 = (_7407.x + _7407.y) + _7407.z;
                vec4 _7553 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x + _7415, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x * 0.75) - _7415, _11936, _11936) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7544 = (((_7553 * _7553) * (vec4(3.0) - (_7553 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _7435 = (_5424 + ((_5334 * (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Ripple.y * ((((_7343 * _7343) * (vec4(3.0) - (_7343 * 2.0))) - vec4(0.5)) * 2.0).x)) * (in_windExtraDataFlag.x * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.x, 1.0, _7248), _7157)))) - _6163;
                float _7439 = _7544.x;
                float _7441 = _7544.y;
                float _7450 = (_7187 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.z) * (_7439 + (_7441 * _7441));
                float _7567 = sin(_7450);
                float _7570 = cos(_7450);
                float _7574 = 1.0 - _7570;
                float _7577 = _7372.x;
                float _7578 = _7574 * _7577;
                float _7590 = _7372.y;
                float _7591 = _7578 * _7590;
                float _7595 = _7372.z;
                float _7596 = _7567 * _7595;
                float _7604 = _7578 * _7595;
                float _7609 = _7567 * _7590;
                float _7627 = _7574 * _7590;
                float _7640 = _7627 * _7595;
                float _7645 = _7567 * _7577;
                vec3 _7456 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7372);
                float _7461 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7372), -1.0, 1.0);
                vec3 _11752 = _7456;
                _11752.y = _7456.y + _7461;
                vec3 _7468 = normalize(_11752);
                float _7485 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.z + _7415;
                vec4 _7738 = abs((fract(vec4(_7485 + (_5747 * _5747), (0.87000000476837158203125 * _7485) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7729 = (((_7738 * _7738) * (vec4(3.0) - (_7738 * 2.0))) - vec4(0.5)) * 2.0;
                float _7707 = _7729.y;
                float _7502 = _7187 * (((acos(_7461) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.w) + ((_7441 - (_7439 * _7439)) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.y)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.x * pow(clamp((((_7729.x * _7707) * _7707) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.y)));
                float _7752 = sin(_7502);
                float _7755 = cos(_7502);
                float _7759 = 1.0 - _7755;
                float _7762 = _7468.x;
                float _7763 = _7759 * _7762;
                float _7775 = _7468.y;
                float _7776 = _7763 * _7775;
                float _7780 = _7468.z;
                float _7781 = _7752 * _7780;
                float _7789 = _7763 * _7780;
                float _7794 = _7752 * _7775;
                float _7812 = _7759 * _7775;
                float _7825 = _7812 * _7780;
                float _7830 = _7752 * _7762;
                _12004 = ((((mat3(vec3((_7578 * _7577) + _7570, _7591 - _7596, _7604 + _7609), vec3(_7591 + _7596, (_7627 * _7590) + _7570, _7640 - _7645), vec3(_7604 - _7609, _7640 + _7645, ((_7574 * _7595) * _7595) + _7570)) * mat3(vec3((_7763 * _7762) + _7755, _7776 - _7781, _7789 + _7794), vec3(_7776 + _7781, (_7812 * _7775) + _7755, _7825 - _7830), vec3(_7789 - _7794, _7825 + _7830, ((_7759 * _7780) * _7780) + _7755))) * _7435) * length(_7435)) + _6163) - _5424;
            }
            _12003 = _12004;
        }
        else
        {
            _12003 = vec3(0.0);
        }
        _12002 = _12003;
    }
    else
    {
        _12002 = vec3(0.0);
    }
    vec3 _12008;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 4u)
    {
        _12008 = _5424 + (_11991 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    }
    else
    {
        vec3 _12009;
        if (_6047)
        {
            _12009 = _5424 + ((_11991 + _11996) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
        }
        else
        {
            vec3 _12010;
            if (_6022)
            {
                _12010 = _5424 + (((_11991 + _11996) + _12002) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
            }
            else
            {
                vec3 _12011;
                if (_6050)
                {
                    _12011 = _5424 + (_11991 + (_11996 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                }
                else
                {
                    vec3 _12012;
                    if (_6024)
                    {
                        _12012 = _5424 + (_11991 + ((_11996 + _12002) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                    }
                    else
                    {
                        vec3 _12013;
                        if (_6027)
                        {
                            _12013 = _5424 + ((_11991 + _11996) + (_12002 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                        }
                        else
                        {
                            vec3 _12014;
                            if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 1u)
                            {
                                _12014 = _5424 + _11991;
                            }
                            else
                            {
                                vec3 _12015;
                                if (_6044)
                                {
                                    _12015 = _5424 + (_11991 + _11996);
                                }
                                else
                                {
                                    vec3 _12016;
                                    if (_6032)
                                    {
                                        _12016 = _5424 + ((_11991 + _11996) + _12002);
                                    }
                                    else
                                    {
                                        _12016 = _5424;
                                    }
                                    _12015 = _12016;
                                }
                                _12014 = _12015;
                            }
                            _12013 = _12014;
                        }
                        _12012 = _12013;
                    }
                    _12011 = _12012;
                }
                _12010 = _12011;
            }
            _12009 = _12010;
        }
        _12008 = _12009;
    }
    vec2 _12031;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiSmooth > 0u)
    {
        _12031 = in_lodPosition.xy * mix(in_lodPosition.w, 1.0, g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    }
    else
    {
        _12031 = in_lodPosition.xy;
    }
    float _5860 = -in_lodPosition.z;
    vec3 _5863 = vec3(_12031, _5860);
    vec3 _5866 = _5863 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.w;
    vec4 _5873 = vec4(_12008, 1.0);
    vec4 _5874 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._mModel * _5873;
    float _5879 = _5874.x;
    float _5880 = _5874.y;
    float _5881 = _5874.z;
    vec4 _5882 = vec4(_5879, _5880, _5881, 1.0);
    vec4 _5883 = _3585.g_cbPass._EyeData._mCurrentFrameMatrices[0]._mView * _5882;
    vec3 _5884 = _5883.xyz;
    vec3 _5887 = _5884 + _5866;
    float _5891 = _5887.x;
    float _5892 = _5887.y;
    float _5893 = _5887.z;
    vec4 _5894 = vec4(_5891, _5892, _5893, 1.0);
    vec4 _5895 = _3585.g_cbPass._EyeData._mCurrentFrameMatrices[0]._mInvView * _5894;
    float _5902 = _5895.x;
    float _5903 = _5895.y;
    float _5904 = _5895.z;
    vec4 _5905 = vec4(_5902, _5903, _5904, 1.0);
    vec4 _5906 = _3585.g_cbPass._EyeData._mCurrentFrameMatrices[0]._mViewJitteredProj * _5905;
    vec4 _5927 = _3585.g_cbPass._EyeData._mCurrentFrameMatrices[0]._mView * _5905;
    vec4 _12033;
    if (_3585.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _8691 = _5906.w;
        vec4 _12034;
        if ((_5906.z / _8691) > 1.0)
        {
            vec4 _12035;
            if (_5927.z > _3585.g_cbPass._fNearPlane)
            {
                vec4 _11926 = _5906;
                _11926.z = _8691;
                _12035 = _11926;
            }
            else
            {
                _12035 = _5906;
            }
            _12034 = _12035;
        }
        else
        {
            _12034 = _5906;
        }
        _12033 = _12034;
    }
    else
    {
        _12033 = _5906;
    }
    interp_instanceID = float(_3329) + 0.5;
    float _5106 = _5927.x;
    float _5107 = _5927.y;
    float _5108 = _5927.z;
    vec4 _5109 = vec4(_5106, _5107, _5108, 1.0);
    float _5110 = dot(_3585.g_cbPass._vfVsClippingPlane[0], _5109);
    float _5111 = -_5110;
    gl_ClipDistance[0] = _5111;
    interp_uv0 = in_uv0;
    interp_vfVsPosition = _5927.xyz;
    interp_vfVsTangent = mat3(_426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView[0].xyz, _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView[1].xyz, _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _5538;
    interp_vfVsBinormal = mat3(_426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView[0].xyz, _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView[1].xyz, _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView[2].xyz) * (cross(_5334, _5538) * ((_5407 != 0.0) ? (-1.0) : 1.0));
    interp_vfVsNormal = mat3(_426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView[0].xyz, _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView[1].xyz, _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _5334;
    gl_Position = _12033;
}

