Skip to content

Commit 44bdd22

Browse files
committed
Fixed some issues with TSTLT.
1 parent 32eae12 commit 44bdd22

File tree

5 files changed

+73
-108
lines changed

5 files changed

+73
-108
lines changed

FinModelUtility/Games/MarioArtist/MarioArtist/src/010/tstlt.bt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,8 @@ typedef struct (uint fSegmentOffset) {
470470
//
471471
// This is done for each triplet (meshSegmentedAddress, primitiveDl, vertexDl).
472472

473-
uint primitiveDl[4] <bgcolor=COLOR_OFFSET>;
474-
uint unk7[9];
475-
476-
uint vertexDl[4] <bgcolor=COLOR_OFFSET>;
477-
uint unk8[9];
473+
uint primitiveDl[13] <bgcolor=COLOR_OFFSET>;
474+
uint vertexDl[13] <bgcolor=COLOR_OFFSET>;
478475
} MeshDefinition <bgcolor=COLOR_HEADER>;
479476

480477
FSeek(0xc6c8);

FinModelUtility/Games/MarioArtist/MarioArtist/src/api/ChosenPart0Util.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public static void SetUp(
4747

4848
if (patternParams.Unk1 == 0 && chosenPart0.Id == 0) {
4949
rsp.UvType = N64UvType.STANDARD;
50+
rsp.TexScaleXShort = rsp.TexScaleYShort = 0xffff;
51+
5052
rdp.CombinerCycleParams0 = new CombinerCycleParams {
5153
ColorMuxA = GenericColorMux.G_CCMUX_0,
5254
ColorMuxB = GenericColorMux.G_CCMUX_ENVIRONMENT,
@@ -156,7 +158,9 @@ public static void SetUpTexture(
156158
32,
157159
32,
158160
F3dWrapMode.CLAMP,
159-
F3dWrapMode.CLAMP);
161+
F3dWrapMode.CLAMP,
162+
// TODO: Pretty sure this is right...???
163+
tileDescriptorIndex: 1);
160164
return;
161165
}
162166

@@ -168,7 +172,7 @@ public static void SetUpTexture(
168172
// TODO: I might be stupid, this might be 0x07c0?
169173
scale = GetTexScaleShortFromCommand_(0x07c0);
170174
} else {
171-
rsp.UvType = N64UvType.LINEAR;
175+
rsp.UvType = N64UvType.STANDARD;
172176
scale = GetTexScaleShortFromCommand_(0xffff);
173177
}
174178

@@ -203,7 +207,9 @@ public static void SetUpTexture(
203207
32,
204208
F3dWrapMode.REPEAT,
205209
F3dWrapMode.MIRROR_REPEAT,
206-
scale: scale);
210+
scale: scale,
211+
// TODO: Pretty sure this is right...???
212+
tileDescriptorIndex: 1);
207213
} else {
208214
ushort shift = patternMaterialType switch {
209215
PatternMaterialType.BLEND_2X2
@@ -267,7 +273,9 @@ public static void SetUpTexture(
267273
F3dWrapMode.REPEAT,
268274
F3dWrapMode.REPEAT,
269275
scale: scale,
270-
shift: shift);
276+
shift: shift,
277+
// TODO: Pretty sure this is right...???
278+
tileDescriptorIndex: 1);
271279
}
272280
}
273281

@@ -277,8 +285,6 @@ public static void SetUpOtherModeLAndCombiner(
277285
int someValue) {
278286
// From decomp, at 0x80115d08
279287

280-
// TODO: Implement
281-
282288
var rdp = n64Hardware.Rdp;
283289
var rsp = n64Hardware.Rsp;
284290
var tmem = rdp.Tmem;

FinModelUtility/Games/MarioArtist/MarioArtist/src/api/TstltModelLoader.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Drawing;
22
using System.Numerics;
3-
using System.Xml.Linq;
43

54
using CommunityToolkit.Diagnostics;
65

@@ -26,7 +25,6 @@
2625
using fin.schema.color;
2726
using fin.schema.vector;
2827
using fin.util.enumerables;
29-
using fin.util.linq;
3028
using fin.util.sets;
3129

3230
using marioartist.schema;
@@ -636,8 +634,6 @@ var primitiveVertexDlTuples
636634
skinChosenPart.ChosenColor0);
637635
}
638636

639-
// TODO: It does something here with a hardcoded chosen part
640-
641637
// TODO: Remove this
642638
n64Hardware.Rsp.CullingMode
643639
= GetCullingModeForChosenPartId_(chosenPart0.Id);

FinModelUtility/Games/MarioArtist/MarioArtist/src/schema/talent_studio/MeshDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public sealed partial class MeshDefinition : IBinaryDeserializable {
1515
public uint[] Unk3 { get; } = new uint[3];
1616
public float[] Unk4 { get; } = new float[6];
1717

18-
public uint Unk5 { get; set; }
19-
2018
public uint[] PrimitiveDisplayListSegmentedAddresses { get; } = new uint[13];
2119
public uint[] VertexDisplayListSegmentedAddresses { get; } = new uint[13];
20+
21+
public uint Unk5 { get; set; }
2222
}

FinModelUtility/Libraries/F3dzex2/F3dzex2/model/DlModelBuilder.cs

Lines changed: 57 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ var primLodFrac
362362
equations.CreateColor(environmentAlpha),
363363
GenericColorMux.G_CCMUX_PRIM_LOD_FRAC
364364
=> primLodFrac.Wrap(),
365-
GenericColorMux.G_CCMUX_SCALE => color1,
366-
GenericColorMux.G_CCMUX_K5 => color1,
365+
GenericColorMux.G_CCMUX_SCALE => color1,
366+
GenericColorMux.G_CCMUX_K5 => color1,
367367
_ => throw new ArgumentOutOfRangeException(
368368
nameof(colorMux),
369369
colorMux,
@@ -433,82 +433,10 @@ var primLodFrac
433433
equations.CreateScalarOutput(FixedFunctionSource.OUTPUT_ALPHA,
434434
combinedAlpha);
435435

436-
// TODO: Handle shade case by writing lighting to alpha
437-
438-
// Shamelessly stolen from:
439-
// https://github.com/magcius/noclip.website/blob/main/src/zelview/f3dzex.ts#L135
440-
441-
BlenderPm srcColor, dstColor;
442-
BlenderA srcFactor;
443-
BlenderB dstFactor;
444-
445-
var doBlend = true;
446-
if (rdp.ForceBlending) {
447-
if (cycleParams1 != null) {
448-
srcColor = rdp.P1;
449-
srcFactor = rdp.A1;
450-
dstColor = rdp.M1;
451-
dstFactor = rdp.B1;
452-
} else {
453-
srcColor = rdp.P0;
454-
srcFactor = rdp.A0;
455-
dstColor = rdp.M0;
456-
dstFactor = rdp.B0;
457-
}
458-
} else {
459-
doBlend = cycleParams1 != null;
460-
srcColor = rdp.P0;
461-
srcFactor = rdp.A0;
462-
dstColor = rdp.M0;
463-
dstFactor = rdp.B0;
464-
}
436+
ApplyBlendMode_(n64Hardware, finMaterial);
465437

466438
// TODO: I'm not sure if alpha compare is ever used on the N64
467439
finMaterial.DisableAlphaCompare();
468-
if (!doBlend) {
469-
finMaterial.SetBlending(BlendEquation.ADD,
470-
BlendFactor.ONE,
471-
BlendFactor.ZERO,
472-
LogicOp.UNDEFINED);
473-
}
474-
475-
if (srcFactor == BlenderA.G_BL_0 &&
476-
dstFactor == BlenderB.G_BL_1) {
477-
finMaterial.SetBlending(BlendEquation.ADD,
478-
BlendFactor.ONE,
479-
BlendFactor.ZERO,
480-
LogicOp.UNDEFINED);
481-
} else if (
482-
srcColor == dstColor &&
483-
srcFactor == BlenderA.G_BL_A_IN &&
484-
dstFactor == BlenderB.G_BL_1MA) {
485-
finMaterial.SetBlending(BlendEquation.ADD,
486-
BlendFactor.SRC_ALPHA,
487-
BlendFactor.ONE_MINUS_SRC_ALPHA,
488-
LogicOp.UNDEFINED);
489-
} else {
490-
BlendFactor blendSrcFactor;
491-
if (srcFactor == BlenderA.G_BL_0) {
492-
blendSrcFactor = BlendFactor.ZERO;
493-
} else if
494-
(rdp is {
495-
UseCoverageForAlpha: true,
496-
MultiplyCoverageWithAlpha: false
497-
}) {
498-
// this is technically "coverage", admitting blending on edges
499-
blendSrcFactor = BlendFactor.ONE;
500-
} else {
501-
blendSrcFactor = BlendFactor.SRC_ALPHA;
502-
}
503-
504-
var blendDstFactor =
505-
TranslateBlendParamB_(dstFactor, blendSrcFactor);
506-
507-
finMaterial.SetBlending(BlendEquation.ADD,
508-
blendSrcFactor,
509-
blendDstFactor,
510-
LogicOp.UNDEFINED);
511-
}
512440

513441
// Shamelessly stolen from:
514442
// https://github.com/magcius/noclip.website/blob/main/src/zelview/f3dzex.ts#L109
@@ -529,6 +457,60 @@ var primLodFrac
529457
});
530458
}
531459

460+
private static void ApplyBlendMode_(
461+
IN64Hardware n64Hardware,
462+
IMaterial finMaterial) {
463+
// TODO: What does "FORCE_BL" do?
464+
// TODO: Is it possible to support two-cycle blending, maybe via a shader?
465+
// TODO: Figure out how to better support this
466+
467+
// HACK: Just kind of tries to see if we should do additive blending.
468+
// I have no idea how to properly implement this.
469+
470+
var rdp = n64Hardware.Rdp;
471+
472+
var doAdditiveBlending
473+
= ShouldDoAdditiveBlendingFor_(rdp.P0, rdp.A0, rdp.M0, rdp.B0);
474+
if (rdp.CycleType is CycleType.TWO_CYCLE) {
475+
doAdditiveBlending
476+
|= ShouldDoAdditiveBlendingFor_(rdp.P1, rdp.A1, rdp.M1, rdp.B1);
477+
}
478+
479+
var useCoverageInsteadOfAlpha = rdp is {
480+
UseCoverageForAlpha: true,
481+
MultiplyCoverageWithAlpha: false
482+
};
483+
484+
if (doAdditiveBlending && !useCoverageInsteadOfAlpha) {
485+
finMaterial.SetBlending(
486+
BlendEquation.ADD,
487+
BlendFactor.SRC_ALPHA,
488+
BlendFactor.ONE_MINUS_SRC_ALPHA,
489+
LogicOp.UNDEFINED);
490+
} else {
491+
finMaterial.SetBlending(
492+
BlendEquation.ADD,
493+
BlendFactor.ONE,
494+
BlendFactor.ZERO,
495+
LogicOp.UNDEFINED);
496+
}
497+
}
498+
499+
private static bool ShouldDoAdditiveBlendingFor_(
500+
BlenderPm p,
501+
BlenderA a,
502+
BlenderPm m,
503+
BlenderB b) {
504+
if (p is BlenderPm.G_BL_CLR_IN &&
505+
m is BlenderPm.G_BL_CLR_MEM &&
506+
a is BlenderA.G_BL_A_IN &&
507+
b is BlenderB.G_BL_1MA or BlenderB.G_BL_A_MEM) {
508+
return true;
509+
}
510+
511+
return false;
512+
}
513+
532514
public ModelImpl<Normal1Color2UvVertexImpl> Model { get; }
533515

534516
public IMesh StartNewMesh(string name) {
@@ -843,22 +825,6 @@ private IReadOnlyMaterial GetOrCreateMaterial_() {
843825
return this.cachedMaterial_;
844826
}
845827

846-
private static BlendFactor TranslateBlendParamB_(
847-
BlenderB paramB,
848-
BlendFactor srcParam) {
849-
return paramB switch {
850-
BlenderB.G_BL_1MA => srcParam switch {
851-
BlendFactor.SRC_ALPHA => BlendFactor.ONE_MINUS_SRC_ALPHA,
852-
BlendFactor.ONE => BlendFactor.ZERO,
853-
_ => BlendFactor.ONE
854-
},
855-
BlenderB.G_BL_A_MEM => BlendFactor.DST_ALPHA,
856-
BlenderB.G_BL_1 => BlendFactor.ONE,
857-
BlenderB.G_BL_0 => BlendFactor.ZERO,
858-
_ => throw new ArgumentOutOfRangeException(nameof(paramB), paramB, null)
859-
};
860-
}
861-
862828
public Color OverrideVertexColor {
863829
get => this.vertices_.OverrideVertexColor;
864830
set => this.vertices_.OverrideVertexColor = value;

0 commit comments

Comments
 (0)