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()
{
for (uint32 iPass = 0; iPass < mPasses.size(); iPass++)
delete mPasses[iPass];
delete mpNextDrawPassMaterial;
delete mpBloomMaterial;
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->mVersion = mVersion;
pOut->mOptions = mOptions;
@ -78,7 +72,7 @@ CMaterial* CMaterial::Clone()
pOut->mPasses.resize(mPasses.size());
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)
pOut->mpNextDrawPassMaterial = mpNextDrawPassMaterial->Clone();
@ -283,19 +277,13 @@ void CMaterial::Update()
void CMaterial::SetNumPasses(uint32 NumPasses)
{
if (NumPasses < mPasses.size())
{
for (uint32 iPass = NumPasses; iPass < mPasses.size(); iPass++)
delete mPasses[iPass];
}
uint32 OldCount = mPasses.size();
mPasses.resize(NumPasses);
if (NumPasses > OldCount)
{
for (uint32 iPass = OldCount; iPass < NumPasses; iPass++)
mPasses[iPass] = new CMaterialPass(this);
mPasses[iPass] = std::make_unique<CMaterialPass>(this);
}
mRecalcHash = true;

View File

@ -92,17 +92,17 @@ private:
uint32 mEchoesUnknownB; // Second unknown value introduced in Echoes. Included for cooking.
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
// blending modes. This serves as a linked list of materials to be drawn successively
// for each surface.
CMaterial* mpNextDrawPassMaterial;
std::unique_ptr<CMaterial> mpNextDrawPassMaterial;
// 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.
// (only set in the head non-bloom CMaterial).
CMaterial* mpBloomMaterial;
std::unique_ptr<CMaterial> mpBloomMaterial;
// Reuse shaders between materials that have identical TEV setups
struct SMaterialShader
@ -117,7 +117,7 @@ public:
CMaterial(EGame Version, FVertexDescription VtxDesc);
~CMaterial();
CMaterial* Clone();
std::unique_ptr<CMaterial> Clone();
void GenerateShader(bool AllowRegen = true);
void ClearShader();
bool SetCurrent(FRenderOptions Options);
@ -139,9 +139,9 @@ public:
inline uint32 EchoesUnknownA() const { return mEchoesUnknownA; }
inline uint32 EchoesUnknownB() const { return mEchoesUnknownB; }
inline uint32 PassCount() const { return mPasses.size(); }
inline CMaterialPass* Pass(uint32 PassIndex) const { return mPasses[PassIndex]; }
inline CMaterial* GetNextDrawPass() const { return mpNextDrawPassMaterial; }
inline CMaterial* GetBloomVersion() const { return mpBloomMaterial; }
inline CMaterialPass* Pass(uint32 PassIndex) const { return mPasses[PassIndex].get(); }
inline CMaterial* GetNextDrawPass() const { return mpNextDrawPassMaterial.get(); }
inline CMaterial* GetBloomVersion() const { return mpBloomMaterial.get(); }
inline void SetName(const TString& rkName) { mName = rkName; }
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->mSettings = mSettings;

View File

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

View File

@ -11,16 +11,12 @@ class CMaterialSet
friend class CMaterialLoader;
friend class CMaterialCooker;
std::vector<CMaterial*> mMaterials;
std::vector<std::unique_ptr<CMaterial>> mMaterials;
public:
CMaterialSet() {}
~CMaterialSet()
{
for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++)
delete mMaterials[iMat];
}
~CMaterialSet() {}
CMaterialSet* Clone()
{
@ -41,7 +37,7 @@ public:
CMaterial* MaterialByIndex(uint32 Index, bool TryBloom)
{
if (Index >= NumMaterials()) return nullptr;
CMaterial* Ret = mMaterials[Index];
CMaterial* Ret = mMaterials[Index].get();
if (TryBloom && Ret->GetBloomVersion())
return Ret->GetBloomVersion();
return Ret;
@ -50,7 +46,7 @@ public:
CMaterial* MaterialByName(const TString& rkName)
{
for (auto it = mMaterials.begin(); it != mMaterials.end(); it++)
if ((*it)->Name() == rkName) return *it;
if ((*it)->Name() == rkName) return it->get();
return nullptr;
}
@ -67,7 +63,7 @@ public:
{
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());
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++)
{
CMaterial *pMat = mpSet->mMaterials[iMat];
CMaterial *pMat = mpSet->mMaterials[iMat].get();
uint32 NumPasses = pMat->PassCount();
for (uint32 iPass = 0; iPass < NumPasses; iPass++)
@ -74,7 +74,7 @@ void CMaterialCooker::WriteMatSetPrime(IOutputStream& rOut)
for (uint32 iMat = 0; iMat < NumMats; iMat++)
{
mpMat = mpSet->mMaterials[iMat];
mpMat = mpSet->mMaterials[iMat].get();
WriteMaterialPrime(rOut);
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
pMat->mOptions = (mpFile->ReadLong() & (uint) EMaterialOption::AllMP1Settings);
@ -133,7 +133,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
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 AlphaIn = mpFile->ReadLong();
@ -150,7 +150,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
pPass->mAlphaInputs[iInput] = (ETevAlphaInput) ((AlphaIn >> (iInput * 5)) & 0x7);
}
pMat->mPasses[iTev] = pPass;
pMat->mPasses[iTev] = std::move(pPass);
}
std::vector<uint8> TevCoordIndices(TevCount);
@ -217,7 +217,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
// Move TexGen and anims into passes
for (uint32 iPass = 0; iPass < pMat->mPasses.size(); iPass++)
{
CMaterialPass *pPass = pMat->mPasses[iPass];
CMaterialPass *pPass = pMat->mPasses[iPass].get();
uint8 TexCoordIdx = TevCoordIndices[iPass];
if ((TexGens.size() == 0) || (TexCoordIdx == 0xFF))
@ -323,7 +323,7 @@ ECLR ClrFourCCToEnum(CFourCC fcc)
return ECLR::CLR;
};
CMaterial* CMaterialLoader::ReadCorruptionMaterial()
std::unique_ptr<CMaterial> CMaterialLoader::ReadCorruptionMaterial()
{
// Flags
FMP3MaterialOptions MP3Options = mpFile->ReadLong();
@ -432,10 +432,10 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
}
// Create non-bloom and bloom versions
CMaterial* pMat = new CMaterial(mVersion, VtxDesc);
CreateCorruptionPasses(pMat, Intermediate, false);
pMat->mpBloomMaterial = new CMaterial(mVersion, VtxDesc);
CreateCorruptionPasses(pMat->mpBloomMaterial, Intermediate, true);
auto pMat = std::make_unique<CMaterial>(mVersion, VtxDesc);
CreateCorruptionPasses(pMat.get(), Intermediate, false);
pMat->mpBloomMaterial = std::make_unique<CMaterial>(mVersion, VtxDesc);
CreateCorruptionPasses(pMat->mpBloomMaterial.get(), Intermediate, true);
return pMat;
}
@ -587,10 +587,10 @@ bool CMaterialLoader::SetupStaticDiffuseLightingStage(STevTracker& Tracker, CMat
EMP3MaterialOption::ForceLightingStage)
return false;
pMat->SetTevColor(Intermediate.GetCLR(ECLR::DIFB), kColor1Reg);
CMaterialPass* pPass = new CMaterialPass(pMat);
auto pPass = std::make_unique<CMaterialPass>(pMat);
if (hasDIFFTexture)
{
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::DIFF));
SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::DIFF));
pPass->SetColorInputs(kZeroRGB, kTextureRGB, kColor1RGB, kRasRGB);
pPass->SetColorOutput(kColor0Reg);
if (FullAlpha)
@ -642,15 +642,15 @@ bool CMaterialLoader::SetupStaticDiffuseLightingStage(STevTracker& Tracker, CMat
pPass->SetRasSel(kRasColor0A0);
Tracker.mStaticLightingAlphaSet = true;
}
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
return true;
}
void CMaterialLoader::SetupStaticDiffuseLightingNoBloomStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate)
{
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::DIFF));
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::DIFF));
pMat->SetTevColor(Intermediate.GetCLR(ECLR::DIFB), kColor1Reg);
pPass->SetColorInputs(kZeroRGB, kTextureRGB, kColor1RGB, kRasRGB);
@ -661,14 +661,14 @@ void CMaterialLoader::SetupStaticDiffuseLightingNoBloomStage(STevTracker& Tracke
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColor0A0);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
}
void CMaterialLoader::SetupStaticDiffuseLightingNoBLOLStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate)
{
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::DIFF));
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::DIFF));
pMat->SetTevColor(Intermediate.GetCLR(ECLR::DIFB), kColor1Reg);
pPass->SetColorInputs(kZeroRGB, kTextureRGB, kColor1RGB, kRasRGB);
@ -693,15 +693,15 @@ void CMaterialLoader::SetupStaticDiffuseLightingNoBLOLStage(STevTracker& Tracker
Tracker.mStaticLightingAlphaSet = true;
pPass->SetRasSel(kRasColor0A0);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
}
void CMaterialLoader::SetupColorTextureStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate,
bool useStageAlpha, uint8 Alpha, bool StaticLighting)
{
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::CLR));
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::CLR));
bool useDynamicLightingAlpha = false;
pPass->SetColorInputs(kZeroRGB, StaticLighting ? kColor0RGB : kRasRGB, kTextureRGB, kZeroRGB);
@ -732,14 +732,14 @@ void CMaterialLoader::SetupColorTextureStage(STevTracker& Tracker, CMaterial* pM
pPass->SetAlphaOutput(kPrevReg);
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,
const SMP3IntermediateMaterial& Intermediate)
{
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::CLR));
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::CLR));
pPass->SetColorInputs(kZeroRGB, kColor0RGB, kTextureRGB, kZeroRGB);
pPass->SetColorOutput(kPrevReg);
@ -748,14 +748,14 @@ void CMaterialLoader::SetupColorTextureAlwaysStaticLightingStage(STevTracker& Tr
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
}
void CMaterialLoader::SetupColorKColorStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate,
bool useStageAlpha, uint8 Alpha, bool StaticLighting)
{
CMaterialPass* pPass = new CMaterialPass(pMat);
auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->mPassType = "CLR ";
bool useDynamicLightingAlpha = false;
@ -782,15 +782,15 @@ void CMaterialLoader::SetupColorKColorStage(STevTracker& Tracker, CMaterial* pMa
pPass->SetRasSel((useDynamicLightingAlpha || !StaticLighting) ? kRasColor0A0 : kRasColorNull);
Tracker.mCurKColor += 1;
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
}
bool CMaterialLoader::SetupTransparencyStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate)
{
if (const auto& IntermediateTran = Intermediate.GetPASS(EPASS::TRAN)) {
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateTran);
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateTran);
if (IntermediateTran->mSettings & EPassSettings::InvertOpacityMap)
{
@ -806,7 +806,7 @@ bool CMaterialLoader::SetupTransparencyStage(STevTracker& Tracker, CMaterial* pM
pPass->SetRasSel(kRasColorNull);
pPass->SetTexSwapComp(3, IntermediateTran->GetSwapAlphaComp());
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
return true;
}
return false;
@ -818,7 +818,7 @@ void CMaterialLoader::SetupTransparencyKAlphaMultiplyStage(STevTracker& Tracker,
{
if (Intermediate.GetPASS(EPASS::CLR) || Intermediate.GetPASS(EPASS::TRAN))
{
CMaterialPass* pPass = new CMaterialPass(pMat);
auto pPass = std::make_unique<CMaterialPass>(pMat);
ETevAlphaInput argA;
if (Alpha < 255)
{
@ -829,8 +829,8 @@ void CMaterialLoader::SetupTransparencyKAlphaMultiplyStage(STevTracker& Tracker,
pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kKonstAlpha, kZeroAlpha);
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass);
pPass = new CMaterialPass(pMat);
pMat->mPasses.push_back(std::move(pPass));
pPass = std::make_unique<CMaterialPass>(pMat);
argA = kPrevAlpha;
}
else
@ -862,21 +862,21 @@ void CMaterialLoader::SetupTransparencyKAlphaMultiplyStage(STevTracker& Tracker,
pPass->SetAlphaOutput(kPrevReg);
if (IntermediateTran)
{
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateTran);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateTran);
pPass->SetRasSel(kRasColorNull);
pPass->SetTexSwapComp(3, IntermediateTran->GetSwapAlphaComp());
}
else
{
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::CLR));
SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::CLR));
pPass->SetRasSel(kRasColorNull);
}
Tracker.mCurKColor += 1;
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
}
else
{
CMaterialPass* pPass = new CMaterialPass(pMat);
auto pPass = std::make_unique<CMaterialPass>(pMat);
pMat->SetKonst(CColor::Integral(255, 255, 255, Alpha), Tracker.mCurKColor);
pPass->SetKAlphaSel(ETevKSel(kKonst0_A + Tracker.mCurKColor));
if (multiplyPrevAlpha)
@ -890,7 +890,7 @@ void CMaterialLoader::SetupTransparencyKAlphaMultiplyStage(STevTracker& Tracker,
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
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))
{
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateRfld);
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateRfld);
pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kPrevRGB);
pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kTextureAlpha, kZeroAlpha);
@ -911,7 +911,7 @@ bool CMaterialLoader::SetupReflectionAlphaStage(STevTracker& Tracker, CMaterial*
pPass->SetRasSel(kRasColorNull);
pPass->SetTexSwapComp(3, 'r');
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
return true;
}
}
@ -926,7 +926,7 @@ bool CMaterialLoader::SetupReflectionStages(STevTracker& Tracker, CMaterial* pMa
return false;
ETevColorInput argC = kOneRGB;
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->SetAlphaOutput(kColor2Reg);
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->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha);
pPass->SetRasSel(kRasColorNull);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateRflv);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateRflv);
}
else if (const auto& IntermediateLrld = Intermediate.GetPASS(EPASS::LRLD))
{
pPass->SetColorInputs(kZeroRGB, StaticLighting ? kColor0RGB : kRasRGB, kTextureRGB, kZeroRGB);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha);
pPass->SetRasSel(StaticLighting ? kRasColorNull : kRasColor0A0);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateLrld);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateLrld);
}
else if (const auto& IntermediateLurd = Intermediate.GetPASS(EPASS::LURD))
{
pPass->SetColorInputs(kZeroRGB, StaticLighting ? kColor0RGB : kRasRGB, kTextureAAA, kTextureRGB);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha);
pPass->SetRasSel(StaticLighting ? kRasColorNull : kRasColor0A0);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateLurd);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateLurd);
}
argC = kColor2RGB;
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
}
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->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha);
pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateRfld);
pMat->mPasses.push_back(pPass);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateRfld);
pMat->mPasses.push_back(std::move(pPass));
}
return true;
}
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->SetKAlphaSel(KColorEighths[Value / 32]);
pPass->SetAlphaInputs(kKonstAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha);
pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
return true;
}
@ -993,8 +993,8 @@ bool CMaterialLoader::SetupIncandecenceStage(STevTracker& Tracker, CMaterial* pM
return false;
}
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateInca);
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateInca);
pPass->SetKColorSel(kKonstOne);
pPass->SetColorInputs(kZeroRGB, kKonstRGB, kTextureRGB, kPrevRGB);
@ -1006,7 +1006,7 @@ bool CMaterialLoader::SetupIncandecenceStage(STevTracker& Tracker, CMaterial* pM
pPass->SetTexSwapComp(3, IntermediateInca->GetSwapAlphaComp());
pPass->SetKAlphaSel(KColorEighths[Intermediate.GetINT(EINT::BNIF) / 32]);
pPass->SetAlphaInputs(kZeroAlpha, kTextureAlpha, kKonstAlpha, kPrevAlpha);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
if (bloi)
SetupQuantizedKAlphaAdd(Tracker, pMat, bloi);
}
@ -1021,7 +1021,7 @@ bool CMaterialLoader::SetupIncandecenceStage(STevTracker& Tracker, CMaterial* pM
{
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha);
}
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
}
return true;
}
@ -1033,8 +1033,8 @@ bool CMaterialLoader::SetupIncandecenceStageNoBloom(STevTracker& Tracker, CMater
if (!IntermediateInca)
return false;
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateInca);
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateInca);
pPass->SetKColorSel(kKonstOne);
pPass->SetColorInputs(kZeroRGB, kKonstRGB, kTextureRGB, kPrevRGB);
@ -1042,7 +1042,7 @@ bool CMaterialLoader::SetupIncandecenceStageNoBloom(STevTracker& Tracker, CMater
pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
return true;
}
@ -1057,21 +1057,21 @@ bool CMaterialLoader::SetupStartingIncandecenceStage(STevTracker& Tracker, CMate
{
if (bloi)
{
CMaterialPass* pPass = new CMaterialPass(pMat);
auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kZeroRGB);
pPass->SetKAlphaSel(KColorEighths[bloi / 32]);
pPass->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kKonstAlpha);
pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
return true;
}
return false;
}
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateInca);
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateInca);
pPass->SetKColorSel(kKonstOne);
pPass->SetColorInputs(kZeroRGB, kTextureRGB, kKonstRGB, kZeroRGB);
@ -1106,7 +1106,7 @@ bool CMaterialLoader::SetupStartingIncandecenceStage(STevTracker& Tracker, CMate
pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
if (needsBloiAdd)
SetupQuantizedKAlphaAdd(Tracker, pMat, bloi);
return true;
@ -1115,8 +1115,8 @@ bool CMaterialLoader::SetupStartingIncandecenceStage(STevTracker& Tracker, CMate
void CMaterialLoader::SetupStartingIncandecenceDynamicKColorStage(STevTracker& Tracker, CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate)
{
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *Intermediate.GetPASS(EPASS::INCA));
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *Intermediate.GetPASS(EPASS::INCA));
pPass->SetKColorSel(kKonstOne);
pPass->SetKAlphaSel(kKonstOne);
@ -1126,7 +1126,7 @@ void CMaterialLoader::SetupStartingIncandecenceDynamicKColorStage(STevTracker& T
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
}
bool CMaterialLoader::SetupStaticBloomLightingStage(STevTracker& Tracker, CMaterial* pMat,
@ -1135,8 +1135,8 @@ bool CMaterialLoader::SetupStaticBloomLightingStage(STevTracker& Tracker, CMater
const auto& IntermediateBlol = Intermediate.GetPASS(EPASS::BLOL);
if (!StaticLighting || !IntermediateBlol)
return false;
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateBlol);
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateBlol);
pPass->SetTexSwapComp(3, IntermediateBlol->GetSwapAlphaComp());
pPass->SetColorOutput(kPrevReg);
@ -1145,7 +1145,7 @@ bool CMaterialLoader::SetupStaticBloomLightingStage(STevTracker& Tracker, CMater
pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kTextureAlpha, kZeroAlpha);
pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
return true;
}
@ -1153,14 +1153,14 @@ bool CMaterialLoader::SetupStaticBloomLightingA1Stages(STevTracker& Tracker, CMa
const SMP3IntermediateMaterial& Intermediate)
{
const auto& IntermediateBlol = Intermediate.GetPASS(EPASS::BLOL);
CMaterialPass* pPass = new CMaterialPass(pMat);
auto pPass = std::make_unique<CMaterialPass>(pMat);
ETevAlphaInput argC = IntermediateBlol ? kTextureAlpha : kZeroAlpha;
pPass->SetAlphaInputs(kZeroAlpha, kColor1Alpha, argC, kRasAlpha);
pPass->SetAlphaOutput(kPrevReg);
if (argC == kTextureAlpha) {
pPass->SetTexSwapComp(3, IntermediateBlol->GetSwapAlphaComp());
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateBlol);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateBlol);
pPass->SetRasSel(kRasColor0A0);
}
else
@ -1168,7 +1168,7 @@ bool CMaterialLoader::SetupStaticBloomLightingA1Stages(STevTracker& Tracker, CMa
pPass->SetRasSel(kRasColor0A0);
}
Tracker.mStaticLightingAlphaSet = true;
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
SetupStaticBloomDiffuseLightingStages(Tracker, pMat, Intermediate, true);
return true;
}
@ -1191,8 +1191,8 @@ bool CMaterialLoader::SetupStaticBloomDiffuseLightingStages(STevTracker& Tracker
}
else
{
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateBlod);
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateBlod);
pPass->SetTexSwapComp(3, IntermediateBlod->GetSwapAlphaComp());
pPass->SetColorOutput(kPrevReg);
@ -1224,14 +1224,14 @@ bool CMaterialLoader::SetupStaticBloomDiffuseLightingStages(STevTracker& Tracker
pPass->SetAlphaInputs(kZeroAlpha, kPrevAlpha, kTextureAlpha, kZeroAlpha);
}
pPass->SetRasSel(argC == kRasAlpha ? kRasColor0A0 : kRasColorNull);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
ret = true;
}
if (useDynamicAlpha)
{
if (Intermediate.GetINT(EINT::BLOD) != 255)
{
CMaterialPass* pPass = new CMaterialPass(pMat);
auto pPass = std::make_unique<CMaterialPass>(pMat);
pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg);
@ -1249,7 +1249,7 @@ bool CMaterialLoader::SetupStaticBloomDiffuseLightingStages(STevTracker& Tracker
pPass->SetRasSel(argB == kPrevAlpha ? kRasColor0A0 : kRasColorNull);
Tracker.mStaticLightingAlphaSet = true;
}
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
ret = true;
}
Tracker.mStaticDiffuseLightingAlphaSet = true;
@ -1263,8 +1263,8 @@ bool CMaterialLoader::SetupStaticBloomIncandecenceLightingStage(STevTracker& Tra
const auto& IntermediateBloi = Intermediate.GetPASS(EPASS::BLOI);
if (!IntermediateBloi)
return false;
CMaterialPass* pPass = new CMaterialPass(pMat);
SetMP3IntermediateIntoMaterialPass(pPass, *IntermediateBloi);
auto pPass = std::make_unique<CMaterialPass>(pMat);
SetMP3IntermediateIntoMaterialPass(pPass.get(), *IntermediateBloi);
pPass->SetColorInputs(kZeroRGB, kZeroRGB, kZeroRGB, kPrevRGB);
pPass->SetColorOutput(kPrevReg);
@ -1273,7 +1273,7 @@ bool CMaterialLoader::SetupStaticBloomIncandecenceLightingStage(STevTracker& Tra
pPass->SetTexSwapComp(3, IntermediateBloi->GetSwapAlphaComp());
pPass->SetAlphaInputs(kTextureAlpha, kZeroAlpha, kZeroAlpha, kPrevAlpha);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
return true;
}
@ -1304,9 +1304,8 @@ void CMaterialLoader::SetupNoBloomAdditiveIncandecence(CMaterial* pMat, const SM
uint8 Alpha)
{
SetupNoBloomTransparent(pMat, Intermediate, Alpha);
CMaterial* pMatNext = new CMaterial(pMat->Version(), pMat->VtxDesc());
pMat->mpNextDrawPassMaterial = pMatNext;
pMat = pMatNext;
pMat->mpNextDrawPassMaterial = std::make_unique<CMaterial>(pMat->Version(), pMat->VtxDesc());
pMat = pMat->mpNextDrawPassMaterial.get();
STevTracker Tracker;
SetupStartingIncandecenceDynamicKColorStage(Tracker, pMat, Intermediate);
pMat->mOptions.AssignFlag(EMaterialOption::DepthWrite, false);
@ -1381,8 +1380,8 @@ void CMaterialLoader::SetupAdditiveIncandecenceOnly(CMaterial* pMat,
pMat->mOptions.AssignFlag(EMaterialOption::Transparent, true);
}
void CMaterialLoader::SetupFullRenderTransparent(CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate,
uint8 Alpha)
CMaterial* CMaterialLoader::SetupFullRenderTransparent(
CMaterial* pMat, const SMP3IntermediateMaterial& Intermediate, uint8 Alpha)
{
STevTracker Tracker;
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::AlphaWrite, false);
CMaterial* pMatNext = new CMaterial(pMat->Version(), pMat->VtxDesc());
pMat->mpNextDrawPassMaterial = pMatNext;
pMat = pMatNext;
pMat->mpNextDrawPassMaterial = std::make_unique<CMaterial>(pMat->Version(), pMat->VtxDesc());
pMat = pMat->mpNextDrawPassMaterial.get();
Tracker = STevTracker();
pMat->mOptions.AssignFlag(EMaterialOption::AlphaWrite, true);
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::ColorWrite, false);
pMatNext = new CMaterial(pMat->Version(), pMat->VtxDesc());
pMat->mpNextDrawPassMaterial = pMatNext;
pMat = pMatNext;
pMat->mpNextDrawPassMaterial = std::make_unique<CMaterial>(pMat->Version(), pMat->VtxDesc());
pMat = pMat->mpNextDrawPassMaterial.get();
Tracker = STevTracker();
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::ColorWrite, true);
}
return pMat;
}
void CMaterialLoader::SetupFullRenderTransparentAdditiveIncandecence(CMaterial* pMat,
const SMP3IntermediateMaterial& Intermediate,
uint8 Alpha)
{
SetupFullRenderTransparent(pMat, Intermediate, Alpha);
CMaterial* pMatNext = new CMaterial(pMat->Version(), pMat->VtxDesc());
pMat->mpNextDrawPassMaterial = pMatNext;
pMat = pMatNext;
pMat = SetupFullRenderTransparent(pMat, Intermediate, Alpha);
pMat->mpNextDrawPassMaterial = std::make_unique<CMaterial>(pMat->Version(), pMat->VtxDesc());
pMat = pMat->mpNextDrawPassMaterial.get();
STevTracker Tracker;
SetupStartingIncandecenceStage(Tracker, pMat, Intermediate);
@ -1473,13 +1471,13 @@ void CMaterialLoader::SetupMaterialAlphaCompare(CMaterial* pMat, const SMP3Inter
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->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha);
pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg);
pPass->SetRasSel(kRasColorNull);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
pMat->mOptions.AssignFlag(EMaterialOption::DepthWrite, false);
pMat->SetBlendMode(GL_ONE, GL_ZERO);
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)
{
CMaterialPass* pPass = new CMaterialPass(pMat);
auto pPass = std::make_unique<CMaterialPass>(pMat);
pMat->SetKonst(Intermediate.GetCLR(ECLR::CLR), 0);
pPass->SetKColorSel(kKonst0_RGB);
pPass->SetKAlphaSel(kKonst0_A);
@ -1497,7 +1495,7 @@ void CMaterialLoader::SetupSolidKColorKAlpha(CMaterial* pMat, const SMP3Intermed
pPass->SetColorOutput(kPrevReg);
pPass->SetAlphaOutput(kPrevReg);
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::Masked, false);
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.
CMaterial *pMat = new CMaterial(mVersion, EVertexAttribute::None);
auto pMat = std::make_unique<CMaterial>(mVersion, EVertexAttribute::None);
aiString Name;
pAiMat->Get(AI_MATKEY_NAME, Name);
pMat->SetName(Name.C_Str());
// 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->SetAlphaInputs(kZeroAlpha, kZeroAlpha, kZeroAlpha, kKonstAlpha);
pPass->SetKColorSel(kKonst0_RGB);
pPass->SetKAlphaSel(kKonstOne);
pPass->SetRasSel(kRasColor0A0);
pMat->mKonstColors[0] = CColor::RandomLightColor(false);
pMat->mPasses.push_back(pPass);
pMat->mPasses.push_back(std::move(pPass));
return pMat;
}
@ -1591,8 +1589,7 @@ CMaterialSet* CMaterialLoader::ImportAssimpMaterials(const aiScene *pScene, EGam
for (uint32 iMat = 0; iMat < pScene->mNumMaterials; iMat++)
{
CMaterial *pMat = Loader.LoadAssimpMaterial(pScene->mMaterials[iMat]);
pOut->mMaterials.push_back(pMat);
pOut->mMaterials.push_back(Loader.LoadAssimpMaterial(pScene->mMaterials[iMat]));
}
return pOut;

View File

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