mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Better normal map handling for parts with no normals
This commit is contained in:
parent
f335aec8ba
commit
af72c28046
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:2f0d11131cd96a994846eb4d9a7128323585b4da184076321440ee5e6bb9e20d
|
oid sha256:f1ab91ca9152d988a3b20881e0dc02d08d9f8538e84a1c14398a09d989d5d71f
|
||||||
size 36352
|
size 36864
|
||||||
|
|
|
@ -7,15 +7,25 @@ using UnityEngine.Rendering;
|
||||||
|
|
||||||
namespace ConformalDecals.MaterialModifiers {
|
namespace ConformalDecals.MaterialModifiers {
|
||||||
public class MaterialPropertyCollection : ScriptableObject, ISerializationCallbackReceiver {
|
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 Shader _shader;
|
||||||
[SerializeField] private MaterialTextureProperty _mainTexture;
|
[SerializeField] private MaterialTextureProperty _mainTexture;
|
||||||
[SerializeField] private string[] _serializedNames;
|
[SerializeField] private string[] _serializedNames;
|
||||||
[SerializeField] private MaterialProperty[] _serializedProperties;
|
[SerializeField] private MaterialProperty[] _serializedProperties;
|
||||||
|
|
||||||
|
|
||||||
private Dictionary<string, MaterialProperty> _materialProperties;
|
private Dictionary<string, MaterialProperty> _materialProperties;
|
||||||
|
|
||||||
private Material _decalMaterial;
|
private Material _decalMaterial;
|
||||||
private Material _previewMaterial;
|
private Material _previewMaterial;
|
||||||
|
private int _renderQueue = 2100;
|
||||||
|
|
||||||
public Shader DecalShader => _shader;
|
public Shader DecalShader => _shader;
|
||||||
|
|
||||||
|
@ -25,6 +35,7 @@ namespace ConformalDecals.MaterialModifiers {
|
||||||
_decalMaterial = new Material(_shader);
|
_decalMaterial = new Material(_shader);
|
||||||
|
|
||||||
_decalMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Off);
|
_decalMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Off);
|
||||||
|
_decalMaterial.renderQueue = RenderQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _decalMaterial;
|
return _decalMaterial;
|
||||||
|
@ -185,10 +196,6 @@ namespace ConformalDecals.MaterialModifiers {
|
||||||
_previewMaterial = null;
|
_previewMaterial = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRenderQueue(int queue) {
|
|
||||||
DecalMaterial.renderQueue = queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateScale(Vector2 scale) {
|
public void UpdateScale(Vector2 scale) {
|
||||||
foreach (var entry in _materialProperties) {
|
foreach (var entry in _materialProperties) {
|
||||||
if (entry.Value is MaterialTextureProperty textureProperty && textureProperty.autoScale) {
|
if (entry.Value is MaterialTextureProperty textureProperty && textureProperty.autoScale) {
|
||||||
|
|
|
@ -250,6 +250,10 @@ namespace ConformalDecals {
|
||||||
|
|
||||||
UpdateMaterials();
|
UpdateMaterials();
|
||||||
|
|
||||||
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
|
UpdateTweakables();
|
||||||
|
}
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
UpdateScale();
|
UpdateScale();
|
||||||
}
|
}
|
||||||
|
@ -278,7 +282,7 @@ namespace ConformalDecals {
|
||||||
UpdateTweakables();
|
UpdateTweakables();
|
||||||
}
|
}
|
||||||
|
|
||||||
materialProperties.SetRenderQueue(DecalQueue);
|
materialProperties.RenderQueue = DecalQueue;
|
||||||
|
|
||||||
UpdateMaterials();
|
UpdateMaterials();
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,7 @@ namespace ConformalDecals {
|
||||||
_decalMPB.SetVector(DecalPropertyIDs._DecalNormal, decalNormal);
|
_decalMPB.SetVector(DecalPropertyIDs._DecalNormal, decalNormal);
|
||||||
_decalMPB.SetVector(DecalPropertyIDs._DecalTangent, decalTangent);
|
_decalMPB.SetVector(DecalPropertyIDs._DecalTangent, decalTangent);
|
||||||
|
|
||||||
if (useBaseNormal) {
|
if (useBaseNormal && targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) {
|
||||||
if (targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) {
|
|
||||||
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap));
|
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap));
|
||||||
|
|
||||||
var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap);
|
var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap);
|
||||||
|
@ -44,11 +43,9 @@ namespace ConformalDecals {
|
||||||
_decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y));
|
_decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Debug.Log("Using blank normal");
|
|
||||||
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal);
|
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public bool Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
|
public bool Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
|
||||||
if (_projectionEnabled) {
|
if (_projectionEnabled) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user