
// 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 _12354;
float _12355;

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 _12356;
    if (_5275 > 512)
    {
        _12356 = _5275 | (-1024);
    }
    else
    {
        _12356 = _5275;
    }
    int _12358;
    if (_5278 > 512)
    {
        _12358 = _5278 | (-1024);
    }
    else
    {
        _12358 = _5278;
    }
    int _12360;
    if (_5281 > 512)
    {
        _12360 = _5281 | (-1024);
    }
    else
    {
        _12360 = _5281;
    }
    vec3 _5334 = vec3(float(_12356), float(_12358), float(_12360)) * 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 _12362;
    if (_5343 > 512)
    {
        _12362 = _5343 | (-1024);
    }
    else
    {
        _12362 = _5343;
    }
    int _12364;
    if (_5346 > 512)
    {
        _12364 = _5346 | (-1024);
    }
    else
    {
        _12364 = _5346;
    }
    int _12366;
    if (_5349 > 512)
    {
        _12366 = _5349 | (-1024);
    }
    else
    {
        _12366 = _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(_12362), float(_12364), float(_12366)) * vec3(0.001956947147846221923828125), _5407).xyz;
    float _5747 = (((100.0 * in_LeafAnchorHint.x) + in_LeafAnchorHint.y) + in_lodPosition.x) + in_lodPosition.y;
    vec3 _12375;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiSmooth > 0u)
    {
        _12375 = mix(in_lodPosition.xyz, _5424, vec3(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
    }
    else
    {
        _12375 = _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 _12383;
    if (true && _5953)
    {
        vec2 _6297 = ((_12375.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 _12384;
        if (_5949)
        {
            _12384 = _5990 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
        }
        else
        {
            _12384 = _5990;
        }
        _12383 = _12384;
    }
    else
    {
        _12383 = 0.0;
    }
    vec3 _12417;
    if (true && (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD != 0u))
    {
        float _6374 = max(_12375.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 _12385;
        if (_6374 != 0.0)
        {
            _12385 = pow(abs(_6374), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.w);
        }
        else
        {
            _12385 = _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 = _12375.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) * _12383)) * _12385));
        _12417 = (normalize(vec3(_6422.x, _12375.y, _6422.y)) * length(_12375)) - _12375;
    }
    else
    {
        _12417 = vec3(0.0);
    }
    vec3 _12422;
    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 _12404;
        if (_6739)
        {
            _12404 = -_6736;
        }
        else
        {
            _12404 = _6736;
        }
        float _12640 = _6739 ? (-1.0) : 1.0;
        _12422 = (_12375 + (((((fract(vec3(in_windBranchData.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * in_windBranchData.x) * (((mix(mix(_6736, _12640, _12404), _12640, _12404) * 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)) - _12375;
    }
    else
    {
        _12422 = vec3(0.0);
    }
    vec3 _12428;
    if (_5953 && true)
    {
        vec3 _12429;
        if (true && _5962)
        {
            vec3 _12430;
            if (in_windExtraDataFlag.w > 0.0)
            {
                float _7894 = 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 _7988 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12355).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 _8010 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _8036 = cos(_7988);
                float _8031 = abs(sin((((3.1415927410125732421875 * _7988.x) * _8010) + (_7988.y * _8010)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_8036.x + _8036.y))));
                float _7998 = _8031 * _8031;
                float _8001 = _7998 * _7998;
                float _7910 = _5949 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0;
                vec4 _8096 = 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 _8125 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _7940 = _7894 * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _8001), _7910);
                vec3 _8160 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5747)) * 30.299999237060546875);
                float _8168 = (_8160.x + _8160.y) + _8160.z;
                vec4 _8307 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x + _8168, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x * 0.75) - _8168, _12355, _12355) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8298 = (((_8307 * _8307) * (vec4(3.0) - (_8307 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _8188 = (_12375 + ((_5334 * (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Ripple.y * ((((_8096 * _8096) * (vec4(3.0) - (_8096 * 2.0))) - vec4(0.5)) * 2.0).x)) * (_7894 * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.x, 1.0, _8001), _7910)))) - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
                float _8192 = _8298.x;
                float _8194 = _8298.y;
                float _8203 = (_7940 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.z) * (_8192 + (_8194 * _8194));
                float _8321 = sin(_8203);
                float _8324 = cos(_8203);
                float _8328 = 1.0 - _8324;
                float _8331 = _8125.x;
                float _8332 = _8328 * _8331;
                float _8344 = _8125.y;
                float _8345 = _8332 * _8344;
                float _8349 = _8125.z;
                float _8350 = _8321 * _8349;
                float _8358 = _8332 * _8349;
                float _8363 = _8321 * _8344;
                float _8381 = _8328 * _8344;
                float _8394 = _8381 * _8349;
                float _8399 = _8321 * _8331;
                vec3 _8209 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8125);
                float _8214 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8125), -1.0, 1.0);
                vec3 _12289 = _8209;
                _12289.y = _8209.y + _8214;
                vec3 _8221 = normalize(_12289);
                float _8238 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.z + _8168;
                vec4 _8492 = abs((fract(vec4(_8238 + (_5747 * _5747), (0.87000000476837158203125 * _8238) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _8483 = (((_8492 * _8492) * (vec4(3.0) - (_8492 * 2.0))) - vec4(0.5)) * 2.0;
                float _8461 = _8483.y;
                float _8255 = _7940 * (((acos(_8214) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.w) + ((_8194 - (_8192 * _8192)) * 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((((_8483.x * _8461) * _8461) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.y)));
                float _8506 = sin(_8255);
                float _8509 = cos(_8255);
                float _8513 = 1.0 - _8509;
                float _8516 = _8221.x;
                float _8517 = _8513 * _8516;
                float _8529 = _8221.y;
                float _8530 = _8517 * _8529;
                float _8534 = _8221.z;
                float _8535 = _8506 * _8534;
                float _8543 = _8517 * _8534;
                float _8548 = _8506 * _8529;
                float _8566 = _8513 * _8529;
                float _8579 = _8566 * _8534;
                float _8584 = _8506 * _8516;
                _12430 = ((normalize((mat3(vec3((_8332 * _8331) + _8324, _8345 - _8350, _8358 + _8363), vec3(_8345 + _8350, (_8381 * _8344) + _8324, _8394 - _8399), vec3(_8358 - _8363, _8394 + _8399, ((_8328 * _8349) * _8349) + _8324)) * mat3(vec3((_8517 * _8516) + _8509, _8530 - _8535, _8543 + _8548), vec3(_8530 + _8535, (_8566 * _8529) + _8509, _8579 - _8584), vec3(_8543 - _8548, _8579 + _8584, ((_8513 * _8534) * _8534) + _8509))) * _8188) * length(_8188)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _12375;
            }
            else
            {
                float _7081 = 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 _7177 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12355).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 _7199 = 5.0 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
                vec2 _7225 = cos(_7177);
                float _7220 = abs(sin((((3.1415927410125732421875 * _7177.x) * _7199) + (_7177.y * _7199)) + (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_7225.x + _7225.y))));
                float _7187 = _7220 * _7220;
                float _7190 = _7187 * _7187;
                float _7097 = _5949 ? g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z : 1.0;
                vec4 _7285 = 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 _7314 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
                float _7129 = _7081 * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _7190), _7097);
                vec3 _7349 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5747)) * 30.299999237060546875);
                float _7357 = (_7349.x + _7349.y) + _7349.z;
                vec4 _7496 = abs((fract(vec4(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x + _7357, (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x * 0.75) - _7357, _12355, _12355) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7487 = (((_7496 * _7496) * (vec4(3.0) - (_7496 * 2.0))) - vec4(0.5)) * 2.0;
                vec3 _7377 = (_12375 + ((((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 * ((((_7285 * _7285) * (vec4(3.0) - (_7285 * 2.0))) - vec4(0.5)) * 2.0).x)) * (_7081 * mix(1.0, mix(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.x, 1.0, _7190), _7097)))) - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
                float _7381 = _7487.x;
                float _7383 = _7487.y;
                float _7392 = (_7129 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.z) * (_7381 + (_7383 * _7383));
                float _7510 = sin(_7392);
                float _7513 = cos(_7392);
                float _7517 = 1.0 - _7513;
                float _7520 = _7314.x;
                float _7521 = _7517 * _7520;
                float _7533 = _7314.y;
                float _7534 = _7521 * _7533;
                float _7538 = _7314.z;
                float _7539 = _7510 * _7538;
                float _7547 = _7521 * _7538;
                float _7552 = _7510 * _7533;
                float _7570 = _7517 * _7533;
                float _7583 = _7570 * _7538;
                float _7588 = _7510 * _7520;
                vec3 _7398 = cross(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7314);
                float _7403 = clamp(dot(g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7314), -1.0, 1.0);
                vec3 _12173 = _7398;
                _12173.y = _7398.y + _7403;
                vec3 _7410 = normalize(_12173);
                float _7427 = g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.z + _7357;
                vec4 _7681 = abs((fract(vec4(_7427 + (_5747 * _5747), (0.87000000476837158203125 * _7427) + _5747, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
                vec4 _7672 = (((_7681 * _7681) * (vec4(3.0) - (_7681 * 2.0))) - vec4(0.5)) * 2.0;
                float _7650 = _7672.y;
                float _7444 = _7129 * (((acos(_7403) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.w) + ((_7383 - (_7381 * _7381)) * 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((((_7672.x * _7650) * _7650) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.y)));
                float _7695 = sin(_7444);
                float _7698 = cos(_7444);
                float _7702 = 1.0 - _7698;
                float _7705 = _7410.x;
                float _7706 = _7702 * _7705;
                float _7718 = _7410.y;
                float _7719 = _7706 * _7718;
                float _7723 = _7410.z;
                float _7724 = _7695 * _7723;
                float _7732 = _7706 * _7723;
                float _7737 = _7695 * _7718;
                float _7755 = _7702 * _7718;
                float _7768 = _7755 * _7723;
                float _7773 = _7695 * _7705;
                _12430 = ((normalize((mat3(vec3((_7521 * _7520) + _7513, _7534 - _7539, _7547 + _7552), vec3(_7534 + _7539, (_7570 * _7533) + _7513, _7583 - _7588), vec3(_7547 - _7552, _7583 + _7588, ((_7517 * _7538) * _7538) + _7513)) * mat3(vec3((_7706 * _7705) + _7698, _7719 - _7724, _7732 + _7737), vec3(_7719 + _7724, (_7755 * _7718) + _7698, _7768 - _7773), vec3(_7732 - _7737, _7768 + _7773, ((_7702 * _7723) * _7723) + _7698))) * _7377) * length(_7377)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _12375;
            }
            _12429 = _12430;
        }
        else
        {
            _12429 = vec3(0.0);
        }
        _12428 = _12429;
    }
    else
    {
        _12428 = vec3(0.0);
    }
    vec3 _12434;
    if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 4u)
    {
        _12434 = _12375 + (_12417 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    }
    else
    {
        vec3 _12435;
        if (_5968)
        {
            _12435 = _12375 + ((_12417 + _12422) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
        }
        else
        {
            vec3 _12436;
            if (_5943)
            {
                _12436 = _12375 + (((_12417 + _12422) + _12428) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
            }
            else
            {
                vec3 _12437;
                if (_5971)
                {
                    _12437 = _12375 + (_12417 + (_12422 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                }
                else
                {
                    vec3 _12438;
                    if (_5945)
                    {
                        _12438 = _12375 + (_12417 + ((_12422 + _12428) * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                    }
                    else
                    {
                        vec3 _12439;
                        if (_5948)
                        {
                            _12439 = _12375 + ((_12417 + _12422) + (_12428 * g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z));
                        }
                        else
                        {
                            vec3 _12440;
                            if (g_rbObjects_Buffer[_3339.g_cbMainArray._aMain[_3330]._Indices._uiObjectIndex].g_rbObjects[0]._uiLOD == 1u)
                            {
                                _12440 = _12375 + _12417;
                            }
                            else
                            {
                                vec3 _12441;
                                if (_5965)
                                {
                                    _12441 = _12375 + (_12417 + _12422);
                                }
                                else
                                {
                                    vec3 _12442;
                                    if (_5953)
                                    {
                                        _12442 = _12375 + ((_12417 + _12422) + _12428);
                                    }
                                    else
                                    {
                                        _12442 = _12375;
                                    }
                                    _12441 = _12442;
                                }
                                _12440 = _12441;
                            }
                            _12439 = _12440;
                        }
                        _12438 = _12439;
                    }
                    _12437 = _12438;
                }
                _12436 = _12437;
            }
            _12435 = _12436;
        }
        _12434 = _12435;
    }
    vec4 _8681 = vec4(_12434, 1.0);
    vec4 _8682 = _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelView * _8681;
    vec4 _8701 = _426.g_rbMatrices[_3339.g_cbMainArray._aMain[_3330]._Indices._uiMatricesIndex]._mModelViewProj * _8681;
    vec4 _12633;
    if (_3585.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _8735 = _8701.w;
        vec4 _12634;
        if ((_8701.z / _8735) > 1.0)
        {
            vec4 _12635;
            if (_8682.z > _3585.g_cbPass._fNearPlane)
            {
                vec4 _12344 = _8701;
                _12344.z = _8735;
                _12635 = _12344;
            }
            else
            {
                _12635 = _8701;
            }
            _12634 = _12635;
        }
        else
        {
            _12634 = _8701;
        }
        _12633 = _12634;
    }
    else
    {
        _12633 = _8701;
    }
    interp_instanceID = float(_3329) + 0.5;
    float _5106 = _8682.x;
    float _5107 = _8682.y;
    float _5108 = _8682.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 = _8682.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 = _12633;
}

