From e9628afaf84ac8afc24eaeddc5a92f12c00e3f2f Mon Sep 17 00:00:00 2001 From: ackwell Date: Sat, 27 Jan 2024 18:35:26 +1100 Subject: [PATCH] Include specular factor in character material export --- .../Import/Models/Export/MaterialExporter.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Penumbra/Import/Models/Export/MaterialExporter.cs b/Penumbra/Import/Models/Export/MaterialExporter.cs index 307e9d2b..cb2cf6f5 100644 --- a/Penumbra/Import/Models/Export/MaterialExporter.cs +++ b/Penumbra/Import/Models/Export/MaterialExporter.cs @@ -89,11 +89,15 @@ public class MaterialExporter // TODO: handle other textures stored in the mask? } + // Specular extension puts colour on RGB and factor on A. We're already packing like that, so we can reuse the texture. + var specularImage = BuildImage(specular, name, "specular"); + return BuildSharedBase(material, name) .WithBaseColor(BuildImage(baseColor, name, "basecolor")) .WithNormal(BuildImage(operation.Normal, name, "normal")) - .WithSpecularColor(BuildImage(specular, name, "specular")) - .WithEmissive(BuildImage(operation.Emissive, name, "emissive"), Vector3.One, 1); + .WithEmissive(BuildImage(operation.Emissive, name, "emissive"), Vector3.One, 1) + .WithSpecularFactor(specularImage, 1) + .WithSpecularColor(specularImage); } // TODO: It feels a little silly to request the entire normal here when extracting the normal only needs some of the components. @@ -102,7 +106,7 @@ public class MaterialExporter { public Image Normal { get; } = normal.Clone(); public Image BaseColor { get; } = new(normal.Width, normal.Height); - public Image Specular { get; } = new(normal.Width, normal.Height); + public Image Specular { get; } = new(normal.Width, normal.Height); public Image Emissive { get; } = new(normal.Width, normal.Height); private Buffer2D NormalBuffer @@ -111,7 +115,7 @@ public class MaterialExporter private Buffer2D BaseColorBuffer => BaseColor.Frames.RootFrame.PixelBuffer; - private Buffer2D SpecularBuffer + private Buffer2D SpecularBuffer => Specular.Frames.RootFrame.PixelBuffer; private Buffer2D EmissiveBuffer @@ -140,7 +144,9 @@ public class MaterialExporter // Specular (table) var lerpedSpecularColor = Vector3.Lerp(prevRow.Specular, nextRow.Specular, tableRow.Weight); - specularSpan[x].FromVector4(new Vector4(lerpedSpecularColor, 1)); + // float.Lerp is .NET8 ;-; + var lerpedSpecularFactor = prevRow.SpecularStrength * (1.0f - tableRow.Weight) + nextRow.SpecularStrength * tableRow.Weight; + specularSpan[x].FromVector4(new Vector4(lerpedSpecularColor, lerpedSpecularFactor)); // Emissive (table) var lerpedEmissive = Vector3.Lerp(prevRow.Emissive, nextRow.Emissive, tableRow.Weight);