public static bool TryGet(UniGLTF.glTFExtension src, out VRMC_materials_mtoon extension) { if (src is UniGLTF.glTFExtensionImport extensions) { foreach (var kv in extensions.ObjectItems()) { if (kv.Key.GetUtf8String() == VRMC_materials_mtoon.ExtensionNameUtf8) { extension = Deserialize(kv.Value); return(true); } } } extension = default; return(false); }
public static void SerializeTo(ref UniGLTF.glTFExtension dst, VRMC_materials_mtoon extension) { if (dst is glTFExtensionImport) { throw new NotImplementedException(); } if (!(dst is glTFExtensionExport extensions)) { extensions = new glTFExtensionExport(); dst = extensions; } var f = new JsonFormatter(); Serialize(f, extension); extensions.Add(VRMC_materials_mtoon.ExtensionName, f.GetStoreBytes()); }
public static bool TryExportMaterialAsMToon(Material src, ITextureExporter textureExporter, out glTFMaterial dst) { try { if (src.shader.name != MToon10Meta.UnityShaderName) { dst = null; return(false); } // Get MToon10 Context var context = new MToon10Context(src); context.Validate(); // base material dst = glTF_KHR_materials_unlit.CreateDefault(); dst.name = src.name; // vrmc_materials_mtoon ext var mtoon = new UniGLTF.Extensions.VRMC_materials_mtoon.VRMC_materials_mtoon(); mtoon.SpecVersion = MTOON_SPEC_VERSION; // Rendering dst.alphaMode = ExportAlphaMode(context.AlphaMode); mtoon.TransparentWithZWrite = context.TransparentWithZWriteMode == MToon10TransparentWithZWriteMode.On; dst.alphaCutoff = Mathf.Max(0, context.AlphaCutoff); mtoon.RenderQueueOffsetNumber = context.RenderQueueOffsetNumber; dst.doubleSided = context.DoubleSidedMode == MToon10DoubleSidedMode.On; // Lighting dst.pbrMetallicRoughness = new glTFPbrMetallicRoughness(); dst.pbrMetallicRoughness.baseColorFactor = context.BaseColorFactorSrgb.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear); var baseColorTextureIndex = textureExporter.RegisterExportingAsSRgb(context.BaseColorTexture, context.AlphaMode != MToon10AlphaMode.Opaque); if (baseColorTextureIndex != -1) { dst.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo { index = baseColorTextureIndex, }; } mtoon.ShadeColorFactor = context.ShadeColorFactorSrgb.ToFloat3(ColorSpace.sRGB, ColorSpace.Linear); var shadeColorTextureIndex = textureExporter.RegisterExportingAsSRgb(context.ShadeColorTexture, needsAlpha: false); if (shadeColorTextureIndex != -1) { mtoon.ShadeMultiplyTexture = new TextureInfo { Index = shadeColorTextureIndex, }; } var normalTextureIndex = textureExporter.RegisterExportingAsNormal(context.NormalTexture); if (normalTextureIndex != -1) { dst.normalTexture = new glTFMaterialNormalTextureInfo { index = normalTextureIndex, scale = context.NormalTextureScale, }; } mtoon.ShadingShiftFactor = context.ShadingShiftFactor; var shadingShiftTextureIndex = textureExporter.RegisterExportingAsLinear(context.ShadingShiftTexture, needsAlpha: false); if (shadingShiftTextureIndex != -1) { mtoon.ShadingShiftTexture = new ShadingShiftTextureInfo { Index = shadingShiftTextureIndex, Scale = context.ShadingShiftTextureScale, }; } mtoon.ShadingToonyFactor = context.ShadingToonyFactor; // GI // TODO: update schema mtoon.GiIntensityFactor = context.GiEqualizationFactor; // Emission dst.emissiveFactor = context.EmissiveFactorLinear.ToFloat3(ColorSpace.Linear, ColorSpace.Linear); var emissiveTextureIndex = textureExporter.RegisterExportingAsSRgb(context.EmissiveTexture, needsAlpha: false); if (emissiveTextureIndex != -1) { dst.emissiveTexture = new glTFMaterialEmissiveTextureInfo { index = emissiveTextureIndex, }; } // Rim Lighting var matcapTextureIndex = textureExporter.RegisterExportingAsSRgb(context.MatcapTexture, needsAlpha: false); if (matcapTextureIndex != -1) { mtoon.MatcapTexture = new TextureInfo { Index = matcapTextureIndex, }; } mtoon.ParametricRimColorFactor = context.ParametricRimColorFactorSrgb.ToFloat3(ColorSpace.sRGB, ColorSpace.Linear); mtoon.ParametricRimFresnelPowerFactor = context.ParametricRimFresnelPowerFactor; mtoon.ParametricRimLiftFactor = context.ParametricRimLiftFactor; var rimMultiplyTextureIndex = textureExporter.RegisterExportingAsSRgb(context.RimMultiplyTexture, needsAlpha: false); if (rimMultiplyTextureIndex != -1) { mtoon.RimMultiplyTexture = new TextureInfo { Index = rimMultiplyTextureIndex, }; } mtoon.RimLightingMixFactor = context.RimLightingMixFactor; // Outline mtoon.OutlineWidthMode = ExportOutlineWidthMode(context.OutlineWidthMode); mtoon.OutlineWidthFactor = context.OutlineWidthFactor; var outlineWidthMultiplyTextureIndex = textureExporter.RegisterExportingAsLinear(context.OutlineWidthMultiplyTexture, needsAlpha: false); if (outlineWidthMultiplyTextureIndex != -1) { mtoon.OutlineWidthMultiplyTexture = new TextureInfo { Index = outlineWidthMultiplyTextureIndex, }; } mtoon.OutlineColorFactor = context.OutlineColorFactorSrgb.ToFloat3(ColorSpace.sRGB, ColorSpace.Linear); mtoon.OutlineLightingMixFactor = context.OutlineLightingMixFactor; // UV Animation var uvAnimationMaskTextureIndex = textureExporter.RegisterExportingAsLinear(context.UvAnimationMaskTexture, needsAlpha: false); if (uvAnimationMaskTextureIndex != -1) { mtoon.UvAnimationMaskTexture = new TextureInfo { Index = uvAnimationMaskTextureIndex, }; } mtoon.UvAnimationScrollXSpeedFactor = context.UvAnimationScrollXSpeedFactor; { // Coordinate Conversion const float invertY = -1f; mtoon.UvAnimationScrollYSpeedFactor = context.UvAnimationScrollYSpeedFactor * invertY; } mtoon.UvAnimationRotationSpeedFactor = context.UvAnimationRotationSpeedFactor; // Texture Transforms var scale = context.TextureScale; var offset = context.TextureOffset; ExportTextureTransform(dst.pbrMetallicRoughness.baseColorTexture, scale, offset); ExportTextureTransform(dst.emissiveTexture, scale, offset); ExportTextureTransform(dst.normalTexture, scale, offset); ExportTextureTransform(mtoon.ShadeMultiplyTexture, scale, offset); ExportTextureTransform(mtoon.ShadingShiftTexture, scale, offset); ExportTextureTransform(mtoon.MatcapTexture, scale, offset); ExportTextureTransform(mtoon.RimMultiplyTexture, scale, offset); ExportTextureTransform(mtoon.OutlineWidthMultiplyTexture, scale, offset); ExportTextureTransform(mtoon.UvAnimationMaskTexture, scale, offset); UniGLTF.Extensions.VRMC_materials_mtoon.GltfSerializer.SerializeTo(ref dst.extensions, mtoon); return(true); } catch (Exception) { dst = null; return(false); } }
public static void Serialize(JsonFormatter f, VRMC_materials_mtoon value) { f.BeginMap(); if (!string.IsNullOrEmpty(value.Version)) { f.Key("version"); f.Value(value.Version); } if (value.TransparentWithZWrite.HasValue) { f.Key("transparentWithZWrite"); f.Value(value.TransparentWithZWrite.GetValueOrDefault()); } if (value.RenderQueueOffsetNumber.HasValue) { f.Key("renderQueueOffsetNumber"); f.Value(value.RenderQueueOffsetNumber.GetValueOrDefault()); } if (value.ShadeFactor != null && value.ShadeFactor.Count() >= 0) { f.Key("shadeFactor"); Serialize_ShadeFactor(f, value.ShadeFactor); } if (value.ShadeMultiplyTexture.HasValue) { f.Key("shadeMultiplyTexture"); f.Value(value.ShadeMultiplyTexture.GetValueOrDefault()); } if (value.ShadingShiftFactor.HasValue) { f.Key("shadingShiftFactor"); f.Value(value.ShadingShiftFactor.GetValueOrDefault()); } if (value.ShadingToonyFactor.HasValue) { f.Key("shadingToonyFactor"); f.Value(value.ShadingToonyFactor.GetValueOrDefault()); } if (value.LightColorAttenuationFactor.HasValue) { f.Key("lightColorAttenuationFactor"); f.Value(value.LightColorAttenuationFactor.GetValueOrDefault()); } if (value.GiIntensityFactor.HasValue) { f.Key("giIntensityFactor"); f.Value(value.GiIntensityFactor.GetValueOrDefault()); } if (value.AdditiveTexture.HasValue) { f.Key("additiveTexture"); f.Value(value.AdditiveTexture.GetValueOrDefault()); } if (value.RimFactor != null && value.RimFactor.Count() >= 0) { f.Key("rimFactor"); Serialize_RimFactor(f, value.RimFactor); } if (value.RimMultiplyTexture.HasValue) { f.Key("rimMultiplyTexture"); f.Value(value.RimMultiplyTexture.GetValueOrDefault()); } if (value.RimLightingMixFactor.HasValue) { f.Key("rimLightingMixFactor"); f.Value(value.RimLightingMixFactor.GetValueOrDefault()); } if (value.RimFresnelPowerFactor.HasValue) { f.Key("rimFresnelPowerFactor"); f.Value(value.RimFresnelPowerFactor.GetValueOrDefault()); } if (value.RimLiftFactor.HasValue) { f.Key("rimLiftFactor"); f.Value(value.RimLiftFactor.GetValueOrDefault()); } if (true) { f.Key("outlineWidthMode"); f.Value(value.OutlineWidthMode.ToString()); } if (value.OutlineWidthFactor.HasValue) { f.Key("outlineWidthFactor"); f.Value(value.OutlineWidthFactor.GetValueOrDefault()); } if (value.OutlineWidthMultiplyTexture.HasValue) { f.Key("outlineWidthMultiplyTexture"); f.Value(value.OutlineWidthMultiplyTexture.GetValueOrDefault()); } if (value.OutlineScaledMaxDistanceFactor.HasValue) { f.Key("outlineScaledMaxDistanceFactor"); f.Value(value.OutlineScaledMaxDistanceFactor.GetValueOrDefault()); } if (true) { f.Key("outlineColorMode"); f.Value(value.OutlineColorMode.ToString()); } if (value.OutlineFactor != null && value.OutlineFactor.Count() >= 0) { f.Key("outlineFactor"); Serialize_OutlineFactor(f, value.OutlineFactor); } if (value.OutlineLightingMixFactor.HasValue) { f.Key("outlineLightingMixFactor"); f.Value(value.OutlineLightingMixFactor.GetValueOrDefault()); } if (value.UvAnimationMaskTexture.HasValue) { f.Key("uvAnimationMaskTexture"); f.Value(value.UvAnimationMaskTexture.GetValueOrDefault()); } if (value.UvAnimationScrollXSpeedFactor.HasValue) { f.Key("uvAnimationScrollXSpeedFactor"); f.Value(value.UvAnimationScrollXSpeedFactor.GetValueOrDefault()); } if (value.UvAnimationScrollYSpeedFactor.HasValue) { f.Key("uvAnimationScrollYSpeedFactor"); f.Value(value.UvAnimationScrollYSpeedFactor.GetValueOrDefault()); } if (value.UvAnimationRotationSpeedFactor.HasValue) { f.Key("uvAnimationRotationSpeedFactor"); f.Value(value.UvAnimationRotationSpeedFactor.GetValueOrDefault()); } f.EndMap(); }
public static VRMC_materials_mtoon Deserialize(JsonNode parsed) { var value = new VRMC_materials_mtoon(); foreach (var kv in parsed.ObjectItems()) { var key = kv.Key.GetString(); if (key == "extensions") { value.Extensions = new glTFExtensionImport(kv.Value); continue; } if (key == "extras") { value.Extras = new glTFExtensionImport(kv.Value); continue; } if (key == "version") { value.Version = kv.Value.GetString(); continue; } if (key == "transparentWithZWrite") { value.TransparentWithZWrite = kv.Value.GetBoolean(); continue; } if (key == "renderQueueOffsetNumber") { value.RenderQueueOffsetNumber = kv.Value.GetInt32(); continue; } if (key == "shadeColorFactor") { value.ShadeColorFactor = Deserialize_ShadeColorFactor(kv.Value); continue; } if (key == "shadeMultiplyTexture") { value.ShadeMultiplyTexture = Deserialize_ShadeMultiplyTexture(kv.Value); continue; } if (key == "shadingShiftFactor") { value.ShadingShiftFactor = kv.Value.GetSingle(); continue; } if (key == "shadingShiftTexture") { value.ShadingShiftTexture = Deserialize_ShadingShiftTexture(kv.Value); continue; } if (key == "shadingToonyFactor") { value.ShadingToonyFactor = kv.Value.GetSingle(); continue; } if (key == "giIntensityFactor") { value.GiIntensityFactor = kv.Value.GetSingle(); continue; } if (key == "matcapTexture") { value.MatcapTexture = Deserialize_MatcapTexture(kv.Value); continue; } if (key == "parametricRimColorFactor") { value.ParametricRimColorFactor = Deserialize_ParametricRimColorFactor(kv.Value); continue; } if (key == "rimMultiplyTexture") { value.RimMultiplyTexture = Deserialize_RimMultiplyTexture(kv.Value); continue; } if (key == "rimLightingMixFactor") { value.RimLightingMixFactor = kv.Value.GetSingle(); continue; } if (key == "parametricRimFresnelPowerFactor") { value.ParametricRimFresnelPowerFactor = kv.Value.GetSingle(); continue; } if (key == "parametricRimLiftFactor") { value.ParametricRimLiftFactor = kv.Value.GetSingle(); continue; } if (key == "outlineWidthMode") { value.OutlineWidthMode = (OutlineWidthMode)Enum.Parse(typeof(OutlineWidthMode), kv.Value.GetString(), true); continue; } if (key == "outlineWidthFactor") { value.OutlineWidthFactor = kv.Value.GetSingle(); continue; } if (key == "outlineWidthMultiplyTexture") { value.OutlineWidthMultiplyTexture = Deserialize_OutlineWidthMultiplyTexture(kv.Value); continue; } if (key == "outlineColorFactor") { value.OutlineColorFactor = Deserialize_OutlineColorFactor(kv.Value); continue; } if (key == "outlineLightingMixFactor") { value.OutlineLightingMixFactor = kv.Value.GetSingle(); continue; } if (key == "uvAnimationMaskTexture") { value.UvAnimationMaskTexture = Deserialize_UvAnimationMaskTexture(kv.Value); continue; } if (key == "uvAnimationScrollXSpeedFactor") { value.UvAnimationScrollXSpeedFactor = kv.Value.GetSingle(); continue; } if (key == "uvAnimationScrollYSpeedFactor") { value.UvAnimationScrollYSpeedFactor = kv.Value.GetSingle(); continue; } if (key == "uvAnimationRotationSpeedFactor") { value.UvAnimationRotationSpeedFactor = kv.Value.GetSingle(); continue; } } return(value); }
public static VRMC_materials_mtoon Deserialize(ListTreeNode <JsonValue> parsed) { var value = new VRMC_materials_mtoon(); foreach (var kv in parsed.ObjectItems()) { var key = kv.Key.GetString(); if (key == "version") { value.Version = kv.Value.GetString(); continue; } if (key == "transparentWithZWrite") { value.TransparentWithZWrite = kv.Value.GetBoolean(); continue; } if (key == "renderQueueOffsetNumber") { value.RenderQueueOffsetNumber = kv.Value.GetInt32(); continue; } if (key == "shadeFactor") { value.ShadeFactor = Deserialize_ShadeFactor(kv.Value); continue; } if (key == "shadeMultiplyTexture") { value.ShadeMultiplyTexture = kv.Value.GetInt32(); continue; } if (key == "shadingShiftFactor") { value.ShadingShiftFactor = kv.Value.GetSingle(); continue; } if (key == "shadingToonyFactor") { value.ShadingToonyFactor = kv.Value.GetSingle(); continue; } if (key == "lightColorAttenuationFactor") { value.LightColorAttenuationFactor = kv.Value.GetSingle(); continue; } if (key == "giIntensityFactor") { value.GiIntensityFactor = kv.Value.GetSingle(); continue; } if (key == "additiveTexture") { value.AdditiveTexture = kv.Value.GetInt32(); continue; } if (key == "rimFactor") { value.RimFactor = Deserialize_RimFactor(kv.Value); continue; } if (key == "rimMultiplyTexture") { value.RimMultiplyTexture = kv.Value.GetInt32(); continue; } if (key == "rimLightingMixFactor") { value.RimLightingMixFactor = kv.Value.GetSingle(); continue; } if (key == "rimFresnelPowerFactor") { value.RimFresnelPowerFactor = kv.Value.GetSingle(); continue; } if (key == "rimLiftFactor") { value.RimLiftFactor = kv.Value.GetSingle(); continue; } if (key == "outlineWidthMode") { value.OutlineWidthMode = (OutlineWidthMode)Enum.Parse(typeof(OutlineWidthMode), kv.Value.GetString(), true); continue; } if (key == "outlineWidthFactor") { value.OutlineWidthFactor = kv.Value.GetSingle(); continue; } if (key == "outlineWidthMultiplyTexture") { value.OutlineWidthMultiplyTexture = kv.Value.GetInt32(); continue; } if (key == "outlineScaledMaxDistanceFactor") { value.OutlineScaledMaxDistanceFactor = kv.Value.GetSingle(); continue; } if (key == "outlineColorMode") { value.OutlineColorMode = (OutlineColorMode)Enum.Parse(typeof(OutlineColorMode), kv.Value.GetString(), true); continue; } if (key == "outlineFactor") { value.OutlineFactor = Deserialize_OutlineFactor(kv.Value); continue; } if (key == "outlineLightingMixFactor") { value.OutlineLightingMixFactor = kv.Value.GetSingle(); continue; } if (key == "uvAnimationMaskTexture") { value.UvAnimationMaskTexture = kv.Value.GetInt32(); continue; } if (key == "uvAnimationScrollXSpeedFactor") { value.UvAnimationScrollXSpeedFactor = kv.Value.GetSingle(); continue; } if (key == "uvAnimationScrollYSpeedFactor") { value.UvAnimationScrollYSpeedFactor = kv.Value.GetSingle(); continue; } if (key == "uvAnimationRotationSpeedFactor") { value.UvAnimationRotationSpeedFactor = kv.Value.GetSingle(); continue; } } return(value); }
public static void Serialize(JsonFormatter f, VRMC_materials_mtoon value) { f.BeginMap(); if (value.Extensions != null) { f.Key("extensions"); (value.Extensions as glTFExtension).Serialize(f); } if (value.Extras != null) { f.Key("extras"); (value.Extras as glTFExtension).Serialize(f); } if (!string.IsNullOrEmpty(value.Version)) { f.Key("version"); f.Value(value.Version); } if (value.TransparentWithZWrite.HasValue) { f.Key("transparentWithZWrite"); f.Value(value.TransparentWithZWrite.GetValueOrDefault()); } if (value.RenderQueueOffsetNumber.HasValue) { f.Key("renderQueueOffsetNumber"); f.Value(value.RenderQueueOffsetNumber.GetValueOrDefault()); } if (value.ShadeColorFactor != null && value.ShadeColorFactor.Count() >= 3) { f.Key("shadeColorFactor"); Serialize_ShadeColorFactor(f, value.ShadeColorFactor); } if (value.ShadeMultiplyTexture != null) { f.Key("shadeMultiplyTexture"); Serialize_ShadeMultiplyTexture(f, value.ShadeMultiplyTexture); } if (value.ShadingShiftFactor.HasValue) { f.Key("shadingShiftFactor"); f.Value(value.ShadingShiftFactor.GetValueOrDefault()); } if (value.ShadingShiftTexture != null) { f.Key("shadingShiftTexture"); Serialize_ShadingShiftTexture(f, value.ShadingShiftTexture); } if (value.ShadingToonyFactor.HasValue) { f.Key("shadingToonyFactor"); f.Value(value.ShadingToonyFactor.GetValueOrDefault()); } if (value.GiIntensityFactor.HasValue) { f.Key("giIntensityFactor"); f.Value(value.GiIntensityFactor.GetValueOrDefault()); } if (value.MatcapTexture != null) { f.Key("matcapTexture"); Serialize_MatcapTexture(f, value.MatcapTexture); } if (value.ParametricRimColorFactor != null && value.ParametricRimColorFactor.Count() >= 3) { f.Key("parametricRimColorFactor"); Serialize_ParametricRimColorFactor(f, value.ParametricRimColorFactor); } if (value.RimMultiplyTexture != null) { f.Key("rimMultiplyTexture"); Serialize_RimMultiplyTexture(f, value.RimMultiplyTexture); } if (value.RimLightingMixFactor.HasValue) { f.Key("rimLightingMixFactor"); f.Value(value.RimLightingMixFactor.GetValueOrDefault()); } if (value.ParametricRimFresnelPowerFactor.HasValue) { f.Key("parametricRimFresnelPowerFactor"); f.Value(value.ParametricRimFresnelPowerFactor.GetValueOrDefault()); } if (value.ParametricRimLiftFactor.HasValue) { f.Key("parametricRimLiftFactor"); f.Value(value.ParametricRimLiftFactor.GetValueOrDefault()); } if (true) { f.Key("outlineWidthMode"); f.Value(value.OutlineWidthMode.ToString()); } if (value.OutlineWidthFactor.HasValue) { f.Key("outlineWidthFactor"); f.Value(value.OutlineWidthFactor.GetValueOrDefault()); } if (value.OutlineWidthMultiplyTexture != null) { f.Key("outlineWidthMultiplyTexture"); Serialize_OutlineWidthMultiplyTexture(f, value.OutlineWidthMultiplyTexture); } if (value.OutlineColorFactor != null && value.OutlineColorFactor.Count() >= 3) { f.Key("outlineColorFactor"); Serialize_OutlineColorFactor(f, value.OutlineColorFactor); } if (value.OutlineLightingMixFactor.HasValue) { f.Key("outlineLightingMixFactor"); f.Value(value.OutlineLightingMixFactor.GetValueOrDefault()); } if (value.UvAnimationMaskTexture != null) { f.Key("uvAnimationMaskTexture"); Serialize_UvAnimationMaskTexture(f, value.UvAnimationMaskTexture); } if (value.UvAnimationScrollXSpeedFactor.HasValue) { f.Key("uvAnimationScrollXSpeedFactor"); f.Value(value.UvAnimationScrollXSpeedFactor.GetValueOrDefault()); } if (value.UvAnimationScrollYSpeedFactor.HasValue) { f.Key("uvAnimationScrollYSpeedFactor"); f.Value(value.UvAnimationScrollYSpeedFactor.GetValueOrDefault()); } if (value.UvAnimationRotationSpeedFactor.HasValue) { f.Key("uvAnimationRotationSpeedFactor"); f.Value(value.UvAnimationRotationSpeedFactor.GetValueOrDefault()); } f.EndMap(); }
public static bool TryExportMaterialAsMToon(Material src, ITextureExporter textureExporter, out glTFMaterial dst) { try { if (src.shader.name != MToon.Utils.ShaderName) { dst = null; return(false); } // convert MToon intermediate value from UnityEngine.Material var def = MToon.Utils.GetMToonParametersFromMaterial(src); // gltfMaterial dst = new glTFMaterial { name = src.name, // Rendering doubleSided = def.Rendering.CullMode == CullMode.Off, alphaMode = ExportAlphaMode(def.Rendering.RenderMode), alphaCutoff = Mathf.Max(def.Color.CutoutThresholdValue, 0), // Lighting pbrMetallicRoughness = new glTFPbrMetallicRoughness { baseColorFactor = def.Color.LitColor.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear), baseColorTexture = new glTFMaterialBaseColorTextureInfo { index = textureExporter.ExportAsSRgb(def.Color.LitMultiplyTexture), }, }, normalTexture = new glTFMaterialNormalTextureInfo { index = textureExporter.ExportAsNormal(def.Lighting.Normal.NormalTexture), scale = def.Lighting.Normal.NormalScaleValue, }, // Emission emissiveFactor = def.Emission.EmissionColor.ToFloat3(ColorSpace.Linear, ColorSpace.Linear), emissiveTexture = new glTFMaterialEmissiveTextureInfo { index = textureExporter.ExportAsSRgb(def.Emission.EmissionMultiplyTexture), }, }; const float centimeterToMeter = 0.01f; const float invertY = -1f; // VRMC_materials_mtoon var mtoon = new UniGLTF.Extensions.VRMC_materials_mtoon.VRMC_materials_mtoon { Version = "", // Rendering TransparentWithZWrite = def.Rendering.RenderMode == RenderMode.TransparentWithZWrite, RenderQueueOffsetNumber = ExportRenderQueueOffset(def.Rendering.RenderMode, def.Rendering.RenderQueueOffsetNumber), // Lighting ShadeColorFactor = def.Color.ShadeColor.ToFloat3(ColorSpace.sRGB, ColorSpace.Linear), ShadeMultiplyTexture = new TextureInfo { Index = textureExporter.ExportAsSRgb(def.Color.ShadeMultiplyTexture), }, ShadingToonyFactor = def.Lighting.LitAndShadeMixing.ShadingToonyValue, ShadingShiftFactor = def.Lighting.LitAndShadeMixing.ShadingShiftValue, ShadingShiftTexture = null, // Global Illumination GiIntensityFactor = def.Lighting.LightingInfluence.GiIntensityValue, // Rim Lighting MatcapTexture = new TextureInfo { Index = textureExporter.ExportAsSRgb(def.MatCap.AdditiveTexture), }, ParametricRimColorFactor = def.Rim.RimColor.ToFloat3(ColorSpace.Linear, ColorSpace.Linear), ParametricRimFresnelPowerFactor = def.Rim.RimFresnelPowerValue, ParametricRimLiftFactor = def.Rim.RimLiftValue, RimMultiplyTexture = new TextureInfo { Index = textureExporter.ExportAsSRgb(def.Rim.RimMultiplyTexture), }, RimLightingMixFactor = def.Rim.RimLightingMixValue, // Outline OutlineWidthMode = ExportOutlineWidthMode(def.Outline.OutlineWidthMode), OutlineWidthFactor = def.Outline.OutlineWidthValue * centimeterToMeter, OutlineWidthMultiplyTexture = new TextureInfo { Index = textureExporter.ExportAsLinear(def.Outline.OutlineWidthMultiplyTexture), }, OutlineColorFactor = def.Outline.OutlineColor.ToFloat3(ColorSpace.sRGB, ColorSpace.Linear), OutlineLightingMixFactor = ExportOutlineLightingMixFactor(def.Outline.OutlineColorMode, def.Outline.OutlineLightingMixValue), // UV Anim UvAnimationMaskTexture = new TextureInfo { Index = textureExporter.ExportAsLinear(def.TextureOption.UvAnimationMaskTexture), }, UvAnimationScrollXSpeedFactor = def.TextureOption.UvAnimationScrollXSpeedValue, UvAnimationScrollYSpeedFactor = def.TextureOption.UvAnimationScrollYSpeedValue * invertY, UvAnimationRotationSpeedFactor = def.TextureOption.UvAnimationRotationSpeedValue, }; // Texture Transforms var scale = def.TextureOption.MainTextureLeftBottomOriginScale; var offset = def.TextureOption.MainTextureLeftBottomOriginOffset; ExportTextureTransform(dst.pbrMetallicRoughness.baseColorTexture, scale, offset); ExportTextureTransform(dst.emissiveTexture, scale, offset); ExportTextureTransform(dst.normalTexture, scale, offset); ExportTextureTransform(mtoon.ShadeMultiplyTexture, scale, offset); ExportTextureTransform(mtoon.MatcapTexture, scale, offset); ExportTextureTransform(mtoon.RimMultiplyTexture, scale, offset); ExportTextureTransform(mtoon.OutlineWidthMultiplyTexture, scale, offset); ExportTextureTransform(mtoon.UvAnimationMaskTexture, scale, offset); UniGLTF.Extensions.VRMC_materials_mtoon.GltfSerializer.SerializeTo(ref dst.extensions, mtoon); return(true); } catch (Exception e) { dst = null; return(false); } }