renderParticleMgr.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 _RENDER_PARTICLE_MGR_H_
  23. #define _RENDER_PARTICLE_MGR_H_
  24. #ifndef _TEXTARGETBIN_MGR_H_
  25. #include "renderInstance/renderTexTargetBinManager.h"
  26. #endif
  27. #ifndef _GFXPRIMITIVEBUFFER_H_
  28. #include "gfx/gfxPrimitiveBuffer.h"
  29. #endif
  30. GFXDeclareVertexFormat( CompositeQuadVert )
  31. {
  32. GFXVertexColor uvCoord;
  33. };
  34. class RenderParticleMgr : public RenderTexTargetBinManager
  35. {
  36. typedef RenderTexTargetBinManager Parent;
  37. friend class RenderTranslucentMgr;
  38. public:
  39. // Generic Deferred Render Instance Type
  40. static const RenderInstType RIT_Particles;
  41. RenderParticleMgr();
  42. RenderParticleMgr( F32 renderOrder, F32 processAddOrder );
  43. virtual ~RenderParticleMgr();
  44. // RenderBinManager
  45. void render(SceneRenderState * state);
  46. void sort();
  47. void clear();
  48. void addElement( RenderInst *inst );
  49. // ConsoleObject
  50. DECLARE_CONOBJECT(RenderParticleMgr);
  51. const static U8 HighResStencilRef = 0x80;
  52. const static U8 ParticleSystemStencilMask = 0x80; // We are using the top bit
  53. const static U32 OffscreenPoolSize = 5;
  54. virtual void setTargetChainLength(const U32 chainLength);
  55. protected:
  56. // Override
  57. virtual bool _handleGFXEvent(GFXDevice::GFXDeviceEventType event);
  58. bool _initShader();
  59. void _initGFXResources();
  60. void _onLMActivate( const char*, bool activate );
  61. // Not only a helper method, but a method for the RenderTranslucentMgr to
  62. // request a particle system draw
  63. void renderInstance(ParticleRenderInst *ri, SceneRenderState *state);
  64. public:
  65. void renderParticle(ParticleRenderInst *ri, SceneRenderState *state);
  66. protected:
  67. bool mOffscreenRenderEnabled;
  68. /// The deferred render target used for the
  69. /// soft particle shader effect.
  70. NamedTexTargetRef mDeferredTarget;
  71. /// The shader used for particle rendering.
  72. GFXShaderRef mParticleShader;
  73. GFXShaderRef mParticleCompositeShader;
  74. NamedTexTargetRef mEdgeTarget;
  75. struct OffscreenSystemEntry
  76. {
  77. S32 targetChainIdx;
  78. MatrixF clipMatrix;
  79. RectF screenRect;
  80. bool drawnThisFrame;
  81. Vector<ParticleRenderInst *> pInstances;
  82. };
  83. Vector<OffscreenSystemEntry> mOffscreenSystems;
  84. struct ShaderConsts
  85. {
  86. GFXShaderConstBufferRef mShaderConsts;
  87. GFXShaderConstHandle *mModelViewProjSC;
  88. GFXShaderConstHandle *mFSModelViewProjSC;
  89. GFXShaderConstHandle *mOneOverFarSC;
  90. GFXShaderConstHandle *mOneOverSoftnessSC;
  91. GFXShaderConstHandle *mDeferredTargetParamsSC;
  92. GFXShaderConstHandle *mAlphaFactorSC;
  93. GFXShaderConstHandle *mAlphaScaleSC;
  94. GFXShaderConstHandle *mSamplerDiffuse;
  95. GFXShaderConstHandle *mSamplerDeferredTex;
  96. GFXShaderConstHandle *mSamplerParaboloidLightMap;
  97. } mParticleShaderConsts;
  98. struct CompositeShaderConsts
  99. {
  100. GFXShaderConstBufferRef mShaderConsts;
  101. GFXShaderConstHandle *mSystemDepth;
  102. GFXShaderConstHandle *mScreenRect;
  103. GFXShaderConstHandle *mSamplerColorSource;
  104. GFXShaderConstHandle *mSamplerEdgeSource;
  105. GFXShaderConstHandle *mEdgeTargetParamsSC;
  106. GFXShaderConstHandle *mOffscreenTargetParamsSC;
  107. } mParticleCompositeShaderConsts;
  108. GFXVertexBufferHandle<CompositeQuadVert> mScreenQuadVertBuff;
  109. GFXPrimitiveBufferHandle mScreenQuadPrimBuff;
  110. GFXStateBlockRef mStencilClearSB;
  111. GFXStateBlockRef mHighResBlocks[ParticleRenderInst::BlendStyle_COUNT];
  112. GFXStateBlockRef mOffscreenBlocks[ParticleRenderInst::BlendStyle_COUNT];
  113. GFXStateBlockRef mBackbufferBlocks[ParticleRenderInst::BlendStyle_COUNT];
  114. GFXStateBlockRef mMixedResBlocks[ParticleRenderInst::BlendStyle_COUNT];
  115. public:
  116. GFXStateBlockRef _getHighResStateBlock(ParticleRenderInst *ri);
  117. GFXStateBlockRef _getMixedResStateBlock(ParticleRenderInst *ri);
  118. GFXStateBlockRef _getOffscreenStateBlock(ParticleRenderInst *ri);
  119. GFXStateBlockRef _getCompositeStateBlock(ParticleRenderInst *ri);
  120. ShaderConsts &_getShaderConsts() { return mParticleShaderConsts; };
  121. };
  122. #endif // _RENDER_TRANSLUCENT_MGR_H_