advancedLightManager.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 _ADVANCEDLIGHTMANAGER_H_
  23. #define _ADVANCEDLIGHTMANAGER_H_
  24. #ifndef _SIMOBJECT_H_
  25. #include "console/simObject.h"
  26. #endif
  27. #ifndef _LIGHTMANAGER_H_
  28. #include "lighting/lightManager.h"
  29. #endif
  30. #ifndef _LIGHTINFO_H_
  31. #include "lighting/lightInfo.h"
  32. #endif
  33. #ifndef _GFXTEXTUREHANDLE_H_
  34. #include "gfx/gfxTextureHandle.h"
  35. #endif
  36. #ifndef _GFXTARGET_H_
  37. #include "gfx/gfxTarget.h"
  38. #endif
  39. #ifndef _TDICTIONARY_H_
  40. #include "core/util/tDictionary.h"
  41. #endif
  42. #ifndef _LIGHTSHADOWMAP_H_
  43. #include "lighting/shadowMap/lightShadowMap.h"
  44. #endif
  45. #ifndef _GFXPRIMITIVEBUFFER_H_
  46. #include "gfx/gfxPrimitiveBuffer.h"
  47. #endif
  48. #ifndef _GFXVERTEXBUFFER_H_
  49. #include "gfx/gfxVertexBuffer.h"
  50. #endif
  51. class AvailableSLInterfaces;
  52. class AdvancedLightBinManager;
  53. class RenderDeferredMgr;
  54. class BaseMatInstance;
  55. class MaterialParameters;
  56. class MaterialParameterHandle;
  57. class GFXShader;
  58. class GFXShaderConstHandle;
  59. class ShadowMapManager;
  60. class AdvancedLightManager : public LightManager
  61. {
  62. typedef LightManager Parent;
  63. public:
  64. /// Return the lightBinManager for this light manager.
  65. AdvancedLightBinManager* getLightBinManager() { return mLightBinManager; }
  66. RenderDeferredMgr* getDeferredRenderBin() { return mDeferredRenderBin; }
  67. // LightManager
  68. virtual bool isCompatible() const;
  69. virtual void activate( SceneManager *sceneManager );
  70. virtual void deactivate();
  71. virtual void registerGlobalLight(LightInfo *light, SimObject *obj);
  72. virtual void unregisterAllLights();
  73. virtual void setLightInfo( ProcessedMaterial *pmat,
  74. const Material *mat,
  75. const SceneData &sgData,
  76. const SceneRenderState *state,
  77. U32 pass,
  78. GFXShaderConstBuffer *shaderConsts );
  79. virtual bool setTextureStage( const SceneData &sgData,
  80. const U32 currTexFlag,
  81. const U32 textureSlot,
  82. GFXShaderConstBuffer *shaderConsts,
  83. ShaderConstHandles *handles );
  84. typedef GFXVertexPC LightVertex;
  85. GFXVertexBufferHandle<LightVertex> getSphereMesh(U32 &outNumPrimitives, GFXPrimitiveBuffer *&outPrimitives );
  86. GFXVertexBufferHandle<LightVertex> getConeMesh(U32 &outNumPrimitives, GFXPrimitiveBuffer *&outPrimitives );
  87. LightShadowMap* findShadowMapForObject( SimObject *object );
  88. #ifndef TORQUE_BASIC_LIGHTING
  89. static F32 getShadowFilterDistance() { return smProjectedShadowFilterDistance; }
  90. #endif
  91. protected:
  92. // LightManager
  93. virtual void _addLightInfoEx( LightInfo *lightInfo );
  94. virtual void _initLightFields();
  95. /// A simple protected singleton. Use LightManager::findByName()
  96. /// to access this light manager.
  97. /// @see LightManager::findByName()
  98. static AdvancedLightManager smSingleton;
  99. // These are protected because we're a singleton and
  100. // no one else should be creating us!
  101. AdvancedLightManager();
  102. virtual ~AdvancedLightManager();
  103. SimObjectPtr<AdvancedLightBinManager> mLightBinManager;
  104. SimObjectPtr<RenderDeferredMgr> mDeferredRenderBin;
  105. LightConstantMap mConstantLookup;
  106. GFXShaderRef mLastShader;
  107. LightingShaderConstants* mLastConstants;
  108. // Convex geometry for lights
  109. GFXVertexBufferHandle<LightVertex> mSphereGeometry;
  110. GFXPrimitiveBufferHandle mSphereIndices;
  111. U32 mSpherePrimitiveCount;
  112. GFXVertexBufferHandle<LightVertex> mConeGeometry;
  113. GFXPrimitiveBufferHandle mConeIndices;
  114. U32 mConePrimitiveCount;
  115. LightingShaderConstants* getLightingShaderConstants(GFXShaderConstBuffer* shader);
  116. #ifndef TORQUE_BASIC_LIGHTING
  117. /// This is used to determine the distance
  118. /// at which the shadow filtering PostEffect
  119. /// will be enabled for ProjectedShadow.
  120. static F32 smProjectedShadowFilterDistance;
  121. #endif
  122. };
  123. #endif // _ADVANCEDLIGHTMANAGER_H_