From 3cd229bc23154b1b74130ca9330594bb5e907513 Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Sun, 13 Mar 2022 14:02:39 -0700 Subject: [PATCH] Fix decals not projecting when loading prefabs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Add support for regex shader blacklisting • Re-allow projecting onto transparentFX --- CHANGELOG.md | 16 ++++++++++++ .../ConformalDecals/Patches/Waterfall.cfg | 7 ++++++ .../Resources/ConformalDecals.cfg | 12 ++------- Source/ConformalDecals/DecalConfig.cs | 25 +++++++++++++++---- .../ConformalDecals/ModuleConformalDecal.cs | 3 --- 5 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 GameData/ConformalDecals/Patches/Waterfall.cfg diff --git a/CHANGELOG.md b/CHANGELOG.md index 854d0b8..0573963 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,22 @@ All notable changes to this project will be documented in this file | website | https://forum.kerbalspaceprogram.com/index.php?/topic/194802-18-111-conformal-decals | | author | Andrew Cassidy | +## Unreleased + +### Fixed + +- Fixed decals not projecting on loading prefabs + +### Changed + +- Re-enabled projecting onto TransparentFX layer + +### Added + +- Allowed for regular expressions to be used when blacklisting shaders +- Added all Waterfall shaders to the shader blacklist when Waterfall is present + + ## 0.2.9 - 2022-03-12 ### Fixed diff --git a/GameData/ConformalDecals/Patches/Waterfall.cfg b/GameData/ConformalDecals/Patches/Waterfall.cfg new file mode 100644 index 0000000..f3e06e6 --- /dev/null +++ b/GameData/ConformalDecals/Patches/Waterfall.cfg @@ -0,0 +1,7 @@ +// Prevent projection onto Waterfall plumes + +CONFORMALDECALS:NEEDS[Waterfall] { + SHADERBLACKLIST { + shaderRegex = Waterfall/.* + } +} diff --git a/GameData/ConformalDecals/Resources/ConformalDecals.cfg b/GameData/ConformalDecals/Resources/ConformalDecals.cfg index 0057e17..e868a65 100644 --- a/GameData/ConformalDecals/Resources/ConformalDecals.cfg +++ b/GameData/ConformalDecals/Resources/ConformalDecals.cfg @@ -4,21 +4,13 @@ CONFORMALDECALS { SHADERBLACKLIST { shader = DepthMask - shader = KSP/Alpha/Cutoff - shader = KSP/Alpha/Cutoff Bumped - shader = KSP/Alpha/Translucent - shader = KSP/Alpha/Translucent Additive - shader = KSP/Alpha/Translucent Specular - shader = KSP/Alpha/Unlit Transparent shader = KSP/Bumped Specular (Transparent) shader = KSP/FX/ScrollingUnlit - shader = KSP/Particles/Additive - shader = KSP/Particles/Additive (Soft) - shader = KSP/Particles/Alpha Blended - shader = KSP/Particles/Alpha Blended Emissive Cutout shader = KSP/Specular (Cutoff) shader = KSP/Specular (Transparent) shader = Solid Color (Alpha) + shaderRegex = KSP/Alpha/.* + shaderRegex = KSP/Particles/.* } FONT { diff --git a/Source/ConformalDecals/DecalConfig.cs b/Source/ConformalDecals/DecalConfig.cs index b681d8e..22ef954 100644 --- a/Source/ConformalDecals/DecalConfig.cs +++ b/Source/ConformalDecals/DecalConfig.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text.RegularExpressions; using ConformalDecals.Text; using ConformalDecals.Util; using TMPro; @@ -10,6 +11,7 @@ namespace ConformalDecals { public static class DecalConfig { private static Texture2D _blankNormal; private static List _shaderBlacklist; + private static List _shaderRegexBlacklist; private static Dictionary _fontList; private static int _decalLayer = 31; private static bool _selectableInFlight; @@ -50,15 +52,23 @@ namespace ConformalDecals { public static bool SelectableInFlight => _selectableInFlight; public static IEnumerable Fonts => _fontList.Values; - - public static DecalFont FallbackFont { get; private set; } public static bool IsBlacklisted(Shader shader) { return IsBlacklisted(shader.name); } public static bool IsBlacklisted(string shaderName) { - return _shaderBlacklist.Contains(shaderName); + if (_shaderBlacklist.Contains(shaderName)) return true; + + foreach (var regex in _shaderRegexBlacklist) { + if (regex.IsMatch(shaderName)) { + _shaderBlacklist.Add(shaderName); + Logging.Log($"Caching blacklisted shader name '{shaderName}' which matches '{regex}'"); + return true; + } + } + + return false; } public static bool IsLegacy(string shaderName, out string newShader, out string[] keywords) { @@ -91,10 +101,14 @@ namespace ConformalDecals { foreach (var shaderName in blacklist.GetValuesList("shader")) { _shaderBlacklist.Add(shaderName); } + + foreach (var shaderRegex in blacklist.GetValuesList("shaderRegex")) { + _shaderRegexBlacklist.Add(new Regex(shaderRegex)); + } } var allFonts = Resources.FindObjectsOfTypeAll(); - + foreach (var fontNode in node.GetNodes("FONT")) { try { var font = new DecalFont(fontNode, allFonts); @@ -128,13 +142,14 @@ namespace ConformalDecals { // ReSharper disable once UnusedMember.Global public static void ModuleManagerPostLoad() { _shaderBlacklist = new List(); + _shaderRegexBlacklist = new List(); _fontList = new Dictionary(); var configs = GameDatabase.Instance.GetConfigs("CONFORMALDECALS"); if (configs.Length > 0) { - Logging.Log("loading config"); foreach (var config in configs) { + Logging.Log($"loading config file '{config.url}'"); ParseConfig(config.config); } } diff --git a/Source/ConformalDecals/ModuleConformalDecal.cs b/Source/ConformalDecals/ModuleConformalDecal.cs index 064c81d..279bc28 100644 --- a/Source/ConformalDecals/ModuleConformalDecal.cs +++ b/Source/ConformalDecals/ModuleConformalDecal.cs @@ -482,9 +482,6 @@ namespace ConformalDecals { // skip disabled renderers if (renderer.gameObject.activeInHierarchy == false) continue; - // skip transparentFX layer, which causes issues with Waterfall - if (renderer.gameObject.layer == 1) continue; - // skip blacklisted shaders if (DecalConfig.IsBlacklisted(renderer.material.shader)) continue;