From 22b0785c737d6a2a2899958a3ca41bc3cb55ac5b Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Wed, 30 Sep 2020 13:50:23 -0500 Subject: [PATCH] augment imageasset with initMapSlot and bindMap class insert macros (and array variants) to make the conversion process for folks shifting from 3.x to 4.x cleaner, as well as autocreation of getter/setter methods andadditoinal acessor macros for consistency --- Engine/source/T3D/assets/ImageAsset.cpp | 2 +- Engine/source/T3D/assets/ImageAsset.h | 25 +++++- .../source/materials/materialDefinition.cpp | 82 ++++++++----------- Engine/source/terrain/terrMaterial.cpp | 57 +++++++------ Engine/source/terrain/terrMaterial.h | 10 --- 5 files changed, 90 insertions(+), 86 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index c00a15c77..1af4a60ab 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -91,7 +91,7 @@ ImplementEnumType(ImageAssetType, "@ingroup gameObjects") { ImageAsset::Albedo, "Albedo", "" }, { ImageAsset::Normal, "Normal", "" }, - { ImageAsset::PBRConfig, "PBRConfig", "" }, + { ImageAsset::ORMConfig, "ORMConfig", "" }, { ImageAsset::GUI, "GUI", "" }, { ImageAsset::Roughness, "Roughness", "" }, { ImageAsset::AO, "AO", "" }, diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 9a502054e..5287c0c00 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -128,15 +128,32 @@ typedef ImageAsset::ImageTypes ImageAssetType; DefineEnumType(ImageAssetType); #define assetText(x,suff) std::string(std::string(#x) + std::string(#suff)).c_str() -#define scriptBindMapSlot(name, consoleClass) addField(#name, TypeImageFilename, Offset(m##name##Filename, consoleClass), assetText(name,texture map.)); \ + +#define initMapSlot(name) m##name##Filename = String::EmptyString; m##name##AssetId = StringTable->EmptyString(); m##name##Asset = NULL; +#define bindMapSlot(name) if (m##name##AssetId != String::EmptyString) m##name##Asset = m##name##AssetId; + +#define scriptBindMapSlot(name, consoleClass, docs) addField(#name, TypeImageFilename, Offset(m##name##Filename, consoleClass), assetText(name, docs)); \ addField(assetText(name,Asset), TypeImageAssetPtr, Offset(m##name##AssetId, consoleClass), assetText(name,asset reference.)); -#define scriptBindMapArraySlot(name, arraySize, consoleClass) addField(#name, TypeImageFilename, Offset(m##name##Filename, consoleClass), arraySize, assetText(name,texture map.)); \ +#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)); \ addField(assetText(name,Asset), TypeImageAssetPtr, Offset(m##name##AssetId, consoleClass), arraySize, assetText(name,asset reference.)); -#define DECLARE_TEXTUREMAP(name) FileName m##name##Filename;\ +#define DECLARE_TEXTUREMAP(name) protected: \ + FileName m##name##Filename;\ StringTableEntry m##name##AssetId;\ - AssetPtr m##name##Asset; + AssetPtr m##name##Asset;\ + public: \ + const String& get##name##() const { return m##name##Filename; }\ + void set##name##(FileName _in) { m##name##Filename = _in; }\ + const AssetPtr & get##name##Asset() const { return m##name##Asset; }\ + void set##name##Asset(AssetPtr_in) { m##name##Asset = _in; } + +#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];\ StringTableEntry m##name##AssetId[max];\ diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index abd4b49c6..66239cd83 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -97,9 +97,6 @@ ImplementEnumType( MaterialWaveType, { 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." }, EndImplementEnumType; -#define initMapSlot(name,id) m##name##Filename[id] = String::EmptyString; m##name##AssetId[id] = StringTable->EmptyString(); m##name##Asset[id] = NULL; -#define bindMapSlot(name,id) if (m##name##AssetId[id] != String::EmptyString) m##name##Asset[id] = m##name##AssetId[id]; - bool Material::sAllowTextureTargetAssignment = false; GFXCubemap * Material::GetNormalizeCube() @@ -138,18 +135,18 @@ Material::Material() mAccuCoverage[i] = 0.9f; mAccuSpecular[i] = 16.0f; - initMapSlot(DiffuseMap, i); - initMapSlot(OverlayMap, i); - initMapSlot(LightMap, i); - initMapSlot(ToneMap, i); - initMapSlot(DetailMap, i); - initMapSlot(NormalMap, i); - initMapSlot(PBRConfigMap, i); - initMapSlot(RoughMap, i); - initMapSlot(AOMap, i); - initMapSlot(MetalMap, i); - initMapSlot(GlowMap, i); - initMapSlot(DetailNormalMap, i); + initMapArraySlot(DiffuseMap, i); + initMapArraySlot(OverlayMap, i); + initMapArraySlot(LightMap, i); + initMapArraySlot(ToneMap, i); + initMapArraySlot(DetailMap, i); + initMapArraySlot(NormalMap, i); + initMapArraySlot(ORMConfigMap, i); + initMapArraySlot(RoughMap, i); + initMapArraySlot(AOMap, i); + initMapArraySlot(MetalMap, i); + initMapArraySlot(GlowMap, i); + initMapArraySlot(DetailNormalMap, i); mParallaxScale[i] = 0.0f; @@ -246,18 +243,18 @@ void Material::initPersistFields() "This color is multiplied against the diffuse texture color. If no diffuse texture " "is present this is the material color." ); - scriptBindMapArraySlot(DiffuseMap, MAX_STAGES, Material); - scriptBindMapArraySlot(OverlayMap, MAX_STAGES, Material); - scriptBindMapArraySlot(LightMap, MAX_STAGES, Material); - scriptBindMapArraySlot(ToneMap, MAX_STAGES, Material); - scriptBindMapArraySlot(DetailMap, MAX_STAGES, Material); - scriptBindMapArraySlot(NormalMap, MAX_STAGES, Material); - scriptBindMapArraySlot(PBRConfigMap, MAX_STAGES, Material); - scriptBindMapArraySlot(RoughMap, MAX_STAGES, Material); - scriptBindMapArraySlot(AOMap, MAX_STAGES, Material); - scriptBindMapArraySlot(MetalMap, MAX_STAGES, Material); - scriptBindMapArraySlot(GlowMap, MAX_STAGES, Material); - scriptBindMapArraySlot(DetailNormalMap, MAX_STAGES, Material); + scriptBindMapArraySlot(DiffuseMap, MAX_STAGES, Material, "Albedo"); + scriptBindMapArraySlot(OverlayMap, MAX_STAGES, Material, "Overlay"); + scriptBindMapArraySlot(LightMap, MAX_STAGES, Material, "LightMap"); + scriptBindMapArraySlot(ToneMap, MAX_STAGES, Material, "ToneMap"); + scriptBindMapArraySlot(DetailMap, MAX_STAGES, Material, "DetailMap"); + scriptBindMapArraySlot(NormalMap, MAX_STAGES, Material, "NormalMap"); + scriptBindMapArraySlot(ORMConfigMap, MAX_STAGES, Material, "AO|Roughness|metalness map"); + scriptBindMapArraySlot(RoughMap, MAX_STAGES, Material, "RoughMap (also needs MetalMap)"); + scriptBindMapArraySlot(AOMap, MAX_STAGES, Material, "AOMap"); + scriptBindMapArraySlot(MetalMap, MAX_STAGES, Material, "MetalMap (also needs RoughMap)"); + scriptBindMapArraySlot(GlowMap, MAX_STAGES, Material, "GlowMap (needs Albedo)"); + scriptBindMapArraySlot(DetailNormalMap, MAX_STAGES, Material, "DetailNormalMap"); addField("diffuseMapSRGB", TypeBool, Offset(mDiffuseMapSRGB, Material), MAX_STAGES, "Enable sRGB for the diffuse color texture map."); @@ -543,29 +540,20 @@ bool Material::onAdd() if ( slash != String::NPos ) mPath = scriptFile.substr( 0, slash + 1 ); - /* //bind any assets we have for (U32 i = 0; i < MAX_STAGES; i++) { - if (mDiffuseMapAssetId[i] != StringTable->EmptyString()) - { - mDiffuseMapAsset[0] = mDiffuseMapAssetId[0]; - } - } - */ - for (U32 i = 0; i < MAX_STAGES; i++) - { - bindMapSlot(DiffuseMap, i); - bindMapSlot(OverlayMap, i); - bindMapSlot(LightMap, i); - bindMapSlot(ToneMap, i); - bindMapSlot(DetailMap, i); - bindMapSlot(PBRConfigMap, i); - bindMapSlot(RoughMap, i); - bindMapSlot(AOMap, i); - bindMapSlot(MetalMap, i); - bindMapSlot(GlowMap, i); - bindMapSlot(DetailNormalMap, i); + bindMapArraySlot(DiffuseMap, i); + bindMapArraySlot(OverlayMap, i); + bindMapArraySlot(LightMap, i); + bindMapArraySlot(ToneMap, i); + bindMapArraySlot(DetailMap, i); + bindMapArraySlot(ORMConfigMap, i); + bindMapArraySlot(RoughMap, i); + bindMapArraySlot(AOMap, i); + bindMapArraySlot(MetalMap, i); + bindMapArraySlot(GlowMap, i); + bindMapArraySlot(DetailNormalMap, i); } _mapMaterial(); diff --git a/Engine/source/terrain/terrMaterial.cpp b/Engine/source/terrain/terrMaterial.cpp index 458ed3961..013fca3d0 100644 --- a/Engine/source/terrain/terrMaterial.cpp +++ b/Engine/source/terrain/terrMaterial.cpp @@ -71,6 +71,11 @@ TerrainMaterial::TerrainMaterial() mIsSRGB(false), mInvertSmoothness(false) { + initMapSlot(DiffuseMap); + initMapSlot(NormalMap); + initMapSlot(DetailMap); + initMapSlot(ORMConfigMap); + initMapSlot(MacroMap); } TerrainMaterial::~TerrainMaterial() @@ -79,33 +84,30 @@ TerrainMaterial::~TerrainMaterial() void TerrainMaterial::initPersistFields() { - scriptBindMapSlot(DiffuseMap, TerrainMaterial); - - //addField( "diffuseMap", TypeStringFilename, Offset( mDiffuseMap, TerrainMaterial ), "Base texture for the material" ); + scriptBindMapSlot(DiffuseMap, TerrainMaterial,"Base Albedo stretched over the whole map"); addField( "diffuseSize", TypeF32, Offset( mDiffuseSize, TerrainMaterial ), "Used to scale the diffuse map to the material square" ); - addField( "normalMap", TypeStringFilename, Offset( mNormalMap, TerrainMaterial ), "Bump map for the material" ); - - addField( "detailMap", TypeStringFilename, Offset( mDetailMap, TerrainMaterial ), "Detail map for the material" ); - addField( "detailSize", TypeF32, Offset( mDetailSize, TerrainMaterial ), "Used to scale the detail map to the material square" ); - - addField( "detailStrength", TypeF32, Offset( mDetailStrength, TerrainMaterial ), "Exponentially sharpens or lightens the detail map rendering on the material" ); - addField( "detailDistance", TypeF32, Offset( mDetailDistance, TerrainMaterial ), "Changes how far camera can see the detail map rendering on the material" ); - addField( "useSideProjection", TypeBool, Offset( mSideProjection, TerrainMaterial ),"Makes that terrain material project along the sides of steep " - "slopes instead of projected downwards"); - - //Macro maps additions - addField( "macroMap", TypeStringFilename, Offset( mMacroMap, TerrainMaterial ), "Macro map for the material" ); - addField( "macroSize", TypeF32, Offset( mMacroSize, TerrainMaterial ), "Used to scale the Macro map to the material square" ); - addField( "macroStrength", TypeF32, Offset( mMacroStrength, TerrainMaterial ), "Exponentially sharpens or lightens the Macro map rendering on the material" ); - addField( "macroDistance", TypeF32, Offset( mMacroDistance, TerrainMaterial ), "Changes how far camera can see the Macro map rendering on the material" ); - + scriptBindMapSlot(NormalMap, TerrainMaterial,"NormalMap"); addField( "parallaxScale", TypeF32, Offset( mParallaxScale, TerrainMaterial ), "Used to scale the height from the normal map to give some self " "occlusion effect (aka parallax) to the terrain material" ); - addField("pbrConfigMap", TypeStringFilename, Offset(mCompositeMap, TerrainMaterial), "Composite map for the PBR Configuration of the material"); + scriptBindMapSlot(DetailMap, TerrainMaterial, "Raises and lowers the RGB result of the Base Albedo up close."); + addField( "detailSize", TypeF32, Offset( mDetailSize, TerrainMaterial ), "Used to scale the detail map to the material square" ); + addField( "detailStrength", TypeF32, Offset( mDetailStrength, TerrainMaterial ), "Exponentially sharpens or lightens the detail map rendering on the material" ); + addField( "detailDistance", TypeF32, Offset( mDetailDistance, TerrainMaterial ), "Changes how far camera can see the detail map rendering on the material" ); + + addField( "useSideProjection", TypeBool, Offset( mSideProjection, TerrainMaterial ),"Makes that terrain material project along the sides of steep " + "slopes instead of projected downwards"); + + scriptBindMapSlot(ORMConfigMap, TerrainMaterial, "AO|Roughness|metalness map (uses DetailMap UV Coords)"); addField("isSRGB", TypeBool, Offset(mIsSRGB, TerrainMaterial), "Is the PBR Config map's image in sRGB format?"); - addField("invertSmoothness", TypeBool, Offset(mInvertSmoothness, TerrainMaterial), "Should the smoothness channel of the PBR Config map be inverted?"); + addField("invertRoughness", TypeBool, Offset(mInvertRoughness, TerrainMaterial), "Should the roughness channel of the PBR Config map be inverted?"); + + //Macro maps additions + scriptBindMapSlot(MacroMap, TerrainMaterial, "Raises and lowers the RGB result of the Base Albedo at a distance."); + addField( "macroSize", TypeF32, Offset( mMacroSize, TerrainMaterial ), "Used to scale the Macro map to the material square" ); + addField( "macroStrength", TypeF32, Offset( mMacroStrength, TerrainMaterial ), "Exponentially sharpens or lightens the Macro map rendering on the material" ); + addField( "macroDistance", TypeF32, Offset( mMacroDistance, TerrainMaterial ), "Changes how far camera can see the Macro map rendering on the material" ); Parent::initPersistFields(); @@ -128,7 +130,14 @@ bool TerrainMaterial::onAdd() SimObject *object = set->findObjectByInternalName( mInternalName ); if ( object ) Con::warnf( "TerrainMaterial::onAdd() - Internal name collision; '%s' already exists!", mInternalName ); - } + } + + //bind any assets we have + bindMapSlot(DiffuseMap); + bindMapSlot(NormalMap); + bindMapSlot(DetailMap); + bindMapSlot(ORMConfigMap); + bindMapSlot(MacroMap); set->addObject( this ); @@ -175,9 +184,9 @@ TerrainMaterial* TerrainMaterial::findOrCreate( const char *nameOrPath ) mat->setInternalName( "warning_material" ); mat->mDiffuseMapFilename = GFXTextureManager::getWarningTexturePath(); mat->mDiffuseSize = 500; - mat->mDetailMap = GFXTextureManager::getWarningTexturePath(); + mat->mDetailMapFilename = GFXTextureManager::getWarningTexturePath(); mat->mDetailSize = 5; - mat->mMacroMap = GFXTextureManager::getWarningTexturePath(); + mat->mMacroMapFilename = GFXTextureManager::getWarningTexturePath(); mat->mMacroSize = 200; mat->registerObject(); diff --git a/Engine/source/terrain/terrMaterial.h b/Engine/source/terrain/terrMaterial.h index 9462cc62e..bbfe38063 100644 --- a/Engine/source/terrain/terrMaterial.h +++ b/Engine/source/terrain/terrMaterial.h @@ -104,18 +104,8 @@ public: /// a material is not found or defined. static TerrainMaterial* getWarningMaterial(); - const String& getDiffuseMap() const { return mDiffuseMapFilename; } - F32 getDiffuseSize() const { return mDiffuseSize; } - const String& getNormalMap() const { return mNormalMap; } - - const String& getDetailMap() const { return mDetailMap; } - - const String& getMacroMap() const { return mMacroMap; } - - const String& getCompositeMap() const { return mCompositeMap; } - F32 getDetailSize() const { return mDetailSize; } F32 getDetailStrength() const { return mDetailStrength; }