Fix MP3 extraction crash

This commit is contained in:
Jack Andersen 2019-11-16 20:48:07 -10:00
parent 8ad13ff4c9
commit 6e2bf5be83
8 changed files with 127 additions and 146 deletions

View File

@ -49,18 +49,12 @@ CMaterial::CMaterial(EGame Version, FVertexDescription VtxDesc)
CMaterial::~CMaterial() CMaterial::~CMaterial()
{ {
for (uint32 iPass = 0; iPass < mPasses.size(); iPass++)
delete mPasses[iPass];
delete mpNextDrawPassMaterial;
delete mpBloomMaterial;
ClearShader(); ClearShader();
} }
CMaterial* CMaterial::Clone() std::unique_ptr<CMaterial> CMaterial::Clone()
{ {
CMaterial *pOut = new CMaterial(); std::unique_ptr<CMaterial> pOut = std::make_unique<CMaterial>();
pOut->mName = mName; pOut->mName = mName;
pOut->mVersion = mVersion; pOut->mVersion = mVersion;
pOut->mOptions = mOptions; pOut->mOptions = mOptions;
@ -78,7 +72,7 @@ CMaterial* CMaterial::Clone()
pOut->mPasses.resize(mPasses.size()); pOut->mPasses.resize(mPasses.size());
for (uint32 iPass = 0; iPass < mPasses.size(); iPass++) for (uint32 iPass = 0; iPass < mPasses.size(); iPass++)
pOut->mPasses[iPass] = mPasses[iPass]->Clone(pOut); pOut->mPasses[iPass] = mPasses[iPass]->Clone(pOut.get());
if (mpNextDrawPassMaterial) if (mpNextDrawPassMaterial)
pOut->mpNextDrawPassMaterial = mpNextDrawPassMaterial->Clone(); pOut->mpNextDrawPassMaterial = mpNextDrawPassMaterial->Clone();
@ -283,19 +277,13 @@ void CMaterial::Update()
void CMaterial::SetNumPasses(uint32 NumPasses) void CMaterial::SetNumPasses(uint32 NumPasses)
{ {
if (NumPasses < mPasses.size())
{
for (uint32 iPass = NumPasses; iPass < mPasses.size(); iPass++)
delete mPasses[iPass];
}
uint32 OldCount = mPasses.size(); uint32 OldCount = mPasses.size();
mPasses.resize(NumPasses); mPasses.resize(NumPasses);
if (NumPasses > OldCount) if (NumPasses > OldCount)
{ {
for (uint32 iPass = OldCount; iPass < NumPasses; iPass++) for (uint32 iPass = OldCount; iPass < NumPasses; iPass++)
mPasses[iPass] = new CMaterialPass(this); mPasses[iPass] = std::make_unique<CMaterialPass>(this);
} }
mRecalcHash = true; mRecalcHash = true;

View File

@ -92,17 +92,17 @@ private:
uint32 mEchoesUnknownB; // Second unknown value introduced in Echoes. Included for cooking. uint32 mEchoesUnknownB; // Second unknown value introduced in Echoes. Included for cooking.
TResPtr<CTexture> mpIndirectTexture; // Optional texture used for the indirect stage for reflections TResPtr<CTexture> mpIndirectTexture; // Optional texture used for the indirect stage for reflections
std::vector<CMaterialPass*> mPasses; std::vector<std::unique_ptr<CMaterialPass>> mPasses;
// Transparent materials in MP3/DKCR may require multiple draw passes to achieve hybrid // Transparent materials in MP3/DKCR may require multiple draw passes to achieve hybrid
// blending modes. This serves as a linked list of materials to be drawn successively // blending modes. This serves as a linked list of materials to be drawn successively
// for each surface. // for each surface.
CMaterial* mpNextDrawPassMaterial; std::unique_ptr<CMaterial> mpNextDrawPassMaterial;
// Bloom in MP3 changes the CMaterialPass layout significantly. This is an alternate // Bloom in MP3 changes the CMaterialPass layout significantly. This is an alternate
// material head that may be conditionally used when the user wants to view bloom. // material head that may be conditionally used when the user wants to view bloom.
// (only set in the head non-bloom CMaterial). // (only set in the head non-bloom CMaterial).
CMaterial* mpBloomMaterial; std::unique_ptr<CMaterial> mpBloomMaterial;
// Reuse shaders between materials that have identical TEV setups // Reuse shaders between materials that have identical TEV setups
struct SMaterialShader struct SMaterialShader
@ -117,7 +117,7 @@ public:
CMaterial(EGame Version, FVertexDescription VtxDesc); CMaterial(EGame Version, FVertexDescription VtxDesc);
~CMaterial(); ~CMaterial();
CMaterial* Clone(); std::unique_ptr<CMaterial> Clone();
void GenerateShader(bool AllowRegen = true); void GenerateShader(bool AllowRegen = true);
void ClearShader(); void ClearShader();
bool SetCurrent(FRenderOptions Options); bool SetCurrent(FRenderOptions Options);
@ -139,9 +139,9 @@ public:
inline uint32 EchoesUnknownA() const { return mEchoesUnknownA; } inline uint32 EchoesUnknownA() const { return mEchoesUnknownA; }
inline uint32 EchoesUnknownB() const { return mEchoesUnknownB; } inline uint32 EchoesUnknownB() const { return mEchoesUnknownB; }
inline uint32 PassCount() const { return mPasses.size(); } inline uint32 PassCount() const { return mPasses.size(); }
inline CMaterialPass* Pass(uint32 PassIndex) const { return mPasses[PassIndex]; } inline CMaterialPass* Pass(uint32 PassIndex) const { return mPasses[PassIndex].get(); }
inline CMaterial* GetNextDrawPass() const { return mpNextDrawPassMaterial; } inline CMaterial* GetNextDrawPass() const { return mpNextDrawPassMaterial.get(); }
inline CMaterial* GetBloomVersion() const { return mpBloomMaterial; } inline CMaterial* GetBloomVersion() const { return mpBloomMaterial.get(); }
inline void SetName(const TString& rkName) { mName = rkName; } inline void SetName(const TString& rkName) { mName = rkName; }
inline void SetOptions(FMaterialOptions Options) { mOptions = Options; Update(); } inline void SetOptions(FMaterialOptions Options) { mOptions = Options; Update(); }

View File

@ -32,9 +32,9 @@ CMaterialPass::~CMaterialPass()
{ {
} }
CMaterialPass* CMaterialPass::Clone(CMaterial *pParent) std::unique_ptr<CMaterialPass> CMaterialPass::Clone(CMaterial* pParent)
{ {
CMaterialPass *pOut = new CMaterialPass(pParent); std::unique_ptr<CMaterialPass> pOut = std::make_unique<CMaterialPass>(pParent);
pOut->mPassType = mPassType; pOut->mPassType = mPassType;
pOut->mSettings = mSettings; pOut->mSettings = mSettings;

View File

@ -48,7 +48,7 @@ class CMaterialPass
public: public:
CMaterialPass(CMaterial *pParent); CMaterialPass(CMaterial *pParent);
~CMaterialPass(); ~CMaterialPass();
CMaterialPass* Clone(CMaterial *pParent); std::unique_ptr<CMaterialPass> Clone(CMaterial *pParent);
void HashParameters(CFNV1A& rHash); void HashParameters(CFNV1A& rHash);
void LoadTexture(uint32 PassIndex); void LoadTexture(uint32 PassIndex);
void SetAnimCurrent(FRenderOptions Options, uint32 PassIndex); void SetAnimCurrent(FRenderOptions Options, uint32 PassIndex);

View File

@ -11,16 +11,12 @@ class CMaterialSet
friend class CMaterialLoader; friend class CMaterialLoader;
friend class CMaterialCooker; friend class CMaterialCooker;
std::vector<CMaterial*> mMaterials; std::vector<std::unique_ptr<CMaterial>> mMaterials;
public: public:
CMaterialSet() {} CMaterialSet() {}
~CMaterialSet() ~CMaterialSet() {}
{
for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++)
delete mMaterials[iMat];
}
CMaterialSet* Clone() CMaterialSet* Clone()
{ {
@ -41,7 +37,7 @@ public:
CMaterial* MaterialByIndex(uint32 Index, bool TryBloom) CMaterial* MaterialByIndex(uint32 Index, bool TryBloom)
{ {
if (Index >= NumMaterials()) return nullptr; if (Index >= NumMaterials()) return nullptr;
CMaterial* Ret = mMaterials[Index]; CMaterial* Ret = mMaterials[Index].get();
if (TryBloom && Ret->GetBloomVersion()) if (TryBloom && Ret->GetBloomVersion())
return Ret->GetBloomVersion(); return Ret->GetBloomVersion();
return Ret; return Ret;
@ -50,7 +46,7 @@ public:
CMaterial* MaterialByName(const TString& rkName) CMaterial* MaterialByName(const TString& rkName)
{ {
for (auto it = mMaterials.begin(); it != mMaterials.end(); it++) for (auto it = mMaterials.begin(); it != mMaterials.end(); it++)
if ((*it)->Name() == rkName) return *it; if ((*it)->Name() == rkName) return it->get();
return nullptr; return nullptr;
} }
@ -67,7 +63,7 @@ public:
{ {
for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++) for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++)
{ {
CMaterial *pMat = mMaterials[iMat]; CMaterial *pMat = mMaterials[iMat].get();
if (pMat->IndTexture()) rOut.insert(pMat->IndTexture()->ID()); if (pMat->IndTexture()) rOut.insert(pMat->IndTexture()->ID());
for (uint32 iPass = 0; iPass < pMat->PassCount(); iPass++) for (uint32 iPass = 0; iPass < pMat->PassCount(); iPass++)

View File

@ -40,7 +40,7 @@ void CMaterialCooker::WriteMatSetPrime(IOutputStream& rOut)
for (uint32 iMat = 0; iMat < NumMats; iMat++) for (uint32 iMat = 0; iMat < NumMats; iMat++)
{ {
CMaterial *pMat = mpSet->mMaterials[iMat]; CMaterial *pMat = mpSet->mMaterials[iMat].get();
uint32 NumPasses = pMat->PassCount(); uint32 NumPasses = pMat->PassCount();
for (uint32 iPass = 0; iPass < NumPasses; iPass++) for (uint32 iPass = 0; iPass < NumPasses; iPass++)
@ -74,7 +74,7 @@ void CMaterialCooker::WriteMatSetPrime(IOutputStream& rOut)
for (uint32 iMat = 0; iMat < NumMats; iMat++) for (uint32 iMat = 0; iMat < NumMats; iMat++)
{ {
mpMat = mpSet->mMaterials[iMat]; mpMat = mpSet->mMaterials[iMat].get();
WriteMaterialPrime(rOut); WriteMaterialPrime(rOut);
MatEndOffsets[iMat] = rOut.Tell() - MatsStart; MatEndOffsets[iMat] = rOut.Tell() - MatsStart;
} }

View File

@ -69,9 +69,9 @@ void CMaterialLoader::ReadPrimeMatSet()
} }
} }
CMaterial* CMaterialLoader::ReadPrimeMaterial() std::unique_ptr<CMaterial> CMaterialLoader::ReadPrimeMaterial()
{ {
CMaterial *pMat = new CMaterial(mVersion, {}); auto pMat = std::make_unique<CMaterial>(mVersion, FVertexDescription{});
// Flags // Flags
pMat->mOptions = (mpFile->ReadLong() & (uint) EMaterialOption::AllMP1Settings); pMat->mOptions = (mpFile->ReadLong() & (uint) EMaterialOption::AllMP1Settings);
@ -133,7 +133,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
for (uint32 iTev = 0; iTev < TevCount; iTev++) for (uint32 iTev = 0; iTev < TevCount; iTev++)
{ {
CMaterialPass *pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat.get());
uint32 ColorIn = mpFile->ReadLong(); uint32 ColorIn = mpFile->ReadLong();
uint32 AlphaIn = mpFile->ReadLong(); uint32 AlphaIn = mpFile->ReadLong();
@ -150,7 +150,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
pPass->mAlphaInputs[iInput] = (ETevAlphaInput) ((AlphaIn >> (iInput * 5)) & 0x7); pPass->mAlphaInputs[iInput] = (ETevAlphaInput) ((AlphaIn >> (iInput * 5)) & 0x7);
} }
pMat->mPasses[iTev] = pPass; pMat->mPasses[iTev] = std::move(pPass);
} }
std::vector<uint8> TevCoordIndices(TevCount); std::vector<uint8> TevCoordIndices(TevCount);
@ -217,7 +217,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
// Move TexGen and anims into passes // Move TexGen and anims into passes
for (uint32 iPass = 0; iPass < pMat->mPasses.size(); iPass++) for (uint32 iPass = 0; iPass < pMat->mPasses.size(); iPass++)
{ {
CMaterialPass *pPass = pMat->mPasses[iPass]; CMaterialPass *pPass = pMat->mPasses[iPass].get();
uint8 TexCoordIdx = TevCoordIndices[iPass]; uint8 TexCoordIdx = TevCoordIndices[iPass];
if ((TexGens.size() == 0) || (TexCoordIdx == 0xFF)) if ((TexGens.size() == 0) || (TexCoordIdx == 0xFF))
@ -323,7 +323,7 @@ ECLR ClrFourCCToEnum(CFourCC fcc)
return ECLR::CLR; return ECLR::CLR;
}; };
CMaterial* CMaterialLoader::ReadCorruptionMaterial() std::unique_ptr<CMaterial> CMaterialLoader::ReadCorruptionMaterial()
{ {
// Flags // Flags
FMP3MaterialOptions MP3Options = mpFile->ReadLong(); FMP3MaterialOptions MP3Options = mpFile->ReadLong();
@ -432,10 +432,10 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
} }
// Create non-bloom and bloom versions // Create non-bloom and bloom versions
CMaterial* pMat = new CMaterial(mVersion, VtxDesc); auto pMat = std::make_unique<CMaterial>(mVersion, VtxDesc);
CreateCorruptionPasses(pMat, Intermediate, false); CreateCorruptionPasses(pMat.get(), Intermediate, false);
pMat->mpBloomMaterial = new CMaterial(mVersion, VtxDesc); pMat->mpBloomMaterial = std::make_unique<CMaterial>(mVersion, VtxDesc);
CreateCorruptionPasses(pMat->mpBloomMaterial, Intermediate, true); CreateCorruptionPasses(pMat->mpBloomMaterial.get(), Intermediate, true);
return pMat; return pMat;
} }
@ -587,10 +587,10 @@ bool CMaterialLoader::SetupStaticDiffuseLightingStage(STevTracker& Tracker, CMat
EMP3MaterialOption::ForceLightingStage) EMP3MaterialOption::ForceLightingStage)
return false; return false;
pMat->SetTevColor(Intermediate.GetCLR(ECLR::DIFB), kColor1Reg); pMat->SetTevColor(Intermediate.GetCLR(ECLR::DIFB), kColor1Reg);
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
if (hasDIFFTexture) if (hasDIFFTexture)
{ {
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::DIFF)); SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::DIFF));
pPass->SetColorInputs(kZeroRGB, kTextureRGB, kColor1RGB, kRasRGB); pPass->SetColorInputs(kZeroRGB, kTextureRGB, kColor1RGB, kRasRGB);
pPass->SetColorOutput(kColor0Reg); pPass->SetColorOutput(kColor0Reg);
if (FullAlpha) if (FullAlpha)
@ -642,15 +642,15 @@ bool CMaterialLoader::SetupStaticDiffuseLightingStage(STevTracker& Tracker, CMat
pPass->SetRasSel(kRasColor0A0); pPass->SetRasSel(kRasColor0A0);
Tracker.mStaticLightingAlphaSet = true; Tracker.mStaticLightingAlphaSet = true;
} }
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
return true; return true;
} }
void CMaterialLoader::SetupStaticDiffuseLightingNoBloomStage(STevTracker& Tracker, CMaterial* pMat, void CMaterialLoader::SetupStaticDiffuseLightingNoBloomStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate) const SMP3IntermediateMaterial& Intermediate)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::DIFF)); SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::DIFF));
pMat->SetTevColor(Intermediate.GetCLR(ECLR::DIFB), kColor1Reg); pMat->SetTevColor(Intermediate.GetCLR(ECLR::DIFB), kColor1Reg);
pPass->SetColorInputs(kZeroRGB, kTextureRGB, kColor1RGB, kRasRGB); pPass->SetColorInputs(kZeroRGB, kTextureRGB, kColor1RGB, kRasRGB);
@ -661,14 +661,14 @@ void CMaterialLoader::SetupStaticDiffuseLightingNoBloomStage(STevTracker& Tracke
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColor0A0); pPass->SetRasSel(kRasColor0A0);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
void CMaterialLoader::SetupStaticDiffuseLightingNoBLOLStage(STevTracker& Tracker, CMaterial* pMat, void CMaterialLoader::SetupStaticDiffuseLightingNoBLOLStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate) const SMP3IntermediateMaterial& Intermediate)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::DIFF)); SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::DIFF));
pMat->SetTevColor(Intermediate.GetCLR(ECLR::DIFB), kColor1Reg); pMat->SetTevColor(Intermediate.GetCLR(ECLR::DIFB), kColor1Reg);
pPass->SetColorInputs(kZeroRGB, kTextureRGB, kColor1RGB, kRasRGB); pPass->SetColorInputs(kZeroRGB, kTextureRGB, kColor1RGB, kRasRGB);
@ -693,15 +693,15 @@ void CMaterialLoader::SetupStaticDiffuseLightingNoBLOLStage(STevTracker& Tracker
Tracker.mStaticLightingAlphaSet = true; Tracker.mStaticLightingAlphaSet = true;
pPass->SetRasSel(kRasColor0A0); pPass->SetRasSel(kRasColor0A0);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
void CMaterialLoader::SetupColorTextureStage(STevTracker& Tracker, CMaterial* pMat, void CMaterialLoader::SetupColorTextureStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate, const SMP3IntermediateMaterial& Intermediate,
bool useStageAlpha, uint8 Alpha, bool StaticLighting) bool useStageAlpha, uint8 Alpha, bool StaticLighting)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::CLR)); SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::CLR));
bool useDynamicLightingAlpha = false; bool useDynamicLightingAlpha = false;
pPass->SetColorInputs(kZeroRGB, StaticLighting ? kColor0RGB : kRasRGB, kTextureRGB, kZeroRGB); pPass->SetColorInputs(kZeroRGB, StaticLighting ? kColor0RGB : kRasRGB, kTextureRGB, kZeroRGB);
@ -732,14 +732,14 @@ void CMaterialLoader::SetupColorTextureStage(STevTracker& Tracker, CMaterial* pM
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel((useDynamicLightingAlpha || !StaticLighting) ? kRasColor0A0 : kRasColorNull); pPass->SetRasSel((useDynamicLightingAlpha || !StaticLighting) ? kRasColor0A0 : kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
void CMaterialLoader::SetupColorTextureAlwaysStaticLightingStage(STevTracker& Tracker, CMaterial* pMat, void CMaterialLoader::SetupColorTextureAlwaysStaticLightingStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate) const SMP3IntermediateMaterial& Intermediate)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::CLR)); SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::CLR));
pPass->SetColorInputs(kZeroRGB, kColor0RGB, kTextureRGB, kZeroRGB); pPass->SetColorInputs(kZeroRGB, kColor0RGB, kTextureRGB, kZeroRGB);
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
@ -748,14 +748,14 @@ void CMaterialLoader::SetupColorTextureAlwaysStaticLightingStage(STevTracker& Tr
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
void CMaterialLoader::SetupColorKColorStage(STevTracker& Tracker, CMaterial* pMat, void CMaterialLoader::SetupColorKColorStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate, const SMP3IntermediateMaterial& Intermediate,
bool useStageAlpha, uint8 Alpha, bool StaticLighting) bool useStageAlpha, uint8 Alpha, bool StaticLighting)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->mPassType = "CLR "; pPass->mPassType = "CLR ";
bool useDynamicLightingAlpha = false; bool useDynamicLightingAlpha = false;
@ -782,15 +782,15 @@ void CMaterialLoader::SetupColorKColorStage(STevTracker& Tracker, CMaterial* pMa
pPass->SetRasSel((useDynamicLightingAlpha || !StaticLighting) ? kRasColor0A0 : kRasColorNull); pPass->SetRasSel((useDynamicLightingAlpha || !StaticLighting) ? kRasColor0A0 : kRasColorNull);
Tracker.mCurKColor += 1; Tracker.mCurKColor += 1;
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
bool CMaterialLoader::SetupTransparencyStage(STevTracker& Tracker, CMaterial* pMat, bool CMaterialLoader::SetupTransparencyStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate) const SMP3IntermediateMaterial& Intermediate)
{ {
if (const auto& IntermediateTran = Intermediate.GetPASS(EPASS::TRAN)) { if (const auto& IntermediateTran = Intermediate.GetPASS(EPASS::TRAN)) {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateTran); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateTran);
if (IntermediateTran->mSettings & EPassSettings::InvertOpacityMap) if (IntermediateTran->mSettings & EPassSettings::InvertOpacityMap)
{ {
@ -806,7 +806,7 @@ bool CMaterialLoader::SetupTransparencyStage(STevTracker& Tracker, CMaterial* pM
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pPass->SetTexSwapComp(3, IntermediateTran->GetSwapAlphaComp()); pPass->SetTexSwapComp(3, IntermediateTran->GetSwapAlphaComp());
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
return true; return true;
} }
return false; return false;
@ -818,7 +818,7 @@ void CMaterialLoader::SetupTransparencyKAlphaMultiplyStage(STevTracker& Tracker,
{ {
if (Intermediate.GetPASS(EPASS::CLR) || Intermediate.GetPASS(EPASS::TRAN)) if (Intermediate.GetPASS(EPASS::CLR) || Intermediate.GetPASS(EPASS::TRAN))
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
ETevAlphaInput argA; ETevAlphaInput argA;
if (Alpha < 255) if (Alpha < 255)
{ {
@ -829,8 +829,8 @@ void CMaterialLoader::SetupTransparencyKAlphaMultiplyStage(STevTracker& Tracker,
pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kKonstAlpha, kZeroAlpha); pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kKonstAlpha, kZeroAlpha);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
pPass = new CMaterialPass(pMat); pPass = std::make_unique<CMaterialPass>(pMat);
argA = kPrevAlpha; argA = kPrevAlpha;
} }
else else
@ -862,21 +862,21 @@ void CMaterialLoader::SetupTransparencyKAlphaMultiplyStage(STevTracker& Tracker,
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
if (IntermediateTran) if (IntermediateTran)
{ {
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateTran); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateTran);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pPass->SetTexSwapComp(3, IntermediateTran->GetSwapAlphaComp()); pPass->SetTexSwapComp(3, IntermediateTran->GetSwapAlphaComp());
} }
else else
{ {
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::CLR)); SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::CLR));
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
} }
Tracker.mCurKColor += 1; Tracker.mCurKColor += 1;
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
else else
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
pMat->SetKonst(CColor::Integral(255, 255, 255, Alpha), Tracker.mCurKColor); pMat->SetKonst(CColor::Integral(255, 255, 255, Alpha), Tracker.mCurKColor);
pPass->SetKAlphaSel(ETevKSel(kKonst0_A + Tracker.mCurKColor)); pPass->SetKAlphaSel(ETevKSel(kKonst0_A + Tracker.mCurKColor));
if (multiplyPrevAlpha) if (multiplyPrevAlpha)
@ -890,7 +890,7 @@ void CMaterialLoader::SetupTransparencyKAlphaMultiplyStage(STevTracker& Tracker,
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
Tracker.mCurKColor += 1; Tracker.mCurKColor += 1;
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
} }
@ -901,8 +901,8 @@ bool CMaterialLoader::SetupReflectionAlphaStage(STevTracker& Tracker, CMaterial*
{ {
if (const auto& IntermediateRfld = Intermediate.GetPASS(EPASS::RFLD)) if (const auto& IntermediateRfld = Intermediate.GetPASS(EPASS::RFLD))
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateRfld); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateRfld);
pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kPrevRGB); pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kPrevRGB);
pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kTextureAlpha, kZeroAlpha); pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kTextureAlpha, kZeroAlpha);
@ -911,7 +911,7 @@ bool CMaterialLoader::SetupReflectionAlphaStage(STevTracker& Tracker, CMaterial*
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pPass->SetTexSwapComp(3, 'r'); pPass->SetTexSwapComp(3, 'r');
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
return true; return true;
} }
} }
@ -926,7 +926,7 @@ bool CMaterialLoader::SetupReflectionStages(STevTracker& Tracker, CMaterial* pMa
return false; return false;
ETevColorInput argC = kOneRGB; ETevColorInput argC = kOneRGB;
if (Intermediate.GetPASS(EPASS::RFLV) || Intermediate.GetPASS(EPASS::LRLD) || Intermediate.GetPASS(EPASS::LURD)) { if (Intermediate.GetPASS(EPASS::RFLV) || Intermediate.GetPASS(EPASS::LRLD) || Intermediate.GetPASS(EPASS::LURD)) {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->SetColorOutput(kColor2Reg); pPass->SetColorOutput(kColor2Reg);
pPass->SetAlphaOutput(kColor2Reg); pPass->SetAlphaOutput(kColor2Reg);
if (const auto& IntermediateRflv = Intermediate.GetPASS(EPASS::RFLV)) if (const auto& IntermediateRflv = Intermediate.GetPASS(EPASS::RFLV))
@ -934,49 +934,49 @@ bool CMaterialLoader::SetupReflectionStages(STevTracker& Tracker, CMaterial* pMa
pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kTextureRGB); pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kTextureRGB);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha); pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateRflv); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateRflv);
} }
else if (const auto& IntermediateLrld = Intermediate.GetPASS(EPASS::LRLD)) else if (const auto& IntermediateLrld = Intermediate.GetPASS(EPASS::LRLD))
{ {
pPass->SetColorInputs(kZeroRGB, StaticLighting ? kColor0RGB : kRasRGB, kTextureRGB, kZeroRGB); pPass->SetColorInputs(kZeroRGB, StaticLighting ? kColor0RGB : kRasRGB, kTextureRGB, kZeroRGB);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha); pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha);
pPass->SetRasSel(StaticLighting ? kRasColorNull : kRasColor0A0); pPass->SetRasSel(StaticLighting ? kRasColorNull : kRasColor0A0);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateLrld); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateLrld);
} }
else if (const auto& IntermediateLurd = Intermediate.GetPASS(EPASS::LURD)) else if (const auto& IntermediateLurd = Intermediate.GetPASS(EPASS::LURD))
{ {
pPass->SetColorInputs(kZeroRGB, StaticLighting ? kColor0RGB : kRasRGB, kTextureAAA, kTextureRGB); pPass->SetColorInputs(kZeroRGB, StaticLighting ? kColor0RGB : kRasRGB, kTextureAAA, kTextureRGB);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha); pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha);
pPass->SetRasSel(StaticLighting ? kRasColorNull : kRasColor0A0); pPass->SetRasSel(StaticLighting ? kRasColorNull : kRasColor0A0);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateLurd); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateLurd);
} }
argC = kColor2RGB; argC = kColor2RGB;
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
if (const auto& IntermediateRfld = Intermediate.GetPASS(EPASS::RFLD)) if (const auto& IntermediateRfld = Intermediate.GetPASS(EPASS::RFLD))
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->SetColorInputs(kZeroRGB, kTextureRGB, argC, argD); pPass->SetColorInputs(kZeroRGB, kTextureRGB, argC, argD);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha); pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha);
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateRfld); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateRfld);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
return true; return true;
} }
bool CMaterialLoader::SetupQuantizedKAlphaAdd(STevTracker& Tracker, CMaterial* pMat, uint8 Value) bool CMaterialLoader::SetupQuantizedKAlphaAdd(STevTracker& Tracker, CMaterial* pMat, uint8 Value)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kPrevRGB); pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kPrevRGB);
pPass->SetKAlphaSel(KColorEighths[Value / 32]); pPass->SetKAlphaSel(KColorEighths[Value / 32]);
pPass->SetAlphaInputs(kKonstAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha); pPass->SetAlphaInputs(kKonstAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha);
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
return true; return true;
} }
@ -993,8 +993,8 @@ bool CMaterialLoader::SetupIncandecenceStage(STevTracker& Tracker, CMaterial* pM
return false; return false;
} }
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateInca); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateInca);
pPass->SetKColorSel(kKonstOne); pPass->SetKColorSel(kKonstOne);
pPass->SetColorInputs(kZeroRGB, kKonstRGB, kTextureRGB, kPrevRGB); pPass->SetColorInputs(kZeroRGB, kKonstRGB, kTextureRGB, kPrevRGB);
@ -1006,7 +1006,7 @@ bool CMaterialLoader::SetupIncandecenceStage(STevTracker& Tracker, CMaterial* pM
pPass->SetTexSwapComp(3, IntermediateInca->GetSwapAlphaComp()); pPass->SetTexSwapComp(3, IntermediateInca->GetSwapAlphaComp());
pPass->SetKAlphaSel(KColorEighths[Intermediate.GetINT(EINT::BNIF) / 32]); pPass->SetKAlphaSel(KColorEighths[Intermediate.GetINT(EINT::BNIF) / 32]);
pPass->SetAlphaInputs(kZeroAlpha, kTextureAlpha, kKonstAlpha, kPrevAlpha); pPass->SetAlphaInputs(kZeroAlpha, kTextureAlpha, kKonstAlpha, kPrevAlpha);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
if (bloi) if (bloi)
SetupQuantizedKAlphaAdd(Tracker, pMat, bloi); SetupQuantizedKAlphaAdd(Tracker, pMat, bloi);
} }
@ -1021,7 +1021,7 @@ bool CMaterialLoader::SetupIncandecenceStage(STevTracker& Tracker, CMaterial* pM
{ {
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha); pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha);
} }
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
return true; return true;
} }
@ -1033,8 +1033,8 @@ bool CMaterialLoader::SetupIncandecenceStageNoBloom(STevTracker& Tracker, CMater
if (!IntermediateInca) if (!IntermediateInca)
return false; return false;
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateInca); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateInca);
pPass->SetKColorSel(kKonstOne); pPass->SetKColorSel(kKonstOne);
pPass->SetColorInputs(kZeroRGB, kKonstRGB, kTextureRGB, kPrevRGB); pPass->SetColorInputs(kZeroRGB, kKonstRGB, kTextureRGB, kPrevRGB);
@ -1042,7 +1042,7 @@ bool CMaterialLoader::SetupIncandecenceStageNoBloom(STevTracker& Tracker, CMater
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
return true; return true;
} }
@ -1057,21 +1057,21 @@ bool CMaterialLoader::SetupStartingIncandecenceStage(STevTracker& Tracker, CMate
{ {
if (bloi) if (bloi)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kZeroRGB); pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kZeroRGB);
pPass->SetKAlphaSel(KColorEighths[bloi / 32]); pPass->SetKAlphaSel(KColorEighths[bloi / 32]);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kKonstAlpha); pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kKonstAlpha);
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
return true; return true;
} }
return false; return false;
} }
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateInca); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateInca);
pPass->SetKColorSel(kKonstOne); pPass->SetKColorSel(kKonstOne);
pPass->SetColorInputs(kZeroRGB, kTextureRGB, kKonstRGB, kZeroRGB); pPass->SetColorInputs(kZeroRGB, kTextureRGB, kKonstRGB, kZeroRGB);
@ -1106,7 +1106,7 @@ bool CMaterialLoader::SetupStartingIncandecenceStage(STevTracker& Tracker, CMate
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
if (needsBloiAdd) if (needsBloiAdd)
SetupQuantizedKAlphaAdd(Tracker, pMat, bloi); SetupQuantizedKAlphaAdd(Tracker, pMat, bloi);
return true; return true;
@ -1115,8 +1115,8 @@ bool CMaterialLoader::SetupStartingIncandecenceStage(STevTracker& Tracker, CMate
void CMaterialLoader::SetupStartingIncandecenceDynamicKColorStage(STevTracker& Tracker, CMaterial* pMat, void CMaterialLoader::SetupStartingIncandecenceDynamicKColorStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate) const SMP3IntermediateMaterial& Intermediate)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::INCA)); SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::INCA));
pPass->SetKColorSel(kKonstOne); pPass->SetKColorSel(kKonstOne);
pPass->SetKAlphaSel(kKonstOne); pPass->SetKAlphaSel(kKonstOne);
@ -1126,7 +1126,7 @@ void CMaterialLoader::SetupStartingIncandecenceDynamicKColorStage(STevTracker& T
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
} }
bool CMaterialLoader::SetupStaticBloomLightingStage(STevTracker& Tracker, CMaterial* pMat, bool CMaterialLoader::SetupStaticBloomLightingStage(STevTracker& Tracker, CMaterial* pMat,
@ -1135,8 +1135,8 @@ bool CMaterialLoader::SetupStaticBloomLightingStage(STevTracker& Tracker, CMater
const auto& IntermediateBlol = Intermediate.GetPASS(EPASS::BLOL); const auto& IntermediateBlol = Intermediate.GetPASS(EPASS::BLOL);
if (!StaticLighting || !IntermediateBlol) if (!StaticLighting || !IntermediateBlol)
return false; return false;
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateBlol); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateBlol);
pPass->SetTexSwapComp(3, IntermediateBlol->GetSwapAlphaComp()); pPass->SetTexSwapComp(3, IntermediateBlol->GetSwapAlphaComp());
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
@ -1145,7 +1145,7 @@ bool CMaterialLoader::SetupStaticBloomLightingStage(STevTracker& Tracker, CMater
pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kTextureAlpha, kZeroAlpha); pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kTextureAlpha, kZeroAlpha);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
return true; return true;
} }
@ -1153,14 +1153,14 @@ bool CMaterialLoader::SetupStaticBloomLightingA1Stages(STevTracker& Tracker, CMa
const SMP3IntermediateMaterial& Intermediate) const SMP3IntermediateMaterial& Intermediate)
{ {
const auto& IntermediateBlol = Intermediate.GetPASS(EPASS::BLOL); const auto& IntermediateBlol = Intermediate.GetPASS(EPASS::BLOL);
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
ETevAlphaInput argC = IntermediateBlol ? kTextureAlpha : kZeroAlpha; ETevAlphaInput argC = IntermediateBlol ? kTextureAlpha : kZeroAlpha;
pPass->SetAlphaInputs(kZeroAlpha, kColor1Alpha, argC, kRasAlpha); pPass->SetAlphaInputs(kZeroAlpha, kColor1Alpha, argC, kRasAlpha);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
if (argC == kTextureAlpha) { if (argC == kTextureAlpha) {
pPass->SetTexSwapComp(3, IntermediateBlol->GetSwapAlphaComp()); pPass->SetTexSwapComp(3, IntermediateBlol->GetSwapAlphaComp());
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateBlol); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateBlol);
pPass->SetRasSel(kRasColor0A0); pPass->SetRasSel(kRasColor0A0);
} }
else else
@ -1168,7 +1168,7 @@ bool CMaterialLoader::SetupStaticBloomLightingA1Stages(STevTracker& Tracker, CMa
pPass->SetRasSel(kRasColor0A0); pPass->SetRasSel(kRasColor0A0);
} }
Tracker.mStaticLightingAlphaSet = true; Tracker.mStaticLightingAlphaSet = true;
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
SetupStaticBloomDiffuseLightingStages(Tracker, pMat, Intermediate, true); SetupStaticBloomDiffuseLightingStages(Tracker, pMat, Intermediate, true);
return true; return true;
} }
@ -1191,8 +1191,8 @@ bool CMaterialLoader::SetupStaticBloomDiffuseLightingStages(STevTracker& Tracker
} }
else else
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateBlod); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateBlod);
pPass->SetTexSwapComp(3, IntermediateBlod->GetSwapAlphaComp()); pPass->SetTexSwapComp(3, IntermediateBlod->GetSwapAlphaComp());
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
@ -1224,14 +1224,14 @@ bool CMaterialLoader::SetupStaticBloomDiffuseLightingStages(STevTracker& Tracker
pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kTextureAlpha, kZeroAlpha); pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kTextureAlpha, kZeroAlpha);
} }
pPass->SetRasSel(argC == kRasAlpha ? kRasColor0A0 : kRasColorNull); pPass->SetRasSel(argC == kRasAlpha ? kRasColor0A0 : kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
ret = true; ret = true;
} }
if (useDynamicAlpha) if (useDynamicAlpha)
{ {
if (Intermediate.GetINT(EINT::BLOD) != 255) if (Intermediate.GetINT(EINT::BLOD) != 255)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
@ -1249,7 +1249,7 @@ bool CMaterialLoader::SetupStaticBloomDiffuseLightingStages(STevTracker& Tracker
pPass->SetRasSel(argB == kPrevAlpha ? kRasColor0A0 : kRasColorNull); pPass->SetRasSel(argB == kPrevAlpha ? kRasColor0A0 : kRasColorNull);
Tracker.mStaticLightingAlphaSet = true; Tracker.mStaticLightingAlphaSet = true;
} }
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
ret = true; ret = true;
} }
Tracker.mStaticDiffuseLightingAlphaSet = true; Tracker.mStaticDiffuseLightingAlphaSet = true;
@ -1263,8 +1263,8 @@ bool CMaterialLoader::SetupStaticBloomIncandecenceLightingStage(STevTracker& Tra
const auto& IntermediateBloi = Intermediate.GetPASS(EPASS::BLOI); const auto& IntermediateBloi = Intermediate.GetPASS(EPASS::BLOI);
if (!IntermediateBloi) if (!IntermediateBloi)
return false; return false;
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateBloi); SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateBloi);
pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kPrevRGB); pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kPrevRGB);
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
@ -1273,7 +1273,7 @@ bool CMaterialLoader::SetupStaticBloomIncandecenceLightingStage(STevTracker& Tra
pPass->SetTexSwapComp(3, IntermediateBloi->GetSwapAlphaComp()); pPass->SetTexSwapComp(3, IntermediateBloi->GetSwapAlphaComp());
pPass->SetAlphaInputs(kTextureAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha); pPass->SetAlphaInputs(kTextureAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
return true; return true;
} }
@ -1304,9 +1304,8 @@ void CMaterialLoader::SetupNoBloomAdditiveIncandecence(CMaterial* pMat, const SM
uint8 Alpha) uint8 Alpha)
{ {
SetupNoBloomTransparent(pMat, Intermediate, Alpha); SetupNoBloomTransparent(pMat, Intermediate, Alpha);
CMaterial* pMatNext = new CMaterial(pMat->Version(), pMat->VtxDesc()); pMat->mpNextDrawPassMaterial = std::make_unique<CMaterial>(pMat->Version(), pMat->VtxDesc());
pMat->mpNextDrawPassMaterial = pMatNext; pMat = pMat->mpNextDrawPassMaterial.get();
pMat = pMatNext;
STevTracker Tracker; STevTracker Tracker;
SetupStartingIncandecenceDynamicKColorStage(Tracker, pMat, Intermediate); SetupStartingIncandecenceDynamicKColorStage(Tracker, pMat, Intermediate);
pMat->mOptions.AssignFlag(EMaterialOption::DepthWrite, false); pMat->mOptions.AssignFlag(EMaterialOption::DepthWrite, false);
@ -1381,8 +1380,8 @@ void CMaterialLoader::SetupAdditiveIncandecenceOnly(CMaterial* pMat,
pMat->mOptions.AssignFlag(EMaterialOption::Transparent, true); pMat->mOptions.AssignFlag(EMaterialOption::Transparent, true);
} }
void CMaterialLoader::SetupFullRenderTransparent(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate, CMaterial* CMaterialLoader::SetupFullRenderTransparent(
uint8 Alpha) CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate, uint8 Alpha)
{ {
STevTracker Tracker; STevTracker Tracker;
bool StaticLighting = SetupStaticDiffuseLightingStage(Tracker, pMat, Intermediate, true); bool StaticLighting = SetupStaticDiffuseLightingStage(Tracker, pMat, Intermediate, true);
@ -1403,9 +1402,8 @@ void CMaterialLoader::SetupFullRenderTransparent(CMaterial* pMat, const SMP3Inte
pMat->mOptions.AssignFlag(EMaterialOption::Transparent, true); pMat->mOptions.AssignFlag(EMaterialOption::Transparent, true);
pMat->mOptions.AssignFlag(EMaterialOption::AlphaWrite, false); pMat->mOptions.AssignFlag(EMaterialOption::AlphaWrite, false);
CMaterial* pMatNext = new CMaterial(pMat->Version(), pMat->VtxDesc()); pMat->mpNextDrawPassMaterial = std::make_unique<CMaterial>(pMat->Version(), pMat->VtxDesc());
pMat->mpNextDrawPassMaterial = pMatNext; pMat = pMat->mpNextDrawPassMaterial.get();
pMat = pMatNext;
Tracker = STevTracker(); Tracker = STevTracker();
pMat->mOptions.AssignFlag(EMaterialOption::AlphaWrite, true); pMat->mOptions.AssignFlag(EMaterialOption::AlphaWrite, true);
SetupTransparencyKAlphaMultiplyStage(Tracker, pMat, Intermediate, false, Alpha); SetupTransparencyKAlphaMultiplyStage(Tracker, pMat, Intermediate, false, Alpha);
@ -1415,9 +1413,8 @@ void CMaterialLoader::SetupFullRenderTransparent(CMaterial* pMat, const SMP3Inte
pMat->mOptions.AssignFlag(EMaterialOption::Transparent, true); pMat->mOptions.AssignFlag(EMaterialOption::Transparent, true);
pMat->mOptions.AssignFlag(EMaterialOption::ColorWrite, false); pMat->mOptions.AssignFlag(EMaterialOption::ColorWrite, false);
pMatNext = new CMaterial(pMat->Version(), pMat->VtxDesc()); pMat->mpNextDrawPassMaterial = std::make_unique<CMaterial>(pMat->Version(), pMat->VtxDesc());
pMat->mpNextDrawPassMaterial = pMatNext; pMat = pMat->mpNextDrawPassMaterial.get();
pMat = pMatNext;
Tracker = STevTracker(); Tracker = STevTracker();
if (SetupStaticBloomLightingA1Stages(Tracker, pMat, Intermediate)) if (SetupStaticBloomLightingA1Stages(Tracker, pMat, Intermediate))
{ {
@ -1428,16 +1425,17 @@ void CMaterialLoader::SetupFullRenderTransparent(CMaterial* pMat, const SMP3Inte
pMat->mOptions.AssignFlag(EMaterialOption::Transparent, true); pMat->mOptions.AssignFlag(EMaterialOption::Transparent, true);
pMat->mOptions.AssignFlag(EMaterialOption::ColorWrite, true); pMat->mOptions.AssignFlag(EMaterialOption::ColorWrite, true);
} }
return pMat;
} }
void CMaterialLoader::SetupFullRenderTransparentAdditiveIncandecence(CMaterial* pMat, void CMaterialLoader::SetupFullRenderTransparentAdditiveIncandecence(CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate, const SMP3IntermediateMaterial& Intermediate,
uint8 Alpha) uint8 Alpha)
{ {
SetupFullRenderTransparent(pMat, Intermediate, Alpha); pMat = SetupFullRenderTransparent(pMat, Intermediate, Alpha);
CMaterial* pMatNext = new CMaterial(pMat->Version(), pMat->VtxDesc()); pMat->mpNextDrawPassMaterial = std::make_unique<CMaterial>(pMat->Version(), pMat->VtxDesc());
pMat->mpNextDrawPassMaterial = pMatNext; pMat = pMat->mpNextDrawPassMaterial.get();
pMat = pMatNext;
STevTracker Tracker; STevTracker Tracker;
SetupStartingIncandecenceStage(Tracker, pMat, Intermediate); SetupStartingIncandecenceStage(Tracker, pMat, Intermediate);
@ -1473,13 +1471,13 @@ void CMaterialLoader::SetupMaterialAlphaCompare(CMaterial* pMat, const SMP3Inter
void CMaterialLoader::SetupSolidWhite(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate) void CMaterialLoader::SetupSolidWhite(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kOneRGB); pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kOneRGB);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha); pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha);
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
pMat->mOptions.AssignFlag(EMaterialOption::DepthWrite, false); pMat->mOptions.AssignFlag(EMaterialOption::DepthWrite, false);
pMat->SetBlendMode(GL_ONE, GL_ZERO); pMat->SetBlendMode(GL_ONE, GL_ZERO);
pMat->mOptions.AssignFlag(EMaterialOption::Transparent, false); pMat->mOptions.AssignFlag(EMaterialOption::Transparent, false);
@ -1488,7 +1486,7 @@ void CMaterialLoader::SetupSolidWhite(CMaterial* pMat, const SMP3IntermediateMat
void CMaterialLoader::SetupSolidKColorKAlpha(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate) void CMaterialLoader::SetupSolidKColorKAlpha(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate)
{ {
CMaterialPass* pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat);
pMat->SetKonst(Intermediate.GetCLR(ECLR::CLR), 0); pMat->SetKonst(Intermediate.GetCLR(ECLR::CLR), 0);
pPass->SetKColorSel(kKonst0_RGB); pPass->SetKColorSel(kKonst0_RGB);
pPass->SetKAlphaSel(kKonst0_A); pPass->SetKAlphaSel(kKonst0_A);
@ -1497,7 +1495,7 @@ void CMaterialLoader::SetupSolidKColorKAlpha(CMaterial* pMat, const SMP3Intermed
pPass->SetColorOutput(kPrevReg); pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg); pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull); pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
pMat->mOptions.AssignFlag(EMaterialOption::DepthWrite, false); pMat->mOptions.AssignFlag(EMaterialOption::DepthWrite, false);
pMat->mOptions.AssignFlag(EMaterialOption::Masked, false); pMat->mOptions.AssignFlag(EMaterialOption::Masked, false);
pMat->SetBlendMode(GL_SRC_ALPHA, GL_ONE); pMat->SetBlendMode(GL_SRC_ALPHA, GL_ONE);
@ -1543,24 +1541,24 @@ void CMaterialLoader::CreateCorruptionPasses(CMaterial* pMat, const SMP3Intermed
} }
} }
CMaterial* CMaterialLoader::LoadAssimpMaterial(const aiMaterial *pAiMat) std::unique_ptr<CMaterial> CMaterialLoader::LoadAssimpMaterial(const aiMaterial *pAiMat)
{ {
// todo: generate new material using import values. // todo: generate new material using import values.
CMaterial *pMat = new CMaterial(mVersion, EVertexAttribute::None); auto pMat = std::make_unique<CMaterial>(mVersion, EVertexAttribute::None);
aiString Name; aiString Name;
pAiMat->Get(AI_MATKEY_NAME, Name); pAiMat->Get(AI_MATKEY_NAME, Name);
pMat->SetName(Name.C_Str()); pMat->SetName(Name.C_Str());
// Create generic custom pass that uses Konst color // Create generic custom pass that uses Konst color
CMaterialPass *pPass = new CMaterialPass(pMat); auto pPass = std::make_unique<CMaterialPass>(pMat.get());
pPass->SetColorInputs(kZeroRGB, kRasRGB, kKonstRGB, kZeroRGB); pPass->SetColorInputs(kZeroRGB, kRasRGB, kKonstRGB, kZeroRGB);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kKonstAlpha); pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kKonstAlpha);
pPass->SetKColorSel(kKonst0_RGB); pPass->SetKColorSel(kKonst0_RGB);
pPass->SetKAlphaSel(kKonstOne); pPass->SetKAlphaSel(kKonstOne);
pPass->SetRasSel(kRasColor0A0); pPass->SetRasSel(kRasColor0A0);
pMat->mKonstColors[0] = CColor::RandomLightColor(false); pMat->mKonstColors[0] = CColor::RandomLightColor(false);
pMat->mPasses.push_back(pPass); pMat->mPasses.push_back(std::move(pPass));
return pMat; return pMat;
} }
@ -1591,8 +1589,7 @@ CMaterialSet* CMaterialLoader::ImportAssimpMaterials(const aiScene *pScene, EGam
for (uint32 iMat = 0; iMat < pScene->mNumMaterials; iMat++) for (uint32 iMat = 0; iMat < pScene->mNumMaterials; iMat++)
{ {
CMaterial *pMat = Loader.LoadAssimpMaterial(pScene->mMaterials[iMat]); pOut->mMaterials.push_back(Loader.LoadAssimpMaterial(pScene->mMaterials[iMat]));
pOut->mMaterials.push_back(pMat);
} }
return pOut; return pOut;

View File

@ -131,10 +131,10 @@ class CMaterialLoader
// Load Functions // Load Functions
void ReadPrimeMatSet(); void ReadPrimeMatSet();
CMaterial* ReadPrimeMaterial(); std::unique_ptr<CMaterial> ReadPrimeMaterial();
void ReadCorruptionMatSet(); void ReadCorruptionMatSet();
CMaterial* ReadCorruptionMaterial(); std::unique_ptr<CMaterial> ReadCorruptionMaterial();
void SetMP3IntermediateIntoMaterialPass(CMaterialPass* pPass, const SMP3IntermediateMaterial::PASS& Intermediate); void SetMP3IntermediateIntoMaterialPass(CMaterialPass* pPass, const SMP3IntermediateMaterial::PASS& Intermediate);
void SelectBestCombinerConfig(EMP3RenderConfig& OutConfig, uint8& OutAlpha, void SelectBestCombinerConfig(EMP3RenderConfig& OutConfig, uint8& OutAlpha,
const SMP3IntermediateMaterial& Material, bool Bloom); const SMP3IntermediateMaterial& Material, bool Bloom);
@ -180,7 +180,7 @@ class CMaterialLoader
void SetupOptimizedDiffuseLightingColorOpaque(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate); void SetupOptimizedDiffuseLightingColorOpaque(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate);
void SetupOptimizedDiffuseBloomLightingColorOpaque(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate); void SetupOptimizedDiffuseBloomLightingColorOpaque(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate);
void SetupAdditiveIncandecenceOnly(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate); void SetupAdditiveIncandecenceOnly(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate);
void SetupFullRenderTransparent(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate, uint8 Alpha); CMaterial* SetupFullRenderTransparent(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate, uint8 Alpha);
void SetupFullRenderTransparentAdditiveIncandecence(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate, void SetupFullRenderTransparentAdditiveIncandecence(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate,
uint8 Alpha); uint8 Alpha);
void SetupMaterialAlphaCompare(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate); void SetupMaterialAlphaCompare(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate);
@ -189,7 +189,7 @@ class CMaterialLoader
void CreateCorruptionPasses(CMaterial *pMat, const SMP3IntermediateMaterial& Intermediate, bool Bloom); void CreateCorruptionPasses(CMaterial *pMat, const SMP3IntermediateMaterial& Intermediate, bool Bloom);
CMaterial* LoadAssimpMaterial(const aiMaterial *pAiMat); std::unique_ptr<CMaterial> LoadAssimpMaterial(const aiMaterial* pAiMat);
// Static // Static
public: public: