mirror of https://github.com/AxioDL/metaforce.git
Add fallback for diffuse expression
This commit is contained in:
parent
a9254f6643
commit
8e8ecaf4aa
|
@ -44,7 +44,8 @@ struct ProgrammableCommon : IBackend {
|
||||||
private:
|
private:
|
||||||
unsigned addTexCoordGen(TexGenSrc src, int uvIdx, int mtx, bool normalize);
|
unsigned addTexCoordGen(TexGenSrc src, int uvIdx, int mtx, bool normalize);
|
||||||
unsigned addTexSampling(unsigned mapIdx, unsigned tcgIdx);
|
unsigned addTexSampling(unsigned mapIdx, unsigned tcgIdx);
|
||||||
std::string RecursiveTraceDiffuseColor(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, bool toSwizzle);
|
std::string RecursiveTraceDiffuseColor(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, bool toSwizzle,
|
||||||
|
bool fallback);
|
||||||
std::string RecursiveTraceColor(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, bool toSwizzle);
|
std::string RecursiveTraceColor(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, bool toSwizzle);
|
||||||
std::string RecursiveTraceAlpha(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, bool toSwizzle);
|
std::string RecursiveTraceAlpha(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, bool toSwizzle);
|
||||||
unsigned RecursiveTraceTexGen(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, int mtx, bool normalize);
|
unsigned RecursiveTraceTexGen(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, int mtx, bool normalize);
|
||||||
|
|
|
@ -96,13 +96,15 @@ unsigned ProgrammableCommon::RecursiveTraceTexGen(const IR& ir, Diagnostics& dia
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ProgrammableCommon::RecursiveTraceDiffuseColor(const IR& ir, Diagnostics& diag, const IR::Instruction& inst,
|
std::string ProgrammableCommon::RecursiveTraceDiffuseColor(const IR& ir, Diagnostics& diag, const IR::Instruction& inst,
|
||||||
bool toSwizzle) {
|
bool toSwizzle, bool fallback) {
|
||||||
switch (inst.m_op) {
|
switch (inst.m_op) {
|
||||||
case IR::OpType::Call: {
|
case IR::OpType::Call: {
|
||||||
const std::string& name = inst.m_call.m_name;
|
const std::string& name = inst.m_call.m_name;
|
||||||
bool normalize = false;
|
bool normalize = false;
|
||||||
if (!name.compare("TextureD") ||
|
if (!name.compare("TextureD") ||
|
||||||
((normalize = true) && !name.compare("TextureDN"))) {
|
(fallback && !name.compare("Texture")) ||
|
||||||
|
((normalize = true) && !name.compare("TextureDN")) ||
|
||||||
|
((normalize = true) && fallback && !name.compare("TextureN"))) {
|
||||||
if (inst.getChildCount() < 2)
|
if (inst.getChildCount() < 2)
|
||||||
diag.reportBackendErr(inst.m_loc, "Texture(map, texgen) requires 2 arguments");
|
diag.reportBackendErr(inst.m_loc, "Texture(map, texgen) requires 2 arguments");
|
||||||
|
|
||||||
|
@ -125,13 +127,13 @@ std::string ProgrammableCommon::RecursiveTraceDiffuseColor(const IR& ir, Diagnos
|
||||||
case IR::OpType::Arithmetic: {
|
case IR::OpType::Arithmetic: {
|
||||||
const IR::Instruction& aInst = inst.getChildInst(ir, 0);
|
const IR::Instruction& aInst = inst.getChildInst(ir, 0);
|
||||||
const IR::Instruction& bInst = inst.getChildInst(ir, 1);
|
const IR::Instruction& bInst = inst.getChildInst(ir, 1);
|
||||||
std::string aTrace = RecursiveTraceDiffuseColor(ir, diag, aInst, false);
|
std::string aTrace = RecursiveTraceDiffuseColor(ir, diag, aInst, false, fallback);
|
||||||
std::string bTrace = RecursiveTraceDiffuseColor(ir, diag, bInst, false);
|
std::string bTrace = RecursiveTraceDiffuseColor(ir, diag, bInst, false, fallback);
|
||||||
return (!aTrace.empty()) ? aTrace : bTrace;
|
return (!aTrace.empty()) ? aTrace : bTrace;
|
||||||
}
|
}
|
||||||
case IR::OpType::Swizzle: {
|
case IR::OpType::Swizzle: {
|
||||||
const IR::Instruction& aInst = inst.getChildInst(ir, 0);
|
const IR::Instruction& aInst = inst.getChildInst(ir, 0);
|
||||||
std::string aTrace = RecursiveTraceDiffuseColor(ir, diag, aInst, true);
|
std::string aTrace = RecursiveTraceDiffuseColor(ir, diag, aInst, true, fallback);
|
||||||
if (!aTrace.empty())
|
if (!aTrace.empty())
|
||||||
return EmitSwizzle3(diag, inst.m_loc, aTrace, inst.m_swizzle.m_idxs);
|
return EmitSwizzle3(diag, inst.m_loc, aTrace, inst.m_swizzle.m_idxs);
|
||||||
return std::string();
|
return std::string();
|
||||||
|
@ -327,7 +329,9 @@ void ProgrammableCommon::reset(const IR& ir, Diagnostics& diag, const char* back
|
||||||
|
|
||||||
/* Follow Color Chain */
|
/* Follow Color Chain */
|
||||||
const IR::Instruction& colorRoot = ir.m_instructions.at(rootCall.m_call.m_argInstIdxs.at(0));
|
const IR::Instruction& colorRoot = ir.m_instructions.at(rootCall.m_call.m_argInstIdxs.at(0));
|
||||||
m_diffuseColorExpr = RecursiveTraceDiffuseColor(ir, diag, colorRoot, false);
|
m_diffuseColorExpr = RecursiveTraceDiffuseColor(ir, diag, colorRoot, false, false);
|
||||||
|
if (m_diffuseColorExpr.empty())
|
||||||
|
m_diffuseColorExpr = RecursiveTraceDiffuseColor(ir, diag, colorRoot, false, true);
|
||||||
m_colorExpr = RecursiveTraceColor(ir, diag, colorRoot, false);
|
m_colorExpr = RecursiveTraceColor(ir, diag, colorRoot, false);
|
||||||
|
|
||||||
/* Follow Alpha Chain */
|
/* Follow Alpha Chain */
|
||||||
|
|
Loading…
Reference in New Issue