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

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

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 _12269;
float _12270;

void main()
{
    int _3243 = gl_InstanceIndex + gl_DrawIDARB;
    int _3244 = readFirstInvocationARB(_3243);
    uint _5138 = uint(gl_VertexIndex);
    uint _5141 = _5138 + _3253.g_cbMainArray._aMain[_3244]._Indices._uiPositionOffset;
    vec4 _5154 = vec4(g_rbVertices_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiPositionsBufferIndex].g_rbVertices[_5141].x, g_rbVertices_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiPositionsBufferIndex].g_rbVertices[_5141].y, g_rbVertices_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiPositionsBufferIndex].g_rbVertices[_5141].z, 1.0);
    uint _5161 = _5138 + _3253.g_cbMainArray._aMain[_3244]._Indices._uiNormalOffset;
    int _5190 = g_rbTBNs_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5161]._iNormal & 1023;
    int _5193 = (g_rbTBNs_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5161]._iNormal >> 10) & 1023;
    int _5196 = (g_rbTBNs_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5161]._iNormal >> 20) & 1023;
    int _12271;
    if (_5190 > 512)
    {
        _12271 = _5190 | (-1024);
    }
    else
    {
        _12271 = _5190;
    }
    int _12273;
    if (_5193 > 512)
    {
        _12273 = _5193 | (-1024);
    }
    else
    {
        _12273 = _5193;
    }
    int _12275;
    if (_5196 > 512)
    {
        _12275 = _5196 | (-1024);
    }
    else
    {
        _12275 = _5196;
    }
    vec3 _5249 = vec3(float(_12271), float(_12273), float(_12275)) * vec3(0.001956947147846221923828125);
    int _5258 = g_rbTBNs_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5161]._iTangent & 1023;
    int _5261 = (g_rbTBNs_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5161]._iTangent >> 10) & 1023;
    int _5264 = (g_rbTBNs_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5161]._iTangent >> 20) & 1023;
    int _12277;
    if (_5258 > 512)
    {
        _12277 = _5258 | (-1024);
    }
    else
    {
        _12277 = _5258;
    }
    int _12279;
    if (_5261 > 512)
    {
        _12279 = _5261 | (-1024);
    }
    else
    {
        _12279 = _5261;
    }
    int _12281;
    if (_5264 > 512)
    {
        _12281 = _5264 | (-1024);
    }
    else
    {
        _12281 = _5264;
    }
    float _5322 = float((g_rbTBNs_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiNormalsBufferIndex].g_rbTBNs[_5161]._iTangent >> 30) != 0);
    vec3 _5339 = _5154.xyz;
    vec3 _5453 = vec4(vec3(float(_12277), float(_12279), float(_12281)) * vec3(0.001956947147846221923828125), _5322).xyz;
    float _5662 = (((100.0 * in_LeafAnchorHint.x) + in_LeafAnchorHint.y) + in_lodPosition.x) + in_lodPosition.y;
    vec3 _5670 = vec3(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    vec3 _5671 = mix(in_lodPosition.xyz, _5339, _5670);
    vec2 _5856 = _5671.xy;
    vec2 _5857 = _5856 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.x;
    vec2 _6022 = vec2(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.zw);
    vec2 _6023 = _5857 - _6022;
    vec2 _6024 = _6023 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
    float _6046 = 5.0 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
    vec2 _6072 = cos(_6024);
    float _6074 = _6072.x;
    float _6076 = _6072.y;
    float _6077 = _6074 + _6076;
    float _6053 = _6024.x;
    float _6054 = 3.1415927410125732421875 * _6053;
    float _6056 = _6054 * _6046;
    float _6058 = _6024.y;
    float _6060 = _6058 * _6046;
    float _6061 = _6056 + _6060;
    float _6064 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * _6077;
    float _6065 = _6061 + _6064;
    float _6066 = sin(_6065);
    float _6067 = abs(_6066);
    float _6034 = _6067 * _6067;
    float _6037 = _6034 * _6034;
    float _5865 = mix(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.y, 1.0, _6037);
    float _5869 = _5865 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
    float _6090 = length(_5671);
    float _6101 = max(_5671.y - (0.25 / g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z), 0.0) * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z;
    float _12290;
    if (_6101 != 0.0)
    {
        _12290 = pow(abs(_6101), g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.w);
    }
    else
    {
        _12290 = _6101;
    }
    float _6115 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x * 0.800000011920928955078125;
    vec4 _6116 = vec4(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x, _6115, 0.0, 0.0);
    vec4 _6172 = _6116 + vec4(0.5);
    vec4 _6173 = fract(_6172);
    vec4 _6174 = _6173 * 2.0;
    vec4 _6176 = _6174 - vec4(1.0);
    vec4 _6177 = abs(_6176);
    vec4 _6181 = _6177 * _6177;
    vec4 _6183 = _6177 * 2.0;
    vec4 _6185 = vec4(3.0) - _6183;
    vec4 _6186 = _6181 * _6185;
    vec4 _6167 = _6186 - vec4(0.5);
    vec4 _6168 = _6167 * 2.0;
    float _6119 = _6168.x;
    float _6121 = _6168.y;
    float _6124 = _6121 * _6121;
    float _6125 = _6119 + _6124;
    float _6129 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.y * _6125;
    float _6134 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchAdherences.x / g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z;
    float _6137 = _6134 * _5869;
    float _6139 = _6129 + _6137;
    float _6142 = _6139 * _12290;
    vec2 _6146 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xz * _6142;
    vec2 _6148 = _5671.xz;
    vec2 _6149 = _6148 + _6146;
    vec3 _6151 = vec3(_6149.x, _5671.y, _6149.y);
    vec3 _6156 = normalize(_6151);
    vec3 _6158 = _6156 * _6090;
    vec3 _5884 = _6158 - _5671;
    vec3 _6360 = vec3(in_windBranchData.y);
    vec3 _6361 = _6360 * vec3(0.0625, -1.0, 16.0);
    vec3 _6362 = fract(_6361);
    vec3 _6364 = _6362.xzy;
    vec3 _6365 = _6364 * 2.0;
    vec3 _6366 = _6365 - vec3(1.0);
    vec3 _6336 = _6366 * in_windBranchData.x;
    float _6435 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x + in_windBranchData.y;
    float _6438 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y;
    float _6440 = _6438 + in_windBranchData.y;
    float _6442 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y * 0.5;
    float _6446 = _6442 * _6435;
    vec4 _6447 = vec4(_6435, _6440, _6446, 0.0);
    vec4 _6586 = _6447 + vec4(0.5);
    vec4 _6587 = fract(_6586);
    vec4 _6588 = _6587 * 2.0;
    vec4 _6590 = _6588 - vec4(1.0);
    vec4 _6591 = abs(_6590);
    vec4 _6595 = _6591 * _6591;
    vec4 _6597 = _6591 * 2.0;
    vec4 _6599 = vec4(3.0) - _6597;
    vec4 _6600 = _6595 * _6599;
    vec4 _6581 = _6600 - vec4(0.5);
    vec4 _6582 = _6581 * 2.0;
    float _6472 = _6582.x;
    float _6474 = _6582.y;
    float _6476 = _6582.z;
    float _6477 = _6474 * _6476;
    bool _6480 = _6477 < 0.0;
    float _12304;
    if (_6480)
    {
        _12304 = -_6477;
    }
    else
    {
        _12304 = _6477;
    }
    float _12375 = _6480 ? (-1.0) : 1.0;
    float _6490 = mix(_6477, _12375, _12304);
    float _6494 = mix(_6490, _12375, _12304);
    float _6497 = _6494 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x;
    float _6500 = 1.0 - g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.w;
    float _6501 = _6497 * _6500;
    float _6504 = 1.0 - g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x;
    float _6505 = _6472 * _6504;
    float _6506 = _6501 + _6505;
    vec3 _6351 = _6336 * _6506;
    vec3 _6353 = _6351 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.y;
    vec3 _6355 = _5671 + _6353;
    vec3 _6671 = vec3(in_windBranchData.w);
    vec3 _6672 = _6671 * vec3(0.0625, -1.0, 16.0);
    vec3 _6673 = fract(_6672);
    vec3 _6675 = _6673.xzy;
    vec3 _6676 = _6675 * 2.0;
    vec3 _6677 = _6676 - vec3(1.0);
    vec3 _6647 = _6677 * in_windBranchData.z;
    float _6746 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.z + in_windBranchData.w;
    float _6749 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.z * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.w;
    float _6751 = _6749 + in_windBranchData.w;
    float _6753 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.w * 0.5;
    float _6757 = _6753 * _6746;
    vec4 _6758 = vec4(_6746, _6751, _6757, 0.0);
    vec4 _6897 = _6758 + vec4(0.5);
    vec4 _6898 = fract(_6897);
    vec4 _6899 = _6898 * 2.0;
    vec4 _6901 = _6899 - vec4(1.0);
    vec4 _6902 = abs(_6901);
    vec4 _6906 = _6902 * _6902;
    vec4 _6908 = _6902 * 2.0;
    vec4 _6910 = vec4(3.0) - _6908;
    vec4 _6911 = _6906 * _6910;
    vec4 _6892 = _6911 - vec4(0.5);
    vec4 _6893 = _6892 * 2.0;
    float _6783 = _6893.x;
    float _6785 = _6893.y;
    float _6787 = _6893.z;
    float _6788 = _6785 * _6787;
    bool _6791 = _6788 < 0.0;
    float _12317;
    if (_6791)
    {
        _12317 = -_6788;
    }
    else
    {
        _12317 = _6788;
    }
    float _12376 = _6791 ? (-1.0) : 1.0;
    float _6801 = mix(_6788, _12376, _12317);
    float _6805 = mix(_6801, _12376, _12317);
    float _6808 = _6805 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.z;
    float _6812 = _6808 * _6500;
    float _6815 = 1.0 - g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.z;
    float _6816 = _6783 * _6815;
    float _6817 = _6812 + _6816;
    vec3 _6662 = _6647 * _6817;
    vec3 _6664 = _6662 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.w;
    vec3 _6666 = _6355 + _6664;
    vec3 _5905 = _6666 - _5671;
    vec3 _12329;
    if (in_windExtraDataFlag.w > 0.0)
    {
        float _7811 = in_windExtraDataFlag.x * mix(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Ripple.z, 1.0, (dot(-normalize(in_LeafAnchorHint.xz), g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xy) + 1.0) * 0.5);
        vec2 _7905 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12270).xy - _6022) * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
        vec2 _7953 = cos(_7905);
        float _7948 = abs(sin((((3.1415927410125732421875 * _7905.x) * _6046) + (_7905.y * _6046)) + (g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_7953.x + _7953.y))));
        float _7915 = _7948 * _7948;
        float _7918 = _7915 * _7915;
        vec4 _8013 = abs((fract(vec4(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Ripple.x + _5662, 0.0, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec3 _8042 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
        float _7857 = _7811 * mix(1.0, mix(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _7918), g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
        vec3 _8077 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5662)) * 30.299999237060546875);
        float _8085 = (_8077.x + _8077.y) + _8077.z;
        vec4 _8222 = abs((fract(vec4(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x + _8085, (g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.x * 0.75) - _8085, _12270, _12270) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _8213 = (((_8222 * _8222) * (vec4(3.0) - (_8222 * 2.0))) - vec4(0.5)) * 2.0;
        vec3 _8105 = (_5671 + ((((fract(vec3(in_windExtraDataFlag.z) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * (g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Ripple.y * ((((_8013 * _8013) * (vec4(3.0) - (_8013 * 2.0))) - vec4(0.5)) * 2.0).x)) * (_7811 * mix(1.0, mix(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.x, 1.0, _7918), g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z)))) - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
        float _8109 = _8213.x;
        float _8111 = _8213.y;
        float _8120 = (_7857 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.z) * (_8109 + (_8111 * _8111));
        float _8236 = sin(_8120);
        float _8239 = cos(_8120);
        float _8243 = 1.0 - _8239;
        float _8246 = _8042.x;
        float _8247 = _8243 * _8246;
        float _8259 = _8042.y;
        float _8260 = _8247 * _8259;
        float _8264 = _8042.z;
        float _8265 = _8236 * _8264;
        float _8273 = _8247 * _8264;
        float _8278 = _8236 * _8259;
        float _8296 = _8243 * _8259;
        float _8309 = _8296 * _8264;
        float _8314 = _8236 * _8246;
        vec3 _8126 = cross(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8042);
        float _8131 = clamp(dot(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _8042), -1.0, 1.0);
        vec3 _12204 = _8126;
        _12204.y = _8126.y + _8131;
        vec3 _8138 = normalize(_12204);
        float _8155 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.z + _8085;
        vec4 _8407 = abs((fract(vec4(_8155 + (_5662 * _5662), (0.87000000476837158203125 * _8155) + _5662, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _8398 = (((_8407 * _8407) * (vec4(3.0) - (_8407 * 2.0))) - vec4(0.5)) * 2.0;
        float _8376 = _8398.y;
        float _8172 = _7857 * (((acos(_8131) * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.w) + ((_8111 - (_8109 * _8109)) * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Tumble.y)) + (g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.x * pow(clamp((((_8398.x * _8376) * _8376) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf2Twitch.y)));
        float _8421 = sin(_8172);
        float _8424 = cos(_8172);
        float _8428 = 1.0 - _8424;
        float _8431 = _8138.x;
        float _8432 = _8428 * _8431;
        float _8444 = _8138.y;
        float _8445 = _8432 * _8444;
        float _8449 = _8138.z;
        float _8450 = _8421 * _8449;
        float _8458 = _8432 * _8449;
        float _8463 = _8421 * _8444;
        float _8481 = _8428 * _8444;
        float _8494 = _8481 * _8449;
        float _8499 = _8421 * _8431;
        _12329 = ((normalize((mat3(vec3((_8247 * _8246) + _8239, _8260 - _8265, _8273 + _8278), vec3(_8260 + _8265, (_8296 * _8259) + _8239, _8309 - _8314), vec3(_8273 - _8278, _8309 + _8314, ((_8243 * _8264) * _8264) + _8239)) * mat3(vec3((_8432 * _8431) + _8424, _8445 - _8450, _8458 + _8463), vec3(_8445 + _8450, (_8481 * _8444) + _8424, _8494 - _8499), vec3(_8458 - _8463, _8494 + _8499, ((_8428 * _8449) * _8449) + _8424))) * _8105) * length(_8105)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _5671;
    }
    else
    {
        float _7002 = in_windExtraDataFlag.x * mix(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Ripple.z, 1.0, (dot(-normalize(in_LeafAnchorHint.xz), g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xy) + 1.0) * 0.5);
        vec2 _7096 = (vec3(in_LeafAnchorHint.x, -in_LeafAnchorHint.z, _12270).xy - _6022) * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
        vec2 _7144 = cos(_7096);
        float _7139 = abs(sin((((3.1415927410125732421875 * _7096.x) * _6046) + (_7096.y * _6046)) + (g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * (_7144.x + _7144.y))));
        float _7106 = _7139 * _7139;
        float _7109 = _7106 * _7106;
        vec4 _7204 = abs((fract(vec4(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Ripple.x + _5662, 0.0, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec3 _7233 = (fract(vec3(in_windExtraDataFlag.y) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0);
        float _7048 = _7002 * mix(1.0, mix(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.y, 1.0, _7109), g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
        vec3 _7268 = fract((vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z) + vec3(_5662)) * 30.299999237060546875);
        float _7276 = (_7268.x + _7268.y) + _7268.z;
        vec4 _7413 = abs((fract(vec4(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x + _7276, (g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.x * 0.75) - _7276, _12270, _12270) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _7404 = (((_7413 * _7413) * (vec4(3.0) - (_7413 * 2.0))) - vec4(0.5)) * 2.0;
        vec3 _7296 = (_5671 + ((((fract(vec3(in_windExtraDataFlag.z) * vec3(0.0625, -1.0, 16.0)).xzy * 2.0) - vec3(1.0)) * (g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Ripple.y * ((((_7204 * _7204) * (vec4(3.0) - (_7204 * 2.0))) - vec4(0.5)) * 2.0).x)) * (_7002 * mix(1.0, mix(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.x, 1.0, _7109), g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z)))) - vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z);
        float _7300 = _7404.x;
        float _7302 = _7404.y;
        float _7311 = (_7048 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.z) * (_7300 + (_7302 * _7302));
        float _7427 = sin(_7311);
        float _7430 = cos(_7311);
        float _7434 = 1.0 - _7430;
        float _7437 = _7233.x;
        float _7438 = _7434 * _7437;
        float _7450 = _7233.y;
        float _7451 = _7438 * _7450;
        float _7455 = _7233.z;
        float _7456 = _7427 * _7455;
        float _7464 = _7438 * _7455;
        float _7469 = _7427 * _7450;
        float _7487 = _7434 * _7450;
        float _7500 = _7487 * _7455;
        float _7505 = _7427 * _7437;
        vec3 _7317 = cross(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7233);
        float _7322 = clamp(dot(g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xyz, _7233), -1.0, 1.0);
        vec3 _12088 = _7317;
        _12088.y = _7317.y + _7322;
        vec3 _7329 = normalize(_12088);
        float _7346 = g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.z + _7276;
        vec4 _7598 = abs((fract(vec4(_7346 + (_5662 * _5662), (0.87000000476837158203125 * _7346) + _5662, 0.0, 0.0) + vec4(0.5)) * 2.0) - vec4(1.0));
        vec4 _7589 = (((_7598 * _7598) * (vec4(3.0) - (_7598 * 2.0))) - vec4(0.5)) * 2.0;
        float _7567 = _7589.y;
        float _7363 = _7048 * (((acos(_7322) * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.w) + ((_7302 - (_7300 * _7300)) * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Tumble.y)) + (g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.x * pow(clamp((((_7589.x * _7567) * _7567) + 1.0) * 0.5, 0.0, 1.0), g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vWindLeaf1Twitch.y)));
        float _7612 = sin(_7363);
        float _7615 = cos(_7363);
        float _7619 = 1.0 - _7615;
        float _7622 = _7329.x;
        float _7623 = _7619 * _7622;
        float _7635 = _7329.y;
        float _7636 = _7623 * _7635;
        float _7640 = _7329.z;
        float _7641 = _7612 * _7640;
        float _7649 = _7623 * _7640;
        float _7654 = _7612 * _7635;
        float _7672 = _7619 * _7635;
        float _7685 = _7672 * _7640;
        float _7690 = _7612 * _7622;
        _12329 = ((normalize((mat3(vec3((_7438 * _7437) + _7430, _7451 - _7456, _7464 + _7469), vec3(_7451 + _7456, (_7487 * _7450) + _7430, _7500 - _7505), vec3(_7464 - _7469, _7500 + _7505, ((_7434 * _7455) * _7455) + _7430)) * mat3(vec3((_7623 * _7622) + _7615, _7636 - _7641, _7649 + _7654), vec3(_7636 + _7641, (_7672 * _7635) + _7615, _7685 - _7690), vec3(_7649 - _7654, _7685 + _7690, ((_7619 * _7640) * _7640) + _7615))) * _7296) * length(_7296)) + vec3(in_LeafAnchorHint.x, in_LeafAnchorHint.y, in_LeafAnchorHint.z)) - _5671;
    }
    vec3 _5983 = _5905 + _12329;
    vec3 _5985 = _5983 * g_rbObjects_Buffer[_3253.g_cbMainArray._aMain[_3244]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
    vec3 _5986 = _5884 + _5985;
    vec3 _5988 = _5671 + _5986;
    float _8593 = _5988.x;
    float _8594 = _5988.y;
    float _8595 = _5988.z;
    vec4 _8596 = vec4(_8593, _8594, _8595, 1.0);
    vec4 _8597 = _426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView * _8596;
    vec4 _8616 = _426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelViewProj * _8596;
    vec4 _12368;
    if (_3500.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _8650 = _8616.w;
        vec4 _12369;
        if ((_8616.z / _8650) > 1.0)
        {
            vec4 _12370;
            if (_8597.z > _3500.g_cbPass._fNearPlane)
            {
                vec4 _12259 = _8616;
                _12259.z = _8650;
                _12370 = _12259;
            }
            else
            {
                _12370 = _8616;
            }
            _12369 = _12370;
        }
        else
        {
            _12369 = _8616;
        }
        _12368 = _12369;
    }
    else
    {
        _12368 = _8616;
    }
    interp_instanceID = float(_3243) + 0.5;
    float _5021 = _8597.x;
    float _5022 = _8597.y;
    float _5023 = _8597.z;
    vec4 _5024 = vec4(_5021, _5022, _5023, 1.0);
    float _5025 = dot(_3500.g_cbPass._vfVsClippingPlane[0], _5024);
    float _5026 = -_5025;
    gl_ClipDistance[0] = _5026;
    interp_uv0 = in_uv0;
    interp_vfVsPosition = _8597.xyz;
    interp_vfVsTangent = mat3(_426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView[0].xyz, _426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView[1].xyz, _426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _5453;
    interp_vfVsBinormal = mat3(_426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView[0].xyz, _426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView[1].xyz, _426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView[2].xyz) * (cross(_5249, _5453) * ((_5322 != 0.0) ? (-1.0) : 1.0));
    interp_vfVsNormal = mat3(_426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView[0].xyz, _426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView[1].xyz, _426.g_rbMatrices[_3253.g_cbMainArray._aMain[_3244]._Indices._uiMatricesIndex]._mModelView[2].xyz) * _5249;
    gl_Position = _12368;
}

