mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
simplify opacity cutoff and wear by using material properties
This commit is contained in:
parent
be3b7f791a
commit
03d2e66543
Binary file not shown.
@ -280,20 +280,6 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
UpdateTile(tile);
|
UpdateTile(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetOpacity(float opacity) {
|
|
||||||
DecalMaterial.SetFloat(DecalPropertyIDs._DecalOpacity, opacity);
|
|
||||||
PreviewMaterial.SetFloat(DecalPropertyIDs._DecalOpacity, opacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetCutoff(float cutoff) {
|
|
||||||
DecalMaterial.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() {
|
||||||
foreach (var material in Materials) {
|
foreach (var material in Materials) {
|
||||||
UpdateMaterial(material);
|
UpdateMaterial(material);
|
||||||
|
@ -71,14 +71,17 @@ namespace ConformalDecals {
|
|||||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-opacity", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
|
[KSPField(guiName = "#LOC_ConformalDecals_gui-opacity", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
|
||||||
UI_FloatRange()]
|
UI_FloatRange()]
|
||||||
public float opacity = 1.0f;
|
public float opacity = 1.0f;
|
||||||
|
private MaterialFloatProperty _opacityProperty;
|
||||||
|
|
||||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-cutoff", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
|
[KSPField(guiName = "#LOC_ConformalDecals_gui-cutoff", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
|
||||||
UI_FloatRange()]
|
UI_FloatRange()]
|
||||||
public float cutoff = 0.5f;
|
public float cutoff = 0.5f;
|
||||||
|
private MaterialFloatProperty _cutoffProperty;
|
||||||
|
|
||||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"),
|
[KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"),
|
||||||
UI_FloatRange()]
|
UI_FloatRange()]
|
||||||
public float wear = 100;
|
public float wear = 100;
|
||||||
|
private MaterialFloatProperty _wearProperty;
|
||||||
|
|
||||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-multiproject", guiActive = false, guiActiveEditor = true, isPersistant = true),
|
[KSPField(guiName = "#LOC_ConformalDecals_gui-multiproject", guiActive = false, guiActiveEditor = true, isPersistant = true),
|
||||||
UI_Toggle()]
|
UI_Toggle()]
|
||||||
@ -131,6 +134,10 @@ namespace ConformalDecals {
|
|||||||
else {
|
else {
|
||||||
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_opacityProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_DecalOpacity");
|
||||||
|
_cutoffProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_Cutoff");
|
||||||
|
_wearProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_EdgeWearStrength");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -227,30 +234,20 @@ 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
|
||||||
UpdateProjection();
|
UpdateProjection();
|
||||||
UpdateTargets();
|
|
||||||
|
|
||||||
foreach (var counterpart in part.symmetryCounterparts) {
|
foreach (var counterpart in part.symmetryCounterparts) {
|
||||||
var decal = counterpart.GetComponent<ModuleConformalDecal>();
|
var decal = counterpart.GetComponent<ModuleConformalDecal>();
|
||||||
decal.UpdateProjection();
|
decal.UpdateProjection();
|
||||||
decal.UpdateTargets();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called when the decal's material is modified through a tweakable
|
/// Called when the decal's material is modified through a tweakable
|
||||||
protected void OnMaterialTweakEvent(BaseField field, object obj) {
|
protected void OnMaterialTweakEvent(BaseField field, object obj) {
|
||||||
materialProperties.SetOpacity(opacity);
|
UpdateMaterials();
|
||||||
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.UpdateMaterials();
|
||||||
decal.materialProperties.SetCutoff(cutoff);
|
|
||||||
if (useBaseNormal) {
|
|
||||||
decal.materialProperties.SetWear(wear);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +255,7 @@ namespace ConformalDecals {
|
|||||||
protected void OnVariantApplied(Part eventPart, PartVariant variant) {
|
protected void OnVariantApplied(Part eventPart, PartVariant variant) {
|
||||||
if (_isAttached && eventPart != null && (!projectMultiple || eventPart == part.parent)) {
|
if (_isAttached && eventPart != null && (!projectMultiple || eventPart == part.parent)) {
|
||||||
_targets.Remove(eventPart);
|
_targets.Remove(eventPart);
|
||||||
UpdateTargets();
|
UpdateProjection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +279,6 @@ namespace ConformalDecals {
|
|||||||
protected void OnPartTransformed(Part eventPart) {
|
protected void OnPartTransformed(Part eventPart) {
|
||||||
if (this.part == eventPart) {
|
if (this.part == eventPart) {
|
||||||
UpdateProjection();
|
UpdateProjection();
|
||||||
UpdateTargets();
|
|
||||||
}
|
}
|
||||||
else if (_isAttached && projectMultiple) {
|
else if (_isAttached && projectMultiple) {
|
||||||
UpdatePartTarget(eventPart, _boundsRenderer.bounds);
|
UpdatePartTarget(eventPart, _boundsRenderer.bounds);
|
||||||
@ -354,7 +350,6 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
UpdateMaterials();
|
UpdateMaterials();
|
||||||
UpdateProjection();
|
UpdateProjection();
|
||||||
UpdateTargets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called when decal is detached from its parent part
|
/// Called when decal is detached from its parent part
|
||||||
@ -542,7 +537,6 @@ namespace ConformalDecals {
|
|||||||
UpdateTextures();
|
UpdateTextures();
|
||||||
UpdateMaterials();
|
UpdateMaterials();
|
||||||
UpdateProjection();
|
UpdateProjection();
|
||||||
UpdateTargets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update decal textures
|
/// Update decal textures
|
||||||
@ -550,12 +544,11 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
/// Update decal materials
|
/// Update decal materials
|
||||||
protected virtual void UpdateMaterials() {
|
protected virtual void UpdateMaterials() {
|
||||||
|
_opacityProperty.value = opacity;
|
||||||
|
_cutoffProperty.value = cutoff;
|
||||||
|
_wearProperty.value = wear;
|
||||||
|
|
||||||
materialProperties.UpdateMaterials();
|
materialProperties.UpdateMaterials();
|
||||||
materialProperties.SetOpacity(opacity);
|
|
||||||
materialProperties.SetCutoff(cutoff);
|
|
||||||
if (useBaseNormal) {
|
|
||||||
materialProperties.SetWear(wear);
|
|
||||||
}
|
|
||||||
|
|
||||||
_decalMaterial = materialProperties.DecalMaterial;
|
_decalMaterial = materialProperties.DecalMaterial;
|
||||||
_previewMaterial = materialProperties.PreviewMaterial;
|
_previewMaterial = materialProperties.PreviewMaterial;
|
||||||
@ -606,21 +599,7 @@ namespace ConformalDecals {
|
|||||||
_orthoMatrix[1, 3] = 0.5f;
|
_orthoMatrix[1, 3] = 0.5f;
|
||||||
|
|
||||||
decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth);
|
decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth);
|
||||||
}
|
|
||||||
else {
|
|
||||||
// rescale preview model
|
|
||||||
decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2);
|
|
||||||
|
|
||||||
// update back material scale
|
|
||||||
if (updateBackScale) {
|
|
||||||
backMaterial.SetTextureScale(PropertyIDs._MainTex, new Vector2(size.x * backTextureBaseScale.x, size.y * backTextureBaseScale.y));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Called when updating decal targets
|
|
||||||
protected void UpdateTargets() {
|
|
||||||
if (!_isAttached) return;
|
|
||||||
var projectionBounds = _boundsRenderer.bounds;
|
var projectionBounds = _boundsRenderer.bounds;
|
||||||
|
|
||||||
// disable all targets
|
// disable all targets
|
||||||
@ -641,6 +620,16 @@ namespace ConformalDecals {
|
|||||||
UpdatePartTarget(targetPart, projectionBounds);
|
UpdatePartTarget(targetPart, projectionBounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// rescale preview model
|
||||||
|
decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2);
|
||||||
|
|
||||||
|
// update back material scale
|
||||||
|
if (updateBackScale) {
|
||||||
|
backMaterial.SetTextureScale(PropertyIDs._MainTex, new Vector2(size.x * backTextureBaseScale.x, size.y * backTextureBaseScale.y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void UpdatePartTarget(Part targetPart, Bounds projectionBounds) {
|
protected void UpdatePartTarget(Part targetPart, Bounds projectionBounds) {
|
||||||
if (targetPart.GetComponent<ModuleConformalDecal>() != null) return; // skip other decals
|
if (targetPart.GetComponent<ModuleConformalDecal>() != null) return; // skip other decals
|
||||||
|
Loading…
Reference in New Issue
Block a user