Documentation

SpeedTree Runtime SDK

Version: 10

SpeedTree Runtime SDK

Version: 10

CWindStateMgr class

The CWindStateMgr class is declared and defined in Include/SpeedTree/Core/SpeedTreeWind.h.
Read time 3 minutesLast updated 2 hours ago

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.
Workflow from asset creation to game loop to in-engine animated model
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 Runtime SDK uses the "SDK" wind mode only. The state passed by
CWindStateMgr
is encapsulated in
SWindInputRuntimeSdk::m_sState
, where
m_sState
is of type
SWindStateRuntimeSdk
also defined in
Include/SpeedTree/Core/SpeedTreeWind.h
but also listed below:
struct SWindBranchStateRuntimeSdk{ float3 m_vNoisePosTurbulence; float m_fIndependence; float m_fBend; float m_fOscillation; float m_fTurbulence; float m_fFlexibility;};struct SWindRippleStateRuntimeSdk{ float3 m_vNoisePosTurbulence; float m_fIndependence; float m_fPlanar; float m_fDirectional; float m_fFlexibility; float m_fShimmer;};struct SWindStateRuntimeSdk{ float3 m_vWindDirection; float m_fWindStrength; float3 m_vBoundingBoxMin; float m_fSharedHeightStart; float3 m_vBoundingBoxMax; float m_fBranch1StretchLimit; SWindBranchStateRuntimeSdk m_sShared; SWindBranchStateRuntimeSdk m_sBranch1; SWindBranchStateRuntimeSdk m_sBranch2; SWindRippleStateRuntimeSdk 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
SConfigRuntimeSdk
.
SConfigRuntimeSdk
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
SConfigRuntimeSdk
-related data embedded in the .stsdk file.
The relationship between
SConfigRuntimeSdk
and
SWindStateRuntimeSdk
is that
SConfigRuntimeSdk
contains a complete definition of the wind profile set in the Modeler whereas
SWindStateRuntimeSdk
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.