From 4fa77b79bf894c148486e6958a037cc5c39ceed7 Mon Sep 17 00:00:00 2001 From: Alvin Meng Date: Sat, 3 Aug 2024 23:00:44 -0400 Subject: [PATCH] fix: remove asNormalMap handling Apparently this does not do what it seems to and should never be used. --- Source/MaterialDef.cs | 50 +++++++++---------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/Source/MaterialDef.cs b/Source/MaterialDef.cs index 8a9c314..470a0bc 100644 --- a/Source/MaterialDef.cs +++ b/Source/MaterialDef.cs @@ -26,27 +26,15 @@ namespace Shabby public static class MaterialDefLibrary { - public static readonly Dictionary normalMapProperties = new Dictionary(); public static readonly Dictionary items = new Dictionary(); public static void Load() { - foreach (var node in GameDatabase.Instance.GetConfigNodes("SHABBY_SHADER_NORMAL_MAP_PROPERTY")) { - var shader = node.GetValue("shader"); - var property = node.GetValue("property"); - if (string.IsNullOrEmpty(shader) || string.IsNullOrEmpty(property)) { - Debug.Log($"[Shabby] invalid shader normal map property specification {shader} = {property}"); - } else { - normalMapProperties[shader] = property; - } - } - foreach (var node in GameDatabase.Instance.GetConfigNodes("SHABBY_MATERIAL_DEF")) { var def = new MaterialDef(node); if (string.IsNullOrEmpty(def.name) || !def.isValid) { Debug.LogError($"[Shabby][MaterialDef {def.name}] removing invalid definition"); - } - else { + } else { items[def.name] = def; } } @@ -70,9 +58,7 @@ public class MaterialDef public readonly Dictionary floats; public readonly Dictionary colors; public readonly Dictionary vectors; - public readonly Dictionary textureNames; - - readonly Dictionary textures = new Dictionary(); + public readonly Dictionary textures; public readonly bool isValid = true; @@ -95,9 +81,13 @@ public MaterialDef(ConfigNode node) keywords = LoadDictionary(node.GetNode("Keyword")); floats = LoadDictionary(node.GetNode("Float")); - colors = LoadDictionary(node.GetNode("Color"), ParseColor); + colors = LoadDictionary( + node.GetNode("Color"), + value => ParseColor(value, out var color) ? (object)color : null); vectors = LoadDictionary(node.GetNode("Vector")); - textureNames = LoadDictionary(node.GetNode("Texture")); + textures = LoadDictionary( + node.GetNode("Texture"), + value => GameDatabase.Instance.GetTexture(value, asNormalMap: false)); } static readonly Func ReadValue = @@ -114,7 +104,7 @@ Dictionary LoadDictionary(ConfigNode node, Func pa if (value is T parsed) { items[item.name] = parsed; } else { - Debug.LogError($"[Shabby][MaterialDef {name}] failed to parse property {item.name} = {item.value} as a {typeof(T).Name}"); + Debug.LogError($"[Shabby][MaterialDef {name}] failed to load {typeof(T).Name} property {item.name} = {item.value}"); } } @@ -128,8 +118,6 @@ public static bool ParseColor(string value, out Color color) return false; } - static object ParseColor(string value) => ParseColor(value, out var color) ? (object)color : null; - /// /// Create a new material based on this definition. The material name is copied from the /// passed reference material. In update-existing mode, all properties are also copied from @@ -161,25 +149,7 @@ public Material Instantiate(Material referenceMaterial) foreach (var kvp in vectors) material.SetVector(kvp.Key, kvp.Value); - foreach (var kvp in textureNames) { - var (propName, texName) = (kvp.Key, kvp.Value); - if (!textures.TryGetValue(texName, out var texture)) { - var texInfo = GameDatabase.Instance.GetTextureInfo(texName); - if (texInfo == null) - { - Debug.LogError($"[Shabby] failed to find texture {texName}"); - continue; - } - - MaterialDefLibrary.normalMapProperties.TryGetValue(material.shader.name, out var nrmPropName); - var isNormalMap = propName == (nrmPropName ?? "_BumpMap"); - - texture = isNormalMap ? texInfo.normalMap : texInfo.texture; - textures[texName] = texture; - } - - material.SetTexture(propName, texture); - } + foreach (var kvp in textures) material.SetTexture(kvp.Key, kvp.Value); return material; }