Skip to content

Commit 08e7ae3

Browse files
committed
- Introduction of Backface Toggle.
- Materials are now updated to proper DX11 mode when their shader is updated.
1 parent 161538e commit 08e7ae3

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

xivModdingFramework/Materials/DataContainers/XivMtrl.cs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ public ShaderInfo GetShaderInfo()
313313

314314
// Check the transparency bit.
315315
const ushort transparencyBit = 16;
316+
const ushort backfaceBit = 1;
316317
var bit = (ushort)(ShaderNumber & transparencyBit);
317318

318319
if(bit > 0)
@@ -323,6 +324,17 @@ public ShaderInfo GetShaderInfo()
323324
info.TransparencyEnabled = false;
324325
}
325326

327+
bit = (ushort)(ShaderNumber & backfaceBit);
328+
329+
if (bit > 0)
330+
{
331+
info.RenderBackfaces = false;
332+
}
333+
else
334+
{
335+
info.RenderBackfaces = true;
336+
}
337+
326338
info.Preset = MtrlShaderPreset.Default;
327339
if (info.Shader == MtrlShader.Standard)
328340
{
@@ -386,6 +398,7 @@ public void SetShaderInfo(ShaderInfo info, bool forced = false)
386398

387399
// Set transparency bit as needed.
388400
const ushort transparencyBit = 16;
401+
const ushort backfaceBit = 1;
389402
var transparency = info.ForcedTransparency == null ? info.TransparencyEnabled : (bool)info.ForcedTransparency;
390403
if (transparency)
391404
{
@@ -396,6 +409,35 @@ public void SetShaderInfo(ShaderInfo info, bool forced = false)
396409
ShaderNumber = (ushort)(ShaderNumber & (~transparencyBit));
397410
}
398411

412+
// Set Backfaces bit.
413+
var backfaces = info.RenderBackfaces;
414+
if (!backfaces)
415+
{
416+
ShaderNumber = (ushort)(ShaderNumber | backfaceBit);
417+
}
418+
else
419+
{
420+
ShaderNumber = (ushort)(ShaderNumber & (~backfaceBit));
421+
}
422+
423+
// Update us to DX11 material style if we're not already.
424+
for (var idx = 0; idx < Unknown2.Length; idx++)
425+
{
426+
if (idx == 0)
427+
{
428+
Unknown2[idx] = 12;
429+
}
430+
else
431+
{
432+
Unknown2[idx] = 0;
433+
}
434+
}
435+
436+
for (var idx = 0; idx < TexturePathUnknownList.Count; idx++)
437+
{
438+
TexturePathUnknownList[idx] = 0;
439+
}
440+
399441

400442
if (forced == false && info.Shader == old.Shader && info.Preset == old.Preset)
401443
{
@@ -474,23 +516,6 @@ public void SetShaderInfo(ShaderInfo info, bool forced = false)
474516
}
475517
}
476518

477-
478-
// Clear out the unknown lists back to known default working values.
479-
for(var idx = 0; idx < TexturePathUnknownList.Count; idx++)
480-
{
481-
TexturePathUnknownList[idx] = 0;
482-
}
483-
484-
for (var idx = 0; idx < Unknown2.Length; idx++)
485-
{
486-
if(idx == 0)
487-
{
488-
Unknown2[idx] = 12;
489-
} else
490-
{
491-
Unknown2[idx] = 0;
492-
}
493-
}
494519
}
495520

496521
/// <summary>
@@ -1444,6 +1469,7 @@ public class ShaderInfo
14441469
public MtrlShader Shader;
14451470
public MtrlShaderPreset Preset;
14461471
public bool TransparencyEnabled;
1472+
public bool RenderBackfaces = false;
14471473
public bool HasColorset
14481474
{
14491475
get

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,15 @@ public byte[] CreateMtrlFile(XivMtrl xivMtrl, IItem item)
690690
foreach (var texPathString in xivMtrl.TexturePathList)
691691
{
692692
xivMtrl.TexturePathOffsetList.Add(stringListBytes.Count);
693-
stringListBytes.AddRange(Encoding.UTF8.GetBytes(texPathString.Replace("--", string.Empty)));
693+
var path = texPathString;
694+
695+
// This is an old style DX9 Material still, make sure to fix it up.
696+
if(xivMtrl.Unknown2[0] != 12)
697+
{
698+
path = path.Replace("--", string.Empty);
699+
}
700+
701+
stringListBytes.AddRange(Encoding.UTF8.GetBytes(path));
694702
stringListBytes.Add(0);
695703
}
696704

0 commit comments

Comments
 (0)