Torque3D Documentation / _generateds / terrCellMaterial.h

terrCellMaterial.h

Engine/source/terrain/terrCellMaterial.h

More...

Classes:

class

This is a complex material which holds one or more optimized shaders for rendering a single cell.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _TERRCELLMATERIAL_H_
 25#define _TERRCELLMATERIAL_H_
 26
 27#ifndef _TVECTOR_H_
 28#include "core/util/tVector.h"
 29#endif
 30#ifndef _MATTEXTURETARGET_H_
 31#include "materials/matTextureTarget.h"
 32#endif
 33#ifndef _GFXTEXTUREHANDLE_H_
 34#include "gfx/gfxTextureHandle.h"
 35#endif
 36#ifndef _GFXSHADER_H_
 37#include "gfx/gfxShader.h"
 38#endif
 39#ifndef _GFXSTATEBLOCK_H_
 40#include "gfx/gfxStateBlock.h"
 41#endif
 42
 43
 44class GFXTextureArray;
 45class SceneRenderState;
 46struct SceneData;
 47class TerrainMaterial;
 48class TerrainBlock;
 49class BaseMatInstance;
 50
 51
 52/// This is a complex material which holds one or more
 53/// optimized shaders for rendering a single cell.
 54class TerrainCellMaterial
 55{
 56protected:
 57
 58   class MaterialInfo
 59   {
 60   public:
 61
 62      MaterialInfo()
 63         :mat(NULL), layerId(0), mBlendDepthConst(NULL), mBlendContrastConst(NULL)
 64      {
 65      }
 66
 67      ~MaterialInfo() 
 68      {
 69      }
 70
 71      TerrainMaterial *mat;
 72      U32 layerId;
 73      GFXShaderConstHandle *mBlendDepthConst;
 74      GFXShaderConstHandle *mBlendContrastConst;
 75   };
 76
 77   ///
 78   GFXShader *mShader;
 79
 80   GFXShaderConstBufferRef mConsts;
 81
 82   GFXStateBlockRef mStateBlock;
 83   GFXStateBlockRef mWireframeStateBlock;
 84   GFXStateBlockRef mReflectionStateBlock;
 85
 86   GFXShaderConstHandle *mModelViewProjConst;
 87   GFXShaderConstHandle *mWorldViewOnlyConst;
 88   GFXShaderConstHandle *mViewToObjConst;
 89
 90   GFXShaderConstHandle *mEyePosWorldConst;
 91   GFXShaderConstHandle *mEyePosConst;
 92
 93   GFXShaderConstHandle *mObjTransConst;
 94   GFXShaderConstHandle *mWorldToObjConst;
 95   GFXShaderConstHandle *mVEyeConst;
 96
 97   GFXShaderConstHandle *mLayerSizeConst;
 98   GFXShaderConstHandle *mLightParamsConst;
 99   GFXShaderConstHandle *mLightInfoBufferConst;
100
101   GFXShaderConstHandle *mBaseTexMapConst;
102   GFXShaderConstHandle *mLayerTexConst;
103
104   GFXShaderConstHandle *mLightMapTexConst;
105
106   GFXShaderConstHandle *mSquareSizeConst;
107   GFXShaderConstHandle *mOneOverTerrainSizeConst;
108
109   GFXShaderConstHandle* mDetailInfoVArrayConst;
110   GFXShaderConstHandle* mDetailInfoPArrayConst;
111   GFXShaderConstHandle* mMacroInfoVArrayConst;
112   GFXShaderConstHandle* mMacroInfoPArrayConst;
113
114   GFXShaderConstHandle *mFogDataConst;
115   GFXShaderConstHandle *mFogColorConst;
116
117   GFXShaderConstHandle *mDetailTexArrayConst;
118   GFXShaderConstHandle *mMacroTexArrayConst;
119   GFXShaderConstHandle *mNormalTexArrayConst;
120   GFXShaderConstHandle *mOrmTexArrayConst;
121
122   GFXShaderConstHandle* mBlendDepthConst;
123
124   TerrainBlock *mTerrain;
125
126   U32 mCurrPass;
127
128   U64 mMaterials;
129   Vector<MaterialInfo*> mMaterialInfos;
130
131   static const Vector<String> mSamplerNames;
132
133   GFXTexHandle mBaseMapTexture;
134
135   GFXTexHandle mLayerMapTexture;
136
137   NamedTexTargetRef mLightInfoTarget;
138
139   /// The deferred material for this material.
140   TerrainCellMaterial *mDeferredMat;
141
142   /// The reflection material for this material.
143   TerrainCellMaterial *mReflectMat;
144
145   /// A vector of all terrain cell materials loaded in the system.
146   static Vector<TerrainCellMaterial*> smAllMaterials;
147
148   bool _initShader( bool deferredMat,
149                     bool reflectMat,
150                     bool baseOnly );
151
152   void _updateMaterialConsts();
153
154public:
155   
156   TerrainCellMaterial();
157   ~TerrainCellMaterial();
158
159   void init(  TerrainBlock *block, 
160               U64 activeMaterials,
161               bool deferredMat = false,
162               bool reflectMat = false,
163               bool baseOnly = false );
164
165   /// Returns a deferred material from this material.
166   TerrainCellMaterial* getDeferredMat();
167
168   /// Returns the reflection material from this material.
169   TerrainCellMaterial* getReflectMat();
170
171   void setTransformAndEye(   const MatrixF &modelXfm, 
172                              const MatrixF &viewXfm,
173                              const MatrixF &projectXfm,
174                              F32 farPlane );
175
176   ///
177   bool setupPass(   const SceneRenderState *state,
178                     const SceneData &sceneData );
179
180   ///
181   static BaseMatInstance* getShadowMat();
182
183   /// 
184   static void _updateDefaultAnisotropy();
185};
186
187#endif // _TERRCELLMATERIAL_H_
188
189