Skip to content

Commit 5d76876

Browse files
committed
fix: remove asNormalMap handling
Apparently this does not do what it seems to and should never be used.
1 parent d0252d7 commit 5d76876

File tree

1 file changed

+10
-40
lines changed

1 file changed

+10
-40
lines changed

Source/MaterialDef.cs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,15 @@ namespace Shabby
2626

2727
public static class MaterialDefLibrary
2828
{
29-
public static readonly Dictionary<string, string> normalMapProperties = new Dictionary<string, string>();
3029
public static readonly Dictionary<string, MaterialDef> items = new Dictionary<string, MaterialDef>();
3130

3231
public static void Load()
3332
{
34-
foreach (var node in GameDatabase.Instance.GetConfigNodes("SHABBY_SHADER_NORMAL_MAP_PROPERTY")) {
35-
var shader = node.GetValue("shader");
36-
var property = node.GetValue("property");
37-
if (string.IsNullOrEmpty(shader) || string.IsNullOrEmpty(property)) {
38-
Debug.Log($"[Shabby] invalid shader normal map property specification {shader} = {property}");
39-
} else {
40-
normalMapProperties[shader] = property;
41-
}
42-
}
43-
4433
foreach (var node in GameDatabase.Instance.GetConfigNodes("SHABBY_MATERIAL_DEF")) {
4534
var def = new MaterialDef(node);
4635
if (string.IsNullOrEmpty(def.name) || !def.isValid) {
4736
Debug.LogError($"[Shabby][MaterialDef {def.name}] removing invalid definition");
48-
}
49-
else {
37+
} else {
5038
items[def.name] = def;
5139
}
5240
}
@@ -70,9 +58,7 @@ public class MaterialDef
7058
public readonly Dictionary<string, float> floats;
7159
public readonly Dictionary<string, Color> colors;
7260
public readonly Dictionary<string, Vector4> vectors;
73-
public readonly Dictionary<string, string> textureNames;
74-
75-
readonly Dictionary<string, Texture> textures = new Dictionary<string, Texture>();
61+
public readonly Dictionary<string, Texture> textures;
7662

7763
public readonly bool isValid = true;
7864

@@ -95,9 +81,13 @@ public MaterialDef(ConfigNode node)
9581

9682
keywords = LoadDictionary<bool>(node.GetNode("Keyword"));
9783
floats = LoadDictionary<float>(node.GetNode("Float"));
98-
colors = LoadDictionary<Color>(node.GetNode("Color"), ParseColor);
84+
colors = LoadDictionary<Color>(
85+
node.GetNode("Color"),
86+
value => ParseColor(value, out var color) ? (object)color : null);
9987
vectors = LoadDictionary<Vector4>(node.GetNode("Vector"));
100-
textureNames = LoadDictionary<string>(node.GetNode("Texture"));
88+
textures = LoadDictionary<Texture>(
89+
node.GetNode("Texture"),
90+
value => GameDatabase.Instance.GetTexture(value, asNormalMap: false));
10191
}
10292

10393
static readonly Func<Type, string, object> ReadValue =
@@ -114,7 +104,7 @@ Dictionary<string, T> LoadDictionary<T>(ConfigNode node, Func<string, object> pa
114104
if (value is T parsed) {
115105
items[item.name] = parsed;
116106
} else {
117-
Debug.LogError($"[Shabby][MaterialDef {name}] failed to parse property {item.name} = {item.value} as a {typeof(T).Name}");
107+
Debug.LogError($"[Shabby][MaterialDef {name}] failed to load {typeof(T).Name} property {item.name} = {item.value}");
118108
}
119109
}
120110

@@ -128,8 +118,6 @@ public static bool ParseColor(string value, out Color color)
128118
return false;
129119
}
130120

131-
static object ParseColor(string value) => ParseColor(value, out var color) ? (object)color : null;
132-
133121
/// <summary>
134122
/// Create a new material based on this definition. The material name is copied from the
135123
/// passed reference material. In update-existing mode, all properties are also copied from
@@ -161,25 +149,7 @@ public Material Instantiate(Material referenceMaterial)
161149

162150
foreach (var kvp in vectors) material.SetVector(kvp.Key, kvp.Value);
163151

164-
foreach (var kvp in textureNames) {
165-
var (propName, texName) = (kvp.Key, kvp.Value);
166-
if (!textures.TryGetValue(texName, out var texture)) {
167-
var texInfo = GameDatabase.Instance.GetTextureInfo(texName);
168-
if (texInfo == null)
169-
{
170-
Debug.LogError($"[Shabby] failed to find texture {texName}");
171-
continue;
172-
}
173-
174-
MaterialDefLibrary.normalMapProperties.TryGetValue(material.shader.name, out var nrmPropName);
175-
var isNormalMap = propName == (nrmPropName ?? "_BumpMap");
176-
177-
texture = isNormalMap ? texInfo.normalMap : texInfo.texture;
178-
textures[texName] = texture;
179-
}
180-
181-
material.SetTexture(propName, texture);
182-
}
152+
foreach (var kvp in textures) material.SetTexture(kvp.Key, kvp.Value);
183153

184154
return material;
185155
}

0 commit comments

Comments
 (0)