projectedShadow.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 _PROJECTEDSHADOW_H_
  23. #define _PROJECTEDSHADOW_H_
  24. #ifndef _DEPTHSORTLIST_H_
  25. #include "collision/depthSortList.h"
  26. #endif
  27. #ifndef _SCENEOBJECT_H_
  28. #include "scene/sceneObject.h"
  29. #endif
  30. #ifndef _TSSHAPEINSTANCE_H_
  31. #include "ts/tsShapeInstance.h"
  32. #endif
  33. #ifndef _LIGHTINGSYSTEM_SHADOWBASE_H_
  34. #include "lighting/common/shadowBase.h"
  35. #endif
  36. class ShapeBase;
  37. class LightInfo;
  38. class DecalData;
  39. class DecalInstance;
  40. class RenderPassManager;
  41. class PostEffect;
  42. class RenderMeshMgr;
  43. class CustomMaterial;
  44. class BaseMatInstance;
  45. class MaterialParameterHandle;
  46. GFX_DeclareTextureProfile( BLProjectedShadowProfile );
  47. GFX_DeclareTextureProfile( BLProjectedShadowZProfile );
  48. class ProjectedShadow : public ShadowBase
  49. {
  50. protected:
  51. /// This parameter is used to
  52. /// adjust the far plane out for our
  53. /// orthographic render in order to
  54. /// force our object towards one end of the
  55. /// the eye space depth range.
  56. static F32 smDepthAdjust;
  57. F32 mRadius;
  58. MatrixF mWorldToLight;
  59. U32 mLastRenderTime;
  60. F32 mShadowLength;
  61. F32 mScore;
  62. bool mUpdateTexture;
  63. Point3F mLastObjectScale;
  64. Point3F mLastObjectPosition;
  65. VectorF mLastLightDir;
  66. DecalData *mDecalData;
  67. DecalInstance *mDecalInstance;
  68. SceneObject *mParentObject;
  69. ShapeBase *mShapeBase;
  70. MaterialParameterHandle *mCasterPositionSC;
  71. MaterialParameterHandle *mShadowLengthSC;
  72. static SimObjectPtr<RenderPassManager> smRenderPass;
  73. static SimObjectPtr<PostEffect> smShadowFilter;
  74. static RenderPassManager* _getRenderPass();
  75. GFXTexHandle mShadowTexture;
  76. GFXTextureTargetRef mRenderTarget;
  77. GFXTextureObject* _getDepthTarget( U32 width, U32 height );
  78. void _renderToTexture( F32 camDist, const TSRenderState &rdata );
  79. bool _updateDecal( const SceneRenderState *sceneState );
  80. void _calcScore( const SceneRenderState *state );
  81. /// Returns a spotlight shadow material for use when
  82. /// rendering meshes into the projected shadow.
  83. static BaseMatInstance* _getShadowMaterial( BaseMatInstance *inMat );
  84. public:
  85. /// @see DecalData
  86. static F32 smFadeStartPixelSize;
  87. static F32 smFadeEndPixelSize;
  88. ProjectedShadow( SceneObject *object );
  89. virtual ~ProjectedShadow();
  90. bool shouldRender( const SceneRenderState *state );
  91. void update( const SceneRenderState *state );
  92. void render( F32 camDist, const TSRenderState &rdata );
  93. U32 getLastRenderTime() const { return mLastRenderTime; }
  94. const F32 getScore() const { return mScore; }
  95. };
  96. #endif // _PROJECTEDSHADOW_H_