Skip to content

Commit

Permalink
Working on cleaning up fixed function approach, exporting materials.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Oct 14, 2021
1 parent 34220d2 commit 4fa6efe
Show file tree
Hide file tree
Showing 14 changed files with 401 additions and 367 deletions.
30 changes: 21 additions & 9 deletions FinModelUtility/Bmd2Fbx/src/Exporter/BmdFixedFunctionMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public BmdFixedFunctionMaterial(
// TODO: Need to support registers
// TODO: Need to support multiple vertex colors
// TODO: Colors should just be RGB in the fixed function library
// TODO: Seems like only texture 1 is used, is this accurate?

for (var i = 0; i < materialEntry.TevStageInfo.Length; ++i) {
var tevStageIndex = materialEntry.TevStageInfo[i];
Expand Down Expand Up @@ -248,7 +249,7 @@ public ColorManager(
IFixedFunctionEquations<FixedFunctionSource> equations) {
this.equations_ = equations;

var colorZero = equations.CreateColorConstant(0, 0);
var colorZero = equations.CreateColorConstant(0);
var colorOne = equations.CreateColorConstant(1);

this.colorValues_[TevStage.GxCc.GX_CC_ZERO] = colorZero;
Expand Down Expand Up @@ -309,18 +310,28 @@ private IColorValue GetTextureColorChannel_() {
return this.colorValues_[TevStage.GxCc.GX_CC_TEXC] = texture;
}

private IColorValue GetVertexColorChannel_() {
private IColorValue GetVertexColorChannel_(TevStage.GxCc colorSource) {
var channelOrNull = this.colorChannel_;
Asserts.Nonnull(channelOrNull);

var channel = channelOrNull.Value;

if (!this.colorChannelsColors_.TryGetValue(channel, out var color)) {
var source = channel switch {
TevOrder.ColorChannel.GX_COLOR0A0 => FixedFunctionSource
.VERTEX_COLOR_ALPHA_0,
TevOrder.ColorChannel.GX_COLOR1A1 => FixedFunctionSource
.VERTEX_COLOR_ALPHA_1,
var source = colorSource switch {
TevStage.GxCc.GX_CC_RASC => channel switch {
TevOrder.ColorChannel.GX_COLOR0A0 => FixedFunctionSource
.VERTEX_COLOR_0,
TevOrder.ColorChannel.GX_COLOR1A1 => FixedFunctionSource
.VERTEX_COLOR_1,
_ => throw new NotImplementedException()
},
TevStage.GxCc.GX_CC_RASA => channel switch {
TevOrder.ColorChannel.GX_COLOR0A0 => FixedFunctionSource
.VERTEX_ALPHA_0,
TevOrder.ColorChannel.GX_COLOR1A1 => FixedFunctionSource
.VERTEX_ALPHA_1,
_ => throw new NotImplementedException()
},
_ => throw new NotImplementedException()
};

Expand All @@ -342,8 +353,9 @@ public IColorValue GetColor(TevStage.GxCc colorSource) {
return this.GetTextureColorChannel_();
}

if (colorSource == TevStage.GxCc.GX_CC_RASC) {
return this.GetVertexColorChannel_();
if (colorSource == TevStage.GxCc.GX_CC_RASC ||
colorSource == TevStage.GxCc.GX_CC_RASA) {
return this.GetVertexColorChannel_(colorSource);
}

throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,38 @@ public void TestInOut() {
public void TestColorMath() {
var equations = new FixedFunctionEquations<string>();

var colRgb =
equations.CreateColorInput("colRgb",
var colRgb1 =
equations.CreateColorInput("colRgb1",
equations.CreateColorConstant(1, 2, 3));
var colRgba =
equations.CreateColorInput("colRgba",
equations.CreateColorConstant(1, 2, 3, 4));
var colI =
equations.CreateColorInput("colI",
var colRgb2 =
equations.CreateColorInput("colRgb2",
equations.CreateColorConstant(2, 3, 4));
var colI1 =
equations.CreateColorInput("colI1",
equations.CreateColorConstant(1));
var colIa =
equations.CreateColorInput("colIa",
equations.CreateColorConstant(1, 2));
var colI2 =
equations.CreateColorInput("colI2",
equations.CreateColorConstant(2));

var colOutput =
equations.CreateColorOutput("colOutput",
(colRgb.Add(colRgba)).Divide(
colI.Subtract(colIa)));
(colRgb1.Add(colRgb2)).Divide(
colI1.Subtract(colI2)));

this.AssertEquals_(equations,
"Scalar inputs:",
"",
"Color inputs:",
"colRgb: rgb<1,2,3>",
"colRgba: rgba<1,2,3,4>",
"colI: i<1>",
"colIa: ia<1,2>",
"colRgb1: rgb<1,2,3>",
"colRgb2: rgb<2,3,4>",
"colI1: i<1>",
"colI2: i<2>",
"",
"",
"Scalar outputs:",
"",
"Color outputs:",
"colOutput: (<colRgb> + <colRgba>)/(<colI> + ia<-1,-1>*<colIa>)"
"colOutput: (<colRgb1> + <colRgb2>)/(<colI1> + i<-1>*<colI2>)"
);
}

Expand All @@ -104,24 +104,24 @@ public void TestColorMath() {
public void TestColorSwizzleOut() {
var equations = new FixedFunctionEquations<string>();

var colRgb =
equations.CreateColorInput("colRgb",
var colRgb1 =
equations.CreateColorInput("colRgb1",
equations.CreateColorConstant(1, 2, 3));
var colRgba =
equations.CreateColorInput("colRgba",
equations.CreateColorConstant(1, 2, 3, 4));
var colI =
equations.CreateColorInput("colI",
var colRgb2 =
equations.CreateColorInput("colRgb2",
equations.CreateColorConstant(2, 3, 4));
var colI1 =
equations.CreateColorInput("colI1",
equations.CreateColorConstant(1));
var colIa =
equations.CreateColorInput("colIa",
equations.CreateColorConstant(1, 2));
var colI2 =
equations.CreateColorInput("colI2",
equations.CreateColorConstant(2));

var scR = equations.CreateScalarOutput("scR", colI.R);
var scA = equations.CreateScalarOutput("scA", colRgb.A);
var scR1 = equations.CreateScalarOutput("scR1", colI1.R);
var scR2 = equations.CreateScalarOutput("scR2", colRgb1.R);

var colOutputExp = (colRgb.Add(colRgba)).Divide(
colI.Subtract(colIa));
var colOutputExp = (colRgb1.Add(colRgb2)).Divide(
colI1.Subtract(colI2));
var colOutput =
equations.CreateColorOutput("colOutput",
colOutputExp);
Expand All @@ -133,20 +133,20 @@ public void TestColorSwizzleOut() {
"Scalar inputs:",
"",
"Color inputs:",
"colRgb: rgb<1,2,3>",
"colRgba: rgba<1,2,3,4>",
"colI: i<1>",
"colIa: ia<1,2>",
"colRgb1: rgb<1,2,3>",
"colRgb2: rgb<2,3,4>",
"colI1: i<1>",
"colI2: i<2>",
"",
"",
"Scalar outputs:",
"scR: <colI>.R",
"scA: <colRgb>.A",
"scBExp: (<colRgb>.B + <colRgba>.B)/(<colI>.B + -1*<colIa>.B)",
"scR1: <colI1>.R",
"scR2: <colRgb1>.R",
"scBExp: (<colRgb1>.B + <colRgb2>.B)/(<colI1>.B + -1*<colI2>.B)",
"scBVar: <colOutput>.B",
"",
"Color outputs:",
"colOutput: (<colRgb> + <colRgba>)/(<colI> + ia<-1,-1>*<colIa>)"
"colOutput: (<colRgb1> + <colRgb2>)/(<colI1> + i<-1>*<colI2>)"
);
}

Expand All @@ -155,28 +155,27 @@ public void TestColorSwizzleOut() {
public void TestColorSwizzleIn() {
var equations = new FixedFunctionEquations<string>();

var colRgba =
equations.CreateColorInput("colRgba",
equations.CreateColorConstant(1, 2, 3, 4));
var colArgb =
equations.CreateColorOutput("colArgb",
var colRgb =
equations.CreateColorInput("colRgb",
equations.CreateColorConstant(1, 2, 3));
var colGbr =
equations.CreateColorOutput("colGbr",
equations.CreateColor(
colRgba.A,
colRgba.R,
colRgba.G,
colRgba.B));
colRgb.G,
colRgb.B,
colRgb.R));

this.AssertEquals_(equations,
"Scalar inputs:",
"",
"Color inputs:",
"colRgba: rgba<1,2,3,4>",
"colRgb: rgb<1,2,3>",
"",
"",
"Scalar outputs:",
"",
"Color outputs:",
"colArgb: rgba<<colRgba>.A,<colRgba>.R,<colRgba>.G,<colRgba>.B>"
"colGbr: rgb<<colRgb>.G,<colRgb>.B,<colRgb>.R>"
);
}

Expand Down
Loading

0 comments on commit 4fa6efe

Please sign in to comment.