simplification of the Class::_set<slotname>Asset methods, (as well as early outting before dAtoi(index) hurt itself if index was invalid)

also since I was in there, fixed isrgb accidently being flipped on by default
This commit is contained in:
AzaezelX 2020-10-12 04:43:47 -05:00
parent f0068c2435
commit 4250e1d1b4
5 changed files with 53 additions and 414 deletions

View file

@ -165,9 +165,9 @@ public:
#define initMapArraySlot(name,id) m##name##Filename[id] = String::EmptyString; m##name##AssetId[id] = StringTable->EmptyString(); m##name##Asset[id] = NULL;
#define bindMapArraySlot(name,id) if (m##name##AssetId[id] != String::EmptyString) m##name##Asset[id] = m##name##AssetId[id];
#define scriptBindMapArraySlot(name, arraySize, consoleClass, docs) addField(#name, TypeImageFilename, Offset(m##name##Filename, consoleClass), arraySize, assetText(name, docs)); \
addProtectedField(assetText(name,Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, &defaultProtectedGetFn, arraySize, assetText(name,asset reference.));
addProtectedField(assetText(name,Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##AssetSlot, &defaultProtectedGetFn, arraySize, assetText(name,asset reference.));
#define DECLARE_TEXTUREMAP(name) protected: \
#define DECLARE_TEXTUREMAP(className,name) protected: \
FileName m##name##Filename;\
StringTableEntry m##name##AssetId;\
AssetPtr<ImageAsset> m##name##Asset;\
@ -175,16 +175,45 @@ public:
const String& get##name() const { return m##name##Filename; }\
void set##name(FileName _in) { m##name##Filename = _in; }\
const AssetPtr<ImageAsset> & get##name##Asset() const { return m##name##Asset; }\
void set##name##Asset(AssetPtr<ImageAsset>_in) { m##name##Asset = _in; }
void set##name##Asset(AssetPtr<ImageAsset>_in) { m##name##Asset = _in; }\
static bool _set##name##Asset(void* obj, const char* index, const char* data)\
{\
##className* mat = static_cast<##className*>(obj);\
mat->m##name##AssetId = StringTable->insert(data);\
if (ImageAsset::getAssetById(mat->m##name##AssetId, &mat->m##name##Asset))\
{\
if (mat->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\
mat->m##name##Filename = StringTable->EmptyString();\
return true;\
}\
return true;\
}
#define GET_TEXTUREMAP(name) get##name()
#define SET_TEXTUREMAP(name,_in) set##name(_in)
#define GET_TEXTUREASSET(name) get##name##Asset()
#define SET_TEXTUREASSET(name,_in) set##name##Asset(_in)
#define DECLARE_TEXTUREARRAY(name,max) FileName m##name##Filename[max];\
#define DECLARE_TEXTUREARRAY(className,name,max) FileName m##name##Filename[max];\
StringTableEntry m##name##AssetId[max];\
AssetPtr<ImageAsset> m##name##Asset[max];
AssetPtr<ImageAsset> m##name##Asset[max];\
static bool _set##name##AssetSlot(void* obj, const char* index, const char* data)\
{\
##className* mat = static_cast<##className*>(obj);\
if (!index) return false;\
U32 idx = dAtoi(index);\
if (idx >= ##max)\
return false;\
mat->m##name##AssetId[idx] = StringTable->insert(data);\
if (ImageAsset::getAssetById(mat->m##name##AssetId[idx], &mat->m##name##Asset[idx]))\
{\
if (mat->m##name##Asset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\
{\
mat->m##name##Filename[idx] = StringTable->EmptyString();\
}\
return true;\
}\
return true;\
}
#endif

View file

@ -121,7 +121,7 @@ Material::Material()
mRoughness[i] = 1.0f;
mMetalness[i] = 0.0f;
mIsSRGb[i] = true;
mIsSRGb[i] = false;
mInvertRoughness[i] = false;
mRoughnessChan[i] = 0;
@ -502,282 +502,6 @@ void Material::initPersistFields()
Parent::initPersistFields();
}
bool Material::_setDiffuseMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mDiffuseMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mDiffuseMapAssetId[idx], &mat->mDiffuseMapAsset[idx]))
{
if (mat->mDiffuseMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mDiffuseMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setOverlayMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mOverlayMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mOverlayMapAssetId[idx], &mat->mOverlayMapAsset[idx]))
{
if (mat->mOverlayMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mOverlayMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setLightMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mLightMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mLightMapAssetId[idx], &mat->mLightMapAsset[idx]))
{
if (mat->mLightMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mLightMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setToneMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mToneMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mToneMapAssetId[idx], &mat->mToneMapAsset[idx]))
{
if (mat->mToneMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mToneMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setDetailMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mDetailMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mDetailMapAssetId[idx], &mat->mDetailMapAsset[idx]))
{
if (mat->mDetailMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mDetailMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setNormalMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mNormalMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mNormalMapAssetId[idx], &mat->mNormalMapAsset[idx]))
{
if (mat->mNormalMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mNormalMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setORMConfigMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mORMConfigMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mORMConfigMapAssetId[idx], &mat->mORMConfigMapAsset[idx]))
{
if (mat->mORMConfigMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mORMConfigMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setRoughMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mRoughMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mRoughMapAssetId[idx], &mat->mRoughMapAsset[idx]))
{
if (mat->mRoughMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mRoughMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setAOMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mAOMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mAOMapAssetId[idx], &mat->mAOMapAsset[idx]))
{
if (mat->mAOMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mAOMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setMetalMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mMetalMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mMetalMapAssetId[idx], &mat->mMetalMapAsset[idx]))
{
if (mat->mMetalMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mMetalMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setGlowMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mGlowMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mGlowMapAssetId[idx], &mat->mGlowMapAsset[idx]))
{
if (mat->mGlowMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mGlowMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::_setDetailNormalMapAsset(void* obj, const char* index, const char* data)
{
Material* mat = static_cast<Material*>(obj);
U32 idx = dAtoi(index);
if (idx >= MAX_STAGES)
return false;
mat->mDetailNormalMapAssetId[idx] = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mDetailNormalMapAssetId[idx], &mat->mDetailNormalMapAsset[idx]))
{
if (mat->mDetailNormalMapAsset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mDetailNormalMapFilename[idx] = StringTable->EmptyString();
}
return true;
}
return true;
}
bool Material::writeField( StringTableEntry fieldname, const char *value )
{
// Never allow the old field names to be written.

View file

@ -204,27 +204,27 @@ public:
//-----------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------
DECLARE_TEXTUREARRAY(DiffuseMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, DiffuseMap, MAX_STAGES);
bool mDiffuseMapSRGB[MAX_STAGES]; // SRGB diffuse
DECLARE_TEXTUREARRAY(OverlayMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(LightMap, MAX_STAGES);;
DECLARE_TEXTUREARRAY(ToneMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(DetailMap, MAX_STAGES);;
DECLARE_TEXTUREARRAY(NormalMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(ORMConfigMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, OverlayMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, LightMap, MAX_STAGES);;
DECLARE_TEXTUREARRAY(Material, ToneMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, DetailMap, MAX_STAGES);;
DECLARE_TEXTUREARRAY(Material, NormalMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, ORMConfigMap, MAX_STAGES);
bool mIsSRGb[MAX_STAGES];
DECLARE_TEXTUREARRAY(RoughMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, RoughMap, MAX_STAGES);
bool mInvertRoughness[MAX_STAGES];
F32 mRoughnessChan[MAX_STAGES];
DECLARE_TEXTUREARRAY(AOMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, AOMap, MAX_STAGES);
F32 mAOChan[MAX_STAGES];
DECLARE_TEXTUREARRAY(MetalMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, MetalMap, MAX_STAGES);
F32 mMetalChan[MAX_STAGES];
DECLARE_TEXTUREARRAY(GlowMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, GlowMap, MAX_STAGES);
F32 mGlowMul[MAX_STAGES];
/// A second normal map which repeats at the detail map
/// scale and blended with the base normal map.
DECLARE_TEXTUREARRAY(DetailNormalMap, MAX_STAGES);
DECLARE_TEXTUREARRAY(Material, DetailNormalMap, MAX_STAGES);
/// The strength scalar for the detail normal map.
F32 mDetailNormalMapStrength[MAX_STAGES];
@ -412,19 +412,6 @@ protected:
/// in the "mapTo" data variable.
virtual void _mapMaterial();
static bool _setDiffuseMapAsset(void* obj, const char* index, const char* data);
static bool _setOverlayMapAsset(void* obj, const char* index, const char* data);
static bool _setLightMapAsset(void* obj, const char* index, const char* data);
static bool _setToneMapAsset(void* obj, const char* index, const char* data);
static bool _setDetailMapAsset(void* obj, const char* index, const char* data);
static bool _setNormalMapAsset(void* obj, const char* index, const char* data);
static bool _setORMConfigMapAsset(void* obj, const char* index, const char* data);
static bool _setRoughMapAsset(void* obj, const char* index, const char* data);
static bool _setAOMapAsset(void* obj, const char* index, const char* data);
static bool _setMetalMapAsset(void* obj, const char* index, const char* data);
static bool _setGlowMapAsset(void* obj, const char* index, const char* data);
static bool _setDetailNormalMapAsset(void* obj, const char* index, const char* data);
private:
static GFXCubemapHandle smNormalizeCube;
};

View file

@ -115,101 +115,6 @@ void TerrainMaterial::initPersistFields()
Sim::getTerrainMaterialSet();
}
bool TerrainMaterial::_setDiffuseMapAsset(void* obj, const char* index, const char* data)
{
TerrainMaterial* mat = static_cast<TerrainMaterial*>(obj);
mat->mDiffuseMapAssetId = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mDiffuseMapAssetId, &mat->mDiffuseMapAsset))
{
if (mat->mDiffuseMapAsset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mDiffuseMapFilename = StringTable->EmptyString();
}
return true;
}
return true;
}
bool TerrainMaterial::_setNormalMapAsset(void* obj, const char* index, const char* data)
{
TerrainMaterial* mat = static_cast<TerrainMaterial*>(obj);
mat->mNormalMapAssetId = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mNormalMapAssetId, &mat->mNormalMapAsset))
{
if (mat->mNormalMapAsset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mNormalMapFilename = StringTable->EmptyString();
}
return true;
}
return true;
}
bool TerrainMaterial::_setDetailMapAsset(void* obj, const char* index, const char* data)
{
TerrainMaterial* mat = static_cast<TerrainMaterial*>(obj);
mat->mDetailMapAssetId = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mDetailMapAssetId, &mat->mDetailMapAsset))
{
if (mat->mDetailMapAsset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mDetailMapFilename = StringTable->EmptyString();
}
return true;
}
return true;
}
bool TerrainMaterial::_setORMConfigMapAsset(void* obj, const char* index, const char* data)
{
TerrainMaterial* mat = static_cast<TerrainMaterial*>(obj);
mat->mORMConfigMapAssetId = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mORMConfigMapAssetId, &mat->mORMConfigMapAsset))
{
if (mat->mORMConfigMapAsset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mORMConfigMapFilename = StringTable->EmptyString();
}
return true;
}
return true;
}
bool TerrainMaterial::_setMacroMapAsset(void* obj, const char* index, const char* data)
{
TerrainMaterial* mat = static_cast<TerrainMaterial*>(obj);
mat->mMacroMapAssetId = StringTable->insert(data);
if (ImageAsset::getAssetById(mat->mMacroMapAssetId, &mat->mMacroMapAsset))
{
if (mat->mMacroMapAsset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))
{
mat->mMacroMapFilename = StringTable->EmptyString();
}
return true;
}
return true;
}
bool TerrainMaterial::onAdd()
{
if ( !Parent::onAdd() )

View file

@ -42,17 +42,17 @@ protected:
//AssetPtr<ImageAsset> mDiffuseAsset;
DECLARE_TEXTUREMAP(DiffuseMap);
DECLARE_TEXTUREMAP(TerrainMaterial, DiffuseMap);
/// The size of the diffuse base map in meters
/// used to generate its texture coordinates.
F32 mDiffuseSize;
///
DECLARE_TEXTUREMAP(NormalMap);
DECLARE_TEXTUREMAP(TerrainMaterial, NormalMap);
///
DECLARE_TEXTUREMAP(DetailMap);
DECLARE_TEXTUREMAP(TerrainMaterial, DetailMap);
/// The size of the detail map in meters used
/// to generate the texture coordinates for the
@ -66,7 +66,7 @@ protected:
F32 mDetailDistance;
///
DECLARE_TEXTUREMAP(ORMConfigMap);
DECLARE_TEXTUREMAP(TerrainMaterial, ORMConfigMap);
bool mIsSRGB;
bool mInvertRoughness;
@ -77,7 +77,7 @@ protected:
/// planes.
bool mSideProjection;
DECLARE_TEXTUREMAP(MacroMap);
DECLARE_TEXTUREMAP(TerrainMaterial, MacroMap);
F32 mMacroSize;
F32 mMacroStrength;
F32 mMacroDistance;
@ -93,12 +93,6 @@ public:
bool onAdd();
static void initPersistFields();
static bool _setDiffuseMapAsset(void* obj, const char* index, const char* data);
static bool _setNormalMapAsset(void* obj, const char* index, const char* data);
static bool _setDetailMapAsset(void* obj, const char* index, const char* data);
static bool _setORMConfigMapAsset(void* obj, const char* index, const char* data);
static bool _setMacroMapAsset(void* obj, const char* index, const char* data);
DECLARE_CONOBJECT( TerrainMaterial );
/// This method locates the TerrainMaterial if it exists, tries