lightFlareData.h 4.2 KB

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