lightFlareData.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. class LightInfo;
  43. struct ObjectRenderInst;
  44. class SceneRenderState;
  45. class BaseMatInstance;
  46. class GFXOcclusionQuery;
  47. struct LightFlareState
  48. {
  49. ~LightFlareState();
  50. void clear();
  51. /// Object calling LightFlareData::prepRender fills these in!
  52. F32 scale;
  53. F32 fullBrightness;
  54. MatrixF lightMat;
  55. LightInfo *lightInfo;
  56. F32 worldRadius;
  57. /// Used internally by LightFlareData!
  58. U32 visChangedTime;
  59. bool visible;
  60. F32 occlusion;
  61. GFXVertexBufferHandle<GFXVertexPCT> vertBuffer;
  62. GFXOcclusionQuery *occlusionQuery;
  63. GFXOcclusionQuery *fullPixelQuery;
  64. };
  65. class LightFlareData : public SimDataBlock
  66. {
  67. typedef SimDataBlock Parent;
  68. #define MAX_ELEMENTS 20
  69. public:
  70. LightFlareData();
  71. virtual ~LightFlareData();
  72. DECLARE_CONOBJECT( LightFlareData );
  73. static void initPersistFields();
  74. virtual void inspectPostApply();
  75. // SimDataBlock
  76. virtual bool preload( bool server, String &errorStr );
  77. virtual void packData( BitStream *stream );
  78. virtual void unpackData( BitStream *stream );
  79. /// Submits render instances for corona and flare effects.
  80. void prepRender( SceneRenderState *state, LightFlareState *flareState );
  81. protected:
  82. bool _testVisibility( const SceneRenderState *state, LightFlareState *flareState,
  83. U32 *outVisDelta, F32 *outOcclusionFade, Point3F *outLightPosSS );
  84. bool _preload( bool server, String &errorStr );
  85. void _makePrimBuffer( GFXPrimitiveBufferHandle *pb, U32 count );
  86. void _renderCorona( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
  87. protected:
  88. static const U32 LosMask;
  89. static const U32 FadeOutTime = 20;
  90. static const U32 FadeInTime = 125;
  91. static Point3F sBasePoints[4];
  92. // Fields...
  93. F32 mScale;
  94. bool mFlareEnabled;
  95. String mFlareTextureName;
  96. GFXTexHandle mFlareTexture;
  97. F32 mOcclusionRadius;
  98. bool mRenderReflectPass;
  99. RectF mElementRect[MAX_ELEMENTS];
  100. F32 mElementDist[MAX_ELEMENTS];
  101. F32 mElementScale[MAX_ELEMENTS];
  102. ColorF mElementTint[MAX_ELEMENTS];
  103. bool mElementRotate[MAX_ELEMENTS];
  104. bool mElementUseLightColor[MAX_ELEMENTS];
  105. protected:
  106. U32 mElementCount;
  107. GFXPrimitiveBufferHandle mFlarePrimBuffer;
  108. };
  109. #endif // _LIGHTFLAREDATA_H_