2020-06-02 20:46:16 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2020-06-10 19:20:47 +00:00
|
|
|
using UnityEngine.Experimental.Rendering;
|
2020-06-02 20:46:16 +00:00
|
|
|
|
|
|
|
namespace ConformalDecals {
|
2020-06-06 04:29:57 +00:00
|
|
|
public static class DecalConfig {
|
2020-06-10 19:20:47 +00:00
|
|
|
private static Texture2D _blankNormal;
|
2020-06-02 20:46:16 +00:00
|
|
|
private static List<string> _shaderBlacklist;
|
2020-06-10 19:20:47 +00:00
|
|
|
|
|
|
|
public static Texture2D BlankNormal => _blankNormal;
|
2020-06-02 20:46:16 +00:00
|
|
|
|
|
|
|
public static bool IsBlacklisted(Shader shader) {
|
|
|
|
return IsBlacklisted(shader.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsBlacklisted(string shaderName) {
|
|
|
|
return _shaderBlacklist.Contains(shaderName);
|
|
|
|
}
|
|
|
|
|
2020-06-03 00:14:52 +00:00
|
|
|
private static void ParseConfig(ConfigNode node) {
|
2020-06-02 20:46:16 +00:00
|
|
|
foreach (var blacklist in node.GetNodes("SHADERBLACKLIST")) {
|
|
|
|
foreach (var shaderName in blacklist.GetValuesList("shader")) {
|
|
|
|
_shaderBlacklist.Add(shaderName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 19:20:47 +00:00
|
|
|
private static Texture2D MakeBlankNormal() {
|
|
|
|
Debug.Log("ConformalDecals: Generating neutral normal map texture");
|
|
|
|
var width = 2;
|
|
|
|
var height = 2;
|
|
|
|
var color = new Color32(255, 128, 128, 128);
|
|
|
|
var colors = new Color32[] { color, color, color, color };
|
|
|
|
|
|
|
|
var tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
|
|
|
|
for (var x = 0; x <= width; x++) {
|
|
|
|
for (var y = 0; y < height; y++) {
|
|
|
|
tex.SetPixels32(colors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tex.Apply();
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2020-06-03 00:14:52 +00:00
|
|
|
public static void ModuleManagerPostLoad() {
|
2020-06-02 20:46:16 +00:00
|
|
|
_shaderBlacklist = new List<string>();
|
|
|
|
|
|
|
|
var configs = GameDatabase.Instance.GetConfigs("CONFORMALDECALS");
|
|
|
|
|
|
|
|
if (configs.Length > 0) {
|
2020-06-03 00:14:52 +00:00
|
|
|
Debug.Log("ConformalDecals: loading config");
|
2020-06-02 20:46:16 +00:00
|
|
|
foreach (var config in configs) {
|
|
|
|
ParseConfig(config.config);
|
|
|
|
}
|
|
|
|
}
|
2020-06-10 19:20:47 +00:00
|
|
|
|
|
|
|
_blankNormal = MakeBlankNormal();
|
2020-06-02 20:46:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|