
// 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 _12312;
float _12313;

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 _12314;
    if (_5275 > 512)
    {
        _12314 = _5275 | (-1024);
    }
    else
    {
        _12314 = _5275;
    }
    int _12316;
    if (_5278 > 512)
    {
        _12316 = _5278 | (-1024);
    }
    else
    {
        _12316 = _5278;
    }
    int _12318;
    if (_5281 > 512)
    {
        _12318 = _5281 | (-1024);
    }
    else
    {
        _12318 = _5281;
    }
    vec3 _5334 = vec3(float(_12314), float(_12316), float(_12318)) * 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 _12320;
    if (_5343 > 512)
    {
        _12320 = _5343 | (-1024);
    }
    else
    {
        _12320 = _5343;
    }
    int _12322;
    if (_5346 > 512)
    {
        _12322 = _5346 | (-1024);
    }
    else
    {
        _12322 = _5346;
    }
    int _12324;
    if (_5349 > 512)
    {
        _12324 = _5349 | (-1024);
    }
    else
    {
        _12324 = _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(_12320), float(_12322), float(_12324)) * vec3(0.001956947147846221923828125), _5407).xyz;
    float _5747 = (((100.0 * in_LeafAnchorHint.x) + in_LeafAnchorHint.y) + in_lodPosition.x) + in_lodPosition.y;
    vec3 _12333;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiSmooth > 0u)
    {
        _12333 = mix(in_lodPosition.xyz, _5424, vec3(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
    }
    else
    {
        _12333 = _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 _12341;
    if (true && _5953)
    {
        vec2 _6297 = ((_12333.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 _12342;
        if (_5949)
        {
            _12342 = _5990 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
        }
        else
        {
            _12342 = _5990;
        }
        _12341 = _12342;
    }
    else
    {
        _12341 = 0.0;
    }
    vec3 _12375;
    if (true && (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD != 0u))
    {
        float _6374 = max(_12333.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 _12343;
        if (_6374 != 0.0)
        {
            _12343 = pow(abs(_6374), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.w);
        }
        else
        {
            _12343 = _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 = _12333.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) * _12341)) * _12343));
        _12375 = (normalize(vec3(_6422.x, _12333.y, _6422.y)) * length(_12333)) - _12333;
    }
    else
    {
        _12375 = vec3(0.0);
    }
    vec3 _12380;
    if (true && (((_5962 || _5965) || _5968) || _5971))
    {
        float _6694 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x + in_windBranchData.y;
        vec4 _6850 = abs((fract(vec4(_6694, (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) * _6694, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _6841 = (((_6850 * _6850) * (vec4(3.0) - (_6850 * 2.0))) - vec4(0.5)) * 2.0;
        float _6736 = _6841.y * _6841.z;
        bool _6739 = _6736 < 0.0;
        float _12362;
        if (_6739)
        {
            _12362 = -_6736;
        }
        else
        {
            _12362 = _6736;
        }
        float _12598 = _6739 ? (-1.0) : 1.0;
        _12380 = (_12333 + (((((fract(vec3(in_windBranchData.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * in_windBranchData.x) * (((mix(mix(_6736, _12598, _12362), _12598, _12362) * 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)) + (_6841.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)) - _12333;
    }
    else
    {
        _12380 = vec3(0.0);
    }
    vec3 _12386;
    if (_5953 && true)
    {
        vec3 _12387;
        if (true && _5962)
        {
            vec3 _12388;
            if (in_windExtraDataFlag.w > 0.0)
            {
                vec2 _7948 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12313).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 _7970 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _7996 = cos(_7948);
                float _7991 = abs(sin((((3.1415927410125732421875 * _7948.x) * _7970) + (_7948.y * _7970)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_7996.x + _7996.y))));
                float _7958 = _7991 * _7991;
                float _7961 = _7958 * _7958;
                float _7870 = _5949 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0;
                vec4 _8056 = 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 _8085 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _7900 = in_windExtraDataFlag.x * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _7961), _7870);
                vec3 _8120 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5747)) * 30.299999237060546875);
                float _8128 = (_8120.x + _8120.y) + _8120.z;
                vec4 _8267 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x + _8128, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x * 0.75) - _8128, _12313, _12313) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8258 = (((_8267 * _8267) * (vec4(3.0) - (_8267 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _8148 = (_12333 + ((_5334 * (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Ripple.y * ((((_8056 * _8056) * (vec4(3.0) - (_8056 * 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, _7961), _7870)))) - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
                float _8152 = _8258.x;
                float _8154 = _8258.y;
                float _8163 = (_7900 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.z) * (_8152 + (_8154 * _8154));
                float _8281 = sin(_8163);
                float _8284 = cos(_8163);
                float _8288 = 1.0 - _8284;
                float _8291 = _8085.x;
                float _8292 = _8288 * _8291;
                float _8304 = _8085.y;
                float _8305 = _8292 * _8304;
                float _8309 = _8085.z;
                float _8310 = _8281 * _8309;
                float _8318 = _8292 * _8309;
                float _8323 = _8281 * _8304;
                float _8341 = _8288 * _8304;
                float _8354 = _8341 * _8309;
                float _8359 = _8281 * _8291;
                vec3 _8169 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8085);
                float _8174 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8085), -1.0, 1.0);
                vec3 _12247 = _8169;
                _12247.y = _8169.y + _8174;
                vec3 _8181 = normalize(_12247);
                float _8198 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.z + _8128;
                vec4 _8452 = abs((fract(vec4(_8198 + (_5747 * _5747), (0.87000000476837158203125 * _8198) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8443 = (((_8452 * _8452) * (vec4(3.0) - (_8452 * 2.0))) - vec4(0.5)) * 2.0;
                float _8421 = _8443.y;
                float _8215 = _7900 * (((acos(_8174) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.w) + ((_8154 - (_8152 * _8152)) * 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((((_8443.x * _8421) * _8421) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.y)));
                float _8466 = sin(_8215);
                float _8469 = cos(_8215);
                float _8473 = 1.0 - _8469;
                float _8476 = _8181.x;
                float _8477 = _8473 * _8476;
                float _8489 = _8181.y;
                float _8490 = _8477 * _8489;
                float _8494 = _8181.z;
                float _8495 = _8466 * _8494;
                float _8503 = _8477 * _8494;
                float _8508 = _8466 * _8489;
                float _8526 = _8473 * _8489;
                float _8539 = _8526 * _8494;
                float _8544 = _8466 * _8476;
                _12388 = ((normalize((mat3(vec3((_8292 * _8291) + _8284, _8305 - _8310, _8318 + _8323), vec3(_8305 + _8310, (_8341 * _8304) + _8284, _8354 - _8359), vec3(_8318 - _8323, _8354 + _8359, ((_8288 * _8309) * _8309) + _8284)) * mat3(vec3((_8477 * _8476) + _8469, _8490 - _8495, _8503 + _8508), vec3(_8490 + _8495, (_8526 * _8489) + _8469, _8539 - _8544), vec3(_8503 - _8508, _8539 + _8544, ((_8473 * _8494) * _8494) + _8469))) * _8148) * length(_8148)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _12333;
            }
            else
            {
                vec2 _7156 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12313).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 _7178 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _7204 = cos(_7156);
                float _7199 = abs(sin((((3.1415927410125732421875 * _7156.x) * _7178) + (_7156.y * _7178)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_7204.x + _7204.y))));
                float _7166 = _7199 * _7199;
                float _7169 = _7166 * _7166;
                float _7078 = _5949 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0;
                vec4 _7264 = 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 _7293 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _7108 = in_windExtraDataFlag.x * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _7169), _7078);
                vec3 _7328 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5747)) * 30.299999237060546875);
                float _7336 = (_7328.x + _7328.y) + _7328.z;
                vec4 _7475 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x + _7336, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x * 0.75) - _7336, _12313, _12313) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7466 = (((_7475 * _7475) * (vec4(3.0) - (_7475 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _7356 = (_12333 + ((_5334 * (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Ripple.y * ((((_7264 * _7264) * (vec4(3.0) - (_7264 * 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, _7169), _7078)))) - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
                float _7360 = _7466.x;
                float _7362 = _7466.y;
                float _7371 = (_7108 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.z) * (_7360 + (_7362 * _7362));
                float _7489 = sin(_7371);
                float _7492 = cos(_7371);
                float _7496 = 1.0 - _7492;
                float _7499 = _7293.x;
                float _7500 = _7496 * _7499;
                float _7512 = _7293.y;
                float _7513 = _7500 * _7512;
                float _7517 = _7293.z;
                float _7518 = _7489 * _7517;
                float _7526 = _7500 * _7517;
                float _7531 = _7489 * _7512;
                float _7549 = _7496 * _7512;
                float _7562 = _7549 * _7517;
                float _7567 = _7489 * _7499;
                vec3 _7377 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7293);
                float _7382 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7293), -1.0, 1.0);
                vec3 _12132 = _7377;
                _12132.y = _7377.y + _7382;
                vec3 _7389 = normalize(_12132);
                float _7406 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.z + _7336;
                vec4 _7660 = abs((fract(vec4(_7406 + (_5747 * _5747), (0.87000000476837158203125 * _7406) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7651 = (((_7660 * _7660) * (vec4(3.0) - (_7660 * 2.0))) - vec4(0.5)) * 2.0;
                float _7629 = _7651.y;
                float _7423 = _7108 * (((acos(_7382) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.w) + ((_7362 - (_7360 * _7360)) * 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((((_7651.x * _7629) * _7629) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.y)));
                float _7674 = sin(_7423);
                float _7677 = cos(_7423);
                float _7681 = 1.0 - _7677;
                float _7684 = _7389.x;
                float _7685 = _7681 * _7684;
                float _7697 = _7389.y;
                float _7698 = _7685 * _7697;
                float _7702 = _7389.z;
                float _7703 = _7674 * _7702;
                float _7711 = _7685 * _7702;
                float _7716 = _7674 * _7697;
                float _7734 = _7681 * _7697;
                float _7747 = _7734 * _7702;
                float _7752 = _7674 * _7684;
                _12388 = ((normalize((mat3(vec3((_7500 * _7499) + _7492, _7513 - _7518, _7526 + _7531), vec3(_7513 + _7518, (_7549 * _7512) + _7492, _7562 - _7567), vec3(_7526 - _7531, _7562 + _7567, ((_7496 * _7517) * _7517) + _7492)) * mat3(vec3((_7685 * _7684) + _7677, _7698 - _7703, _7711 + _7716), vec3(_7698 + _7703, (_7734 * _7697) + _7677, _7747 - _7752), vec3(_7711 - _7716, _7747 + _7752, ((_7681 * _7702) * _7702) + _7677))) * _7356) * length(_7356)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _12333;
            }
            _12387 = _12388;
        }
        else
        {
            _12387 = vec3(0.0);
        }
        _12386 = _12387;
    }
    else
    {
        _12386 = vec3(0.0);
    }
    vec3 _12392;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 4u)
    {
        _12392 = _12333 + (_12375 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    }
    else
    {
        vec3 _12393;
        if (_5968)
        {
            _12393 = _12333 + ((_12375 + _12380) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
        }
        else
        {
            vec3 _12394;
            if (_5943)
            {
                _12394 = _12333 + (((_12375 + _12380) + _12386) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
            }
            else
            {
                vec3 _12395;
                if (_5971)
                {
                    _12395 = _12333 + (_12375 + (_12380 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                }
                else
                {
                    vec3 _12396;
                    if (_5945)
                    {
                        _12396 = _12333 + (_12375 + ((_12380 + _12386) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                    }
                    else
                    {
                        vec3 _12397;
                        if (_5948)
                        {
                            _12397 = _12333 + ((_12375 + _12380) + (_12386 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                        }
                        else
                        {
                            vec3 _12398;
                            if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 1u)
                            {
                                _12398 = _12333 + _12375;
                            }
                            else
                            {
                                vec3 _12399;
                                if (_5965)
                                {
                                    _12399 = _12333 + (_12375 + _12380);
                                }
                                else
                                {
                                    vec3 _12400;
                                    if (_5953)
                                    {
                                        _12400 = _12333 + ((_12375 + _12380) + _12386);
                                    }
                                    else
                                    {
                                        _12400 = _12333;
                                    }
                                    _12399 = _12400;
                                }
                                _12398 = _12399;
                            }
                            _12397 = _12398;
                        }
                        _12396 = _12397;
                    }
                    _12395 = _12396;
                }
                _12394 = _12395;
            }
            _12393 = _12394;
        }
        _12392 = _12393;
    }
    vec4 _8641 = vec4(_12392, 1.0);
    vec4 _8642 = _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView * _8641;
    vec4 _8661 = _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelViewProj * _8641;
    vec4 _12591;
    if (_3585.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _8695 = _8661.w;
        vec4 _12592;
        if ((_8661.z / _8695) > 1.0)
        {
            vec4 _12593;
            if (_8642.z > _3585.g_cbPass._fNearPlane)
            {
                vec4 _12302 = _8661;
                _12302.z = _8695;
                _12593 = _12302;
            }
            else
            {
                _12593 = _8661;
            }
            _12592 = _12593;
        }
        else
        {
            _12592 = _8661;
        }
        _12591 = _12592;
    }
    else
    {
        _12591 = _8661;
    }
    interp_instanceID = float(_3329) + 0.5;
    float _5106 = _8642.x;
    float _5107 = _8642.y;
    float _5108 = _8642.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 = _8642.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 = _12591;
}

