Skip to content

Commit

Permalink
Fixed the Dat fixed function logic by cross-referencing the flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Oct 27, 2023
1 parent a83db84 commit 0b28280
Showing 1 changed file with 46 additions and 23 deletions.
69 changes: 46 additions & 23 deletions FinModelUtility/Formats/Dat/src/api/DatModelImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using fin.model.impl;
using fin.model.io.importers;
using fin.shaders.glsl;
using fin.util.enums;
using fin.util.hex;

using gx;
Expand Down Expand Up @@ -200,30 +201,52 @@ private void PopulateFixedFunctionMaterial_(
FixedFunctionSource.TEXTURE_ALPHA_0);
}

var renderMode = mObj.RenderMode;
var material = mObj.Material;
var diffuseRgba = material.DiffuseColor;
var diffuseColor =
colorOps.Multiply(
equations.CreateOrGetColorInput(
FixedFunctionSource.LIGHT_0_COLOR),
equations.CreateColorConstant(diffuseRgba.Rf,
diffuseRgba.Gf,
diffuseRgba.Bf));

var ambientRgba = material.AmbientColor;
var ambientColor =
equations.CreateColorConstant(ambientRgba.Rf,
ambientRgba.Gf,
ambientRgba.Bf);

var lightColor = colorOps.Add(ambientColor, diffuseColor);

var outputColor = colorOps.Multiply(textureColor, vertexColor);
outputColor = colorOps.Multiply(outputColor, lightColor);

var outputAlpha = scalarOps.Multiply(textureAlpha, vertexAlpha);
outputAlpha = scalarOps.MultiplyWithConstant(outputAlpha, diffuseRgba.Af);
outputAlpha = scalarOps.MultiplyWithConstant(outputAlpha, material.Alpha);

var outputColor = textureColor;

if (renderMode.CheckFlag(RenderMode.VERTEX)) {
outputColor = colorOps.Multiply(outputColor, vertexColor);
}

// TODO: Is this right??
if (renderMode.CheckFlag(RenderMode.DIFFUSE)) {
var ambientRgba = material.AmbientColor;
var ambientColor =
equations.CreateColorConstant(ambientRgba.Rf,
ambientRgba.Gf,
ambientRgba.Bf);
var diffuseRgba = material.DiffuseColor;
var diffuseColor =
colorOps.Multiply(
equations.CreateOrGetColorInput(
FixedFunctionSource.LIGHT_0_COLOR),
equations.CreateColorConstant(diffuseRgba.Rf,
diffuseRgba.Gf,
diffuseRgba.Bf));

var lightColor = colorOps.Add(ambientColor, diffuseColor);
outputColor = colorOps.Multiply(outputColor, lightColor);
} else if (renderMode.CheckFlag(RenderMode.CONSTANT)) {
var diffuseRgba = material.DiffuseColor;
var diffuseColor = equations.CreateColorConstant(diffuseRgba.Rf,
diffuseRgba.Gf,
diffuseRgba.Bf);

outputColor = colorOps.Multiply(outputColor, diffuseColor);
}

var outputAlpha = textureAlpha;
if (renderMode.CheckFlag(RenderMode.ALPHA_VTX)) {
outputAlpha = scalarOps.Multiply(outputAlpha, vertexAlpha);
}

if (renderMode.CheckFlag(RenderMode.ALPHA_MAT)) {
outputAlpha =
scalarOps.MultiplyWithConstant(outputAlpha, material.Alpha);
}


equations.CreateColorOutput(FixedFunctionSource.OUTPUT_COLOR,
outputColor ?? colorOps.Zero);
Expand Down

0 comments on commit 0b28280

Please sign in to comment.