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