mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-26 23:59:30 +00:00
material definition
changing the beast over to the refactor
This commit is contained in:
parent
4d980e5406
commit
cebfdbc5ec
13 changed files with 61 additions and 105 deletions
|
|
@ -142,18 +142,15 @@ Material::Material()
|
|||
mAccuCoverage[i] = 0.9f;
|
||||
mAccuSpecular[i] = 16.0f;
|
||||
|
||||
INIT_IMAGEASSET_ARRAY(DiffuseMap, GFXStaticTextureSRGBProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(OverlayMap, GFXStaticTextureProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(LightMap, GFXStaticTextureProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(ToneMap, GFXStaticTextureProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(DetailMap, GFXStaticTextureProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(NormalMap, GFXNormalMapProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(ORMConfigMap, GFXStaticTextureProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(RoughMap, GFXStaticTextureProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(AOMap, GFXStaticTextureProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(MetalMap, GFXStaticTextureProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(GlowMap, GFXStaticTextureProfile, i);
|
||||
INIT_IMAGEASSET_ARRAY(DetailNormalMap, GFXNormalMapProfile, i);
|
||||
|
||||
mParallaxScale[i] = 0.0f;
|
||||
|
||||
|
|
@ -258,14 +255,14 @@ void Material::initPersistFields()
|
|||
addArray("Stages", MAX_STAGES);
|
||||
|
||||
addGroup("Basic Texture Maps");
|
||||
INITPERSISTFIELD_IMAGEASSET_ARRAY(DiffuseMap, MAX_STAGES, Material, "Albedo");
|
||||
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(DiffuseMap, MAX_STAGES, Material, "Albedo");
|
||||
addField("diffuseColor", TypeColorF, Offset(mDiffuse, Material), MAX_STAGES,
|
||||
"This color is multiplied against the diffuse texture color. If no diffuse texture "
|
||||
"is present this is the material color.");
|
||||
addField("diffuseMapSRGB", TypeBool, Offset(mDiffuseMapSRGB, Material), MAX_STAGES,
|
||||
"Enable sRGB for the diffuse color texture map.");
|
||||
|
||||
INITPERSISTFIELD_IMAGEASSET_ARRAY(NormalMap, MAX_STAGES, Material, "NormalMap");
|
||||
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(NormalMap, MAX_STAGES, Material, "NormalMap");
|
||||
endGroup("Basic Texture Maps");
|
||||
|
||||
addGroup("Light Influence Maps");
|
||||
|
|
@ -303,7 +300,7 @@ void Material::initPersistFields()
|
|||
addField("detailScale", TypePoint2F, Offset(mDetailScale, Material), MAX_STAGES,
|
||||
"The scale factor for the detail map.");
|
||||
|
||||
INITPERSISTFIELD_IMAGEASSET_ARRAY(DetailNormalMap, MAX_STAGES, Material, "DetailNormalMap");
|
||||
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(DetailNormalMap, MAX_STAGES, Material, "DetailNormalMap");
|
||||
addField("detailNormalMapStrength", TypeF32, Offset(mDetailNormalMapStrength, Material), MAX_STAGES,
|
||||
"Used to scale the strength of the detail normal map when blended with the base normal map.");
|
||||
|
||||
|
|
@ -506,18 +503,12 @@ void Material::initPersistFields()
|
|||
// They point at the new 'map' fields, but reads always return
|
||||
// an empty string and writes only apply if the value is not empty.
|
||||
//
|
||||
addProtectedField("baseTex", TypeImageFilename, Offset(mDiffuseMapName, Material),
|
||||
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
|
||||
"For backwards compatibility.\n@see diffuseMap\n", AbstractClassRep::FIELD_HideInInspectors);
|
||||
addProtectedField("detailTex", TypeImageFilename, Offset(mDetailMapName, Material),
|
||||
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
|
||||
"For backwards compatibility.\n@see detailMap\n", AbstractClassRep::FIELD_HideInInspectors);
|
||||
addProtectedField("overlayTex", TypeImageFilename, Offset(mOverlayMapName, Material),
|
||||
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
|
||||
"For backwards compatibility.\n@see overlayMap\n", AbstractClassRep::FIELD_HideInInspectors);
|
||||
addProtectedField("bumpTex", TypeImageFilename, Offset(mNormalMapName, Material),
|
||||
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
|
||||
"For backwards compatibility.\n@see normalMap\n", AbstractClassRep::FIELD_HideInInspectors);
|
||||
addProtectedField("colorMultiply", TypeColorF, Offset(mDiffuse, Material),
|
||||
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
|
||||
"For backwards compatibility.\n@see diffuseColor\n", AbstractClassRep::FIELD_HideInInspectors);
|
||||
|
|
@ -656,26 +647,11 @@ void Material::_mapMaterial()
|
|||
// If mapTo not defined in script, try to use the base texture name instead
|
||||
if (mMapTo.isEmpty())
|
||||
{
|
||||
if (mDiffuseMapName[0] == StringTable->EmptyString() && mDiffuseMapAsset->isNull())
|
||||
if (mDiffuseMapAsset->isNull())
|
||||
return;
|
||||
|
||||
else
|
||||
else if (mDiffuseMapAsset->notNull())
|
||||
{
|
||||
// extract filename from base texture
|
||||
if (mDiffuseMapName[0] != StringTable->EmptyString())
|
||||
{
|
||||
U32 slashPos = String(mDiffuseMapName[0]).find('/', 0, String::Right);
|
||||
if (slashPos == String::NPos)
|
||||
// no '/' character, must be no path, just the filename
|
||||
mMapTo = mDiffuseMapName[0];
|
||||
else
|
||||
// use everything after the last slash
|
||||
mMapTo = String(mDiffuseMapName[0]).substr(slashPos + 1, (U32)strlen(mDiffuseMapName[0]) - slashPos - 1);
|
||||
}
|
||||
else if (!mDiffuseMapAsset->isNull())
|
||||
{
|
||||
mMapTo = mDiffuseMapAsset[0]->getImageFile();
|
||||
}
|
||||
mMapTo = mDiffuseMapAsset[0]->getImageFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -850,16 +826,15 @@ bool Material::_setAccuEnabled(void* object, const char* index, const char* data
|
|||
//material.getDiffuseMap(%layer); //returns the raw file referenced
|
||||
//material.getDiffuseMapAsset(%layer); //returns the asset id
|
||||
//material.setDiffuseMap(%texture, %layer); //tries to set the asset and failing that attempts a flat file reference
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, DiffuseMap)
|
||||
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR(Material, DiffuseMap, Material::Constants::MAX_STAGES)
|
||||
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR(Material, NormalMap, Material::Constants::MAX_STAGES)
|
||||
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR(Material, DetailNormalMap, Material::Constants::MAX_STAGES)
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, OverlayMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, LightMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, ToneMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, NormalMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, ORMConfigMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, RoughMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, AOMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, MetalMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, GlowMap);
|
||||
DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailNormalMap);
|
||||
|
||||
|
|
|
|||
|
|
@ -208,10 +208,9 @@ public:
|
|||
//-----------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------
|
||||
void onImageAssetChanged();
|
||||
|
||||
DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, MAX_STAGES, onImageAssetChanged);
|
||||
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DiffuseMap);
|
||||
DECLARE_IMAGEASSET_ARRAY_REFACTOR(Material, DiffuseMap, GFXStaticTextureSRGBProfile, MAX_STAGES)
|
||||
DECLARE_IMAGEASSET_ARRAY_REFACTOR(Material, NormalMap, GFXNormalMapProfile, MAX_STAGES)
|
||||
DECLARE_IMAGEASSET_ARRAY_REFACTOR(Material, DetailNormalMap, GFXNormalMapProfile, MAX_STAGES)
|
||||
|
||||
bool mDiffuseMapSRGB[MAX_STAGES]; // SRGB diffuse
|
||||
DECLARE_IMAGEASSET_ARRAY(Material, OverlayMap, MAX_STAGES, onImageAssetChanged);
|
||||
|
|
@ -226,8 +225,6 @@ public:
|
|||
DECLARE_IMAGEASSET_ARRAY(Material, DetailMap, MAX_STAGES, onImageAssetChanged);
|
||||
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DetailMap);
|
||||
|
||||
DECLARE_IMAGEASSET_ARRAY(Material, NormalMap, MAX_STAGES, onImageAssetChanged);
|
||||
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, NormalMap);
|
||||
|
||||
DECLARE_IMAGEASSET_ARRAY(Material, ORMConfigMap, MAX_STAGES, onImageAssetChanged);
|
||||
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, ORMConfigMap);
|
||||
|
|
@ -250,10 +247,6 @@ public:
|
|||
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, GlowMap);
|
||||
|
||||
F32 mGlowMul[MAX_STAGES];
|
||||
/// A second normal map which repeats at the detail map
|
||||
/// scale and blended with the base normal map.
|
||||
DECLARE_IMAGEASSET_ARRAY(Material, DetailNormalMap, MAX_STAGES, onImageAssetChanged);
|
||||
DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DetailNormalMap);
|
||||
|
||||
/// The strength scalar for the detail normal map.
|
||||
F32 mDetailNormalMapStrength[MAX_STAGES];
|
||||
|
|
|
|||
|
|
@ -392,9 +392,9 @@ void ProcessedMaterial::_setStageData()
|
|||
for (i = 0; i < Material::MAX_STAGES; i++)
|
||||
{
|
||||
// DiffuseMap
|
||||
if (mMaterial->mDiffuseMapAsset[i] && !mMaterial->mDiffuseMapAsset[i].isNull())
|
||||
if (mMaterial->getDiffuseMapAsset(i).notNull())
|
||||
{
|
||||
mStages[i].setTex(MFT_DiffuseMap, mMaterial->getDiffuseMapResource(i));
|
||||
mStages[i].setTex(MFT_DiffuseMap, mMaterial->getDiffuseMap(i));
|
||||
if (!mStages[i].getTex(MFT_DiffuseMap))
|
||||
{
|
||||
// If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass.
|
||||
|
|
@ -404,20 +404,6 @@ void ProcessedMaterial::_setStageData()
|
|||
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
|
||||
}
|
||||
}
|
||||
else if (mMaterial->mDiffuseMapName[i] != StringTable->EmptyString())
|
||||
{
|
||||
mStages[i].setTex(MFT_DiffuseMap, _createTexture(mMaterial->mDiffuseMapName[i], &GFXStaticTextureSRGBProfile));
|
||||
if (!mStages[i].getTex(MFT_DiffuseMap))
|
||||
{
|
||||
//If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass.
|
||||
if (!String(mMaterial->mDiffuseMapName[i]).startsWith("#") && !String(mMaterial->mDiffuseMapName[i]).startsWith("$"))
|
||||
mMaterial->logError("Failed to load diffuse map %s for stage %i", mMaterial->mDiffuseMapName[i], i);
|
||||
|
||||
// Load a debug texture to make it clear to the user
|
||||
// that the texture for this stage was missing.
|
||||
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
|
||||
}
|
||||
}
|
||||
// OverlayMap
|
||||
if (mMaterial->getOverlayMap(i) != StringTable->EmptyString())
|
||||
{
|
||||
|
|
@ -451,10 +437,9 @@ void ProcessedMaterial::_setStageData()
|
|||
}
|
||||
|
||||
// NormalMap
|
||||
if (mMaterial->mNormalMapAsset[i] && !mMaterial->mNormalMapAsset[i].isNull())
|
||||
if (mMaterial->getNormalMapAsset(i).notNull())
|
||||
{
|
||||
mStages[i].setTex(MFT_NormalMap, mMaterial->getNormalMapResource(i));
|
||||
//mStages[i].setTex(MFT_DiffuseMap, _createTexture(mMaterial->getDiffuseMap(i), &GFXStaticTextureSRGBProfile));
|
||||
mStages[i].setTex(MFT_NormalMap, mMaterial->getNormalMap(i));
|
||||
if (!mStages[i].getTex(MFT_NormalMap))
|
||||
{
|
||||
// Load a debug texture to make it clear to the user
|
||||
|
|
@ -462,24 +447,13 @@ void ProcessedMaterial::_setStageData()
|
|||
mStages[i].setTex(MFT_NormalMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXNormalMapProfile));
|
||||
}
|
||||
}
|
||||
else if (mMaterial->mNormalMapName[i] != StringTable->EmptyString())
|
||||
{
|
||||
mStages[i].setTex(MFT_NormalMap, _createTexture(mMaterial->mNormalMapName[i], &GFXNormalMapProfile));
|
||||
if (!mStages[i].getTex(MFT_NormalMap))
|
||||
{
|
||||
//If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass. So we'll
|
||||
//pass on the error rather than spamming the console
|
||||
if (!String(mMaterial->mNormalMapName[i]).startsWith("#"))
|
||||
mMaterial->logError("Failed to load normal map %s for stage %i", mMaterial->mNormalMapName[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
// Detail Normal Map
|
||||
if (mMaterial->getDetailNormalMap(i) != StringTable->EmptyString())
|
||||
if (mMaterial->getDetailNormalMapAsset(i).notNull())
|
||||
{
|
||||
mStages[i].setTex(MFT_DetailNormalMap, mMaterial->getDetailNormalMapResource(i));
|
||||
mStages[i].setTex(MFT_DetailNormalMap, mMaterial->getDetailNormalMap(i));
|
||||
if (!mStages[i].getTex(MFT_DetailNormalMap))
|
||||
mMaterial->logError("Failed to load normal map %s for stage %i", mMaterial->getDetailNormalMap(i), i);
|
||||
mMaterial->logError("Failed to load normal map %s for stage %i", mMaterial->getDetailNormalMapAsset(i), i);
|
||||
}
|
||||
|
||||
//depending on creation method this may or may not have been shoved into srgb space eroneously
|
||||
|
|
|
|||
|
|
@ -229,9 +229,9 @@ bool ProcessedShaderMaterial::init( const FeatureSet &features,
|
|||
mInstancingState = new InstancingState();
|
||||
mInstancingState->setFormat( _getRPD( 0 )->shader->getInstancingFormat(), mVertexFormat );
|
||||
}
|
||||
if (mMaterial && mMaterial->mDiffuseMapName[0] != StringTable->EmptyString() && String(mMaterial->mDiffuseMapName[0]).startsWith("#"))
|
||||
if (mMaterial && mMaterial->getDiffuseMapAsset(0).notNull() && String(mMaterial->getDiffuseMapAsset(0)->getImageFile()).startsWith("#"))
|
||||
{
|
||||
String texTargetBufferName = String(mMaterial->mDiffuseMapName[0]).substr(1, (U32)strlen(mMaterial->mDiffuseMapName[0]) - 1);
|
||||
String texTargetBufferName = String(mMaterial->getDiffuseMapAsset(0)->getImageFile()).substr(1, (U32)strlen(mMaterial->getDiffuseMapAsset(0)->getImageFile()) - 1);
|
||||
NamedTexTarget *texTarget = NamedTexTarget::find(texTargetBufferName);
|
||||
RenderPassData* rpd = getPass(0);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue