
// 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 _12697;
float _12698;

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 _12699;
    if (_5275 > 512)
    {
        _12699 = _5275 | (-1024);
    }
    else
    {
        _12699 = _5275;
    }
    int _12701;
    if (_5278 > 512)
    {
        _12701 = _5278 | (-1024);
    }
    else
    {
        _12701 = _5278;
    }
    int _12703;
    if (_5281 > 512)
    {
        _12703 = _5281 | (-1024);
    }
    else
    {
        _12703 = _5281;
    }
    vec3 _5334 = vec3(float(_12699), float(_12701), float(_12703)) * 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 _12705;
    if (_5343 > 512)
    {
        _12705 = _5343 | (-1024);
    }
    else
    {
        _12705 = _5343;
    }
    int _12707;
    if (_5346 > 512)
    {
        _12707 = _5346 | (-1024);
    }
    else
    {
        _12707 = _5346;
    }
    int _12709;
    if (_5349 > 512)
    {
        _12709 = _5349 | (-1024);
    }
    else
    {
        _12709 = _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(_12705), float(_12707), float(_12709)) * vec3(0.001956947147846221923828125), _5407).xyz;
    float _5747 = (((100.0 * in_LeafAnchorHint.x) + in_LeafAnchorHint.y) + in_lodPosition.x) + in_lodPosition.y;
    vec3 _12718;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiSmooth > 0u)
    {
        _12718 = mix(in_lodPosition.xyz, _5424, vec3(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
    }
    else
    {
        _12718 = _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 _12726;
    if (true && _5953)
    {
        vec2 _6297 = ((_12718.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 _12727;
        if (_5949)
        {
            _12727 = _5990 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
        }
        else
        {
            _12727 = _5990;
        }
        _12726 = _12727;
    }
    else
    {
        _12726 = 0.0;
    }
    vec3 _12779;
    if (true && (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD != 0u))
    {
        float _6374 = max(_12718.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 _12728;
        if (_6374 != 0.0)
        {
            _12728 = pow(abs(_6374), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.w);
        }
        else
        {
            _12728 = _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 = _12718.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) * _12726)) * _12728));
        _12779 = (normalize(vec3(_6422.x, _12718.y, _6422.y)) * length(_12718)) - _12718;
    }
    else
    {
        _12779 = vec3(0.0);
    }
    vec3 _12785;
    if (true && (((_5962 || _5965) || _5968) || _5971))
    {
        float _6708 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x + in_windBranchData.y;
        vec4 _6864 = abs((fract(vec4(_6708, (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) * _6708, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _6855 = (((_6864 * _6864) * (vec4(3.0) - (_6864 * 2.0))) - vec4(0.5)) * 2.0;
        float _6750 = _6855.y * _6855.z;
        bool _6753 = _6750 < 0.0;
        float _12747;
        if (_6753)
        {
            _12747 = -_6750;
        }
        else
        {
            _12747 = _6750;
        }
        float _13012 = _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 _12764;
        if (_7064)
        {
            _12764 = -_7061;
        }
        else
        {
            _12764 = _7061;
        }
        float _13013 = _7064 ? (-1.0) : 1.0;
        _12785 = ((_12718 + (((((fract(vec3(in_windBranchData.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * in_windBranchData.x) * (((mix(mix(_6750, _13012, _12747), _13012, _12747) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x) * _6773) + (_6855.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)) + (((((fract(vec3(in_windBranchData.w) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * in_windBranchData.z) * (((mix(mix(_7061, _13013, _12764), _13013, _12764) * 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)) - _12718;
    }
    else
    {
        _12785 = vec3(0.0);
    }
    vec3 _12791;
    if (_5953 && true)
    {
        vec3 _12792;
        if (true && _5962)
        {
            vec3 _12793;
            if (in_windExtraDataFlag.w > 0.0)
            {
                float _8219 = in_windExtraDataFlag.x * mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Ripple.z, 1.0, (dot(-normalize(in_LeafAnchorHint.xz), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xy) + 1.0) * 0.5);
                vec2 _8315 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12698).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 _8337 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _8363 = cos(_8315);
                float _8358 = abs(sin((((3.1415927410125732421875 * _8315.x) * _8337) + (_8315.y * _8337)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_8363.x + _8363.y))));
                float _8325 = _8358 * _8358;
                float _8328 = _8325 * _8325;
                float _8235 = _5949 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0;
                vec4 _8423 = 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 _8452 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _8267 = _8219 * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _8328), _8235);
                vec3 _8487 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5747)) * 30.299999237060546875);
                float _8495 = (_8487.x + _8487.y) + _8487.z;
                vec4 _8634 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x + _8495, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x * 0.75) - _8495, _12698, _12698) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8625 = (((_8634 * _8634) * (vec4(3.0) - (_8634 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _8515 = (_12718 + ((((fract(vec3(in_windExtraDataFlag.z) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Ripple.y * ((((_8423 * _8423) * (vec4(3.0) - (_8423 * 2.0))) - vec4(0.5)) * 2.0).x)) * (_8219 * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.x, 1.0, _8328), _8235)))) - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
                float _8519 = _8625.x;
                float _8521 = _8625.y;
                float _8530 = (_8267 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.z) * (_8519 + (_8521 * _8521));
                float _8648 = sin(_8530);
                float _8651 = cos(_8530);
                float _8655 = 1.0 - _8651;
                float _8658 = _8452.x;
                float _8659 = _8655 * _8658;
                float _8671 = _8452.y;
                float _8672 = _8659 * _8671;
                float _8676 = _8452.z;
                float _8677 = _8648 * _8676;
                float _8685 = _8659 * _8676;
                float _8690 = _8648 * _8671;
                float _8708 = _8655 * _8671;
                float _8721 = _8708 * _8676;
                float _8726 = _8648 * _8658;
                vec3 _8536 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8452);
                float _8541 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8452), -1.0, 1.0);
                vec3 _12632 = _8536;
                _12632.y = _8536.y + _8541;
                vec3 _8548 = normalize(_12632);
                float _8565 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.z + _8495;
                vec4 _8819 = abs((fract(vec4(_8565 + (_5747 * _5747), (0.87000000476837158203125 * _8565) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8810 = (((_8819 * _8819) * (vec4(3.0) - (_8819 * 2.0))) - vec4(0.5)) * 2.0;
                float _8788 = _8810.y;
                float _8582 = _8267 * (((acos(_8541) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.w) + ((_8521 - (_8519 * _8519)) * 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((((_8810.x * _8788) * _8788) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.y)));
                float _8833 = sin(_8582);
                float _8836 = cos(_8582);
                float _8840 = 1.0 - _8836;
                float _8843 = _8548.x;
                float _8844 = _8840 * _8843;
                float _8856 = _8548.y;
                float _8857 = _8844 * _8856;
                float _8861 = _8548.z;
                float _8862 = _8833 * _8861;
                float _8870 = _8844 * _8861;
                float _8875 = _8833 * _8856;
                float _8893 = _8840 * _8856;
                float _8906 = _8893 * _8861;
                float _8911 = _8833 * _8843;
                _12793 = ((normalize((mat3(vec3((_8659 * _8658) + _8651, _8672 - _8677, _8685 + _8690), vec3(_8672 + _8677, (_8708 * _8671) + _8651, _8721 - _8726), vec3(_8685 - _8690, _8721 + _8726, ((_8655 * _8676) * _8676) + _8651)) * mat3(vec3((_8844 * _8843) + _8836, _8857 - _8862, _8870 + _8875), vec3(_8857 + _8862, (_8893 * _8856) + _8836, _8906 - _8911), vec3(_8870 - _8875, _8906 + _8911, ((_8840 * _8861) * _8861) + _8836))) * _8515) * length(_8515)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _12718;
            }
            else
            {
                float _7406 = in_windExtraDataFlag.x * mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Ripple.z, 1.0, (dot(-normalize(in_LeafAnchorHint.xz), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xy) + 1.0) * 0.5);
                vec2 _7502 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12698).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 _7524 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _7550 = cos(_7502);
                float _7545 = abs(sin((((3.1415927410125732421875 * _7502.x) * _7524) + (_7502.y * _7524)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_7550.x + _7550.y))));
                float _7512 = _7545 * _7545;
                float _7515 = _7512 * _7512;
                float _7422 = _5949 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0;
                vec4 _7610 = 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 _7639 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _7454 = _7406 * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _7515), _7422);
                vec3 _7674 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5747)) * 30.299999237060546875);
                float _7682 = (_7674.x + _7674.y) + _7674.z;
                vec4 _7821 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x + _7682, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x * 0.75) - _7682, _12698, _12698) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7812 = (((_7821 * _7821) * (vec4(3.0) - (_7821 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _7702 = (_12718 + ((((fract(vec3(in_windExtraDataFlag.z) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Ripple.y * ((((_7610 * _7610) * (vec4(3.0) - (_7610 * 2.0))) - vec4(0.5)) * 2.0).x)) * (_7406 * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.x, 1.0, _7515), _7422)))) - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
                float _7706 = _7812.x;
                float _7708 = _7812.y;
                float _7717 = (_7454 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.z) * (_7706 + (_7708 * _7708));
                float _7835 = sin(_7717);
                float _7838 = cos(_7717);
                float _7842 = 1.0 - _7838;
                float _7845 = _7639.x;
                float _7846 = _7842 * _7845;
                float _7858 = _7639.y;
                float _7859 = _7846 * _7858;
                float _7863 = _7639.z;
                float _7864 = _7835 * _7863;
                float _7872 = _7846 * _7863;
                float _7877 = _7835 * _7858;
                float _7895 = _7842 * _7858;
                float _7908 = _7895 * _7863;
                float _7913 = _7835 * _7845;
                vec3 _7723 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7639);
                float _7728 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7639), -1.0, 1.0);
                vec3 _12516 = _7723;
                _12516.y = _7723.y + _7728;
                vec3 _7735 = normalize(_12516);
                float _7752 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.z + _7682;
                vec4 _8006 = abs((fract(vec4(_7752 + (_5747 * _5747), (0.87000000476837158203125 * _7752) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7997 = (((_8006 * _8006) * (vec4(3.0) - (_8006 * 2.0))) - vec4(0.5)) * 2.0;
                float _7975 = _7997.y;
                float _7769 = _7454 * (((acos(_7728) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.w) + ((_7708 - (_7706 * _7706)) * 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((((_7997.x * _7975) * _7975) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.y)));
                float _8020 = sin(_7769);
                float _8023 = cos(_7769);
                float _8027 = 1.0 - _8023;
                float _8030 = _7735.x;
                float _8031 = _8027 * _8030;
                float _8043 = _7735.y;
                float _8044 = _8031 * _8043;
                float _8048 = _7735.z;
                float _8049 = _8020 * _8048;
                float _8057 = _8031 * _8048;
                float _8062 = _8020 * _8043;
                float _8080 = _8027 * _8043;
                float _8093 = _8080 * _8048;
                float _8098 = _8020 * _8030;
                _12793 = ((normalize((mat3(vec3((_7846 * _7845) + _7838, _7859 - _7864, _7872 + _7877), vec3(_7859 + _7864, (_7895 * _7858) + _7838, _7908 - _7913), vec3(_7872 - _7877, _7908 + _7913, ((_7842 * _7863) * _7863) + _7838)) * mat3(vec3((_8031 * _8030) + _8023, _8044 - _8049, _8057 + _8062), vec3(_8044 + _8049, (_8080 * _8043) + _8023, _8093 - _8098), vec3(_8057 - _8062, _8093 + _8098, ((_8027 * _8048) * _8048) + _8023))) * _7702) * length(_7702)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _12718;
            }
            _12792 = _12793;
        }
        else
        {
            _12792 = vec3(0.0);
        }
        _12791 = _12792;
    }
    else
    {
        _12791 = vec3(0.0);
    }
    vec3 _12797;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 4u)
    {
        _12797 = _12718 + (_12779 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    }
    else
    {
        vec3 _12798;
        if (_5968)
        {
            _12798 = _12718 + ((_12779 + _12785) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
        }
        else
        {
            vec3 _12799;
            if (_5943)
            {
                _12799 = _12718 + (((_12779 + _12785) + _12791) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
            }
            else
            {
                vec3 _12800;
                if (_5971)
                {
                    _12800 = _12718 + (_12779 + (_12785 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                }
                else
                {
                    vec3 _12801;
                    if (_5945)
                    {
                        _12801 = _12718 + (_12779 + ((_12785 + _12791) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                    }
                    else
                    {
                        vec3 _12802;
                        if (_5948)
                        {
                            _12802 = _12718 + ((_12779 + _12785) + (_12791 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                        }
                        else
                        {
                            vec3 _12803;
                            if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 1u)
                            {
                                _12803 = _12718 + _12779;
                            }
                            else
                            {
                                vec3 _12804;
                                if (_5965)
                                {
                                    _12804 = _12718 + (_12779 + _12785);
                                }
                                else
                                {
                                    vec3 _12805;
                                    if (_5953)
                                    {
                                        _12805 = _12718 + ((_12779 + _12785) + _12791);
                                    }
                                    else
                                    {
                                        _12805 = _12718;
                                    }
                                    _12804 = _12805;
                                }
                                _12803 = _12804;
                            }
                            _12802 = _12803;
                        }
                        _12801 = _12802;
                    }
                    _12800 = _12801;
                }
                _12799 = _12800;
            }
            _12798 = _12799;
        }
        _12797 = _12798;
    }
    vec4 _9008 = vec4(_12797, 1.0);
    vec4 _9009 = _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView * _9008;
    vec4 _9028 = _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelViewProj * _9008;
    vec4 _13005;
    if (_3585.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _9062 = _9028.w;
        vec4 _13006;
        if ((_9028.z / _9062) > 1.0)
        {
            vec4 _13007;
            if (_9009.z > _3585.g_cbPass._fNearPlane)
            {
                vec4 _12687 = _9028;
                _12687.z = _9062;
                _13007 = _12687;
            }
            else
            {
                _13007 = _9028;
            }
            _13006 = _13007;
        }
        else
        {
            _13006 = _9028;
        }
        _13005 = _13006;
    }
    else
    {
        _13005 = _9028;
    }
    interp_instanceID = float(_3329) + 0.5;
    float _5106 = _9009.x;
    float _5107 = _9009.y;
    float _5108 = _9009.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 = _9009.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 = _13005;
}

