Skip to content

Commit cf3c84e

Browse files
committed
Disable alpha premultiplication during resizing of the normal map so that the RGB values for colourset row 0 don't get wiped
1 parent 2d073a1 commit cf3c84e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

xivModdingFramework/Models/ModelTextures/ModelTexture.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,18 @@ await Task.Run(() =>
414414
using (var img = Image.LoadPixelData<Rgba32>(texMapData.Normal.Data, texMapData.Normal.Width,
415415
texMapData.Normal.Height))
416416
{
417-
img.Mutate(x => x.Resize(width, height));
417+
// ImageSharp pre-multiplies the RGB by the alpha component during resize, if alpha is 0 (colourset row 0)
418+
// this ends up causing issues and destroying the RGB values resulting in an invisible preview model
419+
// https://github.com/SixLabors/ImageSharp/issues/1498#issuecomment-757519563
420+
img.Mutate(x => x.Resize(
421+
new ResizeOptions
422+
{
423+
Size = new Size(width, height),
424+
PremultiplyAlpha = false
425+
})
426+
);
418427

419-
texMapData.Normal.Data = MemoryMarshal.AsBytes(img.GetPixelSpan()).ToArray();
428+
texMapData.Normal.Data = MemoryMarshal.AsBytes(img.GetPixelMemoryGroup()[0].Span).ToArray();
420429
}
421430
}
422431

@@ -436,7 +445,7 @@ await Task.Run(() =>
436445
}
437446
img.Mutate(x => x.Resize(width, height));
438447

439-
texMapData.Diffuse.Data = MemoryMarshal.AsBytes(img.GetPixelSpan()).ToArray();
448+
texMapData.Diffuse.Data = MemoryMarshal.AsBytes(img.GetPixelMemoryGroup()[0].Span).ToArray();
440449
}
441450
}
442451

@@ -448,7 +457,7 @@ await Task.Run(() =>
448457
{
449458
img.Mutate(x => x.Resize(width, height));
450459

451-
texMapData.Specular.Data = MemoryMarshal.AsBytes(img.GetPixelSpan()).ToArray();
460+
texMapData.Specular.Data = MemoryMarshal.AsBytes(img.GetPixelMemoryGroup()[0].Span).ToArray();
452461
}
453462
}
454463
});

xivModdingFramework/xivModdingFramework.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
2929
<PackageReference Include="SharpDX" Version="4.2.0" />
3030
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
31-
<PackageReference Include="System.Buffers" Version="4.5.0" />
32-
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
31+
<PackageReference Include="System.Buffers" Version="4.5.1" />
32+
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
3333
<PackageReference Include="System.Data.SQLite" Version="1.0.113.1" />
3434
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
3535
<PackageReference Include="TeximpNet" Version="1.4.1" />

0 commit comments

Comments
 (0)