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

vec3 _12567;
float _12568;

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;
    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 _12569;
    if (_5275 > 512)
    {
        _12569 = _5275 | (-1024);
    }
    else
    {
        _12569 = _5275;
    }
    int _12571;
    if (_5278 > 512)
    {
        _12571 = _5278 | (-1024);
    }
    else
    {
        _12571 = _5278;
    }
    int _12573;
    if (_5281 > 512)
    {
        _12573 = _5281 | (-1024);
    }
    else
    {
        _12573 = _5281;
    }
    vec3 _5334 = vec3(float(_12569), float(_12571), float(_12573)) * 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 _12575;
    if (_5343 > 512)
    {
        _12575 = _5343 | (-1024);
    }
    else
    {
        _12575 = _5343;
    }
    int _12577;
    if (_5346 > 512)
    {
        _12577 = _5346 | (-1024);
    }
    else
    {
        _12577 = _5346;
    }
    int _12579;
    if (_5349 > 512)
    {
        _12579 = _5349 | (-1024);
    }
    else
    {
        _12579 = _5349;
    }
    float _5407 = float((g_rbTBNs_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5246]._iTangent >> 30) != 0);
    vec3 _5424 = 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).xyz;
    vec3 _5538 = vec4(vec3(float(_12575), float(_12577), float(_12579)) * vec3(0.001956947147846221923828125), _5407).xyz;
    float _5747 = (((100.0 * in_LeafAnchorHint.x) + in_LeafAnchorHint.y) + in_lodPosition.x) + in_lodPosition.y;
    vec3 _12588;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiSmooth > 0u)
    {
        _12588 = mix(in_lodPosition.xyz, _5424, vec3(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
    }
    else
    {
        _12588 = _5424;
    }
    bool _5943 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 6u;
    bool _5945 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 8u;
    bool _5948 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 9u;
    bool _5949 = (_5943 || _5945) || _5948;
    bool _5953 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 3u;
    bool _5962 = ((_5953 || _5943) || _5945) || _5948;
    bool _5965 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 2u;
    bool _5968 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 5u;
    bool _5971 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 7u;
    float _12596;
    if (true && _5953)
    {
        vec2 _6297 = ((_12588.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 _6319 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
        vec2 _6345 = cos(_6297);
        float _6340 = abs(sin((((3.1415927410125732421875 * _6297.x) * _6319) + (_6297.y * _6319)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_6345.x + _6345.y))));
        float _6307 = _6340 * _6340;
        float _5990 = mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.y, 1.0, _6307 * _6307);
        float _12597;
        if (_5949)
        {
            _12597 = _5990 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
        }
        else
        {
            _12597 = _5990;
        }
        _12596 = _12597;
    }
    else
    {
        _12596 = 0.0;
    }
    vec3 _12649;
    if (true && (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD != 0u))
    {
        float _6374 = max(_12588.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 _12598;
        if (_6374 != 0.0)
        {
            _12598 = pow(abs(_6374), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.w);
        }
        else
        {
            _12598 = _6374;
        }
        vec4 _6450 = 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 _6441 = (((_6450 * _6450) * (vec4(3.0) - (_6450 * 2.0))) - vec4(0.5)) * 2.0;
        float _6394 = _6441.y;
        vec2 _6422 = _12588.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 * (_6441.x + (_6394 * _6394))) + ((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) * _12596)) * _12598));
        _12649 = (normalize(vec3(_6422.x, _12588.y, _6422.y)) * length(_12588)) - _12588;
    }
    else
    {
        _12649 = vec3(0.0);
    }
    vec3 _12655;
    if (true && (((_5962 || _5965) || _5968) || _5971))
    {
        float _6724 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x + in_windBranchData.y;
        vec4 _6891 = abs((fract(vec4(_6724, (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) * _6724, _6724 + (1.0 - in_windBranchData.x)) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _6882 = (((_6891 * _6891) * (vec4(3.0) - (_6891 * 2.0))) - vec4(0.5)) * 2.0;
        float _6750 = _6882.y * _6882.z;
        bool _6753 = _6750 < 0.0;
        float _12617;
        if (_6753)
        {
            _12617 = -_6750;
        }
        else
        {
            _12617 = _6750;
        }
        float _12882 = _6753 ? (-1.0) : 1.0;
        float _6773 = 1.0 - g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.w;
        float _7019 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.z + in_windBranchData.w;
        vec4 _7175 = abs((fract(vec4(_7019, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.z * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.w) + in_windBranchData.w, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.w * 0.5) * _7019, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _7166 = (((_7175 * _7175) * (vec4(3.0) - (_7175 * 2.0))) - vec4(0.5)) * 2.0;
        float _7061 = _7166.y * _7166.z;
        bool _7064 = _7061 < 0.0;
        float _12634;
        if (_7064)
        {
            _12634 = -_7061;
        }
        else
        {
            _12634 = _7061;
        }
        float _12883 = _7064 ? (-1.0) : 1.0;
        _12655 = ((_12588 + (((((fract(vec3(in_windBranchData.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * in_windBranchData.x) * ((((mix(mix(_6750, _12882, _12617), _12882, _12617) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x) * _6773) + (_6882.x * (1.0 - g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x))) * (1.0 + ((_6882.w * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchWhipTurbulences.x) * in_windBranchData.x)))) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.y)) + (((((fract(vec3(in_windBranchData.w) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * in_windBranchData.z) * (((mix(mix(_7061, _12883, _12634), _12883, _12634) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.z) * _6773) + (_7166.x * (1.0 - g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.z)))) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.w)) - _12588;
    }
    else
    {
        _12655 = vec3(0.0);
    }
    vec3 _12661;
    if (_5953 && true)
    {
        vec3 _12662;
        if (true && _5962)
        {
            vec3 _12663;
            if (in_windExtraDataFlag.w > 0.0)
            {
                vec2 _8262 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12568).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 _8284 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _8310 = cos(_8262);
                float _8305 = abs(sin((((3.1415927410125732421875 * _8262.x) * _8284) + (_8262.y * _8284)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_8310.x + _8310.y))));
                float _8272 = _8305 * _8305;
                vec3 _8326 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _8214 = in_windExtraDataFlag.x * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _8272 * _8272), _5949 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0);
                vec3 _8361 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5747)) * 30.299999237060546875);
                float _8369 = (_8361.x + _8361.y) + _8361.z;
                vec4 _8508 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x + _8369, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x * 0.75) - _8369, _12568, _12568) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8499 = (((_8508 * _8508) * (vec4(3.0) - (_8508 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _8389 = _12588 - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
                float _8393 = _8499.x;
                float _8395 = _8499.y;
                float _8404 = (_8214 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.z) * (_8393 + (_8395 * _8395));
                float _8522 = sin(_8404);
                float _8525 = cos(_8404);
                float _8529 = 1.0 - _8525;
                float _8532 = _8326.x;
                float _8533 = _8529 * _8532;
                float _8545 = _8326.y;
                float _8546 = _8533 * _8545;
                float _8550 = _8326.z;
                float _8551 = _8522 * _8550;
                float _8559 = _8533 * _8550;
                float _8564 = _8522 * _8545;
                float _8582 = _8529 * _8545;
                float _8595 = _8582 * _8550;
                float _8600 = _8522 * _8532;
                vec3 _8410 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8326);
                float _8415 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8326), -1.0, 1.0);
                vec3 _12502 = _8410;
                _12502.y = _8410.y + _8415;
                vec3 _8422 = normalize(_12502);
                float _8439 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.z + _8369;
                vec4 _8693 = abs((fract(vec4(_8439 + (_5747 * _5747), (0.87000000476837158203125 * _8439) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8684 = (((_8693 * _8693) * (vec4(3.0) - (_8693 * 2.0))) - vec4(0.5)) * 2.0;
                float _8662 = _8684.y;
                float _8456 = _8214 * (((acos(_8415) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.w) + ((_8395 - (_8393 * _8393)) * 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((((_8684.x * _8662) * _8662) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.y)));
                float _8707 = sin(_8456);
                float _8710 = cos(_8456);
                float _8714 = 1.0 - _8710;
                float _8717 = _8422.x;
                float _8718 = _8714 * _8717;
                float _8730 = _8422.y;
                float _8731 = _8718 * _8730;
                float _8735 = _8422.z;
                float _8736 = _8707 * _8735;
                float _8744 = _8718 * _8735;
                float _8749 = _8707 * _8730;
                float _8767 = _8714 * _8730;
                float _8780 = _8767 * _8735;
                float _8785 = _8707 * _8717;
                _12663 = ((normalize((mat3(vec3((_8533 * _8532) + _8525, _8546 - _8551, _8559 + _8564), vec3(_8546 + _8551, (_8582 * _8545) + _8525, _8595 - _8600), vec3(_8559 - _8564, _8595 + _8600, ((_8529 * _8550) * _8550) + _8525)) * mat3(vec3((_8718 * _8717) + _8710, _8731 - _8736, _8744 + _8749), vec3(_8731 + _8736, (_8767 * _8730) + _8710, _8780 - _8785), vec3(_8744 - _8749, _8780 + _8785, ((_8714 * _8735) * _8735) + _8710))) * _8389) * length(_8389)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _12588;
            }
            else
            {
                vec2 _7481 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12568).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 _7503 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _7529 = cos(_7481);
                float _7524 = abs(sin((((3.1415927410125732421875 * _7481.x) * _7503) + (_7481.y * _7503)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_7529.x + _7529.y))));
                float _7491 = _7524 * _7524;
                float _7494 = _7491 * _7491;
                float _7403 = _5949 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0;
                vec4 _7589 = 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 _7618 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _7433 = in_windExtraDataFlag.x * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _7494), _7403);
                vec3 _7653 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5747)) * 30.299999237060546875);
                float _7661 = (_7653.x + _7653.y) + _7653.z;
                vec4 _7800 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x + _7661, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x * 0.75) - _7661, _12568, _12568) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7791 = (((_7800 * _7800) * (vec4(3.0) - (_7800 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _7681 = (_12588 + ((_5334 * (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Ripple.y * ((((_7589 * _7589) * (vec4(3.0) - (_7589 * 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, _7494), _7403)))) - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
                float _7685 = _7791.x;
                float _7687 = _7791.y;
                float _7696 = (_7433 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.z) * (_7685 + (_7687 * _7687));
                float _7814 = sin(_7696);
                float _7817 = cos(_7696);
                float _7821 = 1.0 - _7817;
                float _7824 = _7618.x;
                float _7825 = _7821 * _7824;
                float _7837 = _7618.y;
                float _7838 = _7825 * _7837;
                float _7842 = _7618.z;
                float _7843 = _7814 * _7842;
                float _7851 = _7825 * _7842;
                float _7856 = _7814 * _7837;
                float _7874 = _7821 * _7837;
                float _7887 = _7874 * _7842;
                float _7892 = _7814 * _7824;
                vec3 _7702 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7618);
                float _7707 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7618), -1.0, 1.0);
                vec3 _12389 = _7702;
                _12389.y = _7702.y + _7707;
                vec3 _7714 = normalize(_12389);
                float _7731 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.z + _7661;
                vec4 _7985 = abs((fract(vec4(_7731 + (_5747 * _5747), (0.87000000476837158203125 * _7731) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7976 = (((_7985 * _7985) * (vec4(3.0) - (_7985 * 2.0))) - vec4(0.5)) * 2.0;
                float _7954 = _7976.y;
                float _7748 = _7433 * (((acos(_7707) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.w) + ((_7687 - (_7685 * _7685)) * 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((((_7976.x * _7954) * _7954) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.y)));
                float _7999 = sin(_7748);
                float _8002 = cos(_7748);
                float _8006 = 1.0 - _8002;
                float _8009 = _7714.x;
                float _8010 = _8006 * _8009;
                float _8022 = _7714.y;
                float _8023 = _8010 * _8022;
                float _8027 = _7714.z;
                float _8028 = _7999 * _8027;
                float _8036 = _8010 * _8027;
                float _8041 = _7999 * _8022;
                float _8059 = _8006 * _8022;
                float _8072 = _8059 * _8027;
                float _8077 = _7999 * _8009;
                _12663 = ((normalize((mat3(vec3((_7825 * _7824) + _7817, _7838 - _7843, _7851 + _7856), vec3(_7838 + _7843, (_7874 * _7837) + _7817, _7887 - _7892), vec3(_7851 - _7856, _7887 + _7892, ((_7821 * _7842) * _7842) + _7817)) * mat3(vec3((_8010 * _8009) + _8002, _8023 - _8028, _8036 + _8041), vec3(_8023 + _8028, (_8059 * _8022) + _8002, _8072 - _8077), vec3(_8036 - _8041, _8072 + _8077, ((_8006 * _8027) * _8027) + _8002))) * _7681) * length(_7681)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _12588;
            }
            _12662 = _12663;
        }
        else
        {
            _12662 = vec3(0.0);
        }
        _12661 = _12662;
    }
    else
    {
        _12661 = vec3(0.0);
    }
    vec3 _12667;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 4u)
    {
        _12667 = _12588 + (_12649 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    }
    else
    {
        vec3 _12668;
        if (_5968)
        {
            _12668 = _12588 + ((_12649 + _12655) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
        }
        else
        {
            vec3 _12669;
            if (_5943)
            {
                _12669 = _12588 + (((_12649 + _12655) + _12661) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
            }
            else
            {
                vec3 _12670;
                if (_5971)
                {
                    _12670 = _12588 + (_12649 + (_12655 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                }
                else
                {
                    vec3 _12671;
                    if (_5945)
                    {
                        _12671 = _12588 + (_12649 + ((_12655 + _12661) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                    }
                    else
                    {
                        vec3 _12672;
                        if (_5948)
                        {
                            _12672 = _12588 + ((_12649 + _12655) + (_12661 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                        }
                        else
                        {
                            vec3 _12673;
                            if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 1u)
                            {
                                _12673 = _12588 + _12649;
                            }
                            else
                            {
                                vec3 _12674;
                                if (_5965)
                                {
                                    _12674 = _12588 + (_12649 + _12655);
                                }
                                else
                                {
                                    vec3 _12675;
                                    if (_5953)
                                    {
                                        _12675 = _12588 + ((_12649 + _12655) + _12661);
                                    }
                                    else
                                    {
                                        _12675 = _12588;
                                    }
                                    _12674 = _12675;
                                }
                                _12673 = _12674;
                            }
                            _12672 = _12673;
                        }
                        _12671 = _12672;
                    }
                    _12670 = _12671;
                }
                _12669 = _12670;
            }
            _12668 = _12669;
        }
        _12667 = _12668;
    }
    vec4 _8882 = vec4(_12667, 1.0);
    vec4 _8883 = _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView * _8882;
    vec4 _8902 = _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelViewProj * _8882;
    vec4 _12875;
    if (_3585.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _8936 = _8902.w;
        vec4 _12876;
        if ((_8902.z / _8936) > 1.0)
        {
            vec4 _12877;
            if (_8883.z > _3585.g_cbPass._fNearPlane)
            {
                vec4 _12557 = _8902;
                _12557.z = _8936;
                _12877 = _12557;
            }
            else
            {
                _12877 = _8902;
            }
            _12876 = _12877;
        }
        else
        {
            _12876 = _8902;
        }
        _12875 = _12876;
    }
    else
    {
        _12875 = _8902;
    }
    interp_instanceID = float(_3329) + 0.5;
    float _5106 = _8883.x;
    float _5107 = _8883.y;
    float _5108 = _8883.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 = _8883.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 = _12875;
}

