fxFoliageReplicator.h
Engine/source/T3D/fx/fxFoliageReplicator.h
Classes:
class
class
class
class
Public Defines
define
AREA_ANIMATION_ARC() (1.0f / 360.0f)
define
FXFOLIAGE_ALPHA_EPSILON() 1e-4
define
FXFOLIAGEREPLICATOR_COLLISION_MASK() ( | \ | \ )
define
Public Functions
GFXDeclareVertexFormat(GFXVertexFoliage )
Detailed Description
Public Defines
AREA_ANIMATION_ARC() (1.0f / 360.0f)
FXFOLIAGE_ALPHA_EPSILON() 1e-4
FXFOLIAGEREPLICATOR_COLLISION_MASK() ( | \ | \ )
FXFOLIAGEREPLICATOR_NOWATER_COLLISION_MASK() ( | \ )
Public Functions
GFXDeclareVertexFormat(GFXVertexFoliage )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames 26// Copyright (C) 2015 Faust Logic, Inc. 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 28 29#ifndef _FOLIAGEREPLICATOR_H_ 30#define _FOLIAGEREPLICATOR_H_ 31 32#ifndef _SCENEOBJECT_H_ 33#include "scene/sceneObject.h" 34#endif 35#ifndef _GFXTEXTUREHANDLE_H_ 36#include "gfx/gfxTextureHandle.h" 37#endif 38#ifndef _GFXPRIMITIVEBUFFER_H_ 39#include "gfx/gfxPrimitiveBuffer.h" 40#endif 41#ifndef _GBITMAP_H_ 42#include "gfx/bitmap/gBitmap.h" 43#endif 44#ifndef _RENDERPASSMANAGER_H_ 45#include "renderInstance/renderPassManager.h" 46#endif 47#ifndef _MATHUTIL_FRUSTUM_H_ 48#include "math/util/frustum.h" 49#endif 50 51#pragma warning( push, 4 ) 52 53#define AREA_ANIMATION_ARC (1.0f / 360.0f) 54 55#define FXFOLIAGEREPLICATOR_COLLISION_MASK ( TerrainObjectType | \ 56 StaticShapeObjectType | \ 57 WaterObjectType ) 58 59#define FXFOLIAGEREPLICATOR_NOWATER_COLLISION_MASK ( TerrainObjectType | \ 60 StaticShapeObjectType ) 61 62 63#define FXFOLIAGE_ALPHA_EPSILON 1e-4 64 65 66 67//------------------------------------------------------------------------------ 68// Class: fxFoliageItem 69//------------------------------------------------------------------------------ 70class fxFoliageItem 71{ 72public: 73 MatrixF Transform; 74 F32 Width; 75 F32 Height; 76 Box3F FoliageBox; 77 bool Flipped; 78 F32 SwayPhase; 79 F32 SwayTimeRatio; 80 F32 LightPhase; 81 F32 LightTimeRatio; 82 U32 LastFrameSerialID; 83}; 84 85//------------------------------------------------------------------------------ 86// Class: fxFoliageCulledList 87//------------------------------------------------------------------------------ 88class fxFoliageCulledList 89{ 90public: 91 fxFoliageCulledList() {}; 92 fxFoliageCulledList(Box3F SearchBox, fxFoliageCulledList* InVec); 93 ~fxFoliageCulledList() {}; 94 95 void FindCandidates(const Box3F& SearchBox, fxFoliageCulledList* InVec); 96 97 U32 GetListCount(void) { return mCulledObjectSet.size(); }; 98 fxFoliageItem* GetElement(U32 index) { return mCulledObjectSet[index]; }; 99 100 Vector<fxFoliageItem*> mCulledObjectSet; // Culled Object Set. 101}; 102 103 104//------------------------------------------------------------------------------ 105// Class: fxFoliageQuadNode 106//------------------------------------------------------------------------------ 107class fxFoliageQuadrantNode { 108public: 109 U32 Level; 110 Box3F QuadrantBox; 111 fxFoliageQuadrantNode* QuadrantChildNode[4]; 112 Vector<fxFoliageItem*> RenderList; 113 // Used in DrawIndexPrimitive call. 114 U32 startIndex; 115 U32 primitiveCount; 116}; 117 118 119//------------------------------------------------------------------------------ 120// Class: fxFoliageRenderList 121//------------------------------------------------------------------------------ 122class fxFoliageRenderList 123{ 124public: 125 126 Box3F mBox; // Clipping Box. 127 Frustum mFrustum; // View frustum. 128 129 Vector<fxFoliageItem*> mVisObjectSet; // Visible Object Set. 130 F32 mHeightLerp; // Height Lerp. 131 132public: 133 bool IsQuadrantVisible(const Box3F VisBox, const MatrixF& RenderTransform); 134 void SetupClipPlanes(SceneRenderState* state, const F32 FarClipPlane); 135 void DrawQuadBox(const Box3F& QuadBox, const LinearColorF Colour); 136}; 137 138 139// Define a vertex 140GFXDeclareVertexFormat( GFXVertexFoliage ) 141{ 142 Point3F point; 143 Point3F normal; 144 Point2F texCoord; 145 Point2F texCoord2; 146}; 147 148 149//------------------------------------------------------------------------------ 150// Class: fxFoliageReplicator 151//------------------------------------------------------------------------------ 152class fxFoliageReplicator : public SceneObject 153{ 154private: 155 typedef SceneObject Parent; 156 157protected: 158 159 void CreateFoliage(void); 160 void DestroyFoliage(void); 161 void DestroyFoliageItems(); 162 163 164 void SyncFoliageReplicators(void); 165 166 Box3F FetchQuadrant(const Box3F& Box, U32 Quadrant); 167 void ProcessQuadrant(fxFoliageQuadrantNode* pParentNode, fxFoliageCulledList* pCullList, U32 Quadrant); 168 void ProcessNodeChildren(fxFoliageQuadrantNode* pParentNode, fxFoliageCulledList* pCullList); 169 170 enum { FoliageReplicationMask = (1 << 0) }; 171 172 173 U32 mCreationAreaAngle; 174 bool mClientReplicationStarted; 175 U32 mCurrentFoliageCount; 176 177 Vector<fxFoliageQuadrantNode*> mFoliageQuadTree; 178 Vector<fxFoliageItem*> mReplicatedFoliage; 179 fxFoliageRenderList mFrustumRenderSet; 180 181 GFXVertexBufferHandle<GFXVertexFoliage> mVertexBuffer; 182 GFXPrimitiveBufferHandle mPrimBuffer; 183 GFXShaderRef mShader; 184 ShaderData* mShaderData; 185 GBitmap* mAlphaLookup; 186 187 MRandomLCG RandomGen; 188 F32 mFadeInGradient; 189 F32 mFadeOutGradient; 190 S32 mLastRenderTime; 191 F32 mGlobalSwayPhase; 192 F32 mGlobalSwayTimeRatio; 193 F32 mGlobalLightPhase; 194 F32 mGlobalLightTimeRatio; 195 U32 mFrameSerialID; 196 197 U32 mQuadTreeLevels; // Quad-Tree Levels. 198 U32 mPotentialFoliageNodes; // Potential Foliage Nodes. 199 U32 mNextAllocatedNodeIdx; // Next Allocated Node Index. 200 U32 mBillboardsAcquired; // Billboards Acquired. 201 202 // Used for alpha lookup in the pixel shader 203 GFXTexHandle mAlphaTexture; 204 205 GFXStateBlockRef mPlacementSB; 206 GFXStateBlockRef mRenderSB; 207 GFXStateBlockRef mDebugSB; 208 209 GFXShaderConstBufferRef mFoliageShaderConsts; 210 211 GFXShaderConstHandle* mFoliageShaderProjectionSC; 212 GFXShaderConstHandle* mFoliageShaderWorldSC; 213 GFXShaderConstHandle* mFoliageShaderGlobalSwayPhaseSC; 214 GFXShaderConstHandle* mFoliageShaderSwayMagnitudeSideSC; 215 GFXShaderConstHandle* mFoliageShaderSwayMagnitudeFrontSC; 216 GFXShaderConstHandle* mFoliageShaderGlobalLightPhaseSC; 217 GFXShaderConstHandle* mFoliageShaderLuminanceMagnitudeSC; 218 GFXShaderConstHandle* mFoliageShaderLuminanceMidpointSC; 219 GFXShaderConstHandle* mFoliageShaderDistanceRangeSC; 220 GFXShaderConstHandle* mFoliageShaderCameraPosSC; 221 GFXShaderConstHandle* mFoliageShaderTrueBillboardSC; 222 223 //pixel shader 224 GFXShaderConstHandle* mFoliageShaderGroundAlphaSC; 225 GFXShaderConstHandle* mFoliageShaderAmbientColorSC; 226 GFXShaderConstHandle* mDiffuseTextureSC; 227 GFXShaderConstHandle* mAlphaMapTextureSC; 228 229 230 231 bool mDirty; 232 233 void SetupShader(); 234 void SetupBuffers(); 235 void renderObject(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance*); 236 void renderBuffers(SceneRenderState* state); 237 void renderArc(const F32 fRadiusX, const F32 fRadiusY); 238 void renderPlacementArea(const F32 ElapsedTime); 239 void renderQuad(fxFoliageQuadrantNode* quadNode, const MatrixF& RenderTransform, const bool UseDebug); 240 void computeAlphaTex(); 241public: 242 fxFoliageReplicator(); 243 ~fxFoliageReplicator(); 244 245 void StartUp(void); 246 void ShowReplication(void); 247 void HideReplication(void); 248 249 // SceneObject 250 virtual void prepRenderImage( SceneRenderState *state ); 251 252 // SimObject 253 bool onAdd(); 254 void onRemove(); 255 void inspectPostApply(); 256 257 // NetObject 258 U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream); 259 void unpackUpdate(NetConnection *conn, BitStream *stream); 260 261 // Editor 262 void onGhostAlwaysDone(); 263 264 // ConObject. 265 static void initPersistFields(); 266 267 // Field Data. 268 class tagFieldData 269 { 270 public: 271 272 bool mUseDebugInfo; 273 F32 mDebugBoxHeight; 274 U32 mSeed; 275 StringTableEntry mFoliageFile; 276 GFXTexHandle mFoliageTexture; 277 U32 mFoliageCount; 278 U32 mFoliageRetries; 279 280 U32 mInnerRadiusX; 281 U32 mInnerRadiusY; 282 U32 mOuterRadiusX; 283 U32 mOuterRadiusY; 284 285 F32 mMinWidth; 286 F32 mMaxWidth; 287 F32 mMinHeight; 288 F32 mMaxHeight; 289 bool mFixAspectRatio; 290 bool mFixSizeToMax; 291 F32 mOffsetZ; 292 bool mRandomFlip; 293 bool mUseTrueBillboards; 294 295 bool mUseCulling; 296 U32 mCullResolution; 297 F32 mViewDistance; 298 F32 mViewClosest; 299 F32 mFadeInRegion; 300 F32 mFadeOutRegion; 301 F32 mAlphaCutoff; 302 F32 mGroundAlpha; 303 304 bool mSwayOn; 305 bool mSwaySync; 306 F32 mSwayMagnitudeSide; 307 F32 mSwayMagnitudeFront; 308 F32 mMinSwayTime; 309 F32 mMaxSwayTime; 310 311 bool mLightOn; 312 bool mLightSync; 313 F32 mMinLuminance; 314 F32 mMaxLuminance; 315 F32 mLightTime; 316 317 bool mAllowOnTerrain; 318 bool mAllowStatics; 319 bool mAllowOnWater; 320 bool mAllowWaterSurface; 321 S32 mAllowedTerrainSlope; 322 323 bool mHideFoliage; 324 bool mShowPlacementArea; 325 U32 mPlacementBandHeight; 326 LinearColorF mPlaceAreaColour; 327 328 F32 mAmbientModulationBias; 329 tagFieldData() 330 { 331 // Set Defaults. 332 mUseDebugInfo = false; 333 mDebugBoxHeight = 1.0f; 334 mSeed = 1376312589; 335 mFoliageFile = StringTable->EmptyString(); 336 mFoliageTexture = GFXTexHandle(); 337 mFoliageCount = 10; 338 mFoliageRetries = 100; 339 340 mInnerRadiusX = 0; 341 mInnerRadiusY = 0; 342 mOuterRadiusX = 128; 343 mOuterRadiusY = 128; 344 345 mMinWidth = 1; 346 mMaxWidth = 3; 347 mMinHeight = 1; 348 mMaxHeight = 5; 349 mFixAspectRatio = true; 350 mFixSizeToMax = false; 351 mOffsetZ = 0; 352 mRandomFlip = true; 353 mUseTrueBillboards = false; 354 355 mUseCulling = true; 356 mCullResolution = 64; 357 mViewDistance = 50.0f; 358 mViewClosest = 1.0f; 359 mFadeInRegion = 10.0f; 360 mFadeOutRegion = 1.0f; 361 mAlphaCutoff = 0.2f; 362 mGroundAlpha = 1.0f; 363 364 mSwayOn = false; 365 mSwaySync = false; 366 mSwayMagnitudeSide = 0.1f; 367 mSwayMagnitudeFront = 0.2f; 368 mMinSwayTime = 3.0f; 369 mMaxSwayTime = 10.0f; 370 371 mLightOn = false; 372 mLightSync = false; 373 mMinLuminance = 0.7f; 374 mMaxLuminance = 1.0f; 375 mLightTime = 5.0f; 376 377 mAllowOnTerrain = true; 378 mAllowStatics = true; 379 mAllowOnWater = false; 380 mAllowWaterSurface = false; 381 mAllowedTerrainSlope = 90; 382 383 mHideFoliage = false; 384 mShowPlacementArea = true; 385 mPlacementBandHeight = 25; 386 mPlaceAreaColour .set(0.4f, 0, 0.8f); 387 mAmbientModulationBias = 1.0f; 388 } 389 390 } mFieldData; 391 392 // Declare Console Object. 393 DECLARE_CONOBJECT(fxFoliageReplicator); 394}; 395#pragma warning( pop ) 396#endif // _FOLIAGEREPLICATOR_H_ 397