From 85463c85acf32a988da14ac695a80859b9dd38de Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Fri, 13 Dec 2024 00:26:39 +0000 Subject: [PATCH 1/6] named targets for image assets image assets can now be bound to a named texture target if used in a material the target needs to exist before the material is initialized --- Engine/source/T3D/assets/ImageAsset.cpp | 39 +++++++++++++-- Engine/source/T3D/assets/ImageAsset.h | 47 +++++++++++++++---- Engine/source/materials/processedMaterial.cpp | 19 ++++++-- 3 files changed, 88 insertions(+), 17 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index b51327c4e6..771ce2ff65 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -111,7 +111,7 @@ ConsoleSetType(TypeImageAssetId) ImplementEnumType(ImageAssetType, "Type of mesh data available in a shape.\n" "@ingroup gameObjects") -{ ImageAsset::Albedo, "Albedo", "" }, +{ ImageAsset::Albedo, "Albedo", "" }, { ImageAsset::Normal, "Normal", "" }, { ImageAsset::ORMConfig, "ORMConfig", "" }, { ImageAsset::GUI, "GUI", "" }, @@ -121,7 +121,8 @@ ImplementEnumType(ImageAssetType, { ImageAsset::Glow, "Glow", "" }, { ImageAsset::Particle, "Particle", "" }, { ImageAsset::Decal, "Decal", "" }, -{ ImageAsset::Cubemap, "Cubemap", "" }, +{ ImageAsset::Cubemap, "Cubemap", "" }, +{ ImageAsset::Target, "Target", "" }, EndImplementEnumType; @@ -274,6 +275,21 @@ U32 ImageAsset::load() if (mLoadedState == AssetErrCode::Ok) return mLoadedState; if (mImagePath) { + // this is a target. + if (mImageFileName[0] == '$' || mImageFileName[0] == '#') + { + NamedTexTarget* namedTarget = NamedTexTarget::find(mImageFileName + 1); + if (namedTarget) { + mLoadedState = Ok; + mIsValidImage = true; + return mLoadedState; + } + else + { + Con::errorf("ImageAsset::initializeAsset: Attempted find named target %s failed.", mImageFileName); + } + } + if (!Torque::FS::IsFile(mImagePath)) { Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFileName); @@ -295,12 +311,26 @@ void ImageAsset::initializeAsset() { ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged); - mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath; + if (mImageFileName[0] != '$' && mImageFileName[0] != '#') + { + mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath; + } + else + { + mImagePath = mImageFileName; + } } void ImageAsset::onAssetRefresh() { - mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath; + if (mImageFileName[0] != '$' && mImageFileName[0] != '#') + { + mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath; + } + else + { + mImagePath = mImageFileName; + } AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId); // Iterate all dependencies. @@ -398,6 +428,7 @@ const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type) "Particle", "Decal", "Cubemap" + "Target" }; if (type < 0 || type >= ImageTypeCount) diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 03bbaa556f..5b9009e715 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -39,7 +39,11 @@ #endif #ifndef _ASSET_PTR_H_ #include "assets/assetPtr.h" -#endif +#endif + +#ifndef _MATTEXTURETARGET_H_ +#include "materials/matTextureTarget.h" +#endif #include "gfx/bitmap/gBitmap.h" #include "gfx/gfxTextureHandle.h" @@ -71,7 +75,8 @@ class ImageAsset : public AssetBase Particle = 8, Decal = 9, Cubemap = 10, - ImageTypeCount = 11 + Target = 11, + ImageTypeCount = 12 }; static StringTableEntry smNoImageAssetFallback; @@ -205,8 +210,8 @@ public: \ }\ else if(_in[0] == '$' || _in[0] == '#')\ {\ - m##name##Name = _in;\ - m##name##AssetId = StringTable->EmptyString();\ + m##name##Name = _in;\ + m##name##AssetId = _in;\ m##name##Asset = NULL;\ m##name.free();\ m##name = NULL;\ @@ -250,6 +255,16 @@ public: \ m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\ }\ \ + if (get##name()[0] == '$' || get##name()[0] == '#') {\ + NamedTexTarget* namedTarget = NamedTexTarget::find(get##name() + 1);\ + if (namedTarget)\ + {\ + m##name = namedTarget->getTexture(0);\ + m##name##Name = get##name();\ + m##name##AssetId = StringTable->EmptyString();\ + }\ + }\ + else\ m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\ }\ else\ @@ -278,7 +293,10 @@ public: \ const StringTableEntry get##name() const\ {\ if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\ - return Platform::makeRelativePathName(m##name##Asset->getImagePath(), Platform::getMainDotCsDir());\ + if (m##name##Asset->getImageFileName()[0] == '#' || m##name##Asset->getImageFileName()[0] == '$')\ + return m##name##Asset->getImageFileName();\ + else\ + return Platform::makeRelativePathName(m##name##Asset->getImagePath(), Platform::getMainDotCsDir());\ else if (m##name##AssetId != StringTable->EmptyString())\ return m##name##AssetId;\ else if (m##name##Name != StringTable->EmptyString())\ @@ -353,8 +371,8 @@ public: \ }\ else if(_in[0] == '$' || _in[0] == '#')\ {\ - m##name##Name[index] = _in;\ - m##name##AssetId[index] = StringTable->EmptyString();\ + m##name##Name[index] = _in;\ + m##name##AssetId[index] = _in;\ m##name##Asset[index] = NULL;\ m##name[index].free();\ m##name[index] = NULL;\ @@ -393,6 +411,16 @@ public: \ }\ if (get##name(index) != StringTable->EmptyString() && m##name##Name[index] != StringTable->insert("texhandle"))\ {\ + if (get##name(index)[0] == '$' || get##name(index)[0] == '#') {\ + NamedTexTarget* namedTarget = NamedTexTarget::find(get##name(index) + 1);\ + if (namedTarget)\ + {\ + m##name[index] = namedTarget->getTexture(0);\ + m##name##Name[index] = get##name(index);\ + m##name##AssetId[index] = StringTable->EmptyString();\ + }\ + }\ + else\ m##name[index].set(get##name(index), m##name##Profile[index], avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\ }\ else\ @@ -421,7 +449,10 @@ public: \ const StringTableEntry get##name(const U32& index) const\ {\ if (m##name##Asset[index] && (m##name##Asset[index]->getImageFileName() != StringTable->EmptyString()))\ - return Platform::makeRelativePathName(m##name##Asset[index]->getImagePath(), Platform::getMainDotCsDir());\ + if (m##name##Asset[index]->getImageFileName()[0] == '#' || m##name##Asset[index]->getImageFileName()[0] == '$')\ + return m##name##Asset[index]->getImageFileName();\ + else\ + return Platform::makeRelativePathName(m##name##Asset[index]->getImagePath(), Platform::getMainDotCsDir());\ else if (m##name##AssetId[index] != StringTable->EmptyString())\ return m##name##AssetId[index];\ else if (m##name##Name[index] != StringTable->EmptyString())\ diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index 682011fec1..c030441edf 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -410,12 +410,21 @@ void ProcessedMaterial::_setStageData() { //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->mDiffuseMapName[i]).startsWith("#")) - mMaterial->logError("Failed to load diffuse map %s for stage %i", mMaterial->mDiffuseMapName[i], i); + if (String(mMaterial->mDiffuseMapName[i]).startsWith("#") || String(mMaterial->mDiffuseMapName[i]).startsWith("$")) + { + NamedTexTarget* namedTarget = NamedTexTarget::find(mMaterial->mDiffuseMapName[i] + 1); + if(namedTarget) + mStages[i].setTex(MFT_DiffuseMap, namedTarget->getTexture(0)); + } + else + { + if (!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)); + // 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)); + } } } From f6dc694bd4dd4a69f03a56caf6fc38f012c4334b Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sat, 14 Dec 2024 01:18:46 +0000 Subject: [PATCH 2/6] fully working --- Engine/source/T3D/assets/ImageAsset.cpp | 48 +++++++++++++------ Engine/source/T3D/assets/ImageAsset.h | 35 +++++++------- Engine/source/T3D/fx/splash.h | 3 +- Engine/source/environment/basicClouds.h | 4 +- Engine/source/gfx/sim/cubemapData.h | 3 +- Engine/source/gui/controls/guiPopUpCtrl.h | 4 +- Engine/source/gui/controls/guiPopUpCtrlEx.h | 4 +- Engine/source/materials/materialDefinition.h | 28 ++++++----- Engine/source/materials/processedMaterial.cpp | 31 +++++------- Engine/source/postFx/postEffect.h | 3 +- 10 files changed, 88 insertions(+), 75 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index 771ce2ff65..8808d40e6e 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -111,7 +111,7 @@ ConsoleSetType(TypeImageAssetId) ImplementEnumType(ImageAssetType, "Type of mesh data available in a shape.\n" "@ingroup gameObjects") -{ ImageAsset::Albedo, "Albedo", "" }, +{ ImageAsset::Albedo, "Albedo", "" }, { ImageAsset::Normal, "Normal", "" }, { ImageAsset::ORMConfig, "ORMConfig", "" }, { ImageAsset::GUI, "GUI", "" }, @@ -121,8 +121,7 @@ ImplementEnumType(ImageAssetType, { ImageAsset::Glow, "Glow", "" }, { ImageAsset::Particle, "Particle", "" }, { ImageAsset::Decal, "Decal", "" }, -{ ImageAsset::Cubemap, "Cubemap", "" }, -{ ImageAsset::Target, "Target", "" }, +{ ImageAsset::Cubemap, "Cubemap", "" }, EndImplementEnumType; @@ -278,7 +277,7 @@ U32 ImageAsset::load() // this is a target. if (mImageFileName[0] == '$' || mImageFileName[0] == '#') { - NamedTexTarget* namedTarget = NamedTexTarget::find(mImageFileName + 1); + NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1); if (namedTarget) { mLoadedState = Ok; mIsValidImage = true; @@ -289,7 +288,6 @@ U32 ImageAsset::load() Con::errorf("ImageAsset::initializeAsset: Attempted find named target %s failed.", mImageFileName); } } - if (!Torque::FS::IsFile(mImagePath)) { Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFileName); @@ -364,6 +362,7 @@ void ImageAsset::setImageFileName(const char* pScriptFile) GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile) { + load(); if (mResourceMap.contains(requestedProfile)) { mLoadedState = Ok; @@ -371,21 +370,41 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile) } else { - //If we don't have an existing map case to the requested format, we'll just create it and insert it in - GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, requestedProfile); - if (newTex) + // this is a target. + if (mImageFileName[0] == '$' || mImageFileName[0] == '#') { - mResourceMap.insert(requestedProfile, newTex); mLoadedState = Ok; - return newTex; + NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1); + if (namedTarget.isValid() && namedTarget->getTexture()) + { + if (mNamedTarget == NULL) { + mNamedTarget = namedTarget; + mResourceMap.insert(requestedProfile, mNamedTarget->getTexture()); + mIsValidImage = true; + mChangeSignal.trigger(); + } + } + if (mNamedTarget == NULL) + return nullptr; + else + return mNamedTarget->getTexture(); + } else - mLoadedState = BadFileReference; + { + //If we don't have an existing map case to the requested format, we'll just create it and insert it in + GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, requestedProfile); + if (newTex) + { + mResourceMap.insert(requestedProfile, newTex); + mLoadedState = Ok; + return newTex; + } + else + mLoadedState = BadFileReference; + } } - //if (mTexture.isValid()) - // return mTexture; - return nullptr; } @@ -428,7 +447,6 @@ const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type) "Particle", "Decal", "Cubemap" - "Target" }; if (type < 0 || type >= ImageTypeCount) diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 5b9009e715..8500329091 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -39,11 +39,7 @@ #endif #ifndef _ASSET_PTR_H_ #include "assets/assetPtr.h" -#endif - -#ifndef _MATTEXTURETARGET_H_ -#include "materials/matTextureTarget.h" -#endif +#endif #include "gfx/bitmap/gBitmap.h" #include "gfx/gfxTextureHandle.h" @@ -54,6 +50,11 @@ #include "assetMacroHelpers.h" #include "gfx/gfxDevice.h" + +#ifndef _MATTEXTURETARGET_H_ +#include "materials/matTextureTarget.h" +#endif + //----------------------------------------------------------------------------- class ImageAsset : public AssetBase { @@ -75,8 +76,7 @@ class ImageAsset : public AssetBase Particle = 8, Decal = 9, Cubemap = 10, - Target = 11, - ImageTypeCount = 12 + ImageTypeCount = 11 }; static StringTableEntry smNoImageAssetFallback; @@ -100,6 +100,7 @@ class ImageAsset : public AssetBase protected: StringTableEntry mImageFileName; StringTableEntry mImagePath; + NamedTexTargetRef mNamedTarget; bool mIsValidImage; bool mUseMips; @@ -256,12 +257,10 @@ public: \ }\ \ if (get##name()[0] == '$' || get##name()[0] == '#') {\ - NamedTexTarget* namedTarget = NamedTexTarget::find(get##name() + 1);\ - if (namedTarget)\ + NamedTexTargetRef namedTarget = NamedTexTarget::find(get##name() + 1);\ + if (namedTarget.isValid())\ {\ m##name = namedTarget->getTexture(0);\ - m##name##Name = get##name();\ - m##name##AssetId = StringTable->EmptyString();\ }\ }\ else\ @@ -306,6 +305,8 @@ public: \ }\ GFXTexHandle get##name##Resource() \ {\ + if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\ + return m##name##Asset->getTexture(m##name##Profile);\ return m##name;\ }\ bool name##Valid() {return (get##name() != StringTable->EmptyString() && m##name##Asset->getStatus() == AssetBase::Ok); } @@ -341,7 +342,7 @@ if (m##name##AssetId != StringTable->EmptyString())\ #pragma region Arrayed Asset Macros //Arrayed Assets -#define DECLARE_IMAGEASSET_ARRAY(className, name, max) public: \ +#define DECLARE_IMAGEASSET_ARRAY(className, name, max, changeFunc) public: \ static const U32 sm##name##Count = max;\ GFXTexHandle m##name[max];\ StringTableEntry m##name##Name[max]; \ @@ -412,13 +413,7 @@ public: \ if (get##name(index) != StringTable->EmptyString() && m##name##Name[index] != StringTable->insert("texhandle"))\ {\ if (get##name(index)[0] == '$' || get##name(index)[0] == '#') {\ - NamedTexTarget* namedTarget = NamedTexTarget::find(get##name(index) + 1);\ - if (namedTarget)\ - {\ - m##name[index] = namedTarget->getTexture(0);\ - m##name##Name[index] = get##name(index);\ - m##name##AssetId[index] = StringTable->EmptyString();\ - }\ + m##name##Asset[index]->getChangedSignal().notify(this, &className::changeFunc);\ }\ else\ m##name[index].set(get##name(index), m##name##Profile[index], avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\ @@ -469,6 +464,8 @@ public: \ {\ if(index >= sm##name##Count || index < 0)\ return nullptr;\ + if (m##name##Asset[index] && (m##name##Asset[index]->getImageFileName() != StringTable->EmptyString()))\ + return m##name##Asset[index]->getTexture(m##name##Profile[index]);\ return m##name[index];\ }\ bool name##Valid(const U32& id) {return (get##name(id) != StringTable->EmptyString() && m##name##Asset[id]->getStatus() == AssetBase::Ok); } diff --git a/Engine/source/T3D/fx/splash.h b/Engine/source/T3D/fx/splash.h index 754103cc5c..de98a5bca4 100644 --- a/Engine/source/T3D/fx/splash.h +++ b/Engine/source/T3D/fx/splash.h @@ -122,8 +122,9 @@ class SplashData : public GameBaseData F32 times[ NUM_TIME_KEYS ]; LinearColorF colors[ NUM_TIME_KEYS ]; - DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, NUM_TEX); + DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, NUM_TEX, onTextureChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(SplashData, Texture) + void onTextureChanged() {} ExplosionData* explosion; S32 explosionId; diff --git a/Engine/source/environment/basicClouds.h b/Engine/source/environment/basicClouds.h index 982b9cf9cc..bd67d1362a 100644 --- a/Engine/source/environment/basicClouds.h +++ b/Engine/source/environment/basicClouds.h @@ -94,9 +94,9 @@ class BasicClouds : public SceneObject static U32 smVertCount; static U32 smTriangleCount; - DECLARE_IMAGEASSET_ARRAY(BasicClouds, Texture, TEX_COUNT); + DECLARE_IMAGEASSET_ARRAY(BasicClouds, Texture, TEX_COUNT, onTextureChanged); DECLARE_IMAGEASSET_ARRAY_NET_SETGET(BasicClouds, Texture, -1); - + void onTextureChanged() {} GFXStateBlockRef mStateblock; GFXShaderRef mShader; diff --git a/Engine/source/gfx/sim/cubemapData.h b/Engine/source/gfx/sim/cubemapData.h index dd35918e20..c79dd42890 100644 --- a/Engine/source/gfx/sim/cubemapData.h +++ b/Engine/source/gfx/sim/cubemapData.h @@ -76,9 +76,10 @@ class CubemapData : public SimObject DECLARE_IMAGEASSET(CubemapData, CubeMap, onCubemapChanged, GFXStaticTextureSRGBProfile); DECLARE_ASSET_SETGET(CubemapData, CubeMap); - DECLARE_IMAGEASSET_ARRAY(CubemapData, CubeMapFace, 6); + DECLARE_IMAGEASSET_ARRAY(CubemapData, CubeMapFace, 6, onCubeMapFaceChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(CubemapData, CubeMapFace); + void onCubeMapFaceChanged() {} GFXTexHandle mDepthBuff; GFXTextureTargetRef mRenderTarget; diff --git a/Engine/source/gui/controls/guiPopUpCtrl.h b/Engine/source/gui/controls/guiPopUpCtrl.h index 40b129274b..12568d2c66 100644 --- a/Engine/source/gui/controls/guiPopUpCtrl.h +++ b/Engine/source/gui/controls/guiPopUpCtrl.h @@ -126,9 +126,9 @@ class GuiPopUpMenuCtrl : public GuiTextCtrl NumBitmapModes = 2 }; - DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrl, Bitmap, NumBitmapModes); + DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrl, Bitmap, NumBitmapModes, onBitmapChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(GuiPopUpMenuCtrl, Bitmap); - + void onBitmapChanged() {} Point2I mBitmapBounds; // Added S32 mIdMax; diff --git a/Engine/source/gui/controls/guiPopUpCtrlEx.h b/Engine/source/gui/controls/guiPopUpCtrlEx.h index 5a361565b5..f389de3e7d 100644 --- a/Engine/source/gui/controls/guiPopUpCtrlEx.h +++ b/Engine/source/gui/controls/guiPopUpCtrlEx.h @@ -131,9 +131,9 @@ class GuiPopUpMenuCtrlEx : public GuiTextCtrl NumBitmapModes = 2 }; - DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrlEx, Bitmap, NumBitmapModes); + DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrlEx, Bitmap, NumBitmapModes, onBitmapChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(GuiPopUpMenuCtrlEx, Bitmap); - + void onBitmapChanged() {} Point2I mBitmapBounds; // Added S32 mIdMax; diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index f3ef304e81..7d4b781082 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -208,49 +208,53 @@ class Material : public BaseMaterialDefinition //----------------------------------------------------------------------- // Data //----------------------------------------------------------------------- - DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, MAX_STAGES); + void onImageAssetChanged() { + reload(); + } + + DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DiffuseMap); bool mDiffuseMapSRGB[MAX_STAGES]; // SRGB diffuse - DECLARE_IMAGEASSET_ARRAY(Material, OverlayMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, OverlayMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, OverlayMap); - DECLARE_IMAGEASSET_ARRAY(Material, LightMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, LightMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, LightMap); - DECLARE_IMAGEASSET_ARRAY(Material, ToneMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, ToneMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, ToneMap); - DECLARE_IMAGEASSET_ARRAY(Material, DetailMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, DetailMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DetailMap); - DECLARE_IMAGEASSET_ARRAY(Material, NormalMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, NormalMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, NormalMap); - DECLARE_IMAGEASSET_ARRAY(Material, ORMConfigMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, ORMConfigMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, ORMConfigMap); bool mIsSRGb[MAX_STAGES]; - DECLARE_IMAGEASSET_ARRAY(Material, AOMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, AOMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, AOMap); F32 mAOChan[MAX_STAGES]; - DECLARE_IMAGEASSET_ARRAY(Material, RoughMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, RoughMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, RoughMap); bool mInvertRoughness[MAX_STAGES]; F32 mRoughnessChan[MAX_STAGES]; - DECLARE_IMAGEASSET_ARRAY(Material, MetalMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, MetalMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, MetalMap); F32 mMetalChan[MAX_STAGES]; - DECLARE_IMAGEASSET_ARRAY(Material, GlowMap, MAX_STAGES); + DECLARE_IMAGEASSET_ARRAY(Material, GlowMap, MAX_STAGES, onImageAssetChanged); 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); + DECLARE_IMAGEASSET_ARRAY(Material, DetailNormalMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DetailNormalMap); /// The strength scalar for the detail normal map. diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index c030441edf..f477d80d67 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -398,29 +398,20 @@ void ProcessedMaterial::_setStageData() //mStages[i].setTex(MFT_DiffuseMap, _createTexture(mMaterial->getDiffuseMap(i), &GFXStaticTextureSRGBProfile)); if (!mStages[i].getTex(MFT_DiffuseMap)) { - // 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)); - } - } - 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. So we'll - //pass on the error rather than spamming the console - if (String(mMaterial->mDiffuseMapName[i]).startsWith("#") || String(mMaterial->mDiffuseMapName[i]).startsWith("$")) + if (String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("#") || String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("$")) { - NamedTexTarget* namedTarget = NamedTexTarget::find(mMaterial->mDiffuseMapName[i] + 1); - if(namedTarget) + NamedTexTarget* namedTarget = NamedTexTarget::find(mMaterial->mDiffuseMapAsset[i]->getImageFileName() + 1); + if (namedTarget) mStages[i].setTex(MFT_DiffuseMap, namedTarget->getTexture(0)); - } - else - { - if (!String(mMaterial->mDiffuseMapName[i]).startsWith("#")) - mMaterial->logError("Failed to load diffuse map %s for stage %i", mMaterial->mDiffuseMapName[i], i); + if (mStages[i].getTex(MFT_DiffuseMap)) + { + mMaterial->mDiffuseMap[i] = namedTarget->getTexture(0); + } + if (!mStages[i].getTex(MFT_DiffuseMap)) + mHasSetStageData = false; + } + else { // 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)); diff --git a/Engine/source/postFx/postEffect.h b/Engine/source/postFx/postEffect.h index 89c4b74277..702fed0a82 100644 --- a/Engine/source/postFx/postEffect.h +++ b/Engine/source/postFx/postEffect.h @@ -90,8 +90,9 @@ class PostEffect : public SimGroup protected: - DECLARE_IMAGEASSET_ARRAY(PostEffect, Texture, NumTextures); + DECLARE_IMAGEASSET_ARRAY(PostEffect, Texture, NumTextures, onTextureChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(PostEffect, Texture); + void onTextureChanged() {} bool mTexSRGB[NumTextures]; From 1edfbcf44776598018751563a5d05ea5b072ce70 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sat, 14 Dec 2024 13:37:23 +0000 Subject: [PATCH 3/6] fixes for reload and flush --- Engine/source/T3D/assets/ImageAsset.cpp | 10 ++--- Engine/source/T3D/assets/ImageAsset.h | 14 ++----- .../source/materials/materialDefinition.cpp | 5 +++ Engine/source/materials/materialDefinition.h | 4 +- Engine/source/materials/materialManager.cpp | 41 +++++++++++++++++-- Engine/source/materials/materialManager.h | 15 +++++-- Engine/source/materials/processedMaterial.cpp | 38 +++++++++++------ 7 files changed, 88 insertions(+), 39 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index 8808d40e6e..25520e138d 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -377,12 +377,10 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile) NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1); if (namedTarget.isValid() && namedTarget->getTexture()) { - if (mNamedTarget == NULL) { - mNamedTarget = namedTarget; - mResourceMap.insert(requestedProfile, mNamedTarget->getTexture()); - mIsValidImage = true; - mChangeSignal.trigger(); - } + mNamedTarget = namedTarget; + mIsValidImage = true; + mResourceMap.insert(requestedProfile, mNamedTarget->getTexture()); + mChangeSignal.trigger(); } if (mNamedTarget == NULL) return nullptr; diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 8500329091..169bf0cdf3 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -212,7 +212,7 @@ public: \ else if(_in[0] == '$' || _in[0] == '#')\ {\ m##name##Name = _in;\ - m##name##AssetId = _in;\ + m##name##AssetId = StringTable->EmptyString();\ m##name##Asset = NULL;\ m##name.free();\ m##name = NULL;\ @@ -256,15 +256,9 @@ public: \ m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\ }\ \ - if (get##name()[0] == '$' || get##name()[0] == '#') {\ - NamedTexTargetRef namedTarget = NamedTexTarget::find(get##name() + 1);\ - if (namedTarget.isValid())\ - {\ - m##name = namedTarget->getTexture(0);\ - }\ + if (get##name()[0] != '$' && get##name()[0] != '#') {\ + m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\ }\ - else\ - m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\ }\ else\ {\ @@ -373,7 +367,7 @@ public: \ else if(_in[0] == '$' || _in[0] == '#')\ {\ m##name##Name[index] = _in;\ - m##name##AssetId[index] = _in;\ + m##name##AssetId[index] = StringTable->EmptyString();\ m##name##Asset[index] = NULL;\ m##name[index].free();\ m##name[index] = NULL;\ diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index 8c5201b472..feb23c81cd 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -243,6 +243,10 @@ Material::Material() mReverbSoundOcclusion = 1.0; } +void Material::onImageAssetChanged() +{ + reload(); +} void Material::initPersistFields() { @@ -857,3 +861,4 @@ DEF_IMAGEASSET_ARRAY_BINDS(Material, AOMap); DEF_IMAGEASSET_ARRAY_BINDS(Material, MetalMap); DEF_IMAGEASSET_ARRAY_BINDS(Material, GlowMap); DEF_IMAGEASSET_ARRAY_BINDS(Material, DetailNormalMap); + diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index 7d4b781082..e17bdd317a 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -208,9 +208,7 @@ class Material : public BaseMaterialDefinition //----------------------------------------------------------------------- // Data //----------------------------------------------------------------------- - void onImageAssetChanged() { - reload(); - } + void onImageAssetChanged(); DECLARE_IMAGEASSET_ARRAY(Material, DiffuseMap, MAX_STAGES, onImageAssetChanged); DECLARE_IMAGEASSET_ARRAY_SETGET(Material, DiffuseMap); diff --git a/Engine/source/materials/materialManager.cpp b/Engine/source/materials/materialManager.cpp index d2979d8ebe..87ce2bef2d 100644 --- a/Engine/source/materials/materialManager.cpp +++ b/Engine/source/materials/materialManager.cpp @@ -61,6 +61,8 @@ MaterialManager::MaterialManager() mLastTime = 0; mDampness = 0.0f; mWarningInst = NULL; + mMatDefToFlush = NULL; + mMatDefToReload = NULL; GFXDevice::getDeviceEventSignal().notify( this, &MaterialManager::_handleGFXEvent ); @@ -73,6 +75,8 @@ MaterialManager::MaterialManager() mUsingDeferred = false; mFlushAndReInit = false; + mMatDefShouldFlush = false; + mMatDefShouldReload = false; mDefaultAnisotropy = 1; Con::addVariable( "$pref::Video::defaultAnisotropy", TypeS32, &mDefaultAnisotropy, @@ -324,6 +328,12 @@ String MaterialManager::getMapEntry(const String & textureName) const } void MaterialManager::flushAndReInitInstances() +{ + // delay flushes and reinits until the start of the next frame. + mFlushAndReInit = true; +} + +void MaterialManager::_flushAndReInitInstances() { // Clear the flag if its set. mFlushAndReInit = false; @@ -359,8 +369,15 @@ void MaterialManager::flushAndReInitInstances() } // Used in the materialEditor. This flushes the material preview object so it can be reloaded easily. -void MaterialManager::flushInstance( BaseMaterialDefinition *target ) +void MaterialManager::flushInstance(BaseMaterialDefinition* target) { + mMatDefToFlush = target; + mMatDefShouldFlush = true; +} + +void MaterialManager::_flushInstance( BaseMaterialDefinition *target ) +{ + mMatDefShouldFlush = false; Vector::iterator iter = mMatInstanceList.begin(); while ( iter != mMatInstanceList.end() ) { @@ -371,16 +388,26 @@ void MaterialManager::flushInstance( BaseMaterialDefinition *target ) } iter++; } + + mMatDefToFlush = NULL; +} + +void MaterialManager::reInitInstance(BaseMaterialDefinition* target) +{ + mMatDefToReload = target; + mMatDefShouldReload = true; } -void MaterialManager::reInitInstance( BaseMaterialDefinition *target ) +void MaterialManager::_reInitInstance( BaseMaterialDefinition *target ) { + mMatDefShouldReload = false; Vector::iterator iter = mMatInstanceList.begin(); for ( ; iter != mMatInstanceList.end(); iter++ ) { if ( (*iter)->getMaterial() == target ) (*iter)->reInit(); } + mMatDefToReload = NULL; } void MaterialManager::updateTime() @@ -499,7 +526,15 @@ bool MaterialManager::_handleGFXEvent( GFXDevice::GFXDeviceEventType event_ ) case GFXDevice::deStartOfFrame: if ( mFlushAndReInit ) - flushAndReInitInstances(); + _flushAndReInitInstances(); + if (mMatDefShouldFlush) + { + _flushInstance(mMatDefToFlush); + } + if (mMatDefShouldReload) + { + _reInitInstance(mMatDefToReload); + } break; default: diff --git a/Engine/source/materials/materialManager.h b/Engine/source/materials/materialManager.h index 6f1889c266..2d983da7a4 100644 --- a/Engine/source/materials/materialManager.h +++ b/Engine/source/materials/materialManager.h @@ -116,11 +116,7 @@ class MaterialManager : public ManagedSingleton /// Returns the signal used to notify systems that the /// procedural shaders have been flushed. FlushSignal& getFlushSignal() { return mFlushSignal; } - - /// Flushes all the procedural shaders and re-initializes all - /// the active materials instances immediately. void flushAndReInitInstances(); - // Flush the instance void flushInstance( BaseMaterialDefinition *target ); @@ -133,7 +129,14 @@ class MaterialManager : public ManagedSingleton friend class MatInstance; void _track(MatInstance*); void _untrack(MatInstance*); + /// Flushes all the procedural shaders and re-initializes all + /// the active materials instances immediately. + void _flushAndReInitInstances(); + // Flush the instance + void _flushInstance(BaseMaterialDefinition* target); + /// Re-initializes the material instances for a specific target material. + void _reInitInstance(BaseMaterialDefinition* target); /// @see LightManager::smActivateSignal void _onLMActivate( const char *lm, bool activate ); @@ -155,6 +158,8 @@ class MaterialManager : public ManagedSingleton /// If set we flush and reinitialize all materials at the /// start of the next rendered frame. bool mFlushAndReInit; + bool mMatDefShouldReload; + bool mMatDefShouldFlush; // material map typedef Map MaterialMap; @@ -169,6 +174,8 @@ class MaterialManager : public ManagedSingleton F32 mDampness; BaseMatInstance* mWarningInst; + BaseMaterialDefinition* mMatDefToFlush; + BaseMaterialDefinition* mMatDefToReload; /// The default max anisotropy used in texture filtering. S32 mDefaultAnisotropy; diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index f477d80d67..1fa542c842 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -395,30 +395,42 @@ void ProcessedMaterial::_setStageData() if (mMaterial->mDiffuseMapAsset[i] && !mMaterial->mDiffuseMapAsset[i].isNull()) { mStages[i].setTex(MFT_DiffuseMap, mMaterial->getDiffuseMapResource(i)); - //mStages[i].setTex(MFT_DiffuseMap, _createTexture(mMaterial->getDiffuseMap(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->mDiffuseMapAsset[i]->getImageFileName()).startsWith("#") || String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("$")) { - NamedTexTarget* namedTarget = NamedTexTarget::find(mMaterial->mDiffuseMapAsset[i]->getImageFileName() + 1); - if (namedTarget) - mStages[i].setTex(MFT_DiffuseMap, namedTarget->getTexture(0)); - if (mStages[i].getTex(MFT_DiffuseMap)) - { - mMaterial->mDiffuseMap[i] = namedTarget->getTexture(0); - } - - if (!mStages[i].getTex(MFT_DiffuseMap)) - mHasSetStageData = false; + mMaterial->logError("Named Target not ready %s for stage %i", mMaterial->mDiffuseMapAsset[i]->getImageFileName(), i); + mHasSetStageData = false; } - else { + else + { + // 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)); + } + } + } + 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. So we'll + //pass on the error rather than spamming the console + if (String(mMaterial->mDiffuseMapName[i]).startsWith("#") || String(mMaterial->mDiffuseMapName[i]).startsWith("$")) + { + mMaterial->logError("Named Target not ready %s for stage %i", mMaterial->mDiffuseMapName[i], i); + mHasSetStageData = false; + } + else + { // 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()) { From f5f50723ed73c77822492dca224a3bb09cdcb6b4 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sat, 14 Dec 2024 14:47:46 +0000 Subject: [PATCH 4/6] final cleanup --- Engine/source/T3D/assets/ImageAsset.h | 8 +++----- Engine/source/materials/materialDefinition.cpp | 1 + Engine/source/materials/processedMaterial.cpp | 18 ++++-------------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index 169bf0cdf3..027dfbac11 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -406,11 +406,9 @@ public: \ }\ if (get##name(index) != StringTable->EmptyString() && m##name##Name[index] != StringTable->insert("texhandle"))\ {\ - if (get##name(index)[0] == '$' || get##name(index)[0] == '#') {\ - m##name##Asset[index]->getChangedSignal().notify(this, &className::changeFunc);\ - }\ - else\ - m##name[index].set(get##name(index), m##name##Profile[index], avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\ + m##name##Asset[index]->getChangedSignal().notify(this, &className::changeFunc);\ + if (get##name(index)[0] != '$' && get##name(index)[0] != '#')\ + m##name[index].set(get##name(index), m##name##Profile[index], avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\ }\ else\ {\ diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index feb23c81cd..c9a09bd0d8 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -245,6 +245,7 @@ Material::Material() void Material::onImageAssetChanged() { + flush(); reload(); } diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index 1fa542c842..1b951751eb 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -401,14 +401,8 @@ void ProcessedMaterial::_setStageData() if (String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("#") || String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("$")) { mMaterial->logError("Named Target not ready %s for stage %i", mMaterial->mDiffuseMapAsset[i]->getImageFileName(), i); - mHasSetStageData = false; - } - else - { - // 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)); } + mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile)); } } else if (mMaterial->mDiffuseMapName[i] != StringTable->EmptyString()) @@ -421,14 +415,10 @@ void ProcessedMaterial::_setStageData() if (String(mMaterial->mDiffuseMapName[i]).startsWith("#") || String(mMaterial->mDiffuseMapName[i]).startsWith("$")) { mMaterial->logError("Named Target not ready %s for stage %i", mMaterial->mDiffuseMapName[i], i); - mHasSetStageData = false; - } - else - { - // 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)); } + // 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 From 7b73ce7a2fd633a7f09ac0b62631516802316958 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sat, 14 Dec 2024 16:26:02 +0000 Subject: [PATCH 5/6] Update ImageAsset.cpp --- Engine/source/T3D/assets/ImageAsset.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index 25520e138d..02f93c314c 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -381,12 +381,8 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile) mIsValidImage = true; mResourceMap.insert(requestedProfile, mNamedTarget->getTexture()); mChangeSignal.trigger(); - } - if (mNamedTarget == NULL) - return nullptr; - else return mNamedTarget->getTexture(); - + } } else { From 0458228e1c404190d5dfb43e93eecf34e21945a8 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sat, 14 Dec 2024 18:58:31 +0000 Subject: [PATCH 6/6] Update processedMaterial.cpp revert console spam --- Engine/source/materials/processedMaterial.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Engine/source/materials/processedMaterial.cpp b/Engine/source/materials/processedMaterial.cpp index 1b951751eb..a4841ac6dd 100644 --- a/Engine/source/materials/processedMaterial.cpp +++ b/Engine/source/materials/processedMaterial.cpp @@ -398,10 +398,9 @@ void ProcessedMaterial::_setStageData() 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->mDiffuseMapAsset[i]->getImageFileName()).startsWith("#") || String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("$")) - { - mMaterial->logError("Named Target not ready %s for stage %i", mMaterial->mDiffuseMapAsset[i]->getImageFileName(), i); - } + if (!String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("#") && !String(mMaterial->mDiffuseMapAsset[i]->getImageFileName()).startsWith("$")) + mMaterial->logError("Failed to load diffuse map %s for stage %i", mMaterial->mDiffuseMapAsset[i]->getImageFileName(), i); + mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile)); } } @@ -410,12 +409,10 @@ void ProcessedMaterial::_setStageData() 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. So we'll - //pass on the error rather than spamming the console - if (String(mMaterial->mDiffuseMapName[i]).startsWith("#") || String(mMaterial->mDiffuseMapName[i]).startsWith("$")) - { - mMaterial->logError("Named Target not ready %s for stage %i", mMaterial->mDiffuseMapName[i], i); - } + //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));