Torque3D Documentation / _generateds / materialDefinition.h

materialDefinition.h

Engine/source/materials/materialDefinition.h

More...

Classes:

class

The basic material definition.

Public Typedefs

MaterialAnimType 
MaterialBlendOp 
MaterialWaveType 

Detailed Description

Public Typedefs

typedef Material::AnimType MaterialAnimType 
typedef Material::BlendOp MaterialBlendOp 
typedef Material::WaveType MaterialWaveType 

Public Functions

DefineBitfieldType(MaterialAnimType )

DefineEnumType(MaterialBlendOp )

DefineEnumType(MaterialWaveType )

  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#ifndef _MATERIALDEFINITION_H_
 24#define _MATERIALDEFINITION_H_
 25
 26#ifndef _BASEMATERIALDEFINITION_H_
 27   #include "materials/baseMaterialDefinition.h"
 28#endif
 29#ifndef _TDICTIONARY_H_
 30   #include "core/util/tDictionary.h"
 31#endif
 32#ifndef _GFXTEXTUREHANDLE_H_
 33   #include "gfx/gfxTextureHandle.h"
 34#endif
 35#ifndef _GFXSTRUCTS_H_
 36   #include "gfx/gfxStructs.h"
 37#endif
 38#ifndef _GFXCUBEMAP_H_
 39   #include "gfx/gfxCubemap.h"
 40#endif
 41#ifndef _DYNAMIC_CONSOLETYPES_H_
 42   #include "console/dynamicTypes.h"
 43#endif
 44
 45
 46class CubemapData;
 47class SFXTrack;
 48struct SceneData;
 49class FeatureSet;
 50class FeatureType;
 51class MaterialSoundProfile;
 52class MaterialPhysicsProfile;
 53
 54
 55/// The basic material definition.
 56class Material : public BaseMaterialDefinition
 57{
 58   typedef BaseMaterialDefinition Parent;
 59public:
 60   static GFXCubemap *GetNormalizeCube();
 61
 62   //-----------------------------------------------------------------------
 63   // Enums
 64   //-----------------------------------------------------------------------
 65   enum Constants
 66   {
 67      MAX_TEX_PER_PASS = 8,         ///< Number of textures per pass
 68      MAX_STAGES = 4,
 69      NUM_EFFECT_COLOR_STAGES = 2,  ///< Number of effect color definitions for transitioning effects.
 70   };
 71
 72   enum TexType
 73   {
 74      NoTexture = 0,
 75      Standard = 1,
 76      Detail,
 77      Bump,
 78      DetailBump,
 79      Env,
 80      Cube,
 81      SGCube,  // scene graph cube - probably dynamic
 82      Lightmap,
 83      ToneMapTex,
 84      Mask,
 85      BackBuff,
 86      ReflectBuff,
 87      Misc,
 88      DynamicLight,
 89      DynamicLightMask,
 90      NormalizeCube,
 91      TexTarget,
 92      AccuMap,
 93      DynamicShadowMap,
 94   };
 95
 96   enum BlendOp
 97   {
 98      None = 0,
 99      Mul,
100      Add,
101      AddAlpha,      // add modulated with alpha channel
102      Sub,
103      LerpAlpha,     // linear interpolation modulated with alpha channel
104      ToneMap,
105      NumBlendTypes
106   };
107
108   enum AnimType
109   {
110      Scroll = 1,
111      Rotate = 2,
112      Wave   = 4,
113      Scale  = 8,
114      Sequence = 16,
115   };
116
117   enum WaveType
118   {
119      Sin = 0,
120      Triangle,
121      Square,
122   };
123
124   class StageData
125   {
126   protected:
127
128      ///
129      typedef HashTable<const FeatureType*,GFXTexHandle> TextureTable;
130
131      /// The sparse table of textures by feature index.
132      /// @see getTex
133      /// @see setTex
134      TextureTable mTextures;
135
136      /// The cubemap for this stage.
137      GFXCubemap *mCubemap;
138
139   public:
140
141      StageData()
142         : mCubemap( NULL )
143      {
144      }
145
146      /// Returns the texture object or NULL if there is no
147      /// texture entry for that feature type in the table.
148      inline GFXTextureObject* getTex( const FeatureType &type ) const
149      {
150         TextureTable::ConstIterator iter = mTextures.find( &type );
151         if ( iter == mTextures.end() )
152            return NULL;
153
154         return iter->value.getPointer();
155      }
156
157      /// Assigns a texture object by feature type.
158      inline void setTex( const FeatureType &type, GFXTextureObject *tex )
159      {
160         if ( !tex )
161         {
162            TextureTable::Iterator iter = mTextures.find( &type );
163            if ( iter != mTextures.end() )
164               mTextures.erase( iter );
165
166            return;
167         }
168
169         TextureTable::Iterator iter = mTextures.findOrInsert( &type );
170         iter->value = tex;
171      }
172
173      /// Returns true if we have a valid texture assigned to
174      /// any feature in the texture table.
175      inline bool hasValidTex() const
176      {
177         TextureTable::ConstIterator iter = mTextures.begin();
178         for (; iter != mTextures.end(); ++iter)
179         {
180            if ( iter->value.isValid() )
181               return true;
182         }
183
184         return false;
185      }
186
187      /// Returns the active texture features.
188      void getFeatureSet( FeatureSet *outFeatures ) const;
189
190      /// Returns the stage cubemap.
191      GFXCubemap* getCubemap() const { return mCubemap; }
192
193      /// Set the stage cubemap.
194      void setCubemap( GFXCubemap *cubemap ) { mCubemap = cubemap; }
195
196   };
197
198public:
199
200   //-----------------------------------------------------------------------
201   // Data
202   //-----------------------------------------------------------------------
203   FileName mDiffuseMapFilename[MAX_STAGES];
204   bool     mAccuEnabled[MAX_STAGES];
205   F32      mAccuScale[MAX_STAGES];
206   F32      mAccuDirection[MAX_STAGES];
207   F32      mAccuStrength[MAX_STAGES];
208   F32      mAccuCoverage[MAX_STAGES];
209   F32      mAccuSpecular[MAX_STAGES];
210   FileName mOverlayMapFilename[MAX_STAGES];
211   FileName mLightMapFilename[MAX_STAGES];
212   FileName mToneMapFilename[MAX_STAGES];
213   FileName mDetailMapFilename[MAX_STAGES];
214   FileName mNormalMapFilename[MAX_STAGES];
215
216   FileName mSpecularMapFilename[MAX_STAGES];
217
218   /// A second normal map which repeats at the detail map
219   /// scale and blended with the base normal map.
220   FileName mDetailNormalMapFilename[MAX_STAGES];
221
222   /// The strength scalar for the detail normal map.
223   F32 mDetailNormalMapStrength[MAX_STAGES];   
224      
225   /// This color is the diffuse color of the material
226   /// or if it has a texture it is multiplied against 
227   /// the diffuse texture color.
228   ColorF mDiffuse[MAX_STAGES];
229
230   ColorF mSpecular[MAX_STAGES];
231
232   F32 mSpecularPower[MAX_STAGES];
233   F32 mSpecularStrength[MAX_STAGES];
234   bool mPixelSpecular[MAX_STAGES];
235
236   bool mVertLit[MAX_STAGES];
237   
238   /// If true for a stage, vertex colors are multiplied
239   /// against diffuse colors.
240   bool mVertColor[ MAX_STAGES ];
241
242   F32 mParallaxScale[MAX_STAGES];   
243  
244   F32 mMinnaertConstant[MAX_STAGES];
245   bool mSubSurface[MAX_STAGES];
246   ColorF mSubSurfaceColor[MAX_STAGES];
247   F32 mSubSurfaceRolloff[MAX_STAGES];
248
249   /// The repetition scale of the detail texture
250   /// over the base texture.
251   Point2F mDetailScale[MAX_STAGES];
252
253   U32 mAnimFlags[MAX_STAGES];
254   Point2F mScrollDir[MAX_STAGES];
255   F32 mScrollSpeed[MAX_STAGES];
256   Point2F mScrollOffset[MAX_STAGES];
257
258   F32 mRotSpeed[MAX_STAGES];
259   Point2F mRotPivotOffset[MAX_STAGES];
260   F32 mRotPos[MAX_STAGES];
261   
262   F32 mWavePos[MAX_STAGES];
263   F32 mWaveFreq[MAX_STAGES];
264   F32 mWaveAmp[MAX_STAGES];
265   U32 mWaveType[MAX_STAGES];
266   
267   F32 mSeqFramePerSec[MAX_STAGES];
268   F32 mSeqSegSize[MAX_STAGES];
269   
270   bool mGlow[MAX_STAGES];          // entire stage glows
271   bool mEmissive[MAX_STAGES];
272
273   Point2I mCellIndex[MAX_STAGES];
274   Point2I mCellLayout[MAX_STAGES];
275   U32 mCellSize[MAX_STAGES];
276   bool mNormalMapAtlas[MAX_STAGES];
277
278   /// Special array of UVs for imposter rendering.
279   /// @see TSLastDetail
280   Vector<RectF> mImposterUVs;
281
282   /// Specual imposter rendering paramters.
283   /// @see TSLastDetail
284   Point4F mImposterLimits;
285
286   /// If the stage should use anisotropic filtering.
287   bool mUseAnisotropic[MAX_STAGES];
288
289   // Deferred Shading: Metalness
290   bool mUseMetalness[MAX_STAGES];
291
292   bool mDoubleSided;
293
294   String mCubemapName;
295   CubemapData* mCubemapData;
296   bool mDynamicCubemap;
297
298   // Deferred Shading
299   F32 mMatInfoFlags[MAX_STAGES];
300   bool mTranslucent;   
301   BlendOp mTranslucentBlendOp;
302   bool mTranslucentZWrite;
303
304   /// A generic setting which tells the system to skip 
305   /// generation of shadows from this material.
306   bool mCastShadows;
307   bool mCastDynamicShadows;
308
309   bool mAlphaTest;
310   U32 mAlphaRef;
311
312   bool mPlanarReflection;
313
314   bool mAutoGenerated;
315
316   static bool sAllowTextureTargetAssignment;
317
318   ///@{
319   /// Behavioral properties.
320
321   bool mShowFootprints;            ///< If true, show footprints when walking on surface with this material.  Defaults to false.
322   bool mShowDust;                  ///< If true, show dust emitters (footpuffs, hover trails, etc) when on surface with this material.  Defaults to false.
323
324   /// Color to use for particle effects and such when located on this material.
325   ColorF mEffectColor[ NUM_EFFECT_COLOR_STAGES ];
326
327   /// Footstep sound to play when walking on surface with this material.
328   /// Numeric ID of footstep sound defined on player datablock (0 == soft,
329   /// 1 == hard, 2 == metal, 3 == snow).
330   /// Defaults to -1 which deactivates default sound.
331   /// @see mFootstepSoundCustom
332   S32 mFootstepSoundId;
333   S32 mImpactSoundId;
334
335   /// Sound effect to play when walking on surface with this material.
336   /// If defined, overrides mFootstepSoundId.
337   /// @see mFootstepSoundId
338   SFXTrack* mFootstepSoundCustom;
339   SFXTrack* mImpactSoundCustom;
340
341   F32 mFriction;                   ///< Friction coefficient when moving along surface.
342
343   F32 mDirectSoundOcclusion;       ///< Amount of volume occlusion on direct sounds.
344   F32 mReverbSoundOcclusion;       ///< Amount of volume occlusion on reverb sounds.
345
346   ///@}
347   
348   String mMapTo; // map Material to this texture name
349  
350   ///
351   /// Material interface
352   ///
353   Material();
354
355   /// Allocates and returns a BaseMatInstance for this material.  Caller is responsible
356   /// for freeing the instance
357   virtual BaseMatInstance* createMatInstance();      
358   virtual bool isTranslucent() const { return mTranslucent && mTranslucentBlendOp != Material::None; }   
359   virtual bool isDoubleSided() const { return mDoubleSided; }
360   virtual bool isAutoGenerated() const { return mAutoGenerated; }
361   virtual void setAutoGenerated(bool isAutoGenerated) { mAutoGenerated = isAutoGenerated; }
362   virtual bool isLightmapped() const;
363   virtual bool castsShadows() const { return mCastShadows; }
364   virtual bool castsDynamicShadows() const { return mCastDynamicShadows; }
365   const String &getPath() const { return mPath; }
366
367   void flush();
368
369   /// Re-initializes all the material instances 
370   /// that use this material.
371   void reload();
372
373   /// Called to update time based parameters for a material.  Ensures 
374   /// that it only happens once per tick.
375   void updateTimeBasedParams();
376
377   // SimObject
378   virtual bool onAdd();
379   virtual void onRemove();
380   virtual void inspectPostApply();
381   virtual bool writeField( StringTableEntry fieldname, const char *value );
382
383   //
384   // ConsoleObject interface
385   //
386   static void initPersistFields();
387
388   // Accumulation
389   static bool _setAccuEnabled( void *object, const char *index, const char *data );
390
391   DECLARE_CONOBJECT(Material);
392protected:
393
394   // Per material animation parameters
395   U32 mLastUpdateTime;
396
397   String mPath;
398
399   static EnumTable mAnimFlagTable;
400   static EnumTable mBlendOpTable;
401   static EnumTable mWaveTypeTable;
402
403   /// Map this material to the texture specified
404   /// in the "mapTo" data variable.
405   virtual void _mapMaterial();
406
407private:
408   static GFXCubemapHandle smNormalizeCube;
409};
410
411typedef Material::AnimType MaterialAnimType;
412typedef Material::BlendOp MaterialBlendOp;
413typedef Material::WaveType MaterialWaveType;
414
415DefineBitfieldType( MaterialAnimType );
416DefineEnumType( MaterialBlendOp );
417DefineEnumType( MaterialWaveType );
418
419#endif // _MATERIALDEFINITION_H_
420