Add slider for edge wear

feature-multiSDF
Andrew Cassidy 4 years ago
parent d52cf6725d
commit a386281fb2

@ -14,6 +14,7 @@ Localization
#LOC_ConformalDecals_gui-depth = Depth #LOC_ConformalDecals_gui-depth = Depth
#LOC_ConformalDecals_gui-opacity = Opacity #LOC_ConformalDecals_gui-opacity = Opacity
#LOC_ConformalDecals_gui-cutoff = Cutoff #LOC_ConformalDecals_gui-cutoff = Cutoff
#LOC_ConformalDecals_gui-wear = Edge Wear
#LOC_ConformalDecals_gui-aspectratio = Aspect Ratio #LOC_ConformalDecals_gui-aspectratio = Aspect Ratio
#LOC_ConformalDecals_gui-select-flag = Select Flag #LOC_ConformalDecals_gui-select-flag = Select Flag
#LOC_ConformalDecals_gui-reset-flag = Reset Flag #LOC_ConformalDecals_gui-reset-flag = Reset Flag

@ -68,7 +68,7 @@ PART
cutoff = 0.5 cutoff = 0.5
cutoffAdjustable = false cutoffAdjustable = false
scaleRange = 0.05, 1 scaleRange = 0.1, 4
shader = ConformalDecals/Paint/Specular shader = ConformalDecals/Paint/Specular
@ -511,7 +511,7 @@ PART
SUBTYPE { SUBTYPE {
name = numeral-0 name = numeral-0
title = #LOC_ConformalDecals_generic-variant-numeral-10 title = #LOC_ConformalDecals_generic-variant-numeral-0
primaryColor = Black primaryColor = Black
secondaryColor = White secondaryColor = White

@ -59,5 +59,6 @@ PART
useBaseNormal = true useBaseNormal = true
defaultDepth = 0.2 defaultDepth = 0.2
defaultCutoff = 0
} }
} }

@ -10,6 +10,7 @@ namespace ConformalDecals {
public static readonly int _DecalNormal = Shader.PropertyToID("_DecalNormal"); public static readonly int _DecalNormal = Shader.PropertyToID("_DecalNormal");
public static readonly int _DecalOpacity = Shader.PropertyToID("_DecalOpacity"); public static readonly int _DecalOpacity = Shader.PropertyToID("_DecalOpacity");
public static readonly int _DecalTangent = Shader.PropertyToID("_DecalTangent"); public static readonly int _DecalTangent = Shader.PropertyToID("_DecalTangent");
public static readonly int _EdgeWearStrength = Shader.PropertyToID("_EdgeWearStrength");
public static readonly int _ProjectionMatrix = Shader.PropertyToID("_ProjectionMatrix"); public static readonly int _ProjectionMatrix = Shader.PropertyToID("_ProjectionMatrix");
} }
} }

@ -238,6 +238,10 @@ namespace ConformalDecals.MaterialModifiers {
PreviewMaterial.SetFloat(DecalPropertyIDs._Cutoff, cutoff); PreviewMaterial.SetFloat(DecalPropertyIDs._Cutoff, cutoff);
} }
public void SetWear(float wear) {
DecalMaterial.SetFloat(DecalPropertyIDs._EdgeWearStrength, wear);
}
public void UpdateMaterials() { public void UpdateMaterials() {
UpdateMaterial(DecalMaterial); UpdateMaterial(DecalMaterial);
UpdateMaterial(PreviewMaterial); UpdateMaterial(PreviewMaterial);

@ -54,9 +54,13 @@ namespace ConformalDecals {
[KSPField] public Vector2 opacityRange = new Vector2(0, 1); [KSPField] public Vector2 opacityRange = new Vector2(0, 1);
[KSPField] public bool cutoffAdjustable = true; [KSPField] public bool cutoffAdjustable = true;
[KSPField] public float defaultCutoff; [KSPField] public float defaultCutoff = 0.5f;
[KSPField] public Vector2 cutoffRange = new Vector2(0, 1); [KSPField] public Vector2 cutoffRange = new Vector2(0, 1);
[KSPField] public bool useBaseNormal = true;
[KSPField] public float defaultWear = 100;
[KSPField] public Vector2 wearRange = new Vector2(0, 100);
[KSPField] public Rect tileRect = new Rect(-1, -1, 0, 0); [KSPField] public Rect tileRect = new Rect(-1, -1, 0, 0);
[KSPField] public Vector2 tileSize; [KSPField] public Vector2 tileSize;
[KSPField] public int tileIndex = -1; [KSPField] public int tileIndex = -1;
@ -66,10 +70,6 @@ namespace ConformalDecals {
/// </summary> /// </summary>
[KSPField] public bool updateBackScale = true; [KSPField] public bool updateBackScale = true;
/// <summary>
/// Should the shader use the normal map of the part its projecting onto? Use only with "paint" shaders.
/// </summary>
[KSPField] public bool useBaseNormal = true;
// INTERNAL VALUES // INTERNAL VALUES
@ -101,6 +101,13 @@ namespace ConformalDecals {
UI_FloatRange(stepIncrement = 0.05f)] UI_FloatRange(stepIncrement = 0.05f)]
public float cutoff = 0.5f; public float cutoff = 0.5f;
/// <summary>
/// Edge wear value for the decal shader. Only relevent when useBaseNormal is true and the shader is a paint shader
/// </summary>
[KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"),
UI_FloatRange()]
public float wear = 100;
[KSPField] public MaterialPropertyCollection materialProperties; [KSPField] public MaterialPropertyCollection materialProperties;
[KSPField] public Transform decalFrontTransform; [KSPField] public Transform decalFrontTransform;
@ -313,7 +320,7 @@ namespace ConformalDecals {
// scale or depth values have been changed, so update scale // scale or depth values have been changed, so update scale
// and update projection matrices if attached // and update projection matrices if attached
UpdateScale(); UpdateScale();
foreach (var counterpart in part.symmetryCounterparts) { foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalDecal>(); var decal = counterpart.GetComponent<ModuleConformalDecal>();
decal.UpdateScale(); decal.UpdateScale();
@ -323,11 +330,17 @@ namespace ConformalDecals {
protected void OnMaterialTweakEvent(BaseField field, object obj) { protected void OnMaterialTweakEvent(BaseField field, object obj) {
materialProperties.SetOpacity(opacity); materialProperties.SetOpacity(opacity);
materialProperties.SetCutoff(cutoff); materialProperties.SetCutoff(cutoff);
if (useBaseNormal) {
materialProperties.SetWear(wear);
}
foreach (var counterpart in part.symmetryCounterparts) { foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalDecal>(); var decal = counterpart.GetComponent<ModuleConformalDecal>();
decal.materialProperties.SetOpacity(opacity); decal.materialProperties.SetOpacity(opacity);
decal.materialProperties.SetCutoff(cutoff); decal.materialProperties.SetCutoff(cutoff);
if (useBaseNormal) {
decal.materialProperties.SetWear(wear);
}
} }
} }
@ -427,6 +440,9 @@ namespace ConformalDecals {
materialProperties.UpdateMaterials(); materialProperties.UpdateMaterials();
materialProperties.SetOpacity(opacity); materialProperties.SetOpacity(opacity);
materialProperties.SetCutoff(cutoff); materialProperties.SetCutoff(cutoff);
if (useBaseNormal) {
materialProperties.SetWear(wear);
}
_decalMaterial = materialProperties.DecalMaterial; _decalMaterial = materialProperties.DecalMaterial;
_previewMaterial = materialProperties.PreviewMaterial; _previewMaterial = materialProperties.PreviewMaterial;
@ -470,11 +486,13 @@ namespace ConformalDecals {
var depthField = Fields[nameof(depth)]; var depthField = Fields[nameof(depth)];
var opacityField = Fields[nameof(opacity)]; var opacityField = Fields[nameof(opacity)];
var cutoffField = Fields[nameof(cutoff)]; var cutoffField = Fields[nameof(cutoff)];
var wearField = Fields[nameof(wear)];
scaleField.guiActiveEditor = scaleAdjustable; scaleField.guiActiveEditor = scaleAdjustable;
depthField.guiActiveEditor = depthAdjustable; depthField.guiActiveEditor = depthAdjustable;
opacityField.guiActiveEditor = opacityAdjustable; opacityField.guiActiveEditor = opacityAdjustable;
cutoffField.guiActiveEditor = cutoffAdjustable; cutoffField.guiActiveEditor = cutoffAdjustable;
wearField.guiActiveEditor = useBaseNormal;
var steps = 20; var steps = 20;
@ -523,6 +541,17 @@ namespace ConformalDecals {
cutoffEditor.stepIncrement = (maxValue - minValue) / steps; cutoffEditor.stepIncrement = (maxValue - minValue) / steps;
cutoffEditor.onFieldChanged = OnMaterialTweakEvent; cutoffEditor.onFieldChanged = OnMaterialTweakEvent;
} }
if (useBaseNormal) {
var minValue = Mathf.Max(0, wearRange.x);
var maxValue = Mathf.Max(minValue, wearRange.y);
var wearEditor = (UI_FloatRange) wearField.uiControlEditor;
wearEditor.minValue = minValue;
wearEditor.maxValue = maxValue;
wearEditor.stepIncrement = (maxValue - minValue) / steps;
wearEditor.onFieldChanged = OnMaterialTweakEvent;
}
} }
protected void Render(Camera camera) { protected void Render(Camera camera) {

Loading…
Cancel
Save