terrCellMaterial.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 _TERRCELLMATERIAL_H_
  23. #define _TERRCELLMATERIAL_H_
  24. #ifndef _TVECTOR_H_
  25. #include "core/util/tVector.h"
  26. #endif
  27. #ifndef _MATTEXTURETARGET_H_
  28. #include "materials/matTextureTarget.h"
  29. #endif
  30. #ifndef _GFXTEXTUREHANDLE_H_
  31. #include "gfx/gfxTextureHandle.h"
  32. #endif
  33. #ifndef _GFXSHADER_H_
  34. #include "gfx/gfxShader.h"
  35. #endif
  36. #ifndef _GFXSTATEBLOCK_H_
  37. #include "gfx/gfxStateBlock.h"
  38. #endif
  39. class SceneRenderState;
  40. struct SceneData;
  41. class TerrainMaterial;
  42. class TerrainBlock;
  43. class BaseMatInstance;
  44. /// This is a complex material which holds one or more
  45. /// optimized shaders for rendering a single cell.
  46. class TerrainCellMaterial
  47. {
  48. protected:
  49. class MaterialInfo
  50. {
  51. public:
  52. MaterialInfo()
  53. {
  54. }
  55. ~MaterialInfo()
  56. {
  57. }
  58. TerrainMaterial *mat;
  59. U32 layerId;
  60. GFXShaderConstHandle *detailTexConst;
  61. GFXTexHandle detailTex;
  62. GFXShaderConstHandle *normalTexConst;
  63. GFXTexHandle normalTex;
  64. GFXShaderConstHandle *detailInfoVConst;
  65. GFXShaderConstHandle *detailInfoPConst;
  66. };
  67. class Pass
  68. {
  69. public:
  70. Pass()
  71. : shader( NULL )
  72. {
  73. }
  74. ~Pass()
  75. {
  76. for ( U32 i=0; i < materials.size(); i++ )
  77. delete materials[i];
  78. }
  79. Vector<MaterialInfo*> materials;
  80. ///
  81. GFXShader *shader;
  82. GFXShaderConstBufferRef consts;
  83. GFXStateBlockRef stateBlock;
  84. GFXStateBlockRef wireframeStateBlock;
  85. GFXShaderConstHandle *modelViewProjConst;
  86. GFXShaderConstHandle *worldViewOnly;
  87. GFXShaderConstHandle *viewToObj;
  88. GFXShaderConstHandle *eyePosWorldConst;
  89. GFXShaderConstHandle *eyePosConst;
  90. GFXShaderConstHandle *objTransConst;
  91. GFXShaderConstHandle *worldToObjConst;
  92. GFXShaderConstHandle *vEyeConst;
  93. GFXShaderConstHandle *layerSizeConst;
  94. GFXShaderConstHandle *lightParamsConst;
  95. GFXShaderConstHandle *lightInfoBufferConst;
  96. GFXShaderConstHandle *baseTexMapConst;
  97. GFXShaderConstHandle *layerTexConst;
  98. GFXShaderConstHandle *lightMapTexConst;
  99. GFXShaderConstHandle *squareSize;
  100. GFXShaderConstHandle *oneOverTerrainSize;
  101. GFXShaderConstHandle *fogDataConst;
  102. GFXShaderConstHandle *fogColorConst;
  103. };
  104. TerrainBlock *mTerrain;
  105. U64 mMaterials;
  106. Vector<Pass> mPasses;
  107. U32 mCurrPass;
  108. GFXTexHandle mBaseMapTexture;
  109. GFXTexHandle mLayerMapTexture;
  110. NamedTexTargetRef mLightInfoTarget;
  111. /// The prepass material for this material.
  112. TerrainCellMaterial *mPrePassMat;
  113. /// The reflection material for this material.
  114. TerrainCellMaterial *mReflectMat;
  115. /// A vector of all terrain cell materials loaded in the system.
  116. static Vector<TerrainCellMaterial*> smAllMaterials;
  117. bool _createPass( Vector<MaterialInfo*> *materials,
  118. Pass *pass,
  119. bool firstPass,
  120. bool prePassMat,
  121. bool reflectMat,
  122. bool baseOnly );
  123. void _updateMaterialConsts( Pass *pass );
  124. public:
  125. TerrainCellMaterial();
  126. ~TerrainCellMaterial();
  127. void init( TerrainBlock *block,
  128. U64 activeMaterials,
  129. bool prePassMat = false,
  130. bool reflectMat = false,
  131. bool baseOnly = false );
  132. /// Returns a prepass material from this material.
  133. TerrainCellMaterial* getPrePassMat();
  134. /// Returns the reflection material from this material.
  135. TerrainCellMaterial* getReflectMat();
  136. void setTransformAndEye( const MatrixF &modelXfm,
  137. const MatrixF &viewXfm,
  138. const MatrixF &projectXfm,
  139. F32 farPlane );
  140. ///
  141. bool setupPass( const SceneRenderState *state,
  142. const SceneData &sceneData );
  143. ///
  144. static BaseMatInstance* getShadowMat();
  145. ///
  146. static void _updateDefaultAnisotropy();
  147. };
  148. #endif // _TERRCELLMATERIAL_H_