meta data for this page
CWindStateMgr class
The CWindStateMgr class is declared and defined in Include/SpeedTree/Core/SpeedTreeWind.h
. 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 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
also defined in Include/SpeedTree/Core/SpeedTreeWind.h
but also listed below:
struct SWindBranchStateSdk { float3 m_vNoisePosTurbulence; float m_fIndependence; float m_fBend; float m_fOscillation; float m_fTurbulence; float m_fFlexibility; }; struct SWindRippleStateSdk { float3 m_vNoisePosTurbulence; float m_fIndependence; float m_fPlanar; float m_fDirectional; float m_fFlexibility; float m_fShimmer; }; struct SWindStateSdk { float3 m_vWindDirection; float m_fWindStrength; float3 m_vBoundingBoxMin; float m_fSharedHeightStart; float3 m_vBoundingBoxMax; float m_fBranch1StretchLimit; SWindBranchStateSdk m_sShared; SWindBranchStateSdk m_sBranch1; SWindBranchStateSdk m_sBranch2; SWindRippleStateSdk m_sRipple; float m_fBranch2StretchLimit; };
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.