From b247e9af4e063fe8c4752ea63449e416be0b7153 Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Thu, 11 Jun 2020 19:59:53 -0700 Subject: [PATCH] Add visible bounding boxes around projection area --- Assets/Shaders/SelectionGlow.shader | 4 ++- .../ConformalDecals/Assets/decal-blank.mu | 4 +-- .../Parts/Generic/decal-generic.cfg | 4 --- .../Parts/Semiotic/decal-semiotic.cfg | 4 --- .../ConformalDecals/Parts/decal-flag.cfg | 5 ---- .../Plugins/ConformalDecals.dll | 2 +- .../Resources/conformaldecals.shab | 4 +-- .../ConformalDecals/ModuleConformalDecal.cs | 30 ++++++++++--------- 8 files changed, 24 insertions(+), 33 deletions(-) diff --git a/Assets/Shaders/SelectionGlow.shader b/Assets/Shaders/SelectionGlow.shader index f74862c..77fb94b 100644 --- a/Assets/Shaders/SelectionGlow.shader +++ b/Assets/Shaders/SelectionGlow.shader @@ -8,6 +8,7 @@ Shader "ConformalDecals/SelectionGlow" _RimEdgeOpacity("Rim Edge Opacity", Range(0,1)) = 0.2 _RimFalloff("Rim Falloff", Range(0.01,5) ) = 0.1 _RimColor("Rim Color", Color) = (0,0,0,0) + _RimOpacity("Rim Opacity", Range(0,1)) = 0.5 } SubShader { @@ -27,6 +28,7 @@ Shader "ConformalDecals/SelectionGlow" half _RimEdgeOpacity; float _RimFalloff; float4 _RimColor; + half _RimOpacity; #include "UnityCG.cginc" #include "Lighting.cginc" @@ -53,7 +55,7 @@ Shader "ConformalDecals/SelectionGlow" float3 worldViewDir = normalize(UnityWorldSpaceViewDir(i.worldPosition)); half rim = 1.0 - saturate(dot (normalize(worldViewDir), i.worldNormal)); - c.rgb = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a; + c.rgb = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a * _RimOpacity; half edgeGlow = 0; edgeGlow = max(edgeGlow, pow(1-saturate(i.uv.x / _RimEdgeGlow), _RimEdgePow)); edgeGlow = max(edgeGlow, pow(1-saturate(i.uv.y / _RimEdgeGlow), _RimEdgePow)); diff --git a/Distribution/GameData/ConformalDecals/Assets/decal-blank.mu b/Distribution/GameData/ConformalDecals/Assets/decal-blank.mu index 5a0984f..0f42d6e 100644 --- a/Distribution/GameData/ConformalDecals/Assets/decal-blank.mu +++ b/Distribution/GameData/ConformalDecals/Assets/decal-blank.mu @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9d7714407c3b6b0bde5cd830e9789f837d44310db16272c6b42299e9af9f2907 -size 3273 +oid sha256:8af8a41d215556458e4f1a77bfd22aaf749c44eb427c1867e5cf8e84fbdaeb37 +size 5164 diff --git a/Distribution/GameData/ConformalDecals/Parts/Generic/decal-generic.cfg b/Distribution/GameData/ConformalDecals/Parts/Generic/decal-generic.cfg index 2042ada..b991cba 100644 --- a/Distribution/GameData/ConformalDecals/Parts/Generic/decal-generic.cfg +++ b/Distribution/GameData/ConformalDecals/Parts/Generic/decal-generic.cfg @@ -51,10 +51,6 @@ PART { name = ModuleConformalDecal - decalFront = Decal-Front - decalBack = Decal-Back - decalModel = Decal-Model - useBaseNormal = true tile = 0, 2, 128, 112 diff --git a/Distribution/GameData/ConformalDecals/Parts/Semiotic/decal-semiotic.cfg b/Distribution/GameData/ConformalDecals/Parts/Semiotic/decal-semiotic.cfg index 46aee23..4855286 100644 --- a/Distribution/GameData/ConformalDecals/Parts/Semiotic/decal-semiotic.cfg +++ b/Distribution/GameData/ConformalDecals/Parts/Semiotic/decal-semiotic.cfg @@ -51,10 +51,6 @@ PART { name = ModuleConformalDecal - decalFront = Decal-Front - decalBack = Decal-Back - decalModel = Decal-Model - useBaseNormal = true tileSize = 64, 64 diff --git a/Distribution/GameData/ConformalDecals/Parts/decal-flag.cfg b/Distribution/GameData/ConformalDecals/Parts/decal-flag.cfg index be12f72..def09fa 100644 --- a/Distribution/GameData/ConformalDecals/Parts/decal-flag.cfg +++ b/Distribution/GameData/ConformalDecals/Parts/decal-flag.cfg @@ -7,7 +7,6 @@ PART { model = ConformalDecals/Assets/decal-blank scale = 1.0, 1.0, 1.0 - texture = blank, ConformalDecals/Flags/Peel-N-Stik } rescaleFactor = 1 @@ -52,10 +51,6 @@ PART { name = ModuleConformalFlag - decalFront = Decal-Front - decalBack = Decal-Back - decalModel = Decal-Model - useBaseNormal = true defaultDepth = 0.2 diff --git a/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll b/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll index b9c0fc9..624202d 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:736862c4f8d664ee4ca4b4c5c201f401878bfa5590eb818b3c91de814ed44e0f +oid sha256:347ae98aa8eb27d0d16974c06ea444d2d6fb72893797ab9201a0fa1ca822f6fb size 37888 diff --git a/Distribution/GameData/ConformalDecals/Resources/conformaldecals.shab b/Distribution/GameData/ConformalDecals/Resources/conformaldecals.shab index a1da13e..abecf5a 100644 --- a/Distribution/GameData/ConformalDecals/Resources/conformaldecals.shab +++ b/Distribution/GameData/ConformalDecals/Resources/conformaldecals.shab @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ece4df735dbfd269e2135234da0e91a54badb48e3515496492ac2d9de8455287 -size 170999 +oid sha256:b22837b8b0daf53718793228d8e965a2604cd209b09150e656000f308c4b7993 +size 171063 diff --git a/Source/ConformalDecals/ModuleConformalDecal.cs b/Source/ConformalDecals/ModuleConformalDecal.cs index 2a05197..47d5d1e 100644 --- a/Source/ConformalDecals/ModuleConformalDecal.cs +++ b/Source/ConformalDecals/ModuleConformalDecal.cs @@ -25,12 +25,12 @@ namespace ConformalDecals { /// /// Decal front transform name. Required /// - [KSPField] public string decalFront = string.Empty; + [KSPField] public string decalFront = "Decal-Front"; /// /// Decal back transform name. Required if is true. /// - [KSPField] public string decalBack = string.Empty; + [KSPField] public string decalBack = "Decal-Back"; /// /// Decal model transform name. Is rescaled to preview the decal scale when unattached. @@ -38,7 +38,7 @@ namespace ConformalDecals { /// /// If unspecified, the decal front transform is used instead. /// - [KSPField] public string decalModel = string.Empty; + [KSPField] public string decalModel = "Decal-Model"; /// /// Decal projector transform name. The decal will project along the +Z axis of this transform. @@ -46,7 +46,7 @@ namespace ConformalDecals { /// /// if unspecified, the part "model" transform will be used instead. /// - [KSPField] public string decalProjector = string.Empty; + [KSPField] public string decalProjector = "Decal-Projector"; // Parameters @@ -389,9 +389,11 @@ namespace ConformalDecals { this.Log($"Decal attached to {part.parent.partName}"); - // hide preview model - decalFrontTransform.gameObject.SetActive(false); - decalBackTransform.gameObject.SetActive(false); + // hide model + decalModelTransform.gameObject.SetActive(false); + + // unhide projector + decalProjectorTransform.gameObject.SetActive(true); // add to preCull delegate Camera.onPreCull += Render; @@ -404,9 +406,11 @@ namespace ConformalDecals { protected void OnDetach() { _isAttached = false; - // unhide preview model - decalFrontTransform.gameObject.SetActive(true); - decalBackTransform.gameObject.SetActive(true); + // unhide model + decalModelTransform.gameObject.SetActive(true); + + // hide projector + decalProjectorTransform.gameObject.SetActive(false); // remove from preCull delegate Camera.onPreCull -= Render; @@ -418,7 +422,7 @@ namespace ConformalDecals { protected void UpdateScale() { var aspectRatio = materialProperties.AspectRatio; Vector2 size; - + switch (scaleMode) { default: case DecalScaleMode.HEIGHT: @@ -452,9 +456,7 @@ namespace ConformalDecals { _orthoMatrix[0, 3] = 0.5f; _orthoMatrix[1, 3] = 0.5f; - _orthoMatrix[0, 0] = 1 / size.x; - _orthoMatrix[1, 1] = 1 / size.y; - _orthoMatrix[2, 2] = 1 / depth; + decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth); // update projection foreach (var target in _targets) {