Merge pull request #1944 from Santarh/shaderInsteadOfString

Remove concrete VRM shader's info from UniGLTF.
This commit is contained in:
ousttrue 2022-12-05 17:16:52 +09:00 committed by GitHub
commit 0d96656c1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 42 deletions

View File

@ -49,7 +49,7 @@ namespace UniGLTF
Data.MigrationFlags.IsRoughnessTextureValueSquared);
MaterialFactory = new MaterialFactory(ExternalObjectMap
.Where(x => x.Value is Material)
.ToDictionary(x => x.Key, x => (Material)x.Value), MaterialFallback.FallbackShaders);
.ToDictionary(x => x.Key, x => (Material)x.Value));
AnimationClipFactory = new AnimationClipFactory(ExternalObjectMap
.Where(x => x.Value is AnimationClip)
.ToDictionary(x => x.Key, x => (AnimationClip)x.Value));

View File

@ -1,20 +0,0 @@
using System.Collections.Generic;
namespace UniGLTF
{
/// <summary>
/// 過去バージョンに含まれていたが、廃止・統合された Shader のフォールバック情報
/// </summary>
public static class MaterialFallback
{
static Dictionary<string, string> s_fallbackShaders = new Dictionary<string, string>
{
{"VRM/UnlitTexture", "Unlit/Texture"},
{"VRM/UnlitTransparent", "Unlit/Transparent"},
{"VRM/UnlitCutout", "Unlit/Transparent Cutout"},
{"UniGLTF/StandardVColor", UniGLTF.UniUnlit.UniUnlitUtil.ShaderName},
};
public static IReadOnlyDictionary<string, string> FallbackShaders => s_fallbackShaders;
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: feb59fa02250d3d4db41cfa1c2e2b032
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -9,6 +9,17 @@ namespace VRM
{
public static class BuiltInVrmMToonMaterialImporter
{
/// <summary>
/// 過去バージョンに含まれていたが、廃止・統合された Shader のフォールバック情報
/// </summary>
public static Dictionary<string, string> FallbackShaders = new Dictionary<string, string>
{
{"VRM/UnlitTexture", "Unlit/Texture"},
{"VRM/UnlitTransparent", "Unlit/Transparent"},
{"VRM/UnlitCutout", "Unlit/Transparent Cutout"},
{"UniGLTF/StandardVColor", UniGLTF.UniUnlit.UniUnlitUtil.ShaderName},
};
private static readonly string[] MToonTextureSlots = new string[]
{
"_MainTex",
@ -51,6 +62,11 @@ namespace VRM
//
// use material.name, because material name may renamed in GltfParser.
var name = data.GLTF.materials[materialIdx].name;
var shaderName = vrmMaterial.shader;
if (FallbackShaders.ContainsKey(shaderName))
{
shaderName = FallbackShaders[shaderName];
}
var textureSlots = new Dictionary<string, TextureDescriptor>();
var floatValues = new Dictionary<string, float>();
@ -59,7 +75,7 @@ namespace VRM
var actions = new List<Action<Material>>();
matDesc = new MaterialDescriptor(
name,
vrmMaterial.shader,
shaderName,
vrmMaterial.renderQueue,
textureSlots,
floatValues,

View File

@ -8,7 +8,8 @@
"GUID:301b251fd9834274c9228e0532f444f7",
"GUID:a9bc101fb0471f94a8f99fd242fdd934",
"GUID:ac229b552c3025545b074203f857547c",
"GUID:1cd941934d098654fa21a13f28346412"
"GUID:1cd941934d098654fa21a13f28346412",
"GUID:60c8346e00a8ddd4cafc5a02eceeec57"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -12,12 +12,10 @@ namespace VRMShaders
public class MaterialFactory : IResponsibilityForDestroyObjects
{
private readonly IReadOnlyDictionary<SubAssetKey, Material> m_externalMap;
private readonly IReadOnlyDictionary<string, string> m_fallbackShaders;
public MaterialFactory(IReadOnlyDictionary<SubAssetKey, Material> externalMaterialMap, IReadOnlyDictionary<string, string> fallbackShaders)
public MaterialFactory(IReadOnlyDictionary<SubAssetKey, Material> externalMaterialMap)
{
m_externalMap = externalMaterialMap;
m_fallbackShaders = fallbackShaders;
}
public struct MaterialLoadInfo
@ -108,11 +106,6 @@ namespace VRMShaders
{
throw new Exception("no shader name");
}
if (m_fallbackShaders.TryGetValue(shaderName, out string fallback))
{
Debug.LogWarning($"fallback: {shaderName} => {fallback}");
shaderName = fallback;
}
var shader = Shader.Find(shaderName);
if (shader == null)