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 SceneRenderState;
 45struct SceneData;
 46class TerrainMaterial;
 47class TerrainBlock;
 48class BaseMatInstance;
 49
 50
 51/// This is a complex material which holds one or more
 52/// optimized shaders for rendering a single cell.
 53class TerrainCellMaterial
 54{
 55protected:
 56
 57   class MaterialInfo
 58   {
 59   public:
 60
 61      MaterialInfo()
 62      {
 63      }
 64
 65      ~MaterialInfo() 
 66      {
 67      }
 68
 69      TerrainMaterial *mat;
 70      U32 layerId;
 71
 72      GFXShaderConstHandle *detailTexConst;
 73      GFXTexHandle detailTex;
 74
 75      GFXShaderConstHandle *macroTexConst;
 76      GFXTexHandle macroTex;
 77
 78      GFXShaderConstHandle *normalTexConst;
 79      GFXTexHandle normalTex;
 80
 81      GFXShaderConstHandle *detailInfoVConst;
 82      GFXShaderConstHandle *detailInfoPConst;
 83
 84     GFXShaderConstHandle *macroInfoVConst;
 85      GFXShaderConstHandle *macroInfoPConst;
 86   };
 87
 88   class Pass
 89   {
 90   public:
 91
 92      Pass() 
 93         :  shader( NULL )                     
 94      {
 95      }
 96
 97      ~Pass() 
 98      {
 99         for ( U32 i=0; i < materials.size(); i++ )
100            delete materials[i];
101      }
102
103      Vector<MaterialInfo*> materials;
104
105      ///
106      GFXShader *shader;
107
108      GFXShaderConstBufferRef consts;
109
110      GFXStateBlockRef stateBlock;
111      GFXStateBlockRef wireframeStateBlock;
112      GFXStateBlockRef reflectionStateBlock;
113
114      GFXShaderConstHandle *modelViewProjConst;
115      GFXShaderConstHandle *worldViewOnly;
116      GFXShaderConstHandle *viewToObj;
117
118      GFXShaderConstHandle *eyePosWorldConst;
119      GFXShaderConstHandle *eyePosConst;
120
121      GFXShaderConstHandle *objTransConst;
122      GFXShaderConstHandle *worldToObjConst;
123      GFXShaderConstHandle *vEyeConst;
124
125      GFXShaderConstHandle *layerSizeConst;
126      GFXShaderConstHandle *lightParamsConst;
127      GFXShaderConstHandle *lightInfoBufferConst;
128
129      GFXShaderConstHandle *baseTexMapConst;
130      GFXShaderConstHandle *layerTexConst;
131
132      GFXShaderConstHandle *lightMapTexConst;
133
134      GFXShaderConstHandle *squareSize;
135      GFXShaderConstHandle *oneOverTerrainSize;
136
137      GFXShaderConstHandle *fogDataConst;
138      GFXShaderConstHandle *fogColorConst;
139   };
140
141   TerrainBlock *mTerrain;
142
143   U64 mMaterials;
144
145   Vector<Pass> mPasses;
146
147   U32 mCurrPass;
148
149   static const Vector<String> mSamplerNames;
150
151   GFXTexHandle mBaseMapTexture;
152
153   GFXTexHandle mLayerMapTexture;
154
155   NamedTexTargetRef mLightInfoTarget;
156
157   /// The prepass material for this material.
158   TerrainCellMaterial *mPrePassMat;
159
160   /// The reflection material for this material.
161   TerrainCellMaterial *mReflectMat;
162
163   /// A vector of all terrain cell materials loaded in the system.
164   static Vector<TerrainCellMaterial*> smAllMaterials;
165
166   bool _createPass( Vector<MaterialInfo*> *materials, 
167                     Pass *pass, 
168                     bool firstPass,
169                     bool prePassMat,
170                     bool reflectMat,
171                     bool baseOnly );
172
173   void _updateMaterialConsts( Pass *pass );
174
175public:
176   
177   TerrainCellMaterial();
178   ~TerrainCellMaterial();
179
180   void init(  TerrainBlock *block, 
181               U64 activeMaterials,
182               bool prePassMat = false,
183               bool reflectMat = false,
184               bool baseOnly = false );
185
186   /// Returns a prepass material from this material.
187   TerrainCellMaterial* getPrePassMat();
188
189   /// Returns the reflection material from this material.
190   TerrainCellMaterial* getReflectMat();
191
192   void setTransformAndEye(   const MatrixF &modelXfm, 
193                              const MatrixF &viewXfm,
194                              const MatrixF &projectXfm,
195                              F32 farPlane );
196
197   ///
198   bool setupPass(   const SceneRenderState *state,
199                     const SceneData &sceneData );
200
201   ///
202   static BaseMatInstance* getShadowMat();
203
204   /// 
205   static void _updateDefaultAnisotropy();
206};
207
208#endif // _TERRCELLMATERIAL_H_
209
210