Torque3D Documentation / _generateds / materialDefinition.cpp

materialDefinition.cpp

Engine/source/materials/materialDefinition.cpp

More...

Public Variables

Public Functions

ConsoleDocClass(Material , "@brief A material in Torque 3D is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> data structure that describes <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">surface.\n\n</a>" "It contains many different types of information <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> rendering properties. " "Torque 3D generates shaders from <a href="/coding/class/classmaterial/">Material</a> definitions. The shaders are compiled " "at runtime and output into the example/shaders directory. Any errors or warnings " "generated from compiling the procedurally generated shaders are output <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console " "as well as the output window in the Visual C <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">IDE.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "singleton <a href="/coding/class/classmaterial/">Material</a>(DECAL_scorch)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	baseTex[0] = \"./scorch_decal.png\";\n" "	vertColor[ 0 ] = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "	translucent = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	translucentBlendOp = None;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	translucentZWrite = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	alphaTest = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	alphaRef = 84;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Rendering\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ShaderData\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )
DefineEngineMethod(Material , dumpInstances , void , () , "Dumps <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> formatted list of the currently allocated material instances <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this material <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console." )
DefineEngineMethod(Material , flush , void , () , "Flushes all material instances that use this material." )
DefineEngineMethod(Material , getAnimFlags , const char * , (U32 id) , "" )
DefineEngineMethod(Material , getAutogeneratedFile , const char * , () , "Get filename of autogenerated shader <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a>" )
DefineEngineMethod(Material , getFilename , const char * , () , "Get filename of material" )
DefineEngineMethod(Material , getMaterialInstances , void , (GuiTreeViewCtrl *matTree) , (nullAsType< GuiTreeViewCtrl * >()) , "Dumps <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> formatted list of the currently allocated material instances <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this material <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console." )
DefineEngineMethod(Material , isAutoGenerated , bool , () , "Returns true <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> this <a href="/coding/class/classmaterial/">Material</a> was automatically generated by <a href="/coding/class/classmateriallist/#classmateriallist_1aad07ac39b327a785c39f539319baf905">MaterialList::mapMaterials</a>()" )
DefineEngineMethod(Material , reload , void , () , "Reloads all material instances that use this material." )
DefineEngineMethod(Material , setAutoGenerated , void , (bool isAutoGenerated) , "setAutoGenerated(bool isAutoGenerated): Set whether or not the <a href="/coding/class/classmaterial/">Material</a> is autogenerated." )
ImplementBitfieldType(MaterialAnimType , "The type of animation effect <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> apply <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">material.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n\n</a>" )
ImplementEnumType(MaterialBlendOp , "The type of graphical blending operation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> apply <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">material\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n\n</a>" )
ImplementEnumType(MaterialWaveType , "When using the Wave material animation, one of these Wave Types will be used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> determine the type of wave <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">display.\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

Detailed Description

Public Variables

 EndImplementEnumType 

Public Functions

ConsoleDocClass(Material , "@brief A material in Torque 3D is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> data structure that describes <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">surface.\n\n</a>" "It contains many different types of information <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> rendering properties. " "Torque 3D generates shaders from <a href="/coding/class/classmaterial/">Material</a> definitions. The shaders are compiled " "at runtime and output into the example/shaders directory. Any errors or warnings " "generated from compiling the procedurally generated shaders are output <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console " "as well as the output window in the Visual C <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">IDE.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "singleton <a href="/coding/class/classmaterial/">Material</a>(DECAL_scorch)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	baseTex[0] = \"./scorch_decal.png\";\n" "	vertColor[ 0 ] = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "	translucent = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	translucentBlendOp = None;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	translucentZWrite = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	alphaTest = true;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	alphaRef = 84;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Rendering\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">ShaderData\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

DefineEngineMethod(Material , dumpInstances , void , () , "Dumps <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> formatted list of the currently allocated material instances <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this material <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console." )

DefineEngineMethod(Material , flush , void , () , "Flushes all material instances that use this material." )

DefineEngineMethod(Material , getAnimFlags , const char * , (U32 id) , "" )

DefineEngineMethod(Material , getAutogeneratedFile , const char * , () , "Get filename of autogenerated shader <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a>" )

DefineEngineMethod(Material , getFilename , const char * , () , "Get filename of material" )

DefineEngineMethod(Material , getMaterialInstances , void , (GuiTreeViewCtrl *matTree) , (nullAsType< GuiTreeViewCtrl * >()) , "Dumps <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> formatted list of the currently allocated material instances <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this material <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console." )

DefineEngineMethod(Material , isAutoGenerated , bool , () , "Returns true <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> this <a href="/coding/class/classmaterial/">Material</a> was automatically generated by <a href="/coding/class/classmateriallist/#classmateriallist_1aad07ac39b327a785c39f539319baf905">MaterialList::mapMaterials</a>()" )

DefineEngineMethod(Material , reload , void , () , "Reloads all material instances that use this material." )

DefineEngineMethod(Material , setAutoGenerated , void , (bool isAutoGenerated) , "setAutoGenerated(bool isAutoGenerated): Set whether or not the <a href="/coding/class/classmaterial/">Material</a> is autogenerated." )

IMPLEMENT_CONOBJECT(Material )

ImplementBitfieldType(MaterialAnimType , "The type of animation effect <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> apply <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">material.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n\n</a>" )

ImplementEnumType(MaterialBlendOp , "The type of graphical blending operation <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> apply <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">material\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n\n</a>" )

ImplementEnumType(MaterialWaveType , "When using the Wave material animation, one of these Wave Types will be used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> determine the type of wave <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">display.\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

  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#include "platform/platform.h"
 25#include "materials/materialDefinition.h"
 26
 27#include "console/consoleTypes.h"
 28#include "console/engineAPI.h"
 29#include "math/mathTypes.h"
 30#include "materials/materialManager.h"
 31#include "sceneData.h"
 32#include "gfx/sim/cubemapData.h"
 33#include "gfx/gfxCubemap.h"
 34#include "math/mathIO.h"
 35#include "materials/matInstance.h"
 36#include "sfx/sfxTrack.h"
 37#include "sfx/sfxTypes.h"
 38#include "core/util/safeDelete.h"
 39#include "T3D/accumulationVolume.h"
 40#include "gui/controls/guiTreeViewCtrl.h"
 41
 42IMPLEMENT_CONOBJECT( Material );
 43
 44ConsoleDocClass( Material,
 45   "@brief A material in Torque 3D is a data structure that describes a surface.\n\n"
 46
 47   "It contains many different types of information for rendering properties. "
 48   "Torque 3D generates shaders from Material definitions. The shaders are compiled "
 49   "at runtime and output into the example/shaders directory. Any errors or warnings "
 50   "generated from compiling the procedurally generated shaders are output to the console "
 51   "as well as the output window in the Visual C IDE.\n\n"
 52
 53   "@tsexample\n"
 54   "singleton Material(DECAL_scorch)\n"
 55   "{\n"
 56   "  baseTex[0] = \"./scorch_decal.png\";\n"
 57   "  vertColor[ 0 ] = true;\n\n"
 58   "  translucent = true;\n"
 59   "  translucentBlendOp = None;\n"
 60   "  translucentZWrite = true;\n"
 61   "  alphaTest = true;\n"
 62   "  alphaRef = 84;\n"
 63   "};\n"
 64   "@endtsexample\n\n"
 65
 66   "@see Rendering\n"
 67   "@see ShaderData\n"
 68
 69   "@ingroup GFX\n");
 70
 71ImplementBitfieldType( MaterialAnimType,
 72   "The type of animation effect to apply to this material.\n"
 73   "@ingroup GFX\n\n")
 74   { Material::Scroll, "Scroll", "Scroll the material along the X/Y axis.\n" },
 75   { Material::Rotate, "Rotate" , "Rotate the material around a point.\n"},
 76   { Material::Wave, "Wave" , "Warps the material with an animation using Sin, Triangle or Square mathematics.\n"},
 77   { Material::Scale, "Scale", "Scales the material larger and smaller with a pulsing effect.\n" },
 78   { Material::Sequence, "Sequence", "Enables the material to have multiple frames of animation in its imagemap.\n" }
 79EndImplementBitfieldType;
 80
 81ImplementEnumType( MaterialBlendOp,
 82   "The type of graphical blending operation to apply to this material\n"
 83   "@ingroup GFX\n\n")
 84   { Material::None,         "None", "Disable blending for this material." },
 85   { Material::Mul,          "Mul", "Multiplicative blending." },
 86   { Material::PreMul,       "PreMul", "Premultiplied alpha." },
 87   { Material::Add,          "Add", "Adds the color of the material to the frame buffer with full alpha for each pixel." },
 88   { Material::AddAlpha,     "AddAlpha", "The color is modulated by the alpha channel before being added to the frame buffer." },
 89   { Material::Sub,          "Sub", "Subtractive Blending. Reverses the color model, causing dark colors to have a stronger visual effect." },
 90   { Material::LerpAlpha,    "LerpAlpha", "Linearly interpolates between Material color and frame buffer color based on alpha." }
 91EndImplementEnumType;
 92
 93ImplementEnumType( MaterialWaveType,
 94   "When using the Wave material animation, one of these Wave Types will be used to determine the type of wave to display.\n" 
 95   "@ingroup GFX\n")
 96   { Material::Sin,          "Sin", "Warps the material along a curved Sin Wave." },
 97   { Material::Triangle,     "Triangle", "Warps the material along a sharp Triangle Wave." },
 98   { Material::Square,       "Square", "Warps the material along a wave which transitions between two oppposite states. As a Square Wave, the transition is quick and sudden." },
 99EndImplementEnumType;
100
101bool Material::sAllowTextureTargetAssignment = false;
102
103GFXCubemap * Material::GetNormalizeCube()
104{
105   if(smNormalizeCube)
106      return smNormalizeCube;
107   smNormalizeCube = GFX->createCubemap();
108   smNormalizeCube->initNormalize(64);
109   return smNormalizeCube;
110}
111
112GFXCubemapHandle Material::smNormalizeCube;
113
114
115Material::Material()
116{
117   for( U32 i=0; i<MAX_STAGES; i++ )
118   {
119      mDiffuse[i].set( 1.0f, 1.0f, 1.0f, 1.0f );
120      mDiffuseMapSRGB[i] = true;
121
122      mRoughness[i] = 1.0f;
123      mMetalness[i] = 0.0f;
124
125      mIsSRGb[i] = false;
126      mInvertRoughness[i] = false;
127
128      mRoughnessChan[i] = 0;
129      mAOChan[i] = 1;
130      mMetalChan[i] = 2;
131
132      mAccuEnabled[i]   = false;
133      mAccuScale[i]     = 1.0f;
134      mAccuDirection[i] = 1.0f;
135      mAccuStrength[i]  = 0.6f;
136      mAccuCoverage[i]  = 0.9f;
137      mAccuSpecular[i]  = 16.0f;
138
139      initMapArraySlot(DiffuseMap, i);
140      initMapArraySlot(OverlayMap, i);
141      initMapArraySlot(LightMap, i);
142      initMapArraySlot(ToneMap, i);
143      initMapArraySlot(DetailMap, i);
144      initMapArraySlot(NormalMap, i);
145      initMapArraySlot(ORMConfigMap, i);
146      initMapArraySlot(RoughMap, i);
147      initMapArraySlot(AOMap, i);
148      initMapArraySlot(MetalMap, i);
149      initMapArraySlot(GlowMap, i);
150      initMapArraySlot(DetailNormalMap, i);
151
152      mParallaxScale[i] = 0.0f;
153
154      mVertLit[i] = false;
155      mVertColor[ i ] = false;
156
157      mGlow[i] = false;
158      mEmissive[i] = false;
159
160      mDetailScale[i].set( 2.0f, 2.0f );
161      
162      mDetailNormalMapStrength[i] = 1.0f;
163
164      mMinnaertConstant[i] = -1.0f;
165      mSubSurface[i] = false;
166      mSubSurfaceColor[i].set( 1.0f, 0.2f, 0.2f, 1.0f );
167      mSubSurfaceRolloff[i] = 0.2f;
168      
169      mAnimFlags[i] = 0;
170
171      mScrollDir[i].set( 0.0f, 0.0f );
172      mScrollSpeed[i] = 0.0f;
173      mScrollOffset[i].set( 0.0f, 0.0f );
174      
175      mRotSpeed[i] = 0.0f;
176      mRotPivotOffset[i].set( 0.0f, 0.0f );
177      mRotPos[i] = 0.0f;
178
179      mWavePos[i] = 0.0f;
180      mWaveFreq[i] = 0.0f;
181      mWaveAmp[i] = 0.0f;
182      mWaveType[i] = 0;
183
184      mSeqFramePerSec[i] = 0.0f;
185      mSeqSegSize[i] = 0.0f;
186
187      // Deferred Shading
188      mMatInfoFlags[i] = 0.0f;
189
190      mGlowMul[i] = 0.0f;
191   }
192
193   dMemset(mCellIndex, 0, sizeof(mCellIndex));
194   dMemset(mCellLayout, 0, sizeof(mCellLayout));
195   dMemset(mCellSize, 0, sizeof(mCellSize));
196   dMemset(mNormalMapAtlas, 0, sizeof(mNormalMapAtlas));
197   dMemset(mUseAnisotropic, 1, sizeof(mUseAnisotropic));
198
199   mImposterLimits = Point4F::Zero;
200
201   mDoubleSided = false;
202
203   mTranslucent = false;
204   mTranslucentBlendOp = LerpAlpha;
205   mTranslucentZWrite = false;
206
207   mAlphaTest = false;
208   mAlphaRef = 1;
209
210   mCastShadows = true;
211
212   mPlanarReflection = false;
213
214   mCubemapData = NULL;
215   mDynamicCubemap = NULL;
216
217   mLastUpdateTime = 0;
218
219   mAutoGenerated = false;
220
221   mShowDust = false;
222   mShowFootprints = true;
223
224   dMemset( mEffectColor,     0, sizeof( mEffectColor ) );
225
226   mFootstepSoundId = -1;     mImpactSoundId = -1;
227   mImpactFXIndex = -1;
228   mFootstepSoundCustom = 0;  mImpactSoundCustom = 0;
229   mFriction = 0.0;
230   
231   mDirectSoundOcclusion = 1.f;
232   mReverbSoundOcclusion = 1.0;
233}
234
235
236void Material::initPersistFields()
237{
238   addField("mapTo", TypeRealString, Offset(mMapTo, Material),
239      "Used to map this material to the material name used by TSShape." );
240
241   addArray( "Stages", MAX_STAGES );
242
243      addField("diffuseColor", TypeColorF, Offset(mDiffuse, Material), MAX_STAGES,
244         "This color is multiplied against the diffuse texture color.  If no diffuse texture "
245         "is present this is the material color." );
246
247      scriptBindMapArraySlot(DiffuseMap, MAX_STAGES, Material, "Albedo");
248      scriptBindMapArraySlot(OverlayMap, MAX_STAGES, Material, "Overlay");
249      scriptBindMapArraySlot(LightMap, MAX_STAGES, Material, "LightMap");
250      scriptBindMapArraySlot(ToneMap, MAX_STAGES, Material, "ToneMap");
251      scriptBindMapArraySlot(DetailMap, MAX_STAGES, Material, "DetailMap");
252      scriptBindMapArraySlot(NormalMap, MAX_STAGES, Material, "NormalMap");
253      scriptBindMapArraySlot(ORMConfigMap, MAX_STAGES, Material, "AO|Roughness|metalness map");
254      scriptBindMapArraySlot(RoughMap, MAX_STAGES, Material, "RoughMap (also needs MetalMap)");
255      scriptBindMapArraySlot(AOMap, MAX_STAGES, Material, "AOMap");
256      scriptBindMapArraySlot(MetalMap, MAX_STAGES, Material, "MetalMap (also needs RoughMap)");
257      scriptBindMapArraySlot(GlowMap, MAX_STAGES, Material, "GlowMap (needs Albedo)");
258      scriptBindMapArraySlot(DetailNormalMap, MAX_STAGES, Material, "DetailNormalMap");
259
260      addField("diffuseMapSRGB", TypeBool, Offset(mDiffuseMapSRGB, Material), MAX_STAGES,
261         "Enable sRGB for the diffuse color texture map.");
262
263      addField("detailScale", TypePoint2F, Offset(mDetailScale, Material), MAX_STAGES,
264         "The scale factor for the detail map." );
265
266      addField( "detailNormalMapStrength", TypeF32, Offset(mDetailNormalMapStrength, Material), MAX_STAGES,
267         "Used to scale the strength of the detail normal map when blended with the base normal map." );
268      
269      addField("roughness", TypeF32, Offset(mRoughness, Material), MAX_STAGES,
270         "The degree of roughness when not using a ORMConfigMap." );
271
272      addField("metalness", TypeF32, Offset(mMetalness, Material), MAX_STAGES,
273         "The degree of Metalness when not using a ORMConfigMap." );
274
275      addField("glowMul", TypeF32, Offset(mGlowMul, Material), MAX_STAGES,
276         "glow mask multiplier");
277
278      addProtectedField( "accuEnabled", TYPEID< bool >(), Offset( mAccuEnabled, Material ),
279            &_setAccuEnabled, &defaultProtectedGetFn, MAX_STAGES, "Accumulation texture." );
280
281      addField("accuScale",      TypeF32, Offset(mAccuScale, Material), MAX_STAGES,
282         "The scale that is applied to the accu map texture. You can use this to fit the texture to smaller or larger objects.");
283       
284      addField("accuDirection",  TypeF32, Offset(mAccuDirection, Material), MAX_STAGES,
285         "The direction of the accumulation. Chose whether you want the accu map to go from top to bottom (ie. snow) or upwards (ie. mold).");
286       
287      addField("accuStrength",   TypeF32, Offset(mAccuStrength, Material), MAX_STAGES,
288         "The strength of the accu map. This changes the transparency of the accu map texture. Make it subtle or add more contrast.");
289       
290      addField("accuCoverage",   TypeF32, Offset(mAccuCoverage, Material), MAX_STAGES,
291         "The coverage ratio of the accu map texture. Use this to make the entire shape pick up some of the accu map texture or none at all.");
292       
293      addField("accuSpecular",   TypeF32, Offset(mAccuSpecular, Material), MAX_STAGES,
294         "Changes specularity to this value where the accumulated material is present.");
295
296      addField("isSRGb", TypeBool, Offset(mIsSRGb, Material), MAX_STAGES,
297         "Substance Designer Workaround.");
298
299      addField("invertRoughness", TypeBool, Offset(mInvertRoughness, Material), MAX_STAGES,
300         "Treat Roughness as Roughness");
301
302      addField("roughnessChan", TypeF32, Offset(mRoughnessChan, Material), MAX_STAGES,
303         "The input channel roughness maps use.");
304
305      addField("AOChan", TypeF32, Offset(mAOChan, Material), MAX_STAGES,
306         "The input channel AO maps use.");
307      addField("metalChan", TypeF32, Offset(mMetalChan, Material), MAX_STAGES,
308         "The input channel metalness maps use.");
309
310      addField("glow", TypeBool, Offset(mGlow, Material), MAX_STAGES,
311         "Enables rendering as glowing.");
312
313      addField( "parallaxScale", TypeF32, Offset(mParallaxScale, Material), MAX_STAGES,
314         "Enables parallax mapping and defines the scale factor for the parallax effect.  Typically "
315         "this value is less than 0.4 else the effect breaks down." );
316      
317      addField( "useAnisotropic", TypeBool, Offset(mUseAnisotropic, Material), MAX_STAGES,
318         "Use anisotropic filtering for the textures of this stage." );
319     
320      addField("vertLit", TypeBool, Offset(mVertLit, Material), MAX_STAGES,
321         "If true the vertex color is used for lighting." );
322
323      addField( "vertColor", TypeBool, Offset( mVertColor, Material ), MAX_STAGES,
324         "If enabled, vertex colors are premultiplied with diffuse colors." );
325
326      addField("minnaertConstant", TypeF32, Offset(mMinnaertConstant, Material), MAX_STAGES,
327         "The Minnaert shading constant value.  Must be greater than 0 to enable the effect." );
328
329      addField("subSurface", TypeBool, Offset(mSubSurface, Material), MAX_STAGES,
330         "Enables the subsurface scattering approximation." );
331
332      addField("subSurfaceColor", TypeColorF, Offset(mSubSurfaceColor, Material), MAX_STAGES,
333         "The color used for the subsurface scattering approximation." );
334
335      addField("subSurfaceRolloff", TypeF32, Offset(mSubSurfaceRolloff, Material), MAX_STAGES,
336         "The 0 to 1 rolloff factor used in the subsurface scattering approximation." );
337
338      addField("emissive", TypeBool, Offset(mEmissive, Material), MAX_STAGES,
339         "Enables emissive lighting for the material." );
340
341      addField("doubleSided", TypeBool, Offset(mDoubleSided, Material),
342         "Disables backface culling casing surfaces to be double sided. "
343         "Note that the lighting on the backside will be a mirror of the front "
344         "side of the surface."  );
345
346      addField("animFlags", TYPEID< AnimType >(), Offset(mAnimFlags, Material), MAX_STAGES,
347         "The types of animation to play on this material." );
348
349      addField("scrollDir", TypePoint2F, Offset(mScrollDir, Material), MAX_STAGES,
350         "The scroll direction in UV space when scroll animation is enabled." );
351
352      addField("scrollSpeed", TypeF32, Offset(mScrollSpeed, Material), MAX_STAGES,
353         "The speed to scroll the texture in UVs per second when scroll animation is enabled." );
354
355      addField("rotSpeed", TypeF32, Offset(mRotSpeed, Material), MAX_STAGES,
356         "The speed to rotate the texture in degrees per second when rotation animation is enabled." );
357
358      addField("rotPivotOffset", TypePoint2F, Offset(mRotPivotOffset, Material), MAX_STAGES,
359         "The piviot position in UV coordinates to center the rotation animation." );
360
361      addField("waveType", TYPEID< WaveType >(), Offset(mWaveType, Material), MAX_STAGES,
362         "The type of wave animation to perform when wave animation is enabled." );
363
364      addField("waveFreq", TypeF32, Offset(mWaveFreq, Material), MAX_STAGES,
365         "The wave frequency when wave animation is enabled." );
366
367      addField("waveAmp", TypeF32, Offset(mWaveAmp, Material), MAX_STAGES,
368         "The wave amplitude when wave animation is enabled." );
369
370      addField("sequenceFramePerSec", TypeF32, Offset(mSeqFramePerSec, Material), MAX_STAGES,
371         "The number of frames per second for frame based sequence animations if greater than zero." );
372
373      addField("sequenceSegmentSize", TypeF32, Offset(mSeqSegSize, Material), MAX_STAGES,
374         "The size of each frame in UV units for sequence animations." );
375
376      // Texture atlasing
377      addField("cellIndex", TypePoint2I, Offset(mCellIndex, Material), MAX_STAGES,
378         "@internal" );
379      addField("cellLayout", TypePoint2I, Offset(mCellLayout, Material), MAX_STAGES,
380         "@internal");
381      addField("cellSize", TypeS32, Offset(mCellSize, Material), MAX_STAGES,
382         "@internal");
383      addField("bumpAtlas", TypeBool, Offset(mNormalMapAtlas, Material), MAX_STAGES,
384         "@internal");
385
386      // For backwards compatibility.  
387      //
388      // They point at the new 'map' fields, but reads always return
389      // an empty string and writes only apply if the value is not empty.
390      //
391      addProtectedField("baseTex",        TypeImageFilename,   Offset(mDiffuseMapFilename, Material), 
392         defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES, 
393         "For backwards compatibility.\n@see diffuseMap\n" ); 
394      addProtectedField("detailTex",      TypeImageFilename,   Offset(mDetailMapFilename, Material), 
395         defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES, 
396         "For backwards compatibility.\n@see detailMap\n"); 
397      addProtectedField("overlayTex",     TypeImageFilename,   Offset(mOverlayMapFilename, Material),
398         defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES, 
399         "For backwards compatibility.\n@see overlayMap\n"); 
400      addProtectedField("bumpTex",        TypeImageFilename,   Offset(mNormalMapFilename, Material),
401         defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES, 
402         "For backwards compatibility.\n@see normalMap\n"); 
403      addProtectedField("colorMultiply",  TypeColorF,          Offset(mDiffuse, Material),
404         defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
405         "For backwards compatibility.\n@see diffuseColor\n"); 
406
407   endArray( "Stages" );
408
409   addField( "castShadows", TypeBool, Offset(mCastShadows, Material),
410      "If set to false the lighting system will not cast shadows from this material." );
411
412   addField("planarReflection", TypeBool, Offset(mPlanarReflection, Material), "@internal" );
413
414   addField("translucent", TypeBool, Offset(mTranslucent, Material),
415      "If true this material is translucent blended." );
416
417   addField("translucentBlendOp", TYPEID< BlendOp >(), Offset(mTranslucentBlendOp, Material),
418      "The type of blend operation to use when the material is translucent." );
419
420   addField("translucentZWrite", TypeBool, Offset(mTranslucentZWrite, Material),
421      "If enabled and the material is translucent it will write into the depth buffer." );
422
423   addField("alphaTest", TypeBool, Offset(mAlphaTest, Material),
424      "Enables alpha test when rendering the material.\n@see alphaRef\n" );
425
426   addField("alphaRef", TypeS32, Offset(mAlphaRef, Material),
427      "The alpha reference value for alpha testing.  Must be between 0 to 255.\n@see alphaTest\n" );
428
429   addField("cubemap", TypeRealString, Offset(mCubemapName, Material),
430      "The name of a CubemapData for environment mapping." );
431
432   addField("dynamicCubemap", TypeBool, Offset(mDynamicCubemap, Material),
433      "Enables the material to use the dynamic cubemap from the ShapeBase object its applied to." );
434
435   addGroup( "Behavioral" );
436
437      addField( "showFootprints", TypeBool, Offset( mShowFootprints, Material ),
438         "Whether to show player footprint decals on this material.\n\n"
439         "@see PlayerData::decalData" );
440         
441      addField( "showDust", TypeBool, Offset( mShowDust, Material ),
442         "Whether to emit dust particles from a shape moving over the material.  This is, for example, used by "
443         "vehicles or players to decide whether to show dust trails." );
444         
445      addField( "effectColor", TypeColorF, Offset( mEffectColor, Material ), NUM_EFFECT_COLOR_STAGES,
446         "If #showDust is true, this is the set of colors to use for the ParticleData of the dust "
447         "emitter.\n\n"
448         "@see ParticleData::colors" );
449         
450      addField( "footstepSoundId", TypeS32, Offset( mFootstepSoundId, Material ),
451         "What sound to play from the PlayerData sound list when the player walks over the material.  -1 (default) to not play any sound.\n"
452         "\n"
453         "The IDs are:\n\n"
454         "- 0: PlayerData::FootSoftSound\n"
455         "- 1: PlayerData::FootHardSound\n"
456         "- 2: PlayerData::FootMetalSound\n"
457         "- 3: PlayerData::FootSnowSound\n"
458         "- 4: PlayerData::FootShallowSound\n"
459         "- 5: PlayerData::FootWadingSound\n"
460         "- 6: PlayerData::FootUnderwaterSound\n"
461         "- 7: PlayerData::FootBubblesSound\n"
462         "- 8: PlayerData::movingBubblesSound\n"
463         "- 9: PlayerData::waterBreathSound\n"
464         "- 10: PlayerData::impactSoftSound\n"
465         "- 11: PlayerData::impactHardSound\n"
466         "- 12: PlayerData::impactMetalSound\n"
467         "- 13: PlayerData::impactSnowSound\n"
468         "- 14: PlayerData::impactWaterEasy\n"
469         "- 15: PlayerData::impactWaterMedium\n"
470         "- 16: PlayerData::impactWaterHard\n"
471         "- 17: PlayerData::exitingWater\n" );
472         
473      addField( "customFootstepSound", TypeSFXTrackName, Offset( mFootstepSoundCustom, Material ),
474         "The sound to play when the player walks over the material.  If this is set, it overrides #footstepSoundId.  This field is "
475         "useful for directly assigning custom footstep sounds to materials without having to rely on the PlayerData sound assignment.\n\n"
476         "@warn Be aware that materials are client-side objects.  This means that the SFXTracks assigned to materials must be client-side, too." );
477      addField( "impactSoundId", TypeS32, Offset( mImpactSoundId, Material ),
478         "What sound to play from the PlayerData sound list when the player impacts on the surface with a velocity equal or greater "
479         "than PlayerData::groundImpactMinSpeed.\n\n"
480         "For a list of IDs, see #footstepSoundId" );
481      addField("ImpactFXIndex", TypeS32, Offset(mImpactFXIndex, Material),
482         "What FX to play from the PlayerData sound list when the player impacts on the surface with a velocity equal or greater "
483         "than PlayerData::groundImpactMinSpeed.\n\n"
484         "For a list of IDs, see #impactFXId");
485      addField( "customImpactSound", TypeSFXTrackName,    Offset( mImpactSoundCustom, Material ),
486         "The sound to play when the player impacts on the surface with a velocity equal or greater than PlayerData::groundImpactMinSpeed.  "
487         "If this is set, it overrides #impactSoundId.  This field is useful for directly assigning custom impact sounds to materials "
488         "without having to rely on the PlayerData sound assignment.\n\n"
489         "@warn Be aware that materials are client-side objects.  This means that the SFXTracks assigned to materials must be client-side, too." );
490      
491      //Deactivate these for the moment as they are not used.
492      
493      #if 0
494      Material ) );
495      Material ) );
496      Material ) );
497      #endif
498
499   endGroup( "Behavioral" );
500
501   Parent::initPersistFields();
502}
503
504bool Material::writeField( StringTableEntry fieldname, const char *value )
505{   
506   // Never allow the old field names to be written.
507   if (  fieldname == StringTable->insert("baseTex") ||
508         fieldname == StringTable->insert("detailTex") ||
509         fieldname == StringTable->insert("overlayTex") ||
510         fieldname == StringTable->insert("bumpTex") || 
511         fieldname == StringTable->insert("envTex") ||
512         fieldname == StringTable->insert("colorMultiply") )
513      return false;
514
515   return Parent::writeField( fieldname, value );
516}
517
518bool Material::onAdd()
519{
520   if (Parent::onAdd() == false)
521      return false;
522
523   mCubemapData = dynamic_cast<CubemapData*>(Sim::findObject( mCubemapName ) );
524
525   if( mTranslucentBlendOp >= NumBlendTypes || mTranslucentBlendOp < 0 )
526   {
527      Con::errorf( "Invalid blend op in material: %s", getName() );
528      mTranslucentBlendOp = LerpAlpha;
529   }
530
531   SimSet *matSet = MATMGR->getMaterialSet();
532   if( matSet )
533      matSet->addObject( (SimObject*)this );
534
535   // save the current script path for texture lookup later
536   const String  scriptFile = Con::getVariable("$Con::File");  // current script file - local materials.tscript
537
538   String::SizeType  slash = scriptFile.find( '/', scriptFile.length(), String::Right );
539   if ( slash != String::NPos )
540      mPath = scriptFile.substr( 0, slash + 1 );
541
542   //bind any assets we have
543   for (U32 i = 0; i < MAX_STAGES; i++)
544   {
545      bindMapArraySlot(DiffuseMap, i);
546      bindMapArraySlot(OverlayMap, i);
547      bindMapArraySlot(LightMap, i);
548      bindMapArraySlot(ToneMap, i);
549      bindMapArraySlot(DetailMap, i);
550      bindMapArraySlot(ORMConfigMap, i);
551      bindMapArraySlot(RoughMap, i);
552      bindMapArraySlot(AOMap, i);
553      bindMapArraySlot(MetalMap, i);
554      bindMapArraySlot(GlowMap, i);
555      bindMapArraySlot(DetailNormalMap, i);
556   }
557
558   _mapMaterial();
559
560   return true;
561}
562
563void Material::onRemove()
564{
565   smNormalizeCube = NULL;
566   Parent::onRemove();
567}
568
569void Material::inspectPostApply()
570{
571   Parent::inspectPostApply();
572
573   // Reload the material instances which 
574   // use this material.
575   if ( isProperlyAdded() )
576      reload();
577}
578
579
580bool Material::isLightmapped() const
581{
582   bool ret = false;
583   for( U32 i=0; i<MAX_STAGES; i++ )
584      ret |= mLightMapFilename[i].isNotEmpty() || mToneMapFilename[i].isNotEmpty() || mVertLit[i];
585   return ret;
586}
587
588void Material::updateTimeBasedParams()
589{
590   U32 lastTime = MATMGR->getLastUpdateTime();
591   F32 dt = MATMGR->getDeltaTime();
592   if (mLastUpdateTime != lastTime)
593   {
594      for (U32 i = 0; i < MAX_STAGES; i++)
595      {
596         mScrollOffset[i] += mScrollDir[i] * mScrollSpeed[i] * dt;
597         mScrollOffset[i].x = mWrapF(mScrollOffset[i].x, 0.0, 1.0);
598         mScrollOffset[i].y = mWrapF(mScrollOffset[i].y, 0.0, 1.0);
599         mRotPos[i] = mWrapF((mRotPos[i] + (mRotSpeed[i] * dt)), 0.0, 360.0);
600         mWavePos[i] = mWrapF((mWavePos[i] + (mWaveFreq[i] * dt)), 0.0, 1.0);
601      }
602      mLastUpdateTime = lastTime;
603   }
604}
605
606void Material::_mapMaterial()
607{
608   if( String(getName()).isEmpty() )
609   {
610      Con::warnf( "[Material::mapMaterial] - Cannot map unnamed Material" );
611      return;
612   }
613
614   // If mapTo not defined in script, try to use the base texture name instead
615   if( mMapTo.isEmpty() )
616   {
617      if ( mDiffuseMapFilename[0].isEmpty() && mDiffuseMapAsset->isNull())
618         return;
619
620      else
621      {
622         // extract filename from base texture
623         if ( mDiffuseMapFilename[0].isNotEmpty() )
624         {
625            U32 slashPos = mDiffuseMapFilename[0].find('/',0,String::Right);
626            if (slashPos == String::NPos)
627               // no '/' character, must be no path, just the filename
628               mMapTo = mDiffuseMapFilename[0];
629            else
630               // use everything after the last slash
631               mMapTo = mDiffuseMapFilename[0].substr(slashPos+1, mDiffuseMapFilename[0].length() - slashPos - 1);
632         }
633         else if (!mDiffuseMapAsset->isNull())
634         {
635            mMapTo = mDiffuseMapAsset[0]->getImageFileName();
636         }
637      }
638   }
639
640   // add mapping
641   MATMGR->mapMaterial(mMapTo,getName());
642}
643
644BaseMatInstance* Material::createMatInstance()
645{
646   return new MatInstance(*this);
647}
648
649void Material::flush()
650{
651   MATMGR->flushInstance( this );
652}
653
654void Material::reload()
655{
656   MATMGR->reInitInstance( this );
657}
658
659void Material::StageData::getFeatureSet( FeatureSet *outFeatures ) const
660{
661   TextureTable::ConstIterator iter = mTextures.begin();
662   for ( ; iter != mTextures.end(); iter++ )
663   {
664      if ( iter->value.isValid() )
665         outFeatures->addFeature( *iter->key );
666   }
667}
668
669DefineEngineMethod( Material, flush, void, (),, 
670   "Flushes all material instances that use this material." )
671{
672   object->flush();
673}
674
675DefineEngineMethod( Material, reload, void, (),, 
676   "Reloads all material instances that use this material." )
677{
678   object->reload();
679}
680
681DefineEngineMethod( Material, dumpInstances, void, (),, 
682   "Dumps a formatted list of the currently allocated material instances for this material to the console." )
683{
684   MATMGR->dumpMaterialInstances( object );
685}
686
687DefineEngineMethod(Material, getMaterialInstances, void, (GuiTreeViewCtrl* matTree), (nullAsType< GuiTreeViewCtrl*>()),
688   "Dumps a formatted list of the currently allocated material instances for this material to the console.")
689{
690   MATMGR->getMaterialInstances(object, matTree);
691}
692
693DefineEngineMethod( Material, getAnimFlags, const char*, (U32 id), , "" )
694{
695   char * animFlags = Con::getReturnBuffer(512);
696
697   if(object->mAnimFlags[ id ] & Material::Scroll)
698   {
699      if(String::compare( animFlags, "" ) == 0)
700         dStrcpy( animFlags, "$Scroll", 512 );
701   }
702   if(object->mAnimFlags[ id ] & Material::Rotate)
703   {
704      if(String::compare( animFlags, "" ) == 0)
705         dStrcpy( animFlags, "$Rotate", 512 );
706      else
707         dStrcat( animFlags, " | $Rotate", 512);
708   }
709   if(object->mAnimFlags[ id ] & Material::Wave)
710   {
711      if(String::compare( animFlags, "" ) == 0)
712         dStrcpy( animFlags, "$Wave", 512 );
713      else
714         dStrcat( animFlags, " | $Wave", 512);
715   }
716   if(object->mAnimFlags[ id ] & Material::Scale)
717   {
718      if(String::compare( animFlags, "" ) == 0)
719         dStrcpy( animFlags, "$Scale", 512 );
720      else
721         dStrcat( animFlags, " | $Scale", 512);
722   }
723   if(object->mAnimFlags[ id ] & Material::Sequence)
724   {
725      if(String::compare( animFlags, "" ) == 0)
726         dStrcpy( animFlags, "$Sequence", 512 );
727      else
728         dStrcat( animFlags, " | $Sequence", 512);
729   }
730
731   return animFlags;
732}
733
734DefineEngineMethod(Material, getFilename, const char*, (),, "Get filename of material")
735{
736   SimObject *material = static_cast<SimObject *>(object);
737   return material->getFilename();
738}
739
740DefineEngineMethod( Material, isAutoGenerated, bool, (),, 
741              "Returns true if this Material was automatically generated by MaterialList::mapMaterials()" )
742{
743   return object->isAutoGenerated();
744}
745
746DefineEngineMethod( Material, setAutoGenerated, void, (bool isAutoGenerated), , 
747              "setAutoGenerated(bool isAutoGenerated): Set whether or not the Material is autogenerated." )
748{
749   object->setAutoGenerated(isAutoGenerated);
750}
751
752DefineEngineMethod(Material, getAutogeneratedFile, const char*, (), , "Get filename of autogenerated shader file")
753{
754   SimObject *material = static_cast<SimObject *>(object);
755   return material->getFilename();
756}
757
758
759// Accumulation
760bool Material::_setAccuEnabled( void *object, const char *index, const char *data )
761{
762   Material* mat = reinterpret_cast< Material* >( object );
763
764   if ( index )
765   {
766      U32 i = dAtoui(index);
767      mat->mAccuEnabled[i] = dAtob(data);
768      AccumulationVolume::refreshVolumes();
769   }
770   return true;
771}
772