diff --git a/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll b/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll index 0174266..a9601b2 100644 Binary files a/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll and b/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll differ diff --git a/Source/ConformalDecals/MaterialModifiers/MaterialPropertyCollection.cs b/Source/ConformalDecals/MaterialModifiers/MaterialPropertyCollection.cs index 827cfc4..c4de994 100644 --- a/Source/ConformalDecals/MaterialModifiers/MaterialPropertyCollection.cs +++ b/Source/ConformalDecals/MaterialModifiers/MaterialPropertyCollection.cs @@ -7,15 +7,25 @@ using UnityEngine.Rendering; namespace ConformalDecals.MaterialModifiers { public class MaterialPropertyCollection : ScriptableObject, ISerializationCallbackReceiver { + public int RenderQueue { + get => _renderQueue; + set { + _renderQueue = value; + if (_decalMaterial != null) _decalMaterial.renderQueue = value; + } + } + [SerializeField] private Shader _shader; [SerializeField] private MaterialTextureProperty _mainTexture; [SerializeField] private string[] _serializedNames; [SerializeField] private MaterialProperty[] _serializedProperties; + private Dictionary _materialProperties; private Material _decalMaterial; private Material _previewMaterial; + private int _renderQueue = 2100; public Shader DecalShader => _shader; @@ -25,6 +35,7 @@ namespace ConformalDecals.MaterialModifiers { _decalMaterial = new Material(_shader); _decalMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Off); + _decalMaterial.renderQueue = RenderQueue; } return _decalMaterial; @@ -185,10 +196,6 @@ namespace ConformalDecals.MaterialModifiers { _previewMaterial = null; } - public void SetRenderQueue(int queue) { - DecalMaterial.renderQueue = queue; - } - public void UpdateScale(Vector2 scale) { foreach (var entry in _materialProperties) { if (entry.Value is MaterialTextureProperty textureProperty && textureProperty.autoScale) { diff --git a/Source/ConformalDecals/ModuleConformalDecal.cs b/Source/ConformalDecals/ModuleConformalDecal.cs index 18af4fd..a213b01 100644 --- a/Source/ConformalDecals/ModuleConformalDecal.cs +++ b/Source/ConformalDecals/ModuleConformalDecal.cs @@ -250,6 +250,10 @@ namespace ConformalDecals { UpdateMaterials(); + if (HighLogic.LoadedSceneIsEditor) { + UpdateTweakables(); + } + if (HighLogic.LoadedSceneIsGame) { UpdateScale(); } @@ -278,7 +282,7 @@ namespace ConformalDecals { UpdateTweakables(); } - materialProperties.SetRenderQueue(DecalQueue); + materialProperties.RenderQueue = DecalQueue; UpdateMaterials(); diff --git a/Source/ConformalDecals/ProjectionTarget.cs b/Source/ConformalDecals/ProjectionTarget.cs index 519aef8..5b8adae 100644 --- a/Source/ConformalDecals/ProjectionTarget.cs +++ b/Source/ConformalDecals/ProjectionTarget.cs @@ -34,19 +34,16 @@ namespace ConformalDecals { _decalMPB.SetVector(DecalPropertyIDs._DecalNormal, decalNormal); _decalMPB.SetVector(DecalPropertyIDs._DecalTangent, decalTangent); - if (useBaseNormal) { - if (targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) { - _decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap)); + if (useBaseNormal && targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) { + _decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap)); - var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap); - var normalOffset = targetMaterial.GetTextureOffset(DecalPropertyIDs._BumpMap); + var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap); + var normalOffset = targetMaterial.GetTextureOffset(DecalPropertyIDs._BumpMap); - _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); - } + _decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y)); + } + else { + _decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal); } }