mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 14:29:52 -05:00
impl KHR_materials_emissive_strength
This commit is contained in:
parent
d19e5c77be
commit
50e08dc9f6
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using UniJSON;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_emissive_strength
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class glTF_KHR_materials_emissive_strength
|
||||
{
|
||||
public const string ExtensionName = "KHR_materials_emissive_strength";
|
||||
public static readonly Utf8String ExtensionNameUtf8 = Utf8String.From(ExtensionName);
|
||||
public float emissiveStrength = 1.0f;
|
||||
|
||||
static glTF_KHR_materials_emissive_strength Deserialize(JsonNode json)
|
||||
{
|
||||
var extension = new glTF_KHR_materials_emissive_strength();
|
||||
if (json.TryGet(nameof(emissiveStrength), out JsonNode found))
|
||||
{
|
||||
extension.emissiveStrength = found.GetSingle();
|
||||
}
|
||||
return extension;
|
||||
}
|
||||
|
||||
public static bool TryGet(glTFExtension src, out glTF_KHR_materials_emissive_strength extension)
|
||||
{
|
||||
if (src is UniGLTF.glTFExtensionImport extensions)
|
||||
{
|
||||
foreach (var kv in extensions.ObjectItems())
|
||||
{
|
||||
if (kv.Key.GetUtf8String() == ExtensionNameUtf8)
|
||||
{
|
||||
extension = Deserialize(kv.Value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
extension = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Serialize(ref glTFExtension materialExtensions, float value)
|
||||
{
|
||||
var f = new JsonFormatter();
|
||||
f.BeginMap();
|
||||
f.Key(nameof(emissiveStrength));
|
||||
f.Value(value);
|
||||
f.EndMap();
|
||||
glTFExtensionExport.GetOrCreate(ref materialExtensions).Add(ExtensionName, f.GetStore().Bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d6a65b35aabda73408a522a2ef8e6a13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -37,11 +37,6 @@ namespace UniGLTF
|
|||
#endif
|
||||
;
|
||||
|
||||
/// <summary>
|
||||
/// VRMC_materials_hdr_emissiveMultiplier
|
||||
/// </summary>
|
||||
public bool UseEmissiveMultiplier;
|
||||
|
||||
/// <summary>
|
||||
/// Keep VertexColor
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -136,7 +136,11 @@ namespace UniGLTF
|
|||
if (src.emissiveFactor != null && src.emissiveFactor.Length == 3)
|
||||
{
|
||||
var emissiveFactor = src.emissiveFactor.ToColor3(ColorSpace.Linear, ColorSpace.Linear);
|
||||
if (UniGLTF.Extensions.VRMC_materials_hdr_emissiveMultiplier.GltfDeserializer.TryGet(src.extensions,
|
||||
if (UniGLTF.glTF_KHR_materials_emissive_strength.TryGet(src.extensions, out UniGLTF.glTF_KHR_materials_emissive_strength emissiveStrength))
|
||||
{
|
||||
emissiveFactor *= emissiveStrength.emissiveStrength;
|
||||
}
|
||||
else if (UniGLTF.Extensions.VRMC_materials_hdr_emissiveMultiplier.GltfDeserializer.TryGet(src.extensions,
|
||||
out UniGLTF.Extensions.VRMC_materials_hdr_emissiveMultiplier.
|
||||
VRMC_materials_hdr_emissiveMultiplier ex))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace UniGLTF
|
|||
// common params
|
||||
material.name = m.name;
|
||||
Export_Color(m, textureExporter, material);
|
||||
Export_Emission(m, textureExporter, material, settings.UseEmissiveMultiplier);
|
||||
Export_Emission(m, textureExporter, material);
|
||||
Export_Normal(m, textureExporter, material);
|
||||
Export_OcclusionMetallicRoughness(m, textureExporter, material);
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ namespace UniGLTF
|
|||
}
|
||||
}
|
||||
|
||||
static void Export_Emission(Material m, ITextureExporter textureExporter, glTFMaterial material, bool useEmissiveMultiplier)
|
||||
static void Export_Emission(Material m, ITextureExporter textureExporter, glTFMaterial material)
|
||||
{
|
||||
if (m.IsKeywordEnabled("_EMISSION") == false)
|
||||
{
|
||||
|
|
@ -168,14 +168,7 @@ namespace UniGLTF
|
|||
{
|
||||
var maxColorComponent = color.maxColorComponent;
|
||||
color /= maxColorComponent;
|
||||
if (useEmissiveMultiplier)
|
||||
{
|
||||
UniGLTF.Extensions.VRMC_materials_hdr_emissiveMultiplier.GltfSerializer.SerializeTo(ref material.extensions,
|
||||
new Extensions.VRMC_materials_hdr_emissiveMultiplier.VRMC_materials_hdr_emissiveMultiplier
|
||||
{
|
||||
EmissiveMultiplier = maxColorComponent,
|
||||
});
|
||||
}
|
||||
UniGLTF.glTF_KHR_materials_emissive_strength.Serialize(ref material.extensions, maxColorComponent);
|
||||
}
|
||||
material.emissiveFactor = color.ToFloat3(ColorSpace.Linear, ColorSpace.Linear);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,12 @@ namespace UniGLTF
|
|||
if (src.emissiveFactor != null && src.emissiveFactor.Length == 3)
|
||||
{
|
||||
var emissiveFactor = src.emissiveFactor.ToColor3(ColorSpace.Linear, ColorSpace.Linear);
|
||||
if (UniGLTF.Extensions.VRMC_materials_hdr_emissiveMultiplier.GltfDeserializer.TryGet(src.extensions,
|
||||
if (UniGLTF.glTF_KHR_materials_emissive_strength.TryGet(src.extensions,
|
||||
out UniGLTF.glTF_KHR_materials_emissive_strength emissiveStrength))
|
||||
{
|
||||
emissiveFactor *= emissiveStrength.emissiveStrength;
|
||||
}
|
||||
else if (UniGLTF.Extensions.VRMC_materials_hdr_emissiveMultiplier.GltfDeserializer.TryGet(src.extensions,
|
||||
out UniGLTF.Extensions.VRMC_materials_hdr_emissiveMultiplier.VRMC_materials_hdr_emissiveMultiplier ex))
|
||||
{
|
||||
emissiveFactor *= ex.EmissiveMultiplier.Value;
|
||||
|
|
@ -175,7 +180,7 @@ namespace UniGLTF
|
|||
|
||||
matDesc = new MaterialDescriptor(
|
||||
GltfMaterialDescriptorGenerator.GetMaterialName(i, src),
|
||||
ShaderName,
|
||||
ShaderName,
|
||||
null,
|
||||
textureSlots,
|
||||
floatValues,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user