basicLightManager.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 _BASICLIGHTMANAGER_H_
  23. #define _BASICLIGHTMANAGER_H_
  24. #ifndef _LIGHTMANAGER_H_
  25. #include "lighting/lightManager.h"
  26. #endif
  27. #ifndef _TDICTIONARY_H_
  28. #include "core/util/tDictionary.h"
  29. #endif
  30. #ifndef _GFXSHADER_H_
  31. #include "gfx/gfxShader.h"
  32. #endif
  33. #ifndef _SIMOBJECT_H_
  34. #include "console/simObject.h"
  35. #endif
  36. #ifndef _TSINGLETON_H_
  37. #include "core/util/tSingleton.h"
  38. #endif
  39. class AvailableSLInterfaces;
  40. class GFXShaderConstHandle;
  41. class RenderDeferredMgr;
  42. class PlatformTimer;
  43. class blTerrainSystem;
  44. class BasicLightManager : public LightManager
  45. {
  46. typedef LightManager Parent;
  47. // For access to protected constructor.
  48. friend class ManagedSingleton<BasicLightManager>;
  49. public:
  50. // LightManager
  51. virtual bool isCompatible() const;
  52. virtual void activate( SceneManager *sceneManager );
  53. virtual void deactivate();
  54. virtual void setLightInfo(ProcessedMaterial* pmat, const Material* mat, const SceneData& sgData, const SceneRenderState *state, U32 pass, GFXShaderConstBuffer* shaderConsts);
  55. virtual bool setTextureStage(const SceneData& sgData, const U32 currTexFlag, const U32 textureSlot, GFXShaderConstBuffer* shaderConsts, ShaderConstHandles* handles) { return false; }
  56. static F32 getShadowFilterDistance() { return smProjectedShadowFilterDistance; }
  57. protected:
  58. // LightManager
  59. virtual void _addLightInfoEx( LightInfo *lightInfo ) { }
  60. virtual void _initLightFields() { }
  61. void _onPreRender( SceneManager *sceneManger, const SceneRenderState *state );
  62. // These are protected because we're a singleton and
  63. // no one else should be creating us!
  64. BasicLightManager();
  65. virtual ~BasicLightManager();
  66. SimObjectPtr<RenderDeferredMgr> mDeferredRenderBin;
  67. struct LightingShaderConstants
  68. {
  69. bool mInit;
  70. GFXShaderRef mShader;
  71. GFXShaderConstHandle *mLightPosition;
  72. GFXShaderConstHandle *mLightDiffuse;
  73. GFXShaderConstHandle *mLightAmbient;
  74. GFXShaderConstHandle *mLightConfigDataSC;
  75. GFXShaderConstHandle *mLightSpotDir;
  76. GFXShaderConstHandle *mLightSpotParamsSC;
  77. GFXShaderConstHandle* mHasVectorLightSC;
  78. GFXShaderConstHandle* mVectorLightDirectionSC;
  79. GFXShaderConstHandle* mVectorLightColorSC;
  80. GFXShaderConstHandle* mVectorLightBrightnessSC;
  81. LightingShaderConstants();
  82. ~LightingShaderConstants();
  83. void init( GFXShader *shader );
  84. void _onShaderReload();
  85. };
  86. typedef Map<GFXShader*, LightingShaderConstants*> LightConstantMap;
  87. LightConstantMap mConstantLookup;
  88. GFXShaderRef mLastShader;
  89. LightingShaderConstants* mLastConstants;
  90. /// Statics used for light manager/projected shadow metrics.
  91. static U32 smActiveShadowPlugins;
  92. static U32 smShadowsUpdated;
  93. static U32 smElapsedUpdateMs;
  94. /// This is used to determine the distance
  95. /// at which the shadow filtering PostEffect
  96. /// will be enabled for ProjectedShadow.
  97. static F32 smProjectedShadowFilterDistance;
  98. /// A timer used for tracking update time.
  99. PlatformTimer *mTimer;
  100. blTerrainSystem* mTerrainSystem;
  101. public:
  102. // For ManagedSingleton.
  103. static const char* getSingletonName() { return "BasicLightManager"; }
  104. };
  105. #define BLM ManagedSingleton<BasicLightManager>::instance()
  106. #endif // _BASICLIGHTMANAGER_H_