| 42 | } |
| 43 | |
| 44 | void WindDeformationConstHandles::setConsts( SceneRenderState *state, |
| 45 | const SceneData &sgData, |
| 46 | GFXShaderConstBuffer *buffer ) |
| 47 | { |
| 48 | PROFILE_SCOPE( WindDeformationConstHandles_setConsts ); |
| 49 | |
| 50 | Point3F windDir( 0, 0, 0 ); |
| 51 | F32 windSpeed = 0; |
| 52 | F32 bendScale = 0; |
| 53 | F32 branchAmp = 0; |
| 54 | F32 detailAmp = 0; |
| 55 | F32 detailFreq = 0; |
| 56 | |
| 57 | const ForestItem *item = (const ForestItem*)sgData.materialHint; |
| 58 | |
| 59 | ForestWindAccumulator *wind = NULL; |
| 60 | if ( item ) |
| 61 | { |
| 62 | // First setup the per-datablock shader constants. |
| 63 | // |
| 64 | // These cannot be skipped as they modifiy the rest |
| 65 | // state of a tree even without wind. |
| 66 | // |
| 67 | const ForestItemData *itemData = item->getData(); |
| 68 | const F32 windScale = itemData->mWindScale; |
| 69 | bendScale = itemData->mTrunkBendScale * windScale; |
| 70 | branchAmp = itemData->mWindBranchAmp * windScale; |
| 71 | detailAmp = itemData->mWindDetailAmp * windScale; |
| 72 | detailFreq = itemData->mWindDetailFreq * windScale; |
| 73 | |
| 74 | // Look for wind state. |
| 75 | wind = WINDMGR->getLocalWind( item->getKey() ); |
| 76 | } |
| 77 | |
| 78 | if ( wind ) |
| 79 | { |
| 80 | // Calculate distance to camera fade. |
| 81 | F32 toCamLen = ( state->getDiffuseCameraPosition() - wind->getPosition()).len(); |
| 82 | F32 toCamInterp = 1.0f - (toCamLen / ForestWindMgr::smWindEffectRadius); |
| 83 | toCamInterp = mClampF( toCamInterp, 0.0f, 1.0f ); |
| 84 | |
| 85 | windDir.set( wind->getDirection().x, wind->getDirection().y, 0.0f ); |
| 86 | windSpeed = wind->getStrength(); |
| 87 | |
| 88 | // Since the effect is just a displacement |
| 89 | // of geometry i need to scale it up for smaller |
| 90 | // trees so it looks like its affecting it more. |
| 91 | // |
| 92 | // TODO: This is possibly a side effect of not |
| 93 | // properly doing the displacement physics in the |
| 94 | // first place. |
| 95 | // |
| 96 | const F32 strengthScale = 1.0f / item->getScale(); |
| 97 | windDir *= strengthScale; |
| 98 | windSpeed *= strengthScale; |
| 99 | |
| 100 | // Add in fade. |
| 101 | windDir *= toCamInterp; |
nothing calls this directly
no test coverage detected