mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-22 16:39:27 +01:00
Handle character mask R same as other shaders
This commit is contained in:
parent
9ff3227cf4
commit
0e50cc9c47
1 changed files with 16 additions and 17 deletions
|
|
@ -49,7 +49,7 @@ public class MaterialExporter
|
||||||
ParallelRowIterator.IterateRows(ImageSharpConfiguration.Default, normal.Bounds(), in operation);
|
ParallelRowIterator.IterateRows(ImageSharpConfiguration.Default, normal.Bounds(), in operation);
|
||||||
|
|
||||||
// Check if full textures are provided, and merge in if available.
|
// Check if full textures are provided, and merge in if available.
|
||||||
Image baseColor = operation.BaseColor;
|
Image<Rgba32> baseColor = operation.BaseColor;
|
||||||
if (material.Textures.TryGetValue(TextureUsage.SamplerDiffuse, out var diffuse))
|
if (material.Textures.TryGetValue(TextureUsage.SamplerDiffuse, out var diffuse))
|
||||||
{
|
{
|
||||||
MultiplyOperation.Execute(diffuse, operation.BaseColor);
|
MultiplyOperation.Execute(diffuse, operation.BaseColor);
|
||||||
|
|
@ -64,32 +64,31 @@ public class MaterialExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pull further information from the mask.
|
// Pull further information from the mask.
|
||||||
Image? occlusion = null;
|
|
||||||
if (material.Textures.TryGetValue(TextureUsage.SamplerMask, out var maskTexture))
|
if (material.Textures.TryGetValue(TextureUsage.SamplerMask, out var maskTexture))
|
||||||
{
|
{
|
||||||
// Extract the red channel for ambient occlusion.
|
// Extract the red channel for "ambient occlusion".
|
||||||
maskTexture.Mutate(context => context.Filter(new ColorMatrix(
|
maskTexture.Mutate(context => context.Resize(baseColor.Width, baseColor.Height));
|
||||||
1f, 1f, 1f, 0f,
|
maskTexture.ProcessPixelRows(baseColor, (maskAccessor, baseColorAccessor) =>
|
||||||
0f, 0f, 0f, 0f,
|
{
|
||||||
0f, 0f, 0f, 0f,
|
for (int y = 0; y < maskAccessor.Height; y++)
|
||||||
0f, 0f, 0f, 1f,
|
{
|
||||||
0f, 0f, 0f, 0f
|
var maskSpan = maskAccessor.GetRowSpan(y);
|
||||||
)));
|
var baseColorSpan = baseColorAccessor.GetRowSpan(y);
|
||||||
occlusion = maskTexture;
|
|
||||||
|
for (int x = 0; x < maskSpan.Length; x++)
|
||||||
|
baseColorSpan[x].FromVector4(baseColorSpan[x].ToVector4() * new Vector4(maskSpan[x].R / 255f));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// TODO: handle other textures stored in the mask?
|
// TODO: handle other textures stored in the mask?
|
||||||
}
|
}
|
||||||
|
|
||||||
var materialBuilder = BuildSharedBase(material, name)
|
return BuildSharedBase(material, name)
|
||||||
.WithBaseColor(BuildImage(baseColor, name, "basecolor"))
|
.WithBaseColor(BuildImage(baseColor, name, "basecolor"))
|
||||||
.WithNormal(BuildImage(operation.Normal, name, "normal"))
|
.WithNormal(BuildImage(operation.Normal, name, "normal"))
|
||||||
.WithSpecularColor(BuildImage(specular, name, "specular"))
|
.WithSpecularColor(BuildImage(specular, name, "specular"))
|
||||||
.WithEmissive(BuildImage(operation.Emissive, name, "emissive"), Vector3.One, 1);
|
.WithEmissive(BuildImage(operation.Emissive, name, "emissive"), Vector3.One, 1);
|
||||||
|
|
||||||
if (occlusion != null)
|
|
||||||
materialBuilder.WithOcclusion(BuildImage(occlusion, name, "occlusion"));
|
|
||||||
|
|
||||||
return materialBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: It feels a little silly to request the entire normal here when extracting the normal only needs some of the components.
|
// TODO: It feels a little silly to request the entire normal here when extracting the normal only needs some of the components.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue