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

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

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

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 = 10) out vec4 prev_hpos;
layout(location = 23) out float interp_instanceID;

void main()
{
    int _3572 = gl_InstanceIndex + gl_DrawIDARB;
    int _3573 = readFirstInvocationARB(_3572);
    uint _5457 = uint(gl_VertexIndex);
    uint _5460 = _5457 + _3582.g_cbMainArray._aMain[_3573]._Indices._uiPositionOffset;
    uint _5480 = _5457 + _3582.g_cbMainArray._aMain[_3573]._Indices._uiNormalOffset;
    int _5509 = g_rbTBNs_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5480]._iNormal & 1023;
    int _5512 = (g_rbTBNs_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5480]._iNormal >> 10) & 1023;
    int _5515 = (g_rbTBNs_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5480]._iNormal >> 20) & 1023;
    int _16222;
    if (_5509 > 512)
    {
        _16222 = _5509 | (-1024);
    }
    else
    {
        _16222 = _5509;
    }
    int _16224;
    if (_5512 > 512)
    {
        _16224 = _5512 | (-1024);
    }
    else
    {
        _16224 = _5512;
    }
    int _16226;
    if (_5515 > 512)
    {
        _16226 = _5515 | (-1024);
    }
    else
    {
        _16226 = _5515;
    }
    vec3 _5568 = vec3(float(_16222), float(_16224), float(_16226)) * vec3(0.001956947147846221923828125);
    int _5577 = g_rbTBNs_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5480]._iTangent & 1023;
    int _5580 = (g_rbTBNs_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5480]._iTangent >> 10) & 1023;
    int _5583 = (g_rbTBNs_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5480]._iTangent >> 20) & 1023;
    int _16228;
    if (_5577 > 512)
    {
        _16228 = _5577 | (-1024);
    }
    else
    {
        _16228 = _5577;
    }
    int _16230;
    if (_5580 > 512)
    {
        _16230 = _5580 | (-1024);
    }
    else
    {
        _16230 = _5580;
    }
    int _16232;
    if (_5583 > 512)
    {
        _16232 = _5583 | (-1024);
    }
    else
    {
        _16232 = _5583;
    }
    float _5641 = float((g_rbTBNs_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5480]._iTangent >> 30) != 0);
    vec3 _5663 = vec4(g_rbVertices_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiPositionsBufferIndex].g_rbVertices[_5460].x, g_rbVertices_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiPositionsBufferIndex].g_rbVertices[_5460].y, g_rbVertices_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiPositionsBufferIndex].g_rbVertices[_5460].z, 1.0).xyz;
    vec3 _5784 = vec4(vec3(float(_16228), float(_16230), float(_16232)) * vec3(0.001956947147846221923828125), _5641).xyz;
    vec3 _16247;
    if (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiSmooth > 0u)
    {
        _16247 = mix(in_lodPosition.xyz, _5663, vec3(g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
    }
    else
    {
        _16247 = _5663;
    }
    bool _6354 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 6u;
    bool _6356 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 8u;
    bool _6359 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 9u;
    bool _6360 = (_6354 || _6356) || _6359;
    bool _6364 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 3u;
    bool _6376 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 2u;
    bool _6379 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 5u;
    bool _6382 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 7u;
    bool _6386 = true && _6364;
    float _16255;
    if (_6386)
    {
        vec2 _6708 = ((_16247.xy * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.x) - vec2(g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.zw)) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
        float _6730 = 5.0 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
        vec2 _6756 = cos(_6708);
        float _6751 = abs(sin((((3.1415927410125732421875 * _6708.x) * _6730) + (_6708.y * _6730)) + (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_6756.x + _6756.y))));
        float _6718 = _6751 * _6751;
        float _6401 = mix(g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.y, 1.0, _6718 * _6718);
        float _16256;
        if (_6360)
        {
            _16256 = _6401 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
        }
        else
        {
            _16256 = _6401;
        }
        _16255 = _16256;
    }
    else
    {
        _16255 = 0.0;
    }
    bool _6409 = true && (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD != 0u);
    vec3 _16282;
    if (_6409)
    {
        float _6785 = max(_16247.y - (0.25 / g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z), 0.0) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z;
        float _16257;
        if (_6785 != 0.0)
        {
            _16257 = pow(abs(_6785), g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.w);
        }
        else
        {
            _16257 = _6785;
        }
        vec4 _6861 = abs((fract(vec4(g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x, g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x * 0.800000011920928955078125, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _6852 = (((_6861 * _6861) * (vec4(3.0) - (_6861 * 2.0))) - vec4(0.5)) * 2.0;
        float _6805 = _6852.y;
        vec2 _6833 = _16247.xz + (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xz * (((g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.y * (_6852.x + (_6805 * _6805))) + ((g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchAdherences.x / g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z) * _16255)) * _16257));
        _16282 = (normalize(vec3(_6833.x, _16247.y, _6833.y)) * length(_16247)) - _16247;
    }
    else
    {
        _16282 = vec3(0.0);
    }
    bool _6422 = true && ((((((_6364 || _6354) || _6356) || _6359) || _6376) || _6379) || _6382);
    vec3 _16285;
    if (_6422)
    {
        float _7105 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x + in_windBranchData.y;
        vec4 _7261 = abs((fract(vec4(_7105, (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y) + in_windBranchData.y, (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y * 0.5) * _7105, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _7252 = (((_7261 * _7261) * (vec4(3.0) - (_7261 * 2.0))) - vec4(0.5)) * 2.0;
        float _7147 = _7252.y * _7252.z;
        bool _7150 = _7147 < 0.0;
        float _16276;
        if (_7150)
        {
            _16276 = -_7147;
        }
        else
        {
            _16276 = _7147;
        }
        float _16764 = _7150 ? (-1.0) : 1.0;
        _16285 = (_16247 + (((((fract(vec3(in_windBranchData.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * in_windBranchData.x) * (((mix(mix(_7147, _16764, _16276), _16764, _16276) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x) * (1.0 - g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.w)) + (_7252.x * (1.0 - g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x)))) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.y)) - _16247;
    }
    else
    {
        _16285 = vec3(0.0);
    }
    bool _6557 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 4u;
    vec3 _16289;
    if (_6557)
    {
        _16289 = _16247 + (_16282 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    }
    else
    {
        vec3 _16290;
        if (_6379)
        {
            _16290 = _16247 + ((_16282 + _16285) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
        }
        else
        {
            vec3 _16291;
            if (_6354)
            {
                _16291 = _16247 + ((_16282 + _16285) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
            }
            else
            {
                vec3 _16292;
                if (_6382)
                {
                    _16292 = _16247 + (_16282 + (_16285 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                }
                else
                {
                    vec3 _16293;
                    if (_6356)
                    {
                        _16293 = _16247 + (_16282 + (_16285 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                    }
                    else
                    {
                        vec3 _16294;
                        if (_6359)
                        {
                            _16294 = _16247 + (_16282 + _16285);
                        }
                        else
                        {
                            vec3 _16295;
                            if (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 1u)
                            {
                                _16295 = _16247 + _16282;
                            }
                            else
                            {
                                vec3 _16296;
                                if (_6376)
                                {
                                    _16296 = _16247 + (_16282 + _16285);
                                }
                                else
                                {
                                    vec3 _16297;
                                    if (_6364)
                                    {
                                        _16297 = _16247 + (_16282 + _16285);
                                    }
                                    else
                                    {
                                        _16297 = _16247;
                                    }
                                    _16296 = _16297;
                                }
                                _16295 = _16296;
                            }
                            _16294 = _16295;
                        }
                        _16293 = _16294;
                    }
                    _16292 = _16293;
                }
                _16291 = _16292;
            }
            _16290 = _16291;
        }
        _16289 = _16290;
    }
    float _16404;
    if (_6386)
    {
        vec2 _9453 = ((_16247.xy * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.x) - vec2(g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.zw)) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
        float _9475 = 5.0 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
        vec2 _9501 = cos(_9453);
        float _9496 = abs(sin((((3.1415927410125732421875 * _9453.x) * _9475) + (_9453.y * _9475)) + (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_9501.x + _9501.y))));
        float _9463 = _9496 * _9496;
        float _9146 = mix(g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.y, 1.0, _9463 * _9463);
        float _16405;
        if (_6360)
        {
            _16405 = _9146 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
        }
        else
        {
            _16405 = _9146;
        }
        _16404 = _16405;
    }
    else
    {
        _16404 = 0.0;
    }
    vec3 _16447;
    if (_6409)
    {
        float _9530 = max(_16247.y - (0.25 / g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobalLast.z), 0.0) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobalLast.z;
        float _16406;
        if (_9530 != 0.0)
        {
            _16406 = pow(abs(_9530), g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobalLast.w);
        }
        else
        {
            _16406 = _9530;
        }
        vec4 _9606 = abs((fract(vec4(g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobalLast.x, g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobalLast.x * 0.800000011920928955078125, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _9597 = (((_9606 * _9606) * (vec4(3.0) - (_9606 * 2.0))) - vec4(0.5)) * 2.0;
        float _9550 = _9597.y;
        vec2 _9578 = _16247.xz + (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xz * (((g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobalLast.y * (_9597.x + (_9550 * _9550))) + ((g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchAdherences.x / g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobalLast.z) * _16404)) * _16406));
        _16447 = (normalize(vec3(_9578.x, _16247.y, _9578.y)) * length(_16247)) - _16247;
    }
    else
    {
        _16447 = vec3(0.0);
    }
    vec3 _16450;
    if (_6422)
    {
        float _9850 = g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchLast.x + in_windBranchData.y;
        vec4 _10006 = abs((fract(vec4(_9850, (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchLast.x * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y) + in_windBranchData.y, (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y * 0.5) * _9850, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _9997 = (((_10006 * _10006) * (vec4(3.0) - (_10006 * 2.0))) - vec4(0.5)) * 2.0;
        float _9892 = _9997.y * _9997.z;
        bool _9895 = _9892 < 0.0;
        float _16441;
        if (_9895)
        {
            _16441 = -_9892;
        }
        else
        {
            _16441 = _9892;
        }
        float _16765 = _9895 ? (-1.0) : 1.0;
        _16450 = (_16247 + (((((fract(vec3(in_windBranchData.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * in_windBranchData.x) * (((mix(mix(_9892, _16765, _16441), _16765, _16441) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x) * (1.0 - g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.w)) + (_9997.x * (1.0 - g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x)))) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchLast.y)) - _16247;
    }
    else
    {
        _16450 = vec3(0.0);
    }
    vec3 _16454;
    if (_6557)
    {
        _16454 = _16247 + (_16447 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    }
    else
    {
        vec3 _16455;
        if (_6379)
        {
            _16455 = _16247 + ((_16447 + _16450) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
        }
        else
        {
            vec3 _16456;
            if (_6354)
            {
                _16456 = _16247 + ((_16447 + _16450) * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
            }
            else
            {
                vec3 _16457;
                if (_6382)
                {
                    _16457 = _16247 + (_16447 + (_16450 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                }
                else
                {
                    vec3 _16458;
                    if (_6356)
                    {
                        _16458 = _16247 + (_16447 + (_16450 * g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                    }
                    else
                    {
                        vec3 _16459;
                        if (_6359)
                        {
                            _16459 = _16247 + (_16447 + _16450);
                        }
                        else
                        {
                            vec3 _16460;
                            if (g_rbObjects_Buffer[_3582.g_cbMainArray._aMain[_3573]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 1u)
                            {
                                _16460 = _16247 + _16447;
                            }
                            else
                            {
                                vec3 _16461;
                                if (_6376)
                                {
                                    _16461 = _16247 + (_16447 + _16450);
                                }
                                else
                                {
                                    vec3 _16462;
                                    if (_6364)
                                    {
                                        _16462 = _16247 + (_16447 + _16450);
                                    }
                                    else
                                    {
                                        _16462 = _16247;
                                    }
                                    _16461 = _16462;
                                }
                                _16460 = _16461;
                            }
                            _16459 = _16460;
                        }
                        _16458 = _16459;
                    }
                    _16457 = _16458;
                }
                _16456 = _16457;
            }
            _16455 = _16456;
        }
        _16454 = _16455;
    }
    vec4 _11797 = vec4(_16289, 1.0);
    vec4 _11798 = _443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView * _11797;
    vec4 _11817 = _443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelViewProj * _11797;
    vec4 _16757;
    if (_3820.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _11887 = _11817.w;
        vec4 _16758;
        if ((_11817.z / _11887) > 1.0)
        {
            vec4 _16759;
            if (_11798.z > _3820.g_cbPass._fNearPlane)
            {
                vec4 _16209 = _11817;
                _16209.z = _11887;
                _16759 = _16209;
            }
            else
            {
                _16759 = _11817;
            }
            _16758 = _16759;
        }
        else
        {
            _16758 = _11817;
        }
        _16757 = _16758;
    }
    else
    {
        _16757 = _11817;
    }
    interp_instanceID = float(_3572) + 0.5;
    float _5341 = _11798.x;
    float _5342 = _11798.y;
    float _5343 = _11798.z;
    vec4 _5344 = vec4(_5341, _5342, _5343, 1.0);
    float _5345 = dot(_3820.g_cbPass._vfVsClippingPlane[0], _5344);
    float _5346 = -_5345;
    gl_ClipDistance[0] = _5346;
    interp_uv0 = in_uv0;
    interp_vfVsPosition = _11798.xyz;
    interp_vfVsTangent = mat3(_443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView[0].xyz, _443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView[1].xyz, _443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _5784;
    interp_vfVsBinormal = mat3(_443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView[0].xyz, _443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView[1].xyz, _443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView[2].xyz) * (cross(_5568, _5784) * ((_5641 != 0.0) ? (-1.0) : 1.0));
    interp_vfVsNormal = mat3(_443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView[0].xyz, _443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView[1].xyz, _443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _5568;
    prev_hpos = _443.g_rbMatrices[_3582.g_cbMainArray._aMain[_3573]._Indices._uiMatricesIndex]._mModelViewProjPrevious * vec4(_16454, 1.0);
    gl_Position = _16757;
}

