Updates ImageAsset usage to utilize AssetRef, and standardizes the setter/getter functions and naming conventions, as well as the ability to use and bind named targets.

This commit is contained in:
JeffR 2026-06-16 17:39:30 -05:00
parent a858d8624e
commit 34e3f78a22
82 changed files with 1451 additions and 951 deletions

View file

@ -92,10 +92,12 @@ FRangeValidator hardnessValidator(0.0f, 0.999f);
void TerrainMaterial::initPersistFields()
{
docsURL;
INITPERSISTFIELD_IMAGEASSET(DiffuseMap, TerrainMaterial,"Base Albedo stretched over the whole map");
ADD_FIELD("diffuseMapAsset", TypeImageAssetRef, Offset(mDiffuseMapAssetRef, TerrainMaterial))
.doc("Base Albedo asset stretched over the whole map");
addFieldV( "diffuseSize", TypeRangedF32, Offset( mDiffuseSize, TerrainMaterial ), &CommonValidators::PositiveFloat, "Used to scale the diffuse map to the material square" );
INITPERSISTFIELD_IMAGEASSET(NormalMap, TerrainMaterial,"NormalMap");
ADD_FIELD("normalMapAsset", TypeImageAssetRef, Offset(mNormalMapAssetRef, TerrainMaterial))
.doc("NormalMap asset");
addFieldV( "parallaxScale", TypeRangedF32, Offset( mParallaxScale, TerrainMaterial ), &CommonValidators::PositiveFloat, "Used to scale the height from the normal map to give some self "
"occlusion effect (aka parallax) to the terrain material" );
@ -109,20 +111,23 @@ void TerrainMaterial::initPersistFields()
addFieldV("blendHeightHardness", TypeRangedF32, Offset(mBlendHardness, TerrainMaterial), &hardnessValidator, "How sharply this layer blends with other textures."
"0->1, soft->hard.");
INITPERSISTFIELD_IMAGEASSET(DetailMap, TerrainMaterial, "Raises and lowers the RGB result of the Base Albedo up close.");
ADD_FIELD("detailMapAsset", TypeImageAssetRef, Offset(mDetailMapAssetRef, TerrainMaterial))
.doc("Raises and lowers the RGB result of the Base Albedo up close.");
addFieldV( "detailSize", TypeRangedF32, Offset( mDetailSize, TerrainMaterial ), &CommonValidators::PositiveFloat, "Used to scale the detail map to the material square" );
addFieldV( "detailStrength", TypeRangedF32, Offset( mDetailStrength, TerrainMaterial ), &CommonValidators::PositiveFloat, "Exponentially sharpens or lightens the detail map rendering on the material" );
addFieldV( "detailDistance", TypeRangedF32, Offset( mDetailDistance, TerrainMaterial ), &CommonValidators::PositiveFloat, "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");
INITPERSISTFIELD_IMAGEASSET(ORMConfigMap, TerrainMaterial, "AO|Roughness|metalness map (uses DetailMap UV Coords)");
ADD_FIELD("ORMConfigMapAsset", TypeImageAssetRef, Offset(mORMConfigMapAssetRef, TerrainMaterial))
.doc("AO|Roughness|metalness map asset (uses DetailMap UV Coords)");
addField("isSRGB", TypeBool, Offset(mIsSRGB, TerrainMaterial), "Is the PBR Config map's image in sRGB format?");
addField("invertRoughness", TypeBool, Offset(mInvertRoughness, TerrainMaterial), "Should the roughness channel of the PBR Config map be inverted?");
//Macro maps additions
INITPERSISTFIELD_IMAGEASSET(MacroMap, TerrainMaterial, "Raises and lowers the RGB result of the Base Albedo at a distance.");
ADD_FIELD("macroMapAsset", TypeImageAssetRef, Offset(mMacroMapAssetRef, TerrainMaterial))
.doc("Raises and lowers the RGB result of the Base Albedo at a distance.");
addFieldV( "macroSize", TypeRangedF32, Offset( mMacroSize, TerrainMaterial ), &CommonValidators::PositiveFloat, "Used to scale the Macro map to the material square" );
addFieldV( "macroStrength", TypeRangedF32, Offset( mMacroStrength, TerrainMaterial ), &CommonValidators::PositiveFloat, "Exponentially sharpens or lightens the Macro map rendering on the material" );
addFieldV( "macroDistance", TypeRangedF32, Offset( mMacroDistance, TerrainMaterial ), &CommonValidators::PositiveFloat, "Changes how far camera can see the Macro map rendering on the material" );
@ -197,7 +202,7 @@ TerrainMaterial* TerrainMaterial::findOrCreate( const char *nameOrPath )
{
mat = new TerrainMaterial();
mat->setInternalName( nameOrPath );
mat->_setDiffuseMap(nameOrPath);
mat->mDiffuseMapAssetRef = ImageAsset::getAssetIdFromFilePath(StringTable->insert(nameOrPath));
mat->registerObject();
Sim::getRootGroup()->addObject( mat );
return mat;
@ -206,11 +211,9 @@ TerrainMaterial* TerrainMaterial::findOrCreate( const char *nameOrPath )
// Ok... return a placeholder material then.
mat = new TerrainMaterial();
mat->setInternalName(nameOrPath);
mat->_setDiffuseMap(GFXTextureManager::getWarningTexturePath());
mat->mDiffuseMapAssetRef = ImageAsset::getAssetIdFromFilePath(StringTable->insert(GFXTextureManager::getWarningTexturePath()));
mat->mDiffuseSize = 500;
mat->_setDetailMap(StringTable->EmptyString());
mat->mDetailSize = 5;
mat->_setMacroMap(StringTable->EmptyString());
mat->mMacroSize = 200;
mat->registerObject();
@ -219,14 +222,53 @@ TerrainMaterial* TerrainMaterial::findOrCreate( const char *nameOrPath )
return mat;
}
//declare general get<entry>, get<entry>Asset and set<entry> methods
//declare general get<entry>Asset and set<entry> methods
//signatures are:
//using DiffuseMap as an example
//material.getDiffuseMap(); //returns the raw file referenced
//material.getDiffuseMapAsset(); //returns the asset id
//material.setDiffuseMap(%texture); //tries to set the asset and failing that attempts a flat file reference
DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, DiffuseMap)
DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, NormalMap)
DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, DetailMap)
DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, ORMConfigMap)
DEF_ASSET_BINDS_REFACTOR(TerrainMaterial, MacroMap)
DefineEngineMethod(TerrainMaterial, getDiffuseMapAsset, StringTableEntry, (), , "DiffuseMap asset reference")
{
return object->getDiffuseMapAssetId();
}
DefineEngineMethod(TerrainMaterial, setDiffuseMap, void, (const char* assetName), , "DiffuseMap assignment.")
{
object->setDiffuseMap(StringTable->insert(assetName));
}
DefineEngineMethod(TerrainMaterial, getNormalMapAsset, StringTableEntry, (), , "NormalMap asset reference")
{
return object->getNormalMapAssetId();
}
DefineEngineMethod(TerrainMaterial, setNormalMap, void, (const char* assetName), , "NormalMap assignment.")
{
object->setNormalMap(StringTable->insert(assetName));
}
DefineEngineMethod(TerrainMaterial, getDetailMapAsset, StringTableEntry, (), , "DetailMap asset reference")
{
return object->getDetailMapAssetId();
}
DefineEngineMethod(TerrainMaterial, setDetailMap, void, (const char* assetName), , "DetailMap assignment.")
{
object->setDetailMap(StringTable->insert(assetName));
}
DefineEngineMethod(TerrainMaterial, getORMConfigMapAsset, StringTableEntry, (), , "ORMConfigMap asset reference")
{
return object->getORMConfigMapAssetId();
}
DefineEngineMethod(TerrainMaterial, setORMConfigMap, void, (const char* assetName), , "ORMConfigMap assignment.")
{
object->setORMConfigMap(StringTable->insert(assetName));
}
DefineEngineMethod(TerrainMaterial, getMacroMapAsset, StringTableEntry, (), , "MacroMap asset reference")
{
return object->getMacroMapAssetId();
}
DefineEngineMethod(TerrainMaterial, setMacroMap, void, (const char* assetName), , "MacroMap assignment.")
{
object->setMacroMap(StringTable->insert(assetName));
}

View file

@ -38,17 +38,17 @@ class TerrainMaterial : public SimObject
protected:
///
DECLARE_IMAGEASSET(TerrainMaterial, DiffuseMap, GFXStaticTextureSRGBProfile)
AssetRef<ImageAsset> mDiffuseMapAssetRef;
/// The size of the diffuse base map in meters
/// used to generate its texture coordinates.
F32 mDiffuseSize;
///
DECLARE_IMAGEASSET(TerrainMaterial, NormalMap, GFXNormalMapProfile)
AssetRef<ImageAsset> mNormalMapAssetRef;
///
DECLARE_IMAGEASSET(TerrainMaterial, DetailMap, GFXStaticTextureProfile)
AssetRef<ImageAsset> mDetailMapAssetRef;
/// The size of the detail map in meters used
/// to generate the texture coordinates for the
@ -62,7 +62,7 @@ protected:
F32 mDetailDistance;
///
DECLARE_IMAGEASSET(TerrainMaterial, ORMConfigMap, GFXStaticTextureProfile)
AssetRef<ImageAsset> mORMConfigMapAssetRef;
bool mIsSRGB;
bool mInvertRoughness;
@ -73,7 +73,7 @@ protected:
/// planes.
bool mSideProjection;
DECLARE_IMAGEASSET(TerrainMaterial, MacroMap, GFXStaticTextureProfile)
AssetRef<ImageAsset> mMacroMapAssetRef;
F32 mMacroSize;
F32 mMacroStrength;
@ -110,6 +110,27 @@ public:
/// a material is not found or defined.
static TerrainMaterial* getWarningMaterial();
GFXTexHandle getDiffuseMap() { return mDiffuseMapAssetRef.notNull() ? mDiffuseMapAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
StringTableEntry getDiffuseMapAssetId() const { return mDiffuseMapAssetRef.getAssetId(); }
void setDiffuseMap(StringTableEntry assetId) { mDiffuseMapAssetRef = assetId; }
GFXTexHandle getNormalMap() { return mNormalMapAssetRef.notNull() ? mNormalMapAssetRef.assetPtr->getTexture(&GFXNormalMapProfile) : NULL; }
StringTableEntry getNormalMapAssetId() const { return mNormalMapAssetRef.getAssetId(); }
void setNormalMap(StringTableEntry assetId) { mNormalMapAssetRef = assetId; }
GFXTexHandle getDetailMap() { return mDetailMapAssetRef.notNull() ? mDetailMapAssetRef.assetPtr->getTexture(&GFXStaticTextureProfile) : NULL; }
StringTableEntry getDetailMapAssetId() const { return mDetailMapAssetRef.getAssetId(); }
void setDetailMap(StringTableEntry assetId) { mDetailMapAssetRef = assetId; }
GFXTexHandle getORMConfigMap() { return mORMConfigMapAssetRef.notNull() ? mORMConfigMapAssetRef.assetPtr->getTexture(&GFXStaticTextureProfile) : NULL; }
AssetPtr<ImageAsset> getORMConfigMapAsset() { return mORMConfigMapAssetRef.assetPtr; }
StringTableEntry getORMConfigMapAssetId() const { return mORMConfigMapAssetRef.getAssetId(); }
void setORMConfigMap(StringTableEntry assetId) { mORMConfigMapAssetRef = assetId; }
GFXTexHandle getMacroMap() { return mMacroMapAssetRef.notNull() ? mMacroMapAssetRef.assetPtr->getTexture(&GFXStaticTextureProfile) : NULL; }
StringTableEntry getMacroMapAssetId() const { return mMacroMapAssetRef.getAssetId(); }
void setMacroMap(StringTableEntry assetId) { mMacroMapAssetRef = assetId; }
F32 getDiffuseSize() const { return mDiffuseSize; }
F32 getDetailSize() const { return mDetailSize; }