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