lightFlareData.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _LIGHTFLAREDATA_H_
  23. #define _LIGHTFLAREDATA_H_
  24. #ifndef _SIMDATABLOCK_H_
  25. #include "console/simDatablock.h"
  26. #endif
  27. #ifndef _GFXTEXTUREHANDLE_H_
  28. #include "gfx/gfxTextureHandle.h"
  29. #endif
  30. #ifndef _GFXPRIMITIVEBUFFER_H_
  31. #include "gfx/gfxPrimitiveBuffer.h"
  32. #endif
  33. #ifndef _CONSOLETYPES_H_
  34. #include "console/consoleTypes.h"
  35. #endif
  36. #ifndef _GFXVERTEXBUFFER_H_
  37. #include "gfx/gfxVertexBuffer.h"
  38. #endif
  39. #ifndef _GFXSTATEBLOCK_H_
  40. #include "gfx/gfxStateBlock.h"
  41. #endif
  42. #ifndef _GFXOCCLUSIONQUERY_H_
  43. #include "gfx/gfxOcclusionQuery.h"
  44. #endif
  45. class LightInfo;
  46. struct ObjectRenderInst;
  47. class SceneRenderState;
  48. class BaseMatInstance;
  49. struct LightFlareState
  50. {
  51. ~LightFlareState();
  52. void clear();
  53. /// Object calling LightFlareData::prepRender fills these in!
  54. F32 scale;
  55. F32 fullBrightness;
  56. MatrixF lightMat;
  57. LightInfo *lightInfo;
  58. F32 worldRadius;
  59. /// Used internally by LightFlareData!
  60. U32 visChangedTime;
  61. bool visible;
  62. F32 occlusion;
  63. GFXVertexBufferHandle<GFXVertexPCT> vertBuffer;
  64. GFXOcclusionQueryHandle occlusionQuery;
  65. GFXOcclusionQueryHandle fullPixelQuery;
  66. };
  67. class LightFlareData : public SimDataBlock
  68. {
  69. typedef SimDataBlock Parent;
  70. #define MAX_ELEMENTS 20
  71. public:
  72. LightFlareData();
  73. virtual ~LightFlareData();
  74. DECLARE_CONOBJECT( LightFlareData );
  75. static void initPersistFields();
  76. virtual void inspectPostApply();
  77. // SimDataBlock
  78. virtual bool preload( bool server, String &errorStr );
  79. virtual void packData( BitStream *stream );
  80. virtual void unpackData( BitStream *stream );
  81. /// Submits render instances for corona and flare effects.
  82. void prepRender( SceneRenderState *state, LightFlareState *flareState );
  83. protected:
  84. bool _testVisibility( const SceneRenderState *state, LightFlareState *flareState,
  85. U32 *outVisDelta, F32 *outOcclusionFade, Point3F *outLightPosSS );
  86. bool _preload( bool server, String &errorStr );
  87. void _makePrimBuffer( GFXPrimitiveBufferHandle *pb, U32 count );
  88. void _renderCorona( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
  89. protected:
  90. static const U32 LosMask;
  91. static const U32 FadeOutTime = 20;
  92. static const U32 FadeInTime = 125;
  93. static Point3F sBasePoints[4];
  94. // Fields...
  95. F32 mScale;
  96. bool mFlareEnabled;
  97. String mFlareTextureName;
  98. GFXTexHandle mFlareTexture;
  99. F32 mOcclusionRadius;
  100. bool mRenderReflectPass;
  101. RectF mElementRect[MAX_ELEMENTS];
  102. F32 mElementDist[MAX_ELEMENTS];
  103. F32 mElementScale[MAX_ELEMENTS];
  104. ColorF mElementTint[MAX_ELEMENTS];
  105. bool mElementRotate[MAX_ELEMENTS];
  106. bool mElementUseLightColor[MAX_ELEMENTS];
  107. protected:
  108. U32 mElementCount;
  109. GFXPrimitiveBufferHandle mFlarePrimBuffer;
  110. };
  111. #endif // _LIGHTFLAREDATA_H_