Skip to content

Adjusted GetShaderMapper call to use colors parameter (Fixes #97) #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions xivModdingFramework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ VisualStudioVersion = 15.0.27428.2015
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "xivModdingFramework", "xivModdingFramework\xivModdingFramework.csproj", "{83A720A7-A039-4FE3-BE65-95146CF5C6F3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xivModdingFramework.xUnit", "xivModdingFramework.xUnit\xivModdingFramework.xUnit.csproj", "{4214BC4D-2FAD-4C9A-9F60-06A3EB22820D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "exChecker", "exChecker\exChecker.csproj", "{D174095D-1B25-471A-B443-83D69E0A3173}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
1 change: 1 addition & 0 deletions xivModdingFramework/Exd/Enums/XivEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ public enum XivEx
recipe,
recipeelement,
recipeleveltable,
recipelookup,
recipenotebooklist,
recommendcontents,
relic,
Expand Down
2 changes: 1 addition & 1 deletion xivModdingFramework/Materials/DataContainers/XivMtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public EShaderPack ShaderPack
/// <summary>
/// The list of half floats containing the ColorSet data
/// </summary>
public List<Half> ColorSetData { get; set; } = new List<Half>(new Half[1024]);
public List<SharpDX.Half> ColorSetData { get; set; } = new List<SharpDX.Half>(new SharpDX.Half[1024]);
/// <summary>
/// The byte array containing the extra ColorSet data
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions xivModdingFramework/Materials/FileTypes/Mtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static XivMtrl GetXivMtrl(byte[] bytes, string internalMtrlPath = "")

xivMtrl.AdditionalData = br.ReadBytes(additionalDataSize);

xivMtrl.ColorSetData = new List<Half>();
xivMtrl.ColorSetData = new List<SharpDX.Half>();
xivMtrl.ColorSetDyeData = new byte[0];

if (colorSetDataSize > 0)
Expand All @@ -273,7 +273,7 @@ public static XivMtrl GetXivMtrl(byte[] bytes, string internalMtrlPath = "")

for (var i = 0; i < colorDataSize / 2; i++)
{
xivMtrl.ColorSetData.Add(new Half(br.ReadUInt16()));
xivMtrl.ColorSetData.Add(new SharpDX.Half(br.ReadUInt16()));
}

// If the color set is 544 (DT: 2080) in length, it has an extra 32 bytes at the end
Expand Down
32 changes: 16 additions & 16 deletions xivModdingFramework/Materials/FileTypes/STM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,30 @@ public class StainingTemplateEntry
{
// Data Entries, in the format of
// [Data Offset] => [Dye Id] = Dye values
public readonly List<List<Half[]>> Entries = new List<List<Half[]>>();
public readonly List<List<SharpDX.Half[]>> Entries = new List<List<SharpDX.Half[]>>();

public Half[] GetDiffuseData(int dyeId = 0)
public SharpDX.Half[] GetDiffuseData(int dyeId = 0)
{
return GetData(0, dyeId);
}
public Half[] GetSpecularData(int dyeId = 0)
public SharpDX.Half[] GetSpecularData(int dyeId = 0)
{
return GetData(1, dyeId);
}
public Half[] GetEmissiveData(int dyeId = 0)
public SharpDX.Half[] GetEmissiveData(int dyeId = 0)
{
return GetData(2, dyeId);
}
public Half[] GetSpecularPowerData(int dyeId = 0)
public SharpDX.Half[] GetSpecularPowerData(int dyeId = 0)
{
return GetData(3, dyeId);
}
public Half[] GetGlossData(int dyeId = 0)
public SharpDX.Half[] GetGlossData(int dyeId = 0)
{
return GetData(4, dyeId);
}

public Half[] GetData(int offset, int dyeId = 0)
public SharpDX.Half[] GetData(int offset, int dyeId = 0)
{
if(offset >= Entries.Count)
{
Expand Down Expand Up @@ -225,7 +225,7 @@ public StainingTemplateEntry(byte[] data, int offset, EStainingTemplate template
var lastOffset = 0;
for (int x = 0; x < _ItemCount; x++)
{
Entries.Add(new List<Half[]>());
Entries.Add(new List<SharpDX.Half[]>());
var elementSize = 1;
if(x < 3)
{
Expand Down Expand Up @@ -265,28 +265,28 @@ public StainingTemplateEntry(byte[] data, int offset, EStainingTemplate template
var arrayStart = lastOffset;
var offsetStart = (start + headerSize + (arrayStart * 2));

List<Half[]> halfData = new List<Half[]>();
List<SharpDX.Half[]> halfData = new List<SharpDX.Half[]>();

for (int i = 0; i < arraySize; i++)
{

Half[] halfs = new Half[elementSize];
SharpDX.Half[] halfs = new SharpDX.Half[elementSize];

var elementStart = offsetStart + ((i * 2) * elementSize);

halfs[0] = new Half(BitConverter.ToUInt16(data, elementStart));
halfs[0] = new SharpDX.Half(BitConverter.ToUInt16(data, elementStart));
if (elementSize > 1)
{
halfs[1] = new Half(BitConverter.ToUInt16(data, elementStart + 2));
halfs[2] = new Half(BitConverter.ToUInt16(data, elementStart + 4));
halfs[1] = new SharpDX.Half(BitConverter.ToUInt16(data, elementStart + 2));
halfs[2] = new SharpDX.Half(BitConverter.ToUInt16(data, elementStart + 4));
}

halfData.Add(halfs);
}

if(type == StainingTemplateArrayType.Indexed)
{
var nArray = new List<Half[]>();
var nArray = new List<SharpDX.Half[]>();
// The first entry in the list is an 0xFF byte that we skip
// Since that would leave us with one less value than we need, as dummy value is added for the last dye
for (int i = 1; i < numDyes + 1; i++)
Expand All @@ -298,11 +298,11 @@ public StainingTemplateEntry(byte[] data, int offset, EStainingTemplate template
{
if (x < 3)
{
nArray.Add(new Half[] { new Half(), new Half(), new Half() });
nArray.Add(new SharpDX.Half[] { new SharpDX.Half(), new SharpDX.Half(), new SharpDX.Half() });
}
else
{
nArray.Add(new Half[] { new Half() });
nArray.Add(new SharpDX.Half[] { new SharpDX.Half() });
}
continue;
}
Expand Down
28 changes: 14 additions & 14 deletions xivModdingFramework/Models/FileTypes/Mdl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static class Mdl
// Simple internal use hashable pair of Halfs.
private struct HalfUV
{
public HalfUV(Half _x, Half _y)
public HalfUV(SharpDX.Half _x, SharpDX.Half _y)
{
x = _x;
y = _y;
Expand All @@ -101,8 +101,8 @@ public HalfUV(float _x, float _y)
y = _y;
}

public Half x;
public Half y;
public SharpDX.Half x;
public SharpDX.Half y;

public override int GetHashCode()
{
Expand Down Expand Up @@ -4120,20 +4120,20 @@ private static bool WriteVectorData(List<byte> buffer, Dictionary<VertexUsageTyp

private static bool WriteVectorData(List<byte> buffer, VertexDataType dataType, Vector3 data, bool handedness = true, int wDefault = 0)
{
Half hx, hy, hz;
SharpDX.Half hx, hy, hz;

if (dataType == VertexDataType.Half4)
{
hx = new Half(data[0]);
hy = new Half(data[1]);
hz = new Half(data[2]);
hx = new SharpDX.Half(data[0]);
hy = new SharpDX.Half(data[1]);
hz = new SharpDX.Half(data[2]);

buffer.AddRange(BitConverter.GetBytes(hx.RawValue));
buffer.AddRange(BitConverter.GetBytes(hy.RawValue));
buffer.AddRange(BitConverter.GetBytes(hz.RawValue));

// Half float positions have a W coordinate that is typically defaulted to either 0 (position data) or 1 (normal data).
var w = new Half(wDefault);
var w = new SharpDX.Half(wDefault);
buffer.AddRange(BitConverter.GetBytes(w.RawValue));

}
Expand Down Expand Up @@ -4248,12 +4248,12 @@ private static int WriteVertex(VertexByteData importData, Dictionary<VertexUsage
}
} else if (texCoordDataType == VertexDataType.Half2 || texCoordDataType == VertexDataType.Half4)
{
importData.VertexData1.AddRange(BitConverter.GetBytes(((Half)v.UV1[0]).RawValue));
importData.VertexData1.AddRange(BitConverter.GetBytes(((Half)v.UV1[1]).RawValue));
importData.VertexData1.AddRange(BitConverter.GetBytes(((SharpDX.Half)v.UV1[0]).RawValue));
importData.VertexData1.AddRange(BitConverter.GetBytes(((SharpDX.Half)v.UV1[1]).RawValue));
if (texCoordDataType == VertexDataType.Half4)
{
importData.VertexData1.AddRange(BitConverter.GetBytes(((Half)v.UV2[0]).RawValue));
importData.VertexData1.AddRange(BitConverter.GetBytes(((Half)v.UV2[1]).RawValue));
importData.VertexData1.AddRange(BitConverter.GetBytes(((SharpDX.Half)v.UV2[0]).RawValue));
importData.VertexData1.AddRange(BitConverter.GetBytes(((SharpDX.Half)v.UV2[1]).RawValue));
}
}
}
Expand All @@ -4268,8 +4268,8 @@ private static int WriteVertex(VertexByteData importData, Dictionary<VertexUsage
}
else if (texCoordDataType == VertexDataType.Half2)
{
importData.VertexData1.AddRange(BitConverter.GetBytes(((Half)v.UV3[0]).RawValue));
importData.VertexData1.AddRange(BitConverter.GetBytes(((Half)v.UV3[1]).RawValue));
importData.VertexData1.AddRange(BitConverter.GetBytes(((SharpDX.Half)v.UV3[0]).RawValue));
importData.VertexData1.AddRange(BitConverter.GetBytes(((SharpDX.Half)v.UV3[1]).RawValue));
}
}

Expand Down
19 changes: 12 additions & 7 deletions xivModdingFramework/Models/ModelTextures/ModelTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class CustomModelColors : ICloneable
public Color EyeColor; // Off eye color customization isn't really sanely doable since it's managed by Vertex Color.
public Color LipColor;
public Color HairColor;
public Color LightColor;

// Also known as Limbal Color or Etc. Color. Just depends on race.
// Most have tattoo color, so that's the default name.
Expand Down Expand Up @@ -89,6 +90,7 @@ public CustomModelColors()
EyeColor = new Color(172, 113, 159, 255);
LipColor = new Color(139, 55, 46, 153);
HairColor = new Color(110, 77, 35, 255);
LightColor = new Color(0, 0, 0, 255);
HairHighlightColor = new Color(91, 110, 129, 255);
TattooColor = new Color(48, 112, 102, 255);
FurnitureColor = new Color(141, 60, 204, 255);
Expand Down Expand Up @@ -284,7 +286,7 @@ public static async Task<ModelTextureData> GetModelMaps(XivMtrl mtrl, bool pbrMa


var dataLength = normalPixels != null ? normalPixels.Length : diffusePixels.Length;
var shaderFn = GetShaderMapper(GetCustomColors(), mtrl, settings);
var shaderFn = GetShaderMapper(colors, mtrl, settings);
bool invertNormalGreen = colors.InvertNormalGreen;

await Task.Run(() =>
Expand Down Expand Up @@ -647,7 +649,7 @@ private static ShaderMapperDelegate GetShaderMapper(CustomModelColors colors, Xi
specularColorMul *= specularColorMul;
emissiveColorMul *= emissiveColorMul;

List<Half> colorset = null;
List<SharpDX.Half> colorset = null;
if(mtrl.ColorSetData != null && mtrl.ColorSetData.Count >= 1024)
{
// Clone the list in case the data is accessed or changed while we're working.
Expand Down Expand Up @@ -920,6 +922,7 @@ private static ShaderMapperDelegate GetShaderMapper(CustomModelColors colors, Xi
{
var hairColor = (Color4)colors.HairColor;
var bonusColor = GetHairBonusColor(mtrl, colors, colors.HairHighlightColor != null ? colors.HairHighlightColor.Value : colors.HairColor);
var lightColor = SrgbToLinear(new Color4(1, 0, 1, 1));

//bonusColor = SrgbToLinear(bonusColor);

Expand All @@ -928,13 +931,15 @@ private static ShaderMapperDelegate GetShaderMapper(CustomModelColors colors, Xi
var metalness = 0.0f;
var occlusion = 1.0f;
float bonusInfluence = normal.Blue;
float lightInfluence = (float)Math.Pow(mask.Red, 4.25f);


//Console.WriteLine($"light influence: {lightInfluence}");

roughness = mask.Green;
var specular = new Color4(mask.Red, mask.Red, mask.Red, 1.0f);

diffuse = Color4.Lerp(hairColor, bonusColor, bonusInfluence);
var baseHairColor = Color4.Lerp(hairColor, bonusColor, bonusInfluence);
diffuse = Color4.Lerp(baseHairColor, colors.LightColor, lightInfluence);
diffuse *= diffuseColorMul;

occlusion = (mask.Alpha * mask.Alpha);
Expand Down Expand Up @@ -1336,7 +1341,7 @@ private static (Color4? Color, bool Blend) GetSkinBonusColor2(XivMtrl mtrl, Cust
/// <param name="colorsetData"></param>
/// <param name="rowNumber"></param>
/// <returns></returns>
public static Half[] GetColorsetRow(List<Half> colorsetData, float indexRed, float indexGreen, bool visualizeOnly = false, int highlightRow = -1)
public static SharpDX.Half[] GetColorsetRow(List<SharpDX.Half> colorsetData, float indexRed, float indexGreen, bool visualizeOnly = false, int highlightRow = -1)
{
if(colorsetData == null || colorsetData.Count == 0) {
return null;
Expand Down Expand Up @@ -1365,7 +1370,7 @@ public static Half[] GetColorsetRow(List<Half> colorsetData, float indexRed, flo
}


var rowData = new Half[_RowSize];
var rowData = new SharpDX.Half[_RowSize];
if (visualizeOnly)
{
for(int i = 0; i < 3; i++) {
Expand Down Expand Up @@ -1430,7 +1435,7 @@ public static Half[] GetColorsetRow(List<Half> colorsetData, float indexRed, flo


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Half LerpHalf(Half a, Half b, float f)
public static SharpDX.Half LerpHalf(SharpDX.Half a, SharpDX.Half b, float f)
{
return a * (1.0f - f) + (b * f);
}
Expand Down
6 changes: 3 additions & 3 deletions xivModdingFramework/Mods/EndwalkerUpgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ private static async Task<Dictionary<string, UpgradeInfo>> UpdateEndwalkerColors
}

// Update Colorset
List<Half> newData = new List<Half>(1024);
List<SharpDX.Half> newData = new List<SharpDX.Half>(1024);

for (int i = 0; i < 32; i++)
{
Expand Down Expand Up @@ -1226,9 +1226,9 @@ private static async Task UpdateEndwalkerHairTextures(string normalPath, string
}
}

public static Half[] GetDefaultColorsetRow(EShaderPack pack)
public static SharpDX.Half[] GetDefaultColorsetRow(EShaderPack pack)
{
var row = new Half[32];
var row = new SharpDX.Half[32];

// Diffuse pixel base
for (int i = 0; i < 8; i++)
Expand Down
2 changes: 1 addition & 1 deletion xivModdingFramework/Mods/FileTypes/TTMP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ public static UpgradesNeeded DoesModpackNeedFix(string version)
string[] parts = version.Split('.');
int.TryParse(parts[0], out major);
if (parts.Length > 1)
int.TryParse(new(parts[1].TakeWhile(char.IsDigit).ToArray()), out minor);
int.TryParse(new string(parts[1].TakeWhile(char.IsDigit).ToArray()), out minor);
if (major < 2)
return UpgradesNeeded.NeedsTexFix | UpgradesNeeded.NeedsMdlFix;
if (major == 2 && minor == 0)
Expand Down
6 changes: 4 additions & 2 deletions xivModdingFramework/Mods/WizardData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public static string WriteImage(string currentPath, string tempFolder, string ne
Directory.CreateDirectory(dir);

using var fs = File.OpenWrite(fName);
var enc = new PngEncoder();
enc.BitDepth = PngBitDepth.Bit16;
var enc = new PngEncoder
{
BitDepth = PngBitDepth.Bit16
};
img.Save(fs, enc);

return path;
Expand Down
6 changes: 3 additions & 3 deletions xivModdingFramework/Resources/XivStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions xivModdingFramework/SqPack/DataContainers/IndexFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public IndexFile(XivDataFile dataFile, BinaryReader index1Stream, BinaryReader i
public virtual void Save() {

var dir = XivCache.GameInfo.GameDirectory;
var index1Path = XivDataFiles.GetFullPath(DataFile, Index.IndexExtension);
var index2Path = XivDataFiles.GetFullPath(DataFile, Index.Index2Extension);
var index1Path = XivDataFiles.GetFullPath(DataFile, xivModdingFramework.SqPack.FileTypes.Index.IndexExtension);
var index2Path = XivDataFiles.GetFullPath(DataFile, xivModdingFramework.SqPack.FileTypes.Index.Index2Extension);
using (var index1Stream = new BinaryWriter(File.Open(index1Path, FileMode.OpenOrCreate, FileAccess.Write)))
{
using (var index2Stream = new BinaryWriter(File.Open(index2Path, FileMode.OpenOrCreate, FileAccess.Write)))
Expand Down
Loading