User Tools

Site Tools


CWindStateMgr Class

As highlighted in yellow in the figure below, CWindStateMgr feeds state information into a wind-enabled vertex shader through shader constants. The state is defined by an artist in the Modeler application when the wind behavior is tuned.

CWindStateMgr is the same class used by all versions of the Modeler (games, cinematic, and subscription) and can support all of SpeedTree's different wind modes, though the Games 8 SDK uses the “SDK” wind mode only. The state passed by CWindStateMgr is encapsulated in SWindInputSdk::m_sState, where m_sState is of type SWindStateSdk defined in Include/SpeedTree/Core/WindTypes.h but also listed below:

struct SWindBranchStateSdk
{
    float3              m_vNoisePosTurbulence;
    float               m_fNoiseTurbulenceIndependence;
 
    float               m_fBend;
    float               m_fTurbulence;
    float               m_fFlex;
    float               m_fNoiseOffset;
};
 
struct SWindRippleStateSdk
{
    float3              m_vNoisePosTurbulence;
    float               m_fNoiseTurbulenceIndependence;
 
    float               m_fBend;
    float               m_fTurbulence;
    float               m_fNoiseOffset;
};
 
struct SWindStateSdk
{
    float3              m_vWindDirection;
    float               m_fWindStrength;
 
    float               m_fGlobalHeightInverse;
    float               m_fFullBranchMove;
    float               m_fFullRipple;
 
    float3              m_vBoundingBoxMin;
    float               m_fBranchStiffnessAmount;
    float3              m_vBoundingBoxMax;
    float               m_fBranchStiffnessUp;
 
    SWindBranchStateSdk m_sShared;
    SWindBranchStateSdk m_sBranch;
    SWindRippleStateSdk m_sRipple;
 
    float3              m_vWindProjDir;
    float               m_fBranchStretch;
    float3              m_vWindProjRight;
    float               m_fShimmer;
    float3              m_vWindProjUp;
    float               m_fIsGrass;
};

Initialization

Each instantiation of a CCore object (which represents a base tree model) has its own CWindStateMgr object. CWindStateMgr has a series of overloading Configure() functions, one of which takes a SConfigSdk. SConfigSdk contains all of the wind behavior parameters set by the artist in the Modeler. When an .stsdk file is loaded via CCore::LoadTree(), the CWindStateMgr object embedded in that CCore object is automatically initialized with the SConfigSdk-related data embedded in the .stsdk file.

The relationship between SConfigSdk and SWindStateSdk is that SConfigSdk contains a complete definition of the wind profile set in the Modeler whereas SWindStateSdk houses the data the wind shader functions need at a particular snapshot in time.

Forest Library Wind Functions

The CForest class provides convenience functions for controlling the wind for a set of base trees without having to access each tree separately. The functions include the following:

Function Description
CForest::WindEnable() This is an initialization-level function and shouldn't be called to enable/disable the wind while the rendering loop is active. If wind is to be supported, call this function once during initialization.
CForest::WindAdvance() Advances the wind simulation for all of the base tree objects in the forest. The second parameter, time, is in seconds and represents time since the beginning of the simulation, not the time since the last call or frame. Not free in terms of CPU but not expensive.
CForest::WindPreroll() A convenience function for bypassing the start-up state of the wind simulation. It's common to use a 10-second or so pre-roll.
CForest::WindSetStrength() Updates the strength of all of the base trees in the forest.
CForest::WindSetDirection() Updates the direction of all of the base trees in the forest.

You can still set an individual base tree's wind parameters by querying the CWind object of a CTree and setting its parameters directly. All of the instances of a CTree share this wind object. Each will have its own slight variation of the wind, as provided by the wind shader's usage of the tree's position as a unique numerical identifier. However, all of the wind parameters set for the base tree in the Modeler application will remain the same across all its instances.