diff --git a/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll b/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll index 049113c..2bebe85 100644 --- a/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll +++ b/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:143945aeb89bfa4899ca3aa81544026a16315edf746c8fbf8b719b3a7cc86378 +oid sha256:2f0d11131cd96a994846eb4d9a7128323585b4da184076321440ee5e6bb9e20d size 36352 diff --git a/Source/ConformalDecals/DecalConfig.cs b/Source/ConformalDecals/DecalConfig.cs index be98770..e446b94 100644 --- a/Source/ConformalDecals/DecalConfig.cs +++ b/Source/ConformalDecals/DecalConfig.cs @@ -1,9 +1,13 @@ using System.Collections.Generic; using UnityEngine; +using UnityEngine.Experimental.Rendering; namespace ConformalDecals { public static class DecalConfig { + private static Texture2D _blankNormal; private static List _shaderBlacklist; + + public static Texture2D BlankNormal => _blankNormal; public static bool IsBlacklisted(Shader shader) { return IsBlacklisted(shader.name); @@ -21,6 +25,24 @@ namespace ConformalDecals { } } + 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; + } + public static void ModuleManagerPostLoad() { _shaderBlacklist = new List(); @@ -32,6 +54,8 @@ namespace ConformalDecals { ParseConfig(config.config); } } + + _blankNormal = MakeBlankNormal(); } } } \ No newline at end of file diff --git a/Source/ConformalDecals/ModuleConformalDecal.cs b/Source/ConformalDecals/ModuleConformalDecal.cs index 0acaba4..18af4fd 100644 --- a/Source/ConformalDecals/ModuleConformalDecal.cs +++ b/Source/ConformalDecals/ModuleConformalDecal.cs @@ -228,6 +228,12 @@ namespace ConformalDecals { } // handle texture tiling parameters + var tileString = node.GetValue("tile"); + this.Log(tileString); + if (!string.IsNullOrEmpty(tileString)) { + var tileValid = ParseExtensions.TryParseRect(tileString, out tileRect); + if (!tileValid) throw new FormatException($"Invalid rect value for tile '{tileString}'"); + } if (tileRect.x >= 0) { materialProperties.UpdateTile(tileRect); } @@ -338,6 +344,7 @@ namespace ConformalDecals { break; case ConstructionEventType.PartOffsetting: case ConstructionEventType.PartRotating: + UpdateScale(); break; } } diff --git a/Source/ConformalDecals/ProjectionTarget.cs b/Source/ConformalDecals/ProjectionTarget.cs index 405e9c7..519aef8 100644 --- a/Source/ConformalDecals/ProjectionTarget.cs +++ b/Source/ConformalDecals/ProjectionTarget.cs @@ -1,4 +1,3 @@ -using ConformalDecals.Util; using UnityEngine; using UnityEngine.Rendering; @@ -35,10 +34,8 @@ namespace ConformalDecals { _decalMPB.SetVector(DecalPropertyIDs._DecalNormal, decalNormal); _decalMPB.SetVector(DecalPropertyIDs._DecalTangent, decalTangent); - if (useBaseNormal && targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) { - var normal = targetMaterial.GetTexture(DecalPropertyIDs._BumpMap); - if (normal != null) { - + if (useBaseNormal) { + if (targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) { _decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap)); var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap); @@ -46,6 +43,10 @@ namespace ConformalDecals { _decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y)); } + else { + Debug.Log("Using blank normal"); + _decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal); + } } }