
// 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_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 = 0, binding = 52, std140) uniform dyn_CONSTANT_BUFFER_BLOCK_CB_S_MAIN_ARRAY_BINDING
{
    S_MAIN_DEFAULT_ARRAY g_cbMainArray;
} _3224;

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

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 = 23) out float interp_instanceID;

void main()
{
    int _3214 = gl_InstanceIndex + gl_DrawIDARB;
    int _3215 = readFirstInvocationARB(_3214);
    uint _5109 = uint(gl_VertexIndex);
    uint _5112 = _5109 + _3224.g_cbMainArray._aMain[_3215]._Indices._uiPositionOffset;
    vec4 _5125 = vec4(g_rbVertices_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiPositionsBufferIndex].g_rbVertices[_5112].x, g_rbVertices_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiPositionsBufferIndex].g_rbVertices[_5112].y, g_rbVertices_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiPositionsBufferIndex].g_rbVertices[_5112].z, 1.0);
    vec3 _5310 = _5125.xyz;
    vec3 _5641 = vec3(g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z);
    vec3 _5642 = mix(in_lodPosition.xyz, _5310, _5641);
    vec2 _5827 = _5642.xy;
    vec2 _5828 = _5827 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.x;
    vec2 _5930 = vec2(g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingLeafOffset.zw);
    vec2 _5931 = _5828 - _5930;
    vec2 _5932 = _5931 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.y;
    float _5954 = 5.0 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.x;
    vec2 _5980 = cos(_5932);
    float _5982 = _5980.x;
    float _5984 = _5980.y;
    float _5985 = _5982 + _5984;
    float _5961 = _5932.x;
    float _5962 = 3.1415927410125732421875 * _5961;
    float _5964 = _5962 * _5954;
    float _5966 = _5932.y;
    float _5968 = _5966 * _5954;
    float _5969 = _5964 + _5968;
    float _5972 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingNoise.w * _5985;
    float _5973 = _5969 + _5972;
    float _5974 = sin(_5973);
    float _5975 = abs(_5974);
    float _5942 = _5975 * _5975;
    float _5945 = _5942 * _5942;
    float _5836 = mix(g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vRollingBranch.y, 1.0, _5945);
    float _5840 = _5836 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vTreeRotation.z;
    float _5998 = length(_5642);
    float _6009 = max(_5642.y - (0.25 / g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z), 0.0) * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z;
    float _10292;
    if (_6009 != 0.0)
    {
        _10292 = pow(abs(_6009), g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.w);
    }
    else
    {
        _10292 = _6009;
    }
    float _6023 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x * 0.800000011920928955078125;
    vec4 _6024 = vec4(g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.x, _6023, 0.0, 0.0);
    vec4 _6080 = _6024 + vec4(0.5);
    vec4 _6081 = fract(_6080);
    vec4 _6082 = _6081 * 2.0;
    vec4 _6084 = _6082 - vec4(1.0);
    vec4 _6085 = abs(_6084);
    vec4 _6089 = _6085 * _6085;
    vec4 _6091 = _6085 * 2.0;
    vec4 _6093 = vec4(3.0) - _6091;
    vec4 _6094 = _6089 * _6093;
    vec4 _6075 = _6094 - vec4(0.5);
    vec4 _6076 = _6075 * 2.0;
    float _6027 = _6076.x;
    float _6029 = _6076.y;
    float _6032 = _6029 * _6029;
    float _6033 = _6027 + _6032;
    float _6037 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.y * _6033;
    float _6042 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchAdherences.x / g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindGlobal.z;
    float _6045 = _6042 * _5840;
    float _6047 = _6037 + _6045;
    float _6050 = _6047 * _10292;
    vec2 _6054 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.xz * _6050;
    vec2 _6056 = _5642.xz;
    vec2 _6057 = _6056 + _6054;
    vec3 _6059 = vec3(_6057.x, _5642.y, _6057.y);
    vec3 _6064 = normalize(_6059);
    vec3 _6066 = _6064 * _5998;
    vec3 _5855 = _6066 - _5642;
    vec3 _6268 = vec3(in_windBranchData.y);
    vec3 _6269 = _6268 * vec3(0.0625, -1.0, 16.0);
    vec3 _6270 = fract(_6269);
    vec3 _6272 = _6270.xzy;
    vec3 _6273 = _6272 * 2.0;
    vec3 _6274 = _6273 - vec3(1.0);
    vec3 _6244 = _6274 * in_windBranchData.x;
    float _6343 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x + in_windBranchData.y;
    float _6346 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.x * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y;
    float _6348 = _6346 + in_windBranchData.y;
    float _6350 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.y * 0.5;
    float _6354 = _6350 * _6343;
    vec4 _6355 = vec4(_6343, _6348, _6354, 0.0);
    vec4 _6494 = _6355 + vec4(0.5);
    vec4 _6495 = fract(_6494);
    vec4 _6496 = _6495 * 2.0;
    vec4 _6498 = _6496 - vec4(1.0);
    vec4 _6499 = abs(_6498);
    vec4 _6503 = _6499 * _6499;
    vec4 _6505 = _6499 * 2.0;
    vec4 _6507 = vec4(3.0) - _6505;
    vec4 _6508 = _6503 * _6507;
    vec4 _6489 = _6508 - vec4(0.5);
    vec4 _6490 = _6489 * 2.0;
    float _6380 = _6490.x;
    float _6382 = _6490.y;
    float _6384 = _6490.z;
    float _6385 = _6382 * _6384;
    bool _6388 = _6385 < 0.0;
    float _10300;
    if (_6388)
    {
        _10300 = -_6385;
    }
    else
    {
        _10300 = _6385;
    }
    float _10327 = _6388 ? (-1.0) : 1.0;
    float _6398 = mix(_6385, _10327, _10300);
    float _6402 = mix(_6398, _10327, _10300);
    float _6405 = _6402 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x;
    float _6408 = 1.0 - g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindVector.w;
    float _6409 = _6405 * _6408;
    float _6412 = 1.0 - g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.x;
    float _6413 = _6380 * _6412;
    float _6414 = _6409 + _6413;
    vec3 _6259 = _6244 * _6414;
    vec3 _6261 = _6259 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.y;
    vec3 _6263 = _5642 + _6261;
    vec3 _6579 = vec3(in_windBranchData.w);
    vec3 _6580 = _6579 * vec3(0.0625, -1.0, 16.0);
    vec3 _6581 = fract(_6580);
    vec3 _6583 = _6581.xzy;
    vec3 _6584 = _6583 * 2.0;
    vec3 _6585 = _6584 - vec3(1.0);
    vec3 _6555 = _6585 * in_windBranchData.z;
    float _6654 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.z + in_windBranchData.w;
    float _6657 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.z * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.w;
    float _6659 = _6657 + in_windBranchData.w;
    float _6661 = g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.w * 0.5;
    float _6665 = _6661 * _6654;
    vec4 _6666 = vec4(_6654, _6659, _6665, 0.0);
    vec4 _6805 = _6666 + vec4(0.5);
    vec4 _6806 = fract(_6805);
    vec4 _6807 = _6806 * 2.0;
    vec4 _6809 = _6807 - vec4(1.0);
    vec4 _6810 = abs(_6809);
    vec4 _6814 = _6810 * _6810;
    vec4 _6816 = _6810 * 2.0;
    vec4 _6818 = vec4(3.0) - _6816;
    vec4 _6819 = _6814 * _6818;
    vec4 _6800 = _6819 - vec4(0.5);
    vec4 _6801 = _6800 * 2.0;
    float _6691 = _6801.x;
    float _6693 = _6801.y;
    float _6695 = _6801.z;
    float _6696 = _6693 * _6695;
    bool _6699 = _6696 < 0.0;
    float _10307;
    if (_6699)
    {
        _10307 = -_6696;
    }
    else
    {
        _10307 = _6696;
    }
    float _10328 = _6699 ? (-1.0) : 1.0;
    float _6709 = mix(_6696, _10328, _10307);
    float _6713 = mix(_6709, _10328, _10307);
    float _6716 = _6713 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.z;
    float _6720 = _6716 * _6408;
    float _6723 = 1.0 - g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranchTwitch.z;
    float _6724 = _6691 * _6723;
    float _6725 = _6720 + _6724;
    vec3 _6570 = _6555 * _6725;
    vec3 _6572 = _6570 * g_rbObjects_Buffer[_3224.g_cbMainArray._aMain[_3215]._Indices._uiObjectIndex].g_rbObjects[0]._vWindBranch.w;
    vec3 _6574 = _6263 + _6572;
    vec3 _5876 = _6574 - _5642;
    vec3 _5887 = _5855 + _5876;
    vec3 _5895 = _5642 + _5887;
    float _6883 = _5895.x;
    float _6884 = _5895.y;
    float _6885 = _5895.z;
    vec4 _6886 = vec4(_6883, _6884, _6885, 1.0);
    vec4 _6887 = _426.g_rbMatrices[_3224.g_cbMainArray._aMain[_3215]._Indices._uiMatricesIndex]._mModelView * _6886;
    vec4 _6906 = _426.g_rbMatrices[_3224.g_cbMainArray._aMain[_3215]._Indices._uiMatricesIndex]._mModelViewProj * _6886;
    vec4 _10323;
    if (_3471.g_cbPass._uDepthClamp == 4294967295u)
    {
        float _6940 = _6906.w;
        vec4 _10324;
        if ((_6906.z / _6940) > 1.0)
        {
            vec4 _10325;
            if (_6887.z > _3471.g_cbPass._fNearPlane)
            {
                vec4 _10282 = _6906;
                _10282.z = _6940;
                _10325 = _10282;
            }
            else
            {
                _10325 = _6906;
            }
            _10324 = _10325;
        }
        else
        {
            _10324 = _6906;
        }
        _10323 = _10324;
    }
    else
    {
        _10323 = _6906;
    }
    interp_instanceID = float(_3214) + 0.5;
    float _4992 = _6887.x;
    float _4993 = _6887.y;
    float _4994 = _6887.z;
    vec4 _4995 = vec4(_4992, _4993, _4994, 1.0);
    float _4996 = dot(_3471.g_cbPass._vfVsClippingPlane[0], _4995);
    float _4997 = -_4996;
    gl_ClipDistance[0] = _4997;
    gl_Position = _10323;
}

