121 Commits

Author SHA1 Message Date
1e7c6d81c9 Merge branch 'main' into release 2020-11-29 16:31:55 -08:00
dda988db17 Quick bugfix 2020-11-29 16:31:41 -08:00
900061f7f6 Merge branch 'main' into release 2020-11-29 16:09:03 -08:00
e56278c6cb Fix stock flags being stretched 2020-11-29 16:02:45 -08:00
2793f5fcb1 Fix DLL copying 2020-11-26 19:17:31 -08:00
833ec43a52 Update project files 2020-11-26 17:47:42 -08:00
e6856124e7 Another attempt at fixing the planet glitch 2020-11-25 02:44:04 -08:00
8ed7a130ab Alternate rendertex handling 2020-11-22 20:18:16 -08:00
d8d3d4ed92 Merge branch 'main' into release 2020-11-16 16:49:01 -08:00
334af786f6 Version change 2020-11-16 16:48:45 -08:00
17ef93bb6e Copy other text parameters to symmetry counterparts 2020-11-16 16:45:54 -08:00
a6d58690f9 Merge branch 'main' into release 2020-11-16 15:45:16 -08:00
a6de537e4a ScaleRange change 2020-11-16 15:44:40 -08:00
33b0307aa2 Lower text decal default size 2020-11-16 15:39:41 -08:00
121428414c Add input locks for text entry 2020-11-16 15:34:10 -08:00
98f774b2ae More font fixes and UI changes
- Lowered step size for decal size and depth to 1cm.
 - Changed default max size to 10m.
 - Text decals now show as a circle if they contain only whitespace.
 - Fixed font name in config and defaulted to Calibri if its missing
2020-11-16 15:05:55 -08:00
d31576fb0b Fix font saving and rendering 2020-11-16 14:44:07 -08:00
c9853049c5 Clear rendertex because KSP wont 2020-11-16 14:01:10 -08:00
f108341068 Merge branch 'main' into release 2020-11-14 21:26:28 -08:00
40d4e2cc8a Update changelog 2020-11-14 21:26:16 -08:00
fb0070f92f Merge branch 'main' into release 2020-11-14 21:22:56 -08:00
6f0c1f8ff5 Update Travis 2020-11-14 21:19:26 -08:00
4cf6de9693 Add defaults to text decal config 2020-11-14 21:17:54 -08:00
06137357c1 Close windows when text part is destroyed 2020-11-14 21:15:43 -08:00
dbbc621181 Fix text decal saving and loading
Closes #25
2020-11-14 21:11:16 -08:00
c6b9812fe3 Fix MM patch 2020-11-13 03:20:51 -08:00
8accabe9e5 Fix FAR incompatability 2020-11-13 02:22:56 -08:00
981a167864 Revert "Add fallbacks to all fonts, even squad ones"
This reverts commit ac1289a46e.
2020-11-13 01:55:42 -08:00
d4978b1b3c Update changelog 2020-11-13 01:44:52 -08:00
c42e443b4b Add minimum size for text decals 2020-11-13 01:43:08 -08:00
a6e2edc475 use URL-style string escaping 2020-11-13 01:42:55 -08:00
e82b02b0e5 Fix overlapping text and add text escaping 2020-11-12 21:25:24 -08:00
ea8c069d68 Fix issues with fallback fonts
Fixed TMP subobjects being deleted, causing fallback fonts to fail in some situations.
closes #24
2020-11-12 20:10:40 -08:00
ac1289a46e Add fallbacks to all fonts, even squad ones 2020-11-12 14:55:04 -08:00
16ef53ea65 remove lfs stuff from travis config 2020-10-14 20:08:25 -07:00
7b01848acc Merge branch 'release' into main 2020-10-11 16:55:18 -07:00
f37c3d57b7 For real this time 2020-10-11 16:49:59 -07:00
a937888c0d Fix deploy script 2020-10-11 16:48:10 -07:00
5065a8abf3 Merge branch 'main' into release 2020-10-11 16:21:34 -07:00
1ebed608a8 Fix corrupted text rendering
Fix text corruption when rendering text right after a scene change by delaying it by a single frame in OnLoad
2020-10-11 03:05:07 -07:00
98a790630e Remove call to get_dataPath from constructor
Fixes error in development build of KSP
2020-10-07 00:12:15 -07:00
ef90f73288 Update ConformalDecals.version 2020-10-04 21:03:46 -07:00
880f463ee0 Merge branch 'master' into release 2020-10-04 16:15:45 -07:00
0066cc332e Changelog and version bump 2020-10-04 16:15:06 -07:00
8f22856064 Use enter/return for newline in text entry 2020-10-04 16:05:24 -07:00
5ef33b1d85 Use supported render texture format on DirectX 2020-10-04 14:59:58 -07:00
27ecd82193 Rename font file to avoid windows legacy features 2020-10-04 14:40:07 -07:00
ea08bd84f0 Merge pull request #21 from drewcassidy/master
Release v0.2.0
2020-09-30 13:53:11 -07:00
e155526808 Readme and changelog changes 2020-09-30 00:24:28 -07:00
da4c780ce6 Update modulemanager 2020-09-30 00:20:09 -07:00
bb0829c0a7 Merge branch 'develop' 2020-09-30 00:01:52 -07:00
ddce97ee05 Fix styles updating textbox 2020-09-29 23:34:47 -07:00
d1029ca0c1 Fix color parsing and serialization 2020-09-29 19:46:14 -07:00
bf7d5dd933 Fix error on running texture modifiers for text decals 2020-09-28 19:55:44 -07:00
885dfb3397 Logging refactor
dll update
2020-09-28 01:07:33 -07:00
1859e51a2e Documentation and cleanup pass 2020-09-27 18:26:55 -07:00
5a18943db9 Remove test debug stuff 2020-09-27 18:01:44 -07:00
9f32a42e51 Merge branch 'feature-text' into develop 2020-09-27 17:57:02 -07:00
13bf70fd8a Changelog update 2020-09-27 17:55:00 -07:00
5faa26ae95 TextRenderer cleanup 2020-09-27 00:48:39 -07:00
2d299f99f3 Add text decal part flavor text 2020-09-26 19:44:10 -07:00
0b15a3125c Fix bounds antialiasing on text
Previously the gradient was being calculated before taking the boundaries into account, resulting in the edges being too hard or too soft
2020-09-26 19:39:44 -07:00
4a6d019227 More minor tweaks 2020-09-26 19:33:12 -07:00
bb48782eff Remove nonfunctioning builtin font 2020-09-26 11:33:50 -07:00
3df3e08aae Fix text rendering user counter for new renders 2020-09-26 11:32:41 -07:00
8b05dc57e8 Fix localization and material updates 2020-09-26 00:02:34 -07:00
54cd5dce20 Fix text rendering yet again 2020-09-25 22:03:59 -07:00
7495a6f509 Fix blit shader 2020-09-24 23:31:42 -07:00
f3aea02da7 Better UI and shaders 2020-08-21 23:45:10 -07:00
93c3ff8a49 Fix text rendering more 2020-08-21 23:44:58 -07:00
ae351c021f Fix text rendering again, but break bold text again 2020-08-17 13:50:36 -07:00
53f8e74836 Fix repeating on text shader and add outline-only support 2020-08-15 23:24:39 -07:00
7ec4c85e8c Handle bold text and several events, wondering whats up with Actions[] 2020-08-06 22:54:51 -07:00
86548a1037 Non-async text rendering integration 2020-07-27 16:16:15 -07:00
cdc8794c54 Various text rendering changes 2020-07-26 19:32:58 -07:00
da3bcf7819 text input changes 2020-07-26 19:30:19 -07:00
f367a30dec Prefab updates 2020-07-26 19:21:36 -07:00
7e3f4b84ff Unity serialization rules are stupid 2020-07-25 23:49:47 -07:00
42e6b18845 Text rendering job system 2020-07-25 20:01:41 -07:00
1c776c0969 Allow fonts to disable certain unsupported styles
Also clean up some stuff
2020-07-25 01:36:19 -07:00
30870b263a Add text decal shader 2020-07-25 00:54:21 -07:00
2994da628b Fix fitting algorithm for text rendering 2020-07-25 00:47:36 -07:00
dbb3281e95 First working text rendering 2020-07-24 14:39:35 -07:00
f3698fc108 More text rendering tests 2020-07-24 01:53:10 -07:00
7574614776 UI loading cleanup 2020-07-23 17:49:42 -07:00
1aebdb4e0e dll update 2020-07-22 22:37:28 -07:00
10da3dd402 Working color picker UI 2020-07-22 22:37:16 -07:00
e57bed6ed9 Add rounded rectangle shaders and remove masks 2020-07-21 16:41:26 -07:00
d5702ee0e7 Color picker UI integration 2020-07-21 00:52:23 -07:00
b1d6e43512 Color picker UI code 2020-07-21 00:07:18 -07:00
365dabc90f Add ColorHSL struct 2020-07-20 17:10:39 -07:00
dfef071175 Box slider script 2020-07-20 00:46:44 -07:00
af05ed43c2 Add start of color picker and reorganize 2020-07-19 23:56:38 -07:00
e87fc48edf Decal text input UI 2020-07-19 21:12:48 -07:00
1316dbb553 Add basic ui controller 2020-07-15 18:12:50 -07:00
b630ddce5e Fix texture initialization 2020-07-13 18:04:10 -07:00
66dd0a6206 Name MODCAT node for ease of patching 2020-07-13 17:33:48 -07:00
47727ef0ce Fix some gui issues 2020-07-12 22:38:37 -07:00
4a3569a7be UI experiments 2020-07-12 20:27:19 -07:00
a9b05a677e Merge branch 'develop' into feature-text 2020-07-02 20:13:46 -07:00
be641272ad Shader fixes and legacy shader code 2020-07-02 19:40:00 -07:00
0aaf0088d8 Tweak and compile shaders 2020-07-01 22:54:30 -07:00
0b83155c42 idk 2020-07-01 01:30:46 -07:00
f78093bbb6 Major shader overhaul
• All shaders merged into one using shader variants
• new SDF-based antialiasing engine
• Smoothness on SDFs is now disabled
2020-07-01 01:28:45 -07:00
1ab8d0f6bc Merge branch 'master' into develop 2020-06-29 22:19:31 -07:00
bf2c2cf940 update csproj 2020-06-28 18:18:19 -07:00
48819878dc Add shader keyword support 2020-06-28 18:18:04 -07:00
14ea974a1d Comment changes 2020-06-22 14:54:39 -07:00
83acfbf866 Update changelog 2020-06-22 14:50:41 -07:00
0be2f650f9 Merge branch 'feature-munar' into develop 2020-06-22 14:48:04 -07:00
ab254595ab Fix inverted scale modes and remove unused logs 2020-06-22 14:47:47 -07:00
1a455ea92c scale mode for some variants 2020-06-22 14:37:58 -07:00
adf6f7171a Add Munar decals 2020-06-22 01:41:51 -07:00
545f0d538b Merge branch 'master' into develop 2020-06-20 11:46:51 -07:00
96c625f6f2 changes 2020-06-19 10:36:13 -07:00
0a77ef57b7 Play around more with text rendering 2020-06-19 01:01:46 -07:00
2c8773ce61 Update gitignore 2020-06-17 21:24:10 -07:00
b3c050be26 Fix rebase 2020-06-17 21:22:16 -07:00
2122b6a0a7 Working font!
thank you sarbian!
2020-06-17 16:53:51 -07:00
f9d9c228ae Various dead-end attempts at font loading and rendering 2020-06-17 16:53:50 -07:00
ecb3eccfe5 Add blit functions 2020-06-17 16:52:33 -07:00
92 changed files with 17061 additions and 1276 deletions

9
.gitignore vendored
View File

@ -2,15 +2,19 @@
Assets/*
!Assets/Shaders/
!Assets/Textures/
!Assets/Scripts/
!Assets/UI/
!Assets/ConformalDecals/
KSP/
Library/
Logs/
Packages/
ProjectSettings/
Temp/
# Unity Assetbundle Manifest Files
GameData/ConformalDecals/Resources/Resources
GameData/ConformalDecals/Resources/Resources.manifest
GameData/ConformalDecals/Resources/conformaldecals.shab.manifest
GameData/ConformalDecals/Resources/*.manifest
# Unity Project Files
PartTools.cfg
@ -46,3 +50,4 @@ Source/ConformalDecals/bin
*.sublime*
.idea
obj
*.swp

View File

@ -12,7 +12,7 @@ package:
dependencies: # Configure dependencies
ModuleManager:
location: url
url: https://ksp.sarbian.com/jenkins/job/ModuleManager/157/artifact/ModuleManager.4.1.3.dll
url: https://ksp.sarbian.com/jenkins/job/ModuleManager/159/artifact/ModuleManager.4.1.4.dll
zip: false
B9PartSwitch:
location: url

View File

@ -3,15 +3,13 @@ python:
- 3.6
before_install:
- echo -e "machine github.com\n login $GITHUB_OAUTH_TOKEN" > ~/.netrc
- git lfs pull
- git lfs fetch --all
install:
- pip install awscli boto3 requests
branches:
only:
- release
script:
- git clone https://github.com/post-kerbin-mining-corporation/build-deploy.git
- git clone https://github.com/post-kerbin-mining-corporation/build-deploy.git
- cd build-deploy
- git checkout master
- cd ..
@ -24,4 +22,4 @@ deploy:
script: python build-deploy/src/deploy.py --f ".mod_data.yml" # Deploy package to spacedock, curse, github
skip_cleanup: true
on:
branch: release
branch: release

View File

@ -0,0 +1,36 @@
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace ConformalDecals.UI {
[AddComponentMenu("UI/BoxSlider", 35)]
[RequireComponent(typeof(RectTransform))]
public class BoxSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement {
[Serializable]
public class BoxSliderEvent : UnityEvent<Vector2> { }
[SerializeField] private RectTransform _handleRect;
[SerializeField] private Vector2 _value = Vector2.zero;
// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
[SerializeField] private BoxSliderEvent _onValueChanged = new BoxSliderEvent();
public BoxSliderEvent OnValueChanged {
get => _onValueChanged;
set => _onValueChanged = value;
}
// Private fields
public void OnDrag(PointerEventData eventData) { }
public void OnInitializePotentialDrag(PointerEventData eventData) { }
public void Rebuild(CanvasUpdate executing) { }
public void LayoutComplete() { }
public void GraphicUpdateComplete() { }
}
}

View File

@ -0,0 +1,13 @@
using UnityEngine;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class ColorBoxSlider : MonoBehaviour{
[SerializeField] private Vector2 _value;
[SerializeField] private BoxSlider _slider;
[SerializeField] private Image _image;
public void OnSliderUpdate(Vector2 value) { }
}
}

View File

@ -0,0 +1,18 @@
using UnityEngine;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class ColorChannelSlider : MonoBehaviour {
[SerializeField] private float _value;
[SerializeField] private int _channel;
[SerializeField] private bool _hsv;
[SerializeField] private Selectable _textBox;
[SerializeField] private Slider _slider;
[SerializeField] private Image _image;
public void OnTextBoxUpdate(string text) { }
public void OnSliderUpdate(float value) { }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class ColorPickerController : MonoBehaviour {
[SerializeField] private Color _value;
[SerializeField] private Image _previewImage;
[SerializeField] private Selectable _hexTextBox;
public void Close() { }
public void OnHexColorUpdate(string text) { }
}
}

View File

@ -0,0 +1,3 @@
{
"name": "ConformalDecals"
}

View File

@ -0,0 +1,10 @@
using UnityEngine;
namespace ConformalDecals.UI {
public class FontMenuController : MonoBehaviour {
[SerializeField] private GameObject _menuItem;
[SerializeField] private GameObject _menuList;
public void Close() { }
}
}

View File

@ -0,0 +1,37 @@
using UnityEngine;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class TextEntryController : MonoBehaviour {
[SerializeField] private Selectable _textBox;
[SerializeField] private Button _fontButton;
[SerializeField] private Slider _lineSpacingSlider;
[SerializeField] private Selectable _lineSpacingTextBox;
[SerializeField] private Slider _charSpacingSlider;
[SerializeField] private Selectable _charSpacingTextBox;
[SerializeField] private Toggle _boldButton;
[SerializeField] private Toggle _italicButton;
[SerializeField] private Toggle _underlineButton;
[SerializeField] private Toggle _smallCapsButton;
[SerializeField] private Toggle _verticalButton;
public void Close() { }
public void OnTextUpdate(string text) { }
public void OnFontMenu() { }
public void OnLineSpacingUpdate(float value) { }
public void OnLineSpacingUpdate(string text) { }
public void OnCharSpacingUpdate(float value) { }
public void OnCharSpacingUpdate(string text) { }
public void OnBoldUpdate(bool state) { }
public void OnItalicUpdate(bool state) { }
public void OnUnderlineUpdate(bool state) { }
public void OnSmallCapsUpdate(bool state) { }
public void OnVerticalUpdate(bool state) { }
}
}

View File

@ -0,0 +1 @@
/Users/drewcassidy/Projects/KSP-Conformal-Decals/Source/ConformalDecals/UI/UITag.cs

View File

@ -1,4 +1,5 @@
using UnityEngine;
using System;
using UnityEngine;
[ExecuteInEditMode]
public class DecalProjectorTest : MonoBehaviour
@ -23,9 +24,6 @@ public class DecalProjectorTest : MonoBehaviour
void Awake()
{
_projectionMatrix = Matrix4x4.identity;
_matrixID = Shader.PropertyToID("_ProjectionMatrix");
_normalID = Shader.PropertyToID("_DecalNormal");
_tangentID= Shader.PropertyToID("_DecalTangent");
targetRenderer = target.GetComponent<MeshRenderer>();
}
@ -40,8 +38,9 @@ public class DecalProjectorTest : MonoBehaviour
var projectorToTarget = targetRenderer.worldToLocalMatrix * transform.localToWorldMatrix;
_projectionMatrix = _OrthoMatrix * targetToProjector;
targetMaterial.SetMatrix(_matrixID, _projectionMatrix);
targetMaterial.SetVector(_normalID, projectorToTarget.MultiplyVector(Vector3.back).normalized);
targetMaterial.SetVector(_tangentID, projectorToTarget.MultiplyVector(Vector3.right).normalized);
targetMaterial.SetMatrix("_ProjectionMatrix", _projectionMatrix);
targetMaterial.SetVector("_DecalNormal", projectorToTarget.MultiplyVector(Vector3.back).normalized);
targetMaterial.SetVector("_DecalTangent", projectorToTarget.MultiplyVector(Vector3.right).normalized);
}
}

View File

@ -0,0 +1,117 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
public class TextRenderTest : MonoBehaviour {
//[InspectorButton("go")] public bool button;
public Camera _camera;
public GameObject _cameraObject;
public TextMeshPro _tmp;
public Material _blitMaterial;
public Material _targetMaterial;
public RenderTexture renderTex;
private float pixelDensity = 8;
private int MaxTextureSize = 4096;
private static readonly int Decal = Shader.PropertyToID("_Decal");
public const TextureFormat TextTextureFormat = TextureFormat.RG16;
public const RenderTextureFormat TextRenderTextureFormat = RenderTextureFormat.R8;
// Start is called before the first frame update
void Start() {
Debug.Log("starting...");
StartCoroutine(OnRender());
}
// Update is called once per frame
void Update() { }
private IEnumerator OnRender() {
Debug.Log("starting...2");
// calculate camera and texture size
_tmp.ForceMeshUpdate();
var mesh = _tmp.mesh;
mesh.RecalculateBounds();
var bounds = mesh.bounds;
Debug.Log(bounds.size);
var width = bounds.size.x * pixelDensity;
var height = bounds.size.y * pixelDensity;
var widthPoT = Mathf.NextPowerOfTwo((int) width);
var heightPoT = Mathf.NextPowerOfTwo((int) height);
if (widthPoT > MaxTextureSize) {
widthPoT /= widthPoT / MaxTextureSize;
heightPoT /= widthPoT / MaxTextureSize;
}
if (heightPoT > MaxTextureSize) {
widthPoT /= heightPoT / MaxTextureSize;
heightPoT /= heightPoT / MaxTextureSize;
}
widthPoT = Mathf.Min(widthPoT, MaxTextureSize);
heightPoT = Mathf.Min(heightPoT, MaxTextureSize);
var widthRatio = widthPoT / width;
var heightRatio = heightPoT / height;
var sizeRatio = Mathf.Min(widthRatio, heightRatio);
Debug.Log(sizeRatio);
int scaledHeight = (int) (sizeRatio * height);
int scaledWidth = (int) (sizeRatio * width);
Debug.Log($"width = {scaledWidth}");
Debug.Log($"height = {scaledHeight}");
_camera.orthographicSize = scaledHeight / pixelDensity / 2;
_camera.aspect = (float) widthPoT / heightPoT;
_cameraObject.transform.localPosition = new Vector3(bounds.center.x, bounds.center.y, -1);
var halfHeight = heightPoT / pixelDensity / 2 / sizeRatio;
var halfWidth = widthPoT / pixelDensity / 2 / sizeRatio;
var matrix = Matrix4x4.Ortho(bounds.center.x - halfWidth, bounds.center.x + halfWidth,
bounds.center.y - halfHeight, bounds.center.y + halfHeight, -1, 1);
// setup texture
var texture = new Texture2D(widthPoT, heightPoT, TextTextureFormat, true);
_targetMaterial.SetTexture(Decal, texture);
// setup render texture
renderTex = RenderTexture.GetTemporary(widthPoT, heightPoT, 0, TextRenderTextureFormat, RenderTextureReadWrite.Linear, 1);
renderTex.autoGenerateMips = false;
RenderTexture.active = renderTex;
GL.PushMatrix();
GL.LoadProjectionMatrix(matrix);
_blitMaterial.SetPass(0);
Graphics.DrawMeshNow(mesh, Matrix4x4.identity);
GL.PopMatrix();
// setup material
_blitMaterial.mainTexture = _tmp.font.atlas;
yield return null;
RenderTexture.active = renderTex;
texture.ReadPixels(new Rect(0, 0, widthPoT, heightPoT), 0, 0, true);
texture.Apply(false, true);
RenderTexture.ReleaseTemporary(renderTex);
}
}

View File

@ -0,0 +1,143 @@
Shader "ConformalDecals/UI/Color Slider"
{
Properties
{
_Color("Color", Color) = (0,0,0,0)
_Radius("Radius", Float) = 4
_OutlineGradient("Outline Gradient Step", Range (0, 1)) = 0.6
_OutlineOpacity("Outline Opacity", Range (0, 0.5)) = 0.1
_OutlineWidth("Outline Width", Float) = 3
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
[Toggle(HUE)] _Hue ("Hue", int) = 0
[Toggle(RED)] _Red ("Red", int) = 0
[Toggle(GREEN)] _Green ("Green", int) = 0
[Toggle(BLUE)] _Blue ("Blue", int) = 0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma require integers
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#include "HSL.cginc"
#include "SDF.cginc"
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP
#pragma multi_compile_local HUE RED GREEN BLUE
float4 _ClipRect;
float _Radius;
float4 _Color;
float _OutlineGradient;
float _OutlineOpacity;
float _OutlineWidth;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPosition = v.vertex;
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float4 color = 1;
#ifdef HUE
color.rgb = HSV2RGB(float3(i.uv.y, _Color.y, _Color.z));
#endif //HUE
#ifdef RED
color.rgb = float3(i.uv.x, _Color.g, _Color.b);
#endif //RED
#ifdef GREEN
color.rgb = float3(_Color.r, i.uv.x, _Color.b);
#endif //GREEN
#ifdef BLUE
color.rgb = float3(_Color.r, _Color.g, i.uv.x);
#endif //BLUE
float rrect = sdRoundedUVBox(i.uv, _Radius);
float gradient = smoothstep(_OutlineGradient, 1 - _OutlineGradient, i.uv.y);
float outlineOpacity = _OutlineOpacity * smoothstep(-1*_OutlineWidth, 0, rrect);
color.rgb = lerp(color.rgb, gradient, outlineOpacity);
color.a = saturate(0.5 - rrect);
#ifdef UNITY_UI_CLIP_RECT
color.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
#endif
#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
return color;
}
ENDCG
}
}
}

View File

@ -0,0 +1,122 @@
Shader "ConformalDecals/UI/HSV Square"
{
Properties
{
_Color("Color", Color) = (0,0,0,0)
_Radius("Radius", Float) = 4
_OutlineGradient("Outline Gradient Step", Range (0, 1)) = 0.6
_OutlineOpacity("Outline Opacity", Range (0, 0.5)) = 0.1
_OutlineWidth("Outline Width", Float) = 3
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma require integers
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#include "HSL.cginc"
#include "SDF.cginc"
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP
float4 _ClipRect;
float _Radius;
float4 _Color;
float _OutlineGradient;
float _OutlineOpacity;
float _OutlineWidth;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPosition = v.vertex;
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 color = 1;
color.a = saturate(0.5 - sdRoundedUVBox(i.uv, _Radius));
color.rgb = HSV2RGB(float3(_Color.x, i.uv.x, i.uv.y));
float rrect = sdRoundedUVBox(i.uv, _Radius);
float gradient = smoothstep(_OutlineGradient, 1 - _OutlineGradient, i.uv.y);
float outlineOpacity = _OutlineOpacity * smoothstep(-1*_OutlineWidth, 0, rrect);
color.rgb = lerp(color.rgb, gradient, outlineOpacity);
#ifdef UNITY_UI_CLIP_RECT
color.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
#endif
#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
return color;
}
ENDCG
}
}
}

View File

@ -0,0 +1,120 @@
Shader "ConformalDecals/UI/Color Swatch"
{
Properties
{
_Color("Color", Color) = (0,0,0,0)
_Radius("Radius", Float) = 4
_OutlineGradient("Outline Gradient Step", Range (0, 1)) = 0.6
_OutlineOpacity("Outline Opacity", Range (0, 0.5)) = 0.1
_OutlineWidth("Outline Width", Float) = 3
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma require integers
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#include "HSL.cginc"
#include "SDF.cginc"
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP
#pragma multi_compile_local HUE RED GREEN BLUE
float4 _ClipRect;
float _Radius;
float4 _Color;
float _OutlineGradient;
float _OutlineOpacity;
float _OutlineWidth;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPosition = v.vertex;
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 color = _Color;
color.a = saturate(0.5 - sdRoundedUVBox(i.uv, _Radius));
float rrect = sdRoundedUVBox(i.uv, _Radius);
float gradient = smoothstep(_OutlineGradient, 1 - _OutlineGradient, i.uv.y);
float outlineOpacity = _OutlineOpacity * smoothstep(-1*_OutlineWidth, 0, rrect);
color.rgb = lerp(color.rgb, gradient, outlineOpacity);
#ifdef UNITY_UI_CLIP_RECT
color.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
#endif
#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
return color;
}
ENDCG
}
}
}

View File

@ -1,130 +0,0 @@
Shader "ConformalDecals/Feature/Bumped"
{
Properties
{
[Header(Texture Maps)]
_Decal("Decal Texture", 2D) = "gray" {}
_DecalBumpMap("Decal Bump Map", 2D) = "bump" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_DecalOpacity("Opacity", Range(0,1) ) = 1
_Background("Background Color", Color) = (0.9,0.9,0.9,0.7)
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", int) = 2
[Toggle(DECAL_PREVIEW)] _Preview ("Preview", int) = 0
[Header(Effects)]
[PerRendererData]_Opacity("_Opacity", Range(0,1) ) = 1
[PerRendererData]_Color("_Color", Color) = (1,1,1,1)
[PerRendererData]_RimFalloff("_RimFalloff", Range(0.01,5) ) = 0.1
[PerRendererData]_RimColor("_RimColor", Color) = (0,0,0,0)
[PerRendererData]_UnderwaterFogFactor ("Underwater Fog Factor", Range(0,1)) = 0
}
SubShader
{
Tags { "Queue" = "Geometry+100" "IgnoreProjector" = "true"}
Cull [_Cull]
Ztest LEqual
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
#pragma multi_compile DECAL_PROJECT DECAL_PREVIEW
sampler2D _Decal;
sampler2D _DecalBumpMap;
float4 _Decal_ST;
float4 _DecalBumpMap_ST;
float _RimFalloff;
float4 _RimColor;
#define DECAL_NORMAL
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
float3 normal = UnpackNormalDXT5nm(tex2D(_DecalBumpMap, IN.uv_bump));
decalClipAlpha(color.a - _Cutoff);
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a * _DecalOpacity;
o.Emission = emission;
o.Normal = normal;
}
ENDCG
}
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardAdd" }
Blend One One
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
#pragma multi_compile DECAL_PROJECT DECAL_PREVIEW
sampler2D _Decal;
sampler2D _DecalBumpMap;
float4 _Decal_ST;
float4 _DecalBumpMap_ST;
float _RimFalloff;
float4 _RimColor;
#define DECAL_NORMAL
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
float3 normal = UnpackNormal(tex2D(_DecalBumpMap, IN.uv_bump));
decalClipAlpha(color.a - _Cutoff);
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a * _DecalOpacity;
o.Emission = emission;
o.Normal = normal;
}
ENDCG
}
// shadow casting support
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}

View File

@ -1,143 +0,0 @@
Shader "ConformalDecals/Paint/Diffuse"
{
Properties
{
[Header(Texture Maps)]
_Decal("Decal Texture", 2D) = "gray" {}
_BumpMap("Bump Map", 2D) = "bump" {}
_EdgeWearStrength("Edge Wear Strength", Range(0,500)) = 100
_EdgeWearOffset("Edge Wear Offset", Range(0,1)) = 0.1
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_DecalOpacity("Opacity", Range(0,1) ) = 1
_Background("Background Color", Color) = (0.9,0.9,0.9,0.7)
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", int) = 2
[Toggle(DECAL_PREVIEW)] _Preview ("Preview", int) = 0
[Header(Effects)]
[PerRendererData]_Opacity("_Opacity", Range(0,1) ) = 1
[PerRendererData]_Color("_Color", Color) = (1,1,1,1)
[PerRendererData]_RimFalloff("_RimFalloff", Range(0.01,5) ) = 0.1
[PerRendererData]_RimColor("_RimColor", Color) = (0,0,0,0)
[PerRendererData]_UnderwaterFogFactor ("Underwater Fog Factor", Range(0,1)) = 0
}
SubShader
{
Tags { "Queue" = "Geometry+100" "IgnoreProjector" = "true"}
Cull [_Cull]
Ztest LEqual
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
#pragma multi_compile __ DECAL_PREVIEW
sampler2D _Decal;
float4 _Decal_ST;
float _EdgeWearStrength;
float _EdgeWearOffset;
float _RimFalloff;
float4 _RimColor;
#define DECAL_BASE_NORMAL
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
decalClipAlpha(color.a - _Cutoff);
float3 normal = IN.normal;
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a * _DecalOpacity;
o.Emission = emission;
}
ENDCG
}
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardAdd" }
Blend One One
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
#pragma multi_compile __ DECAL_PREVIEW
sampler2D _Decal;
float4 _Decal_ST;
float _EdgeWearStrength;
float _EdgeWearOffset;
float _RimFalloff;
float4 _RimColor;
#define DECAL_BASE_NORMAL
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
decalClipAlpha(color.a - _Cutoff);
float3 normal = IN.normal;
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a * _DecalOpacity;
o.Emission = emission;
}
ENDCG
}
// shadow casting support
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}

View File

@ -1,159 +0,0 @@
Shader "ConformalDecals/Paint/DiffuseSDF"
{
Properties
{
[Header(Texture Maps)]
_Decal("Decal Texture", 2D) = "gray" {}
_BumpMap("Bump Map", 2D) = "bump" {}
_EdgeWearStrength("Edge Wear Strength", Range(0,500)) = 100
_EdgeWearOffset("Edge Wear Offset", Range(0,1)) = 0.1
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_Smoothness ("SDF smoothness", Range(0,1)) = 0.15
_SmoothnessMipScale ("Smoothness fadeout", Range(0,1)) = 0.1
_DecalOpacity("Opacity", Range(0,1) ) = 1
_Background("Background Color", Color) = (0.9,0.9,0.9,0.7)
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", int) = 2
[Toggle(DECAL_PREVIEW)] _Preview ("Preview", int) = 0
[Header(Effects)]
[PerRendererData]_Opacity("_Opacity", Range(0,1) ) = 1
[PerRendererData]_Color("_Color", Color) = (1,1,1,1)
[PerRendererData]_RimFalloff("_RimFalloff", Range(0.01,5) ) = 0.1
[PerRendererData]_RimColor("_RimColor", Color) = (0,0,0,0)
[PerRendererData]_UnderwaterFogFactor ("Underwater Fog Factor", Range(0,1)) = 0
}
SubShader
{
Tags { "Queue" = "Geometry+100" "IgnoreProjector" = "true"}
Cull [_Cull]
Ztest LEqual
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
#pragma multi_compile __ DECAL_PREVIEW
sampler2D _Decal;
float4 _Decal_ST;
float4 _Decal_TexelSize;
float _Smoothness;
float _SmoothnessMipScale;
float _EdgeWearStrength;
float _EdgeWearOffset;
float _RimFalloff;
float4 _RimColor;
#define DECAL_BASE_NORMAL
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
float3 normal = IN.normal;
float smoothScale = (1 - saturate(1-(CalcMipLevel(IN.uv_decal * _Decal_TexelSize.zw) * _SmoothnessMipScale))) / 2;
color.a = smoothstep(_Cutoff - smoothScale, saturate(_Smoothness + smoothScale + _Cutoff), color.a);
decalClipAlpha(color.a);
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a * _DecalOpacity;
o.Emission = emission;
}
ENDCG
}
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardAdd" }
Blend One One
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
#pragma multi_compile __ DECAL_PREVIEW
sampler2D _Decal;
float4 _Decal_ST;
float4 _Decal_TexelSize;
float _Smoothness;
float _SmoothnessMipScale;
float _EdgeWearStrength;
float _EdgeWearOffset;
float _RimFalloff;
float4 _RimColor;
#define DECAL_BASE_NORMAL
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
float3 normal = IN.normal;
float smoothScale = (1 - saturate(1-(CalcMipLevel(IN.uv_decal * _Decal_TexelSize.zw) * _SmoothnessMipScale))) / 2;
color.a = smoothstep(_Cutoff - smoothScale, saturate(_Smoothness + smoothScale + _Cutoff), color.a);
decalClipAlpha(color.a);
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a * _DecalOpacity;
o.Emission = emission;
}
ENDCG
}
// shadow casting support
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}

View File

@ -1,165 +0,0 @@
Shader "ConformalDecals/Paint/Specular"
{
Properties
{
[Header(Texture Maps)]
_Decal("Decal Texture", 2D) = "gray" {}
_BumpMap("Bump Map", 2D) = "bump" {}
_SpecMap("Specular Map", 2D) = "black" {}
_EdgeWearStrength("Edge Wear Strength", Range(0,500)) = 100
_EdgeWearOffset("Edge Wear Offset", Range(0,1)) = 0.1
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_DecalOpacity("Opacity", Range(0,1) ) = 1
_Background("Background Color", Color) = (0.9,0.9,0.9,0.7)
[Header(Specularity)]
_SpecColor ("_SpecColor", Color) = (0.25, 0.25, 0.25, 1)
_Shininess ("Shininess", Range (0.03, 10)) = 0.3
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", int) = 2
[Toggle(DECAL_PREVIEW)] _Preview ("Preview", int) = 0
[Header(Effects)]
[PerRendererData]_Opacity("_Opacity", Range(0,1) ) = 1
[PerRendererData]_Color("_Color", Color) = (1,1,1,1)
[PerRendererData]_RimFalloff("_RimFalloff", Range(0.01,5) ) = 0.1
[PerRendererData]_RimColor("_RimColor", Color) = (0,0,0,0)
[PerRendererData]_UnderwaterFogFactor ("Underwater Fog Factor", Range(0,1)) = 0
}
SubShader
{
Tags { "Queue" = "Geometry+100" "IgnoreProjector" = "true"}
Cull [_Cull]
Ztest LEqual
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
#pragma multi_compile __ DECAL_PREVIEW
sampler2D _Decal;
sampler2D _SpecMap;
float4 _Decal_ST;
float4 _SpecMap_ST;
float _EdgeWearStrength;
float _EdgeWearOffset;
half _Shininess;
float _RimFalloff;
float4 _RimColor;
#define DECAL_BASE_NORMAL
#define DECAL_SPECULAR
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
float3 specular = tex2D(_SpecMap, IN.uv_spec);
decalClipAlpha(color.a - _Cutoff);
float3 normal = IN.normal;
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
color.a *= _DecalOpacity;
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a;
o.Emission = emission;
o.Specular = _Shininess;
o.Gloss = specular.r * color.a;
}
ENDCG
}
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardAdd" }
Blend One One
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
#pragma multi_compile __ DECAL_PREVIEW
sampler2D _Decal;
sampler2D _SpecMap;
float4 _Decal_ST;
float4 _SpecMap_ST;
float _EdgeWearStrength;
float _EdgeWearOffset;
half _Shininess;
float _RimFalloff;
float4 _RimColor;
#define DECAL_BASE_NORMAL
#define DECAL_SPECULAR
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
float3 specular = tex2D(_SpecMap, IN.uv_spec);
float3 normal = IN.normal;
decalClipAlpha(color.a - _Cutoff);
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a * _DecalOpacity;
o.Emission = emission;
o.Specular = _Shininess;
o.Gloss = specular.r;
}
ENDCG
}
// shadow casting support
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}

View File

@ -1,180 +0,0 @@
Shader "ConformalDecals/Paint/SpecularSDF"
{
Properties
{
[Header(Texture Maps)]
_Decal("Decal Texture", 2D) = "gray" {}
_BumpMap("Bump Map", 2D) = "bump" {}
_SpecMap("Specular Map", 2D) = "black" {}
_EdgeWearStrength("Edge Wear Strength", Range(0,500)) = 100
_EdgeWearOffset("Edge Wear Offset", Range(0,1)) = 0.1
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_Smoothness ("SDF smoothness", Range(0,1)) = 0.15
_SmoothnessMipScale ("Smoothness fadeout", Range(0,1)) = 0.1
_DecalOpacity("Opacity", Range(0,1) ) = 1
_Background("Background Color", Color) = (0.9,0.9,0.9,0.7)
[Header(Specularity)]
_SpecColor ("_SpecColor", Color) = (0.25, 0.25, 0.25, 1)
_Shininess ("Shininess", Range (0.03, 10)) = 0.3
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", int) = 2
[Toggle(DECAL_PREVIEW)] _Preview ("Preview", int) = 0
[Header(Effects)]
[PerRendererData]_Opacity("_Opacity", Range(0,1) ) = 1
[PerRendererData]_Color("_Color", Color) = (1,1,1,1)
[PerRendererData]_RimFalloff("_RimFalloff", Range(0.01,5) ) = 0.1
[PerRendererData]_RimColor("_RimColor", Color) = (0,0,0,0)
[PerRendererData]_UnderwaterFogFactor ("Underwater Fog Factor", Range(0,1)) = 0
}
SubShader
{
Tags { "Queue" = "Geometry+100" "IgnoreProjector" = "true"}
Cull [_Cull]
Ztest LEqual
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
#pragma multi_compile __ DECAL_PREVIEW
sampler2D _Decal;
sampler2D _SpecMap;
float4 _Decal_ST;
float4 _Decal_TexelSize;
float4 _SpecMap_ST;
float _Smoothness;
float _SmoothnessMipScale;
float _EdgeWearStrength;
float _EdgeWearOffset;
half _Shininess;
float _RimFalloff;
float4 _RimColor;
#define DECAL_BASE_NORMAL
#define DECAL_SPECULAR
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
float3 specular = tex2D(_SpecMap, IN.uv_spec);
float3 normal = IN.normal;
float smoothScale = (1 - saturate(1-(CalcMipLevel(IN.uv_decal * _Decal_TexelSize.zw) * _SmoothnessMipScale))) / 2;
color.a = smoothstep(_Cutoff - smoothScale, saturate(_Smoothness + smoothScale + _Cutoff), color.a);
decalClipAlpha(color.a);
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a * _DecalOpacity;
o.Emission = emission;
o.Specular = _Shininess;
o.Gloss = specular.r;
}
ENDCG
}
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardAdd" }
Blend One One
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
#pragma multi_compile __ DECAL_PREVIEW
sampler2D _Decal;
sampler2D _SpecMap;
float4 _Decal_ST;
float4 _Decal_TexelSize;
float4 _SpecMap_ST;
float _Smoothness;
float _SmoothnessMipScale;
float _EdgeWearStrength;
float _EdgeWearOffset;
half _Shininess;
float _RimFalloff;
float4 _RimColor;
#define DECAL_BASE_NORMAL
#define DECAL_SPECULAR
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
#include "DecalsCommon.cginc"
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
{
float4 color = tex2D(_Decal, IN.uv_decal);
float3 specular = tex2D(_SpecMap, IN.uv_spec);
float3 normal = IN.normal;
float smoothScale = (1 - saturate(1-(CalcMipLevel(IN.uv_decal * _Decal_TexelSize.zw) * _SmoothnessMipScale))) / 2;
color.a = smoothstep(_Cutoff - smoothScale, saturate(_Smoothness + smoothScale + _Cutoff), color.a);
decalClipAlpha(color.a);
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = color.a * _DecalOpacity;
o.Emission = emission;
o.Specular = _Shininess;
o.Gloss = specular.r;
}
ENDCG
}
// shadow casting support
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}

View File

@ -1,26 +1,93 @@
#ifndef DECALS_COMMON_INCLUDED
#define DECALS_COMMON_INCLUDED
#include "AutoLight.cginc"
#include "Lighting.cginc"
#define CLIP_MARGIN 0.05
#define EDGE_MARGIN 0.01
// UNIFORM VARIABLES
// Projection matrix, normal, and tangent vectors
float4x4 _ProjectionMatrix;
float3 _DecalNormal;
float3 _DecalTangent;
// Common Shading Paramaters
float _Cutoff;
float _DecalOpacity;
float4 _Background;
sampler2D _Decal;
float4 _Decal_ST;
// Variant Shading Parameters
#ifdef DECAL_BASE_NORMAL
sampler2D _BumpMap;
float4 _BumpMap_ST;
float _EdgeWearStrength;
float _EdgeWearOffset;
#endif //DECAL_BASE_NORMAL
#ifdef DECAL_BUMPMAP
sampler2D _BumpMap;
float4 _BumpMap_ST;
#endif //DECAL_BUMPMAP
#ifdef DECAL_SPECMAP
sampler2D _SpecMap;
float4 _SpecMap_ST;
// specular color is declared in a unity CGINC for some reason??
fixed _Shininess;
#endif //DECAL_SPECMAP
#ifdef DECAL_EMISSIVE
sampler2D _Emissive;
float4 _Emissive_ST;
fixed4 _Emissive_Color;
#endif //DECAL_EMISSIVE
// KSP EFFECTS
// opacity and color
float _Opacity;
float4 _Color;
float _RimFalloff;
float4 _RimColor;
// fog
float4 _LocalCameraPos;
float4 _LocalCameraDir;
float4 _UnderwaterFogColor;
float _UnderwaterMinAlphaFogDistance;
float _UnderwaterMaxAlbedoFog;
float _UnderwaterMaxAlphaFog;
float _UnderwaterAlbedoDistanceScalar;
float _UnderwaterAlphaDistanceScalar;
float _UnderwaterFogFactor;
// SURFACE INPUT STRUCT
struct DecalSurfaceInput
{
float3 uv;
float2 uv_decal;
#ifdef DECAL_NORMAL
float2 uv_bump;
#endif //DECAL_NORMAL
#ifdef DECAL_BUMPMAP
float2 uv_bumpmap;
#endif //DECAL_BUMPMAP
#ifdef DECAL_SPECULAR
float2 uv_spec;
#endif //DECAL_SPECULAR
#ifdef DECAL_SPECMAP
float2 uv_specmap;
#endif //DECAL_SPECMAP
#ifdef DECAL_EMISSIVE
float2 uv_glow;
float2 uv_emissive;
#endif //DECAL_EMISSIVE
#ifdef DECAL_BASE_NORMAL
float3 normal;
#endif
#endif //DECAL_BASE_NORMAL
float3 vertex_normal;
float3 viewDir;
float3 worldPosition;
};
@ -59,20 +126,6 @@ struct v2f
#endif //UNITY_PASS_FORWARDADD
};
// Projection matrix, normal, and tangent vectors
float4x4 _ProjectionMatrix;
float3 _DecalNormal;
float3 _DecalTangent;
#ifdef DECAL_BASE_NORMAL
sampler2D _BumpMap;
float4 _BumpMap_ST;
#endif //DECAL_BASE_NORMAL
float _Cutoff;
float _DecalOpacity;
float _Opacity;
float4 _Background;
inline void decalClipAlpha(float alpha) {
#ifndef DECAL_PREVIEW
@ -88,200 +141,16 @@ inline float CalcMipLevel(float2 texture_coord) {
return 0.5 * log2(delta_max_sqr);
}
// modifed version of the KSP BlinnPhong because it does some weird things
inline fixed4 LightingBlinnPhongDecal(SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
{
s.Normal = normalize(s.Normal);
half3 h = normalize(lightDir + viewDir);
fixed diff = max(0, dot(s.Normal, lightDir));
float nh = max(0, dot(s.Normal, h));
float spec = pow(nh, s.Specular*128.0) * s.Gloss;
fixed4 c = 0;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten);
return c;
}
// declare surf function,
// this must be defined in any shader using this cginc
void surf (DecalSurfaceInput IN, inout SurfaceOutput o);
v2f vert_forward(appdata_decal v)
{
v2f o;
UNITY_INITIALIZE_OUTPUT(v2f,o);
o.pos = UnityObjectToClipPos(v.vertex);
o.normal = v.normal;
inline float BoundsDist(float3 p, float3 normal, float3 projNormal) {
float3 q = abs(p - 0.5) - 0.5; // 1x1 square/cube centered at (0.5,0.5)
//float dist = length(max(q,0)) + min(max(q.x,max(q.y,q.z)),0.0); // true SDF
#ifdef DECAL_PREVIEW
o.uv_decal = v.texcoord;
return 10 * max(q.x, q.y); // 2D pseudo SDF
#else
o.uv_decal = mul (_ProjectionMatrix, v.vertex);
float dist = max(max(q.x, q.y), q.z); // pseudo SDF
float ndist = EDGE_MARGIN - dot(normal, projNormal); // SDF to normal
return 10 * max(dist, ndist); // return intersection
#endif //DECAL_PREVIEW
#ifdef DECAL_BASE_NORMAL
o.uv_base = TRANSFORM_TEX(v.texcoord, _BumpMap);
#endif //DECAL_BASE_NORMAL
float3 worldPosition = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
#if defined(DECAL_BASE_NORMAL) || defined(DECAL_PREVIEW)
// use tangent of base geometry
fixed3 worldTangent = UnityObjectToWorldDir(v.tangent.xyz);
fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
fixed3 worldBinormal = cross(worldNormal, worldTangent) * tangentSign;
#else
// use tangent of projector
fixed3 decalTangent = UnityObjectToWorldDir(_DecalTangent);
fixed3 worldBinormal = cross(decalTangent, worldNormal);
fixed3 worldTangent = cross(worldNormal, worldBinormal);
#endif //defined(DECAL_BASE_NORMAL) || defined(DECAL_PREVIEW)
o.tSpace0 = float4(worldTangent.x, worldBinormal.x, worldNormal.x, worldPosition.x);
o.tSpace1 = float4(worldTangent.y, worldBinormal.y, worldNormal.y, worldPosition.y);
o.tSpace2 = float4(worldTangent.z, worldBinormal.z, worldNormal.z, worldPosition.z);
// forward base pass specific lighting code
#ifdef UNITY_PASS_FORWARDBASE
// SH/ambient light
#if UNITY_SHOULD_SAMPLE_SH
float3 shlight = ShadeSH9 (float4(worldNormal,1.0));
o.vlight = shlight;
#else
o.vlight = 0.0;
#endif // UNITY_SHOULD_SAMPLE_SH
// vertex light
#ifdef VERTEXLIGHT_ON
o.vlight += Shade4PointLights (
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
unity_4LightAtten0, worldPosition, worldNormal );
#endif // VERTEXLIGHT_ON
#endif // UNITY_PASS_FORWARDBASE
// pass shadow and, possibly, light cookie coordinates to pixel shader
UNITY_TRANSFER_LIGHTING(o, 0.0);
return o;
}
fixed4 frag_forward(v2f IN) : SV_Target
{
// declare data
DecalSurfaceInput i;
SurfaceOutput o;
fixed4 c = 0;
// setup world-space TBN vectors
UNITY_EXTRACT_TBN(IN);
float3 worldPosition = float3(IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w);
float3 worldTangent = float3(IN.tSpace0.x, IN.tSpace1.x, IN.tSpace2.x);
// setup world-space light and view direction vectors
#ifndef USING_DIRECTIONAL_LIGHT
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(worldPosition));
#else
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
#endif
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPosition));
float3 viewDir = _unity_tbn_0 * worldViewDir.x + _unity_tbn_1 * worldViewDir.y + _unity_tbn_2 * worldViewDir.z;
#ifdef DECAL_PREVIEW
fixed4 uv_projected = IN.uv_decal;
#else
// perform decal projection
fixed4 uv_projected = UNITY_PROJ_COORD(IN.uv_decal);
// clip texture outside of xyz bounds
clip(uv_projected.xyz);
clip(1-uv_projected.xyz);
// clip backsides
clip(dot(_DecalNormal, IN.normal));
#endif //DECAL_PREVIEW
// initialize surface input
UNITY_INITIALIZE_OUTPUT(DecalSurfaceInput, i)
i.uv_decal = TRANSFORM_TEX(uv_projected, _Decal);
#ifdef DECAL_NORMAL
i.uv_bump = TRANSFORM_TEX(uv_projected, _DecalBumpMap);
#endif //DECAL_NORMAL
#ifdef DECAL_SPECULAR
i.uv_spec = TRANSFORM_TEX(uv_projected, _SpecMap);
#endif //DECAL_SPECULAR
#ifdef DECAL_EMISSIVE
i.uv_glow = TRANSFORM_TEX(uv_projected, _GlowMap);
#endif //DECAL_EMISSIVE
#ifdef DECAL_BASE_NORMAL
#ifdef DECAL_PREVIEW
i.normal = fixed3(0,0,1);
#else
i.normal = UnpackNormalDXT5nm(tex2D(_BumpMap, IN.uv_base));
#endif //DECAL_PREVIEW
#endif //DECAL_BASE_NORMAL
//i.normal = IN.normal;
i.viewDir = viewDir;
i.worldPosition = worldPosition;
// initialize surface output
o.Albedo = 0.0;
o.Emission = 0.0;
o.Specular = 0.0;
o.Alpha = 0.0;
o.Gloss = 0.0;
o.Normal = fixed3(0,0,1);
// call surface function
surf(i, o);
#ifdef DECAL_PREVIEW
if (any(IN.uv_decal > 1) || any(IN.uv_decal < 0)) o.Alpha = 0;
o.Albedo = lerp(_Background.rgb, o.Albedo, o.Alpha) * _Color.rgb;
o.Normal = lerp(float3(0,0,1), o.Normal, o.Alpha);
o.Gloss = lerp(_Background.a, o.Gloss, o.Alpha);
o.Emission = lerp(0, o.Emission, o.Alpha);
o.Alpha = _Opacity;
#endif //DECAL_PREVIEW
// compute lighting & shadowing factor
UNITY_LIGHT_ATTENUATION(atten, IN, worldPosition)
// compute world normal
float3 WorldNormal;
WorldNormal.x = dot(_unity_tbn_0, o.Normal);
WorldNormal.y = dot(_unity_tbn_1, o.Normal);
WorldNormal.z = dot(_unity_tbn_2, o.Normal);
WorldNormal = normalize(WorldNormal);
o.Normal = WorldNormal;
//call modified KSP lighting function
c += LightingBlinnPhongDecal(o, lightDir, worldViewDir, atten);
// Forward base emission and ambient/vertex lighting
#ifdef UNITY_PASS_FORWARDBASE
c.rgb += o.Emission;
c.rgb += o.Albedo * IN.vlight;
c.a = o.Alpha;
#endif //UNITY_PASS_FORWARDBASE
// Forward add multiply by alpha
#ifdef UNITY_PASS_FORWARDADD
c.rgb *= o.Alpha;
#endif
return c;
}
#endif
#endif

View File

@ -0,0 +1,33 @@
#ifndef DECALS_LIGHTING_INCLUDED
#define DECALS_LIGHTING_INCLUDED
// modifed version of the KSP BlinnPhong because it does some weird things
inline fixed4 LightingBlinnPhongDecal(SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
{
s.Normal = normalize(s.Normal);
half3 h = normalize(lightDir + viewDir);
fixed diff = max(0, dot(s.Normal, lightDir));
float nh = max(0, dot(s.Normal, h));
float spec = pow(nh, s.Specular*128.0) * s.Gloss;
fixed4 c = 0;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten);
return c;
}
// KSP underwater fog function
float4 UnderwaterFog(float3 worldPos, float3 color)
{
float3 toPixel = worldPos - _LocalCameraPos.xyz;
float toPixelLength = length(toPixel);
float underwaterDetection = _UnderwaterFogFactor * _LocalCameraDir.w;
float albedoLerpValue = underwaterDetection * (_UnderwaterMaxAlbedoFog * saturate(toPixelLength * _UnderwaterAlbedoDistanceScalar));
float alphaFactor = 1 - underwaterDetection * (_UnderwaterMaxAlphaFog * saturate((toPixelLength - _UnderwaterMinAlphaFogDistance) * _UnderwaterAlphaDistanceScalar));
return float4(lerp(color, _UnderwaterFogColor.rgb, albedoLerpValue), alphaFactor);
}
#endif

View File

@ -0,0 +1,183 @@
#ifndef DECALS_SURFACE_INCLUDED
#define DECALS_SURFACE_INCLUDED
#include "DecalsCommon.cginc"
#include "DecalsLighting.cginc"
// declare surf function,
// this must be defined in any shader using this cginc
void surf (DecalSurfaceInput IN, inout SurfaceOutput o);
v2f vert_forward(appdata_decal v)
{
v2f o;
UNITY_INITIALIZE_OUTPUT(v2f,o);
o.pos = UnityObjectToClipPos(v.vertex);
o.normal = v.normal;
#ifdef DECAL_PREVIEW
o.uv_decal = v.texcoord;
#else
o.uv_decal = mul (_ProjectionMatrix, v.vertex);
#endif //DECAL_PREVIEW
#ifdef DECAL_BASE_NORMAL
o.uv_base = TRANSFORM_TEX(v.texcoord, _BumpMap);
#endif //DECAL_BASE_NORMAL
float3 worldPosition = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
#if defined(DECAL_BASE_NORMAL) || defined(DECAL_PREVIEW)
// use tangent of base geometry
fixed3 worldTangent = UnityObjectToWorldDir(v.tangent.xyz);
fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
fixed3 worldBinormal = cross(worldNormal, worldTangent) * tangentSign;
#else
// use tangent of projector
fixed3 decalTangent = UnityObjectToWorldDir(_DecalTangent);
fixed3 worldBinormal = cross(decalTangent, worldNormal);
fixed3 worldTangent = cross(worldNormal, worldBinormal);
#endif //defined(DECAL_BASE_NORMAL) || defined(DECAL_PREVIEW)
o.tSpace0 = float4(worldTangent.x, worldBinormal.x, worldNormal.x, worldPosition.x);
o.tSpace1 = float4(worldTangent.y, worldBinormal.y, worldNormal.y, worldPosition.y);
o.tSpace2 = float4(worldTangent.z, worldBinormal.z, worldNormal.z, worldPosition.z);
// forward base pass specific lighting code
#ifdef UNITY_PASS_FORWARDBASE
// SH/ambient light
#if UNITY_SHOULD_SAMPLE_SH
float3 shlight = ShadeSH9 (float4(worldNormal,1.0));
o.vlight = shlight;
#else
o.vlight = 0.0;
#endif // UNITY_SHOULD_SAMPLE_SH
// vertex light
#ifdef VERTEXLIGHT_ON
o.vlight += Shade4PointLights (
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
unity_4LightAtten0, worldPosition, worldNormal );
#endif // VERTEXLIGHT_ON
#endif // UNITY_PASS_FORWARDBASE
// pass shadow and, possibly, light cookie coordinates to pixel shader
UNITY_TRANSFER_LIGHTING(o, 0.0);
return o;
}
fixed4 frag_forward(v2f IN) : SV_Target
{
#ifdef DECAL_PREVIEW
fixed4 uv_projected = IN.uv_decal;
#else
// perform decal projection
fixed4 uv_projected = UNITY_PROJ_COORD(IN.uv_decal);
clip(uv_projected.xyz + CLIP_MARGIN);
clip(CLIP_MARGIN + (1-uv_projected.xyz));
#endif //DECAL_PREVIEW
// declare data
DecalSurfaceInput i;
SurfaceOutput o;
// setup world-space TBN vectors
UNITY_EXTRACT_TBN(IN);
float3 worldPosition = float3(IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w);
float3 worldTangent = float3(IN.tSpace0.x, IN.tSpace1.x, IN.tSpace2.x);
// setup world-space light and view direction vectors
#ifndef USING_DIRECTIONAL_LIGHT
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(worldPosition));
#else
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
#endif
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPosition));
float3 viewDir = _unity_tbn_0 * worldViewDir.x + _unity_tbn_1 * worldViewDir.y + _unity_tbn_2 * worldViewDir.z;
// initialize surface input
UNITY_INITIALIZE_OUTPUT(DecalSurfaceInput, i)
i.uv_decal = TRANSFORM_TEX(uv_projected, _Decal);
i.uv = uv_projected;
#ifdef DECAL_BUMPMAP
i.uv_bumpmap = TRANSFORM_TEX(uv_projected, _BumpMap);
#endif //DECAL_BUMPMAP
#ifdef DECAL_SPECMAP
i.uv_specmap = TRANSFORM_TEX(uv_projected, _SpecMap);
#endif //DECAL_SPECMAP
#ifdef DECAL_EMISSIVE
i.uv_emissive = TRANSFORM_TEX(uv_projected, _Emissive);
#endif //DECAL_EMISSIVE
#ifdef DECAL_BASE_NORMAL
#ifdef DECAL_PREVIEW
i.normal = fixed3(0,0,1);
#else
i.normal = UnpackNormalDXT5nm(tex2D(_BumpMap, IN.uv_base));
#endif //DECAL_PREVIEW
#endif //DECAL_BASE_NORMAL
i.vertex_normal = IN.normal;
i.viewDir = viewDir;
i.worldPosition = worldPosition;
// initialize surface output
o.Albedo = 0.0;
o.Emission = 0.0;
o.Specular = 0.0;
o.Alpha = 0.0;
o.Gloss = 0.0;
o.Normal = fixed3(0,0,1);
// call surface function
surf(i, o);
#ifdef DECAL_PREVIEW
if (any(IN.uv_decal > 1) || any(IN.uv_decal < 0)) o.Alpha = 0;
o.Albedo = lerp(_Background.rgb, o.Albedo, o.Alpha) * _Color.rgb;
o.Normal = lerp(float3(0,0,1), o.Normal, o.Alpha);
o.Gloss = lerp(_Background.a, o.Gloss, o.Alpha);
o.Emission = lerp(0, o.Emission, o.Alpha);
o.Alpha = _Opacity;
#endif //DECAL_PREVIEW
// compute lighting & shadowing factor
UNITY_LIGHT_ATTENUATION(atten, IN, worldPosition)
// compute world normal
float3 WorldNormal;
WorldNormal.x = dot(_unity_tbn_0, o.Normal);
WorldNormal.y = dot(_unity_tbn_1, o.Normal);
WorldNormal.z = dot(_unity_tbn_2, o.Normal);
WorldNormal = normalize(WorldNormal);
o.Normal = WorldNormal;
//call modified KSP lighting function
float4 c = LightingBlinnPhongDecal(o, lightDir, worldViewDir, atten);
// Forward base emission and ambient/vertex lighting
#ifdef UNITY_PASS_FORWARDBASE
c.rgb += o.Emission;
c.rgb += o.Albedo * IN.vlight;
c.a = o.Alpha;
#endif //UNITY_PASS_FORWARDBASE
// Forward add multiply by alpha
#ifdef UNITY_PASS_FORWARDADD
c.rgb *= o.Alpha;
#endif
return c;
}
#endif

17
Assets/Shaders/HSL.cginc Normal file
View File

@ -0,0 +1,17 @@
#ifndef HSL_INCLUDED
#define HSL_INCLUDED
inline float3 HSL2RGB(float3 hsl) {
int3 n = int3(0, 8, 4);
float3 k = (n + hsl.x * 12) % 12;
float a = hsl.y * min(hsl.z, 1 - hsl.z);
return hsl.z - a * max(-1, min(k - 3, min(9 - k, 1)));
}
inline float3 HSV2RGB(float3 hsv) {
int3 n = int3(5, 3, 1);
float3 k = (n + hsv.x * 6) % 6;
return hsv.z - hsv.z * hsv.y * max(0, min(1, min(k, 4 - k)));
}
#endif

45
Assets/Shaders/SDF.cginc Normal file
View File

@ -0,0 +1,45 @@
#ifndef SDF_INCLUDED
#define SDF_INCLUDED
// based on functions by Inigo Quilez
// https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm
// SDF of a box
float sdBox( in float2 p, in float2 b ) {
float2 d = abs(p)-b;
return length(max(d,0.0)) + min(max(d.x,d.y),0.0);
}
// SDF of a box with corner radius r
float sdRoundedBox( in float2 p, in float2 b, in float r ) {
float2 d = abs(p)-b+r;
return min(max(d.x,d.y),0.0) + length(max(d,0.0)) - r;
}
// SDF of a box with corner radius r, based on the current UV position
// UV must be ∈ (0,1), with (0,0) on one corner
float sdRoundedUVBox( float2 uv, float r ) {
float dx = ddx(uv.x);
float dy = ddy(uv.y);
float2 dim = abs(float2(1/dx, 1/dy));
float2 halfDim = dim / 2;
float2 pos = (dim * uv) - halfDim;
return sdRoundedBox(pos, halfDim, r);
}
inline float SDFdDist(float dist) {
return length(float2(ddx(dist), ddy(dist)));
}
inline float SDFAA(float dist, float ddist) {
float pixelDist = dist / ddist;
return saturate(0.5-pixelDist);
}
inline float SDFAA(float dist) {
return SDFAA(dist, SDFdDist(dist));
}
#endif

View File

@ -0,0 +1,38 @@
void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
float4 color = tex2D(_Decal, IN.uv_decal);
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = _DecalOpacity;
#ifdef DECAL_BASE_NORMAL
float3 normal = IN.normal;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
o.Alpha *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
#endif
#ifdef DECAL_BUMPMAP
o.Normal = tex2D(_BumpMap, IN.uv_bumpmap);
#endif
#ifdef DECAL_SPECMAP
float4 specular = tex2D(_SpecMap, IN.uv_specmap);
o.Gloss = specular.r;
o.Specular = _Shininess;
#endif
half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
o.Emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
#ifdef DECAL_EMISSIVE
o.Emission += tex2D(_Emissive, IN.uv_emissive).rgb * _Emissive_Color.rgb * _Emissive_Color.a;
#endif
float dist = BoundsDist(IN.uv, IN.vertex_normal, _DecalNormal);
#ifdef DECAL_SDF_ALPHA
float decalDist = _Cutoff - color.a;
o.Alpha *= SDFAA(max(decalDist, dist));
#else
o.Alpha *= SDFAA(dist);
o.Alpha *= color.a;
#endif
}

View File

@ -0,0 +1,111 @@
Shader "ConformalDecals/Decal/Standard"
{
Properties
{
[Header(Decal)]
_Decal("Decal Texture", 2D) = "gray" {}
[Toggle(DECAL_SDF_ALPHA)] _Decal_SDF_Alpha ("SDF in Alpha", int) = 0
[Header(Normal)]
[Toggle(DECAL_BASE_NORMAL)] _BaseNormal ("Use Base Normal", int) = 0
[Toggle(DECAL_BUMPMAP)] _Decal_BumpMap ("Has BumpMap", int) = 0
_BumpMap("Bump Map", 2D) = "bump" {}
_EdgeWearStrength("Edge Wear Strength", Range(0,500)) = 100
_EdgeWearOffset("Edge Wear Offset", Range(0,1)) = 0.1
[Header(Specularity)]
[Toggle(DECAL_SPECMAP)] _Decal_SpecMap ("Has SpecMap", int) = 0
_SpecMap ("Specular Map)", 2D) = "black" {}
_SpecColor ("_SpecColor", Color) = (0.25, 0.25, 0.25, 1)
_Shininess ("Shininess", Range (0.03, 10)) = 0.3
[Header(Emissive)]
[Toggle(DECAL_EMISSIVE)] _Decal_Emissive ("Has Emissive", int) = 0
_Emissive("_Emissive", 2D) = "black" {}
_EmissiveColor("_EmissiveColor", Color) = (0,0,0,1)
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_DecalOpacity("Opacity", Range(0,1) ) = 1
_Background("Background Color", Color) = (0.9,0.9,0.9,0.7)
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", int) = 2
[Toggle] _ZWrite ("ZWrite", Float) = 1.0
[Toggle(DECAL_PREVIEW)] _Preview ("Preview", int) = 0
[Header(Effects)]
[PerRendererData]_Opacity("_Opacity", Range(0,1) ) = 1
[PerRendererData]_Color("_Color", Color) = (1,1,1,1)
[PerRendererData]_RimFalloff("_RimFalloff", Range(0.01,5) ) = 0.1
[PerRendererData]_RimColor("_RimColor", Color) = (0,0,0,0)
[PerRendererData]_UnderwaterFogFactor ("Underwater Fog Factor", Range(0,1)) = 0
}
SubShader
{
Tags { "Queue" = "Geometry+100" "IgnoreProjector" = "true" "DisableBatching" = "true"}
Cull [_Cull]
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
ZWrite [_ZWrite]
ZTest LEqual
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
#pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP
#pragma multi_compile_local __ DECAL_SPECMAP
#pragma multi_compile_local __ DECAL_EMISSIVE
#pragma multi_compile_local __ DECAL_SDF_ALPHA
#include "UnityCG.cginc"
#include "DecalsCommon.cginc"
#include "DecalsSurface.cginc"
#include "SDF.cginc"
#include "StandardDecal.cginc"
ENDCG
}
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardAdd" }
ZWrite Off
ZTest LEqual
Blend One One
Offset -1, -1
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
#pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP
#pragma multi_compile_local __ DECAL_SPECMAP
#pragma multi_compile_local __ DECAL_EMISSIVE
#pragma multi_compile_local __ DECAL_SDF_ALPHA
#include "UnityCG.cginc"
#include "DecalsCommon.cginc"
#include "DecalsSurface.cginc"
#include "SDF.cginc"
#include "StandardDecal.cginc"
ENDCG
}
// shadow casting support
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}

View File

@ -0,0 +1,73 @@
Shader "ConformalDecals/Text Blit"
{
Properties
{
_MainTex("_MainTex (RGB spec(A))", 2D) = "white" {}
_WeightNormal("Weight Normal", float) = 0
_WeightBold("Weight Bold", float) = 0.5
_ScaleRatioA("Scale RatioA", float) = 1
_ScaleRatioB("Scale RatioB", float) = 1
_ScaleRatioC("Scale RatioC", float) = 1
}
SubShader
{
Tags { "Queue" = "Transparent" }
Cull Off
ZWrite Off
Pass
{
BlendOp Max
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
// font weights to fake bold
float _WeightNormal;
float _WeightBold;
// no idea what these do
float _ScaleRatioA;
float _ScaleRatioB;
float _ScaleRatioC;
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
struct v2f {
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0; // u, v, bias, 0
};
v2f vert(float4 vertex : POSITION, float2 uv0 : TEXCOORD0, float2 uv1 : TEXCOORD1) {
float bold = step(uv1.y, 0);
float weight = lerp(_WeightNormal, _WeightBold, bold) * _ScaleRatioA / 8.0;
float bias = 1 - weight;
v2f o;
o.pos = UnityObjectToClipPos(vertex);
o.uv = float4(uv0.x, uv0.y, bias, weight);
return o;
}
fixed4 frag (v2f i) : SV_Target {
float2 uv = i.uv.xy;
float bias = i.uv.z;
float weight = i.uv.w;
fixed4 c = 0;
c.r = saturate(tex2D(_MainTex,(uv)).a + weight);
return c;
}
ENDCG
}
}
}

View File

@ -0,0 +1,49 @@
float4 _DecalColor;
float4 _OutlineColor;
float _OutlineWidth;
void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
float4 color = _DecalColor;
float dist = _Cutoff - tex2D(_Decal, IN.uv_decal).r; // text distance
#ifdef DECAL_OUTLINE
// Outline
float outlineOffset = _OutlineWidth * 0.25;
float outlineRadius = _OutlineWidth * 0.5;
#ifdef DECAL_FILL
// Outline and Fill
float outlineDist = -dist - outlineOffset;
float outlineFactor = SDFAA(outlineDist);
dist -= outlineOffset;
color = lerp(_DecalColor, _OutlineColor, outlineFactor);
#else
// Outline Only
float outlineDist = abs(dist) - outlineOffset;
dist = outlineDist;
color = _OutlineColor;
#endif
#endif
dist = max(dist, BoundsDist(IN.uv, IN.vertex_normal, _DecalNormal));
float ddist = SDFdDist(dist); // distance gradient magnitude
o.Alpha = _DecalOpacity * SDFAA(dist, ddist);
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
#ifdef DECAL_BASE_NORMAL
float3 normal = IN.normal;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
o.Alpha *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
#endif
#ifdef DECAL_SPECMAP
float4 specular = tex2D(_SpecMap, IN.uv_specmap);
o.Gloss = specular.r;
o.Specular = _Shininess;
#endif
half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
o.Emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
}

View File

@ -0,0 +1,112 @@
Shader "ConformalDecals/Decal/Text"
{
Properties
{
[Header(Decal)]
[Toggle(DECAL_FILL)] _Fill ("Fill", int) = 0
_Decal("Decal Texture", 2D) = "gray" {}
_DecalColor("Decal Color", Color) = (1,1,1,1)
_Weight("Text Weight", Range(0,1)) = 0
[Header(Outline)]
[Toggle(DECAL_OUTLINE)] _Outline ("Outline", int) = 0
_OutlineColor("Outline Color", Color) = (0,0,0,1)
_OutlineWidth("Outline Width", Range(0,1)) = 0.1
[Header(Normal)]
[Toggle(DECAL_BASE_NORMAL)] _BaseNormal ("Use Base Normal", int) = 0
_BumpMap("Bump Map", 2D) = "bump" {}
_EdgeWearStrength("Edge Wear Strength", Range(0,500)) = 100
_EdgeWearOffset("Edge Wear Offset", Range(0,1)) = 0.1
[Header(Specularity)]
[Toggle(DECAL_SPECMAP)] _Decal_SpecMap ("Has SpecMap", int) = 0
_SpecMap ("Specular Map)", 2D) = "black" {}
_SpecColor ("_SpecColor", Color) = (0.25, 0.25, 0.25, 1)
_Shininess ("Shininess", Range (0.03, 10)) = 0.3
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_DecalOpacity("Opacity", Range(0,1) ) = 1
_Background("Background Color", Color) = (0.9,0.9,0.9,0.7)
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", int) = 2
[Toggle] _ZWrite ("ZWrite", Float) = 1.0
[Toggle(DECAL_PREVIEW)] _Preview ("Preview", int) = 0
[Header(Effects)]
[PerRendererData]_Opacity("_Opacity", Range(0,1) ) = 1
_Color("_Color", Color) = (1,1,1,1)
[PerRendererData]_RimFalloff("_RimFalloff", Range(0.01,5) ) = 0.1
[PerRendererData]_RimColor("_RimColor", Color) = (0,0,0,0)
[PerRendererData]_UnderwaterFogFactor ("Underwater Fog Factor", Range(0,1)) = 0
}
SubShader
{
Tags { "Queue" = "Geometry+100" "IgnoreProjector" = "true" "DisableBatching" = "true"}
Cull [_Cull]
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
ZWrite [_ZWrite]
ZTest LEqual
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
#pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL
#pragma multi_compile_local __ DECAL_SPECMAP
#pragma multi_compile_local __ DECAL_OUTLINE
#pragma multi_compile_local __ DECAL_FILL
#include "UnityCG.cginc"
#include "DecalsCommon.cginc"
#include "DecalsSurface.cginc"
#include "SDF.cginc"
#include "TextDecal.cginc"
ENDCG
}
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardAdd" }
ZWrite Off
ZTest LEqual
Blend One One
Offset -1, -1
CGPROGRAM
#pragma vertex vert_forward
#pragma fragment frag_forward
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
#pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL
#pragma multi_compile_local __ DECAL_SPECMAP
#pragma multi_compile_local __ DECAL_OUTLINE
#pragma multi_compile_local __ DECAL_FILL
#include "UnityCG.cginc"
#include "DecalsCommon.cginc"
#include "DecalsSurface.cginc"
#include "SDF.cginc"
#include "TextDecal.cginc"
ENDCG
}
// shadow casting support
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 KiB

BIN
Assets/Textures/UI.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

93
Assets/UI/BSlider.mat Normal file
View File

@ -0,0 +1,93 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: BSlider
m_Shader: {fileID: 4800000, guid: a6b2542ba8ea844e7b0526fab69d88ed, type: 3}
m_ShaderKeywords: BLUE
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Blue: 1
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _GradientStep: 0.331
- _Green: 0
- _Hue: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _OutlineGradient: 0.7
- _OutlineOpacity: 0.15
- _OutlineWidth: 2.5
- _Parallax: 0.02
- _Radius: 4
- _Red: 0
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

93
Assets/UI/GSlider.mat Normal file
View File

@ -0,0 +1,93 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: GSlider
m_Shader: {fileID: 4800000, guid: a6b2542ba8ea844e7b0526fab69d88ed, type: 3}
m_ShaderKeywords: GREEN
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Blue: 0
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _GradientStep: 0.2
- _Green: 1
- _Hue: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _OutlineGradient: 0.7
- _OutlineOpacity: 0.15
- _OutlineWidth: 2.5
- _Parallax: 0.02
- _Radius: 4
- _Red: 0
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

93
Assets/UI/HSLSlider.mat Normal file
View File

@ -0,0 +1,93 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: HSLSlider
m_Shader: {fileID: 4800000, guid: a6b2542ba8ea844e7b0526fab69d88ed, type: 3}
m_ShaderKeywords: HUE
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Blue: 0
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _GradientStep: 0.2
- _Green: 0
- _Hue: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _OutlineGradient: 0.55
- _OutlineOpacity: 0.15
- _OutlineWidth: 2.5
- _Parallax: 0.02
- _Radius: 4
- _Red: 0
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

89
Assets/UI/HSLSquare.mat Normal file
View File

@ -0,0 +1,89 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: HSLSquare
m_Shader: {fileID: 4800000, guid: 41b82117f67243a4851d2ce6bbed0d6a, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Hue: 0.566
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _OutlineGradient: 0.55
- _OutlineOpacity: 0.15
- _OutlineWidth: 2.5
- _Parallax: 0.02
- _Radius: 4
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

93
Assets/UI/RSlider.mat Normal file
View File

@ -0,0 +1,93 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: RSlider
m_Shader: {fileID: 4800000, guid: a6b2542ba8ea844e7b0526fab69d88ed, type: 3}
m_ShaderKeywords: RED
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Blue: 0
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _GradientStep: 0.2
- _Green: 0
- _Hue: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _OutlineGradient: 0.7
- _OutlineOpacity: 0.15
- _OutlineWidth: 2.5
- _Parallax: 0.02
- _Radius: 4
- _Red: 1
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

92
Assets/UI/Swatch.mat Normal file
View File

@ -0,0 +1,92 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Swatch
m_Shader: {fileID: 4800000, guid: a6e04e87fe864ed6a3f6a3ce52f57024, type: 3}
m_ShaderKeywords: RED
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _Blue: 0
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Green: 0
- _Hue: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _OutlineGradient: 0.3
- _OutlineOpacity: 0.15
- _OutlineWidth: 2.5
- _Parallax: 0.02
- _Radius: 4
- _Red: 1
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.5176471, g: 0.5019608, b: 0.5019608, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,14 @@ Localization
#LOC_ConformalDecals_gui-aspectratio = Aspect Ratio
#LOC_ConformalDecals_gui-select-flag = Select Flag
#LOC_ConformalDecals_gui-reset-flag = Reset Flag
#LOC_ConformalDecals_gui-set-text = Set Text
#LOC_ConformalDecals_gui-group-fill = Fill
#LOC_ConformalDecals_gui-group-outline = Outline
#LOC_ConformalDecals_gui-fill = Fill
#LOC_ConformalDecals_gui-set-fill-color = Set Fill Color
#LOC_ConformalDecals_gui-outline = Outline
#LOC_ConformalDecals_gui-outline-width = Outline Width
#LOC_ConformalDecals_gui-set-outline-color = Set Outline Color
// PARTS
@ -26,6 +34,11 @@ Localization
#LOC_ConformalDecals_flag-description = A simple switchable flag. Can either use the mission flag or select a specific flag to use.
#LOC_ConformalDecals_flag-tags = conformal decal sticker flag
// Text
#LOC_ConformalDecals_text-title = CDL-T Text Decal
#LOC_ConformalDecals_text-description = A decal that can display custom text in a variety of fonts
#LOC_ConformalDecals_text-tags = conformal decal sticker text font
// Generic Decals
#LOC_ConformalDecals_generic-title = CDL-1 Generic Decal
#LOC_ConformalDecals_generic-description = A set of generic warning decals and signs to add to your vehicles.
@ -64,7 +77,7 @@ Localization
// Semiotic Decals
#LOC_ConformalDecals_semiotic-title = CDL-2 Semiotic Standard Decal
#LOC_ConformalDecals_semiotic-description = After several unfortunate mishaps with confusing signage on spacecraft, The Peel-N-Stik™ Corporation teamed up with Kerland-Mutani to unveil the Semiotic Standard for Kerbal Vessels, a set of standardized icons for use on ships and stations.
#LOC_ConformalDecals_semiotic-description = After several unfortunate mishaps with confusing signage on spacecraft, The Peel-N-Stik™ Corporation teamed up with Kerland-Mutani to unveil the Semiotic Standard for Kerbal Vessels, a set of standardized icons for use on ships and stations. (Based on the work of Ron Cobb)
#LOC_ConformalDecals_semiotic-tags = conformal decal sticker semiotic standard for kerbal vessels Ron Cobb Alien
#LOC_ConformalDecals_semiotic-variant-00 = Hazard
#LOC_ConformalDecals_semiotic-variant-01 = Blank
@ -98,5 +111,47 @@ Localization
#LOC_ConformalDecals_semiotic-variant-29 = Radiation Hazard
#LOC_ConformalDecals_semiotic-variant-30 = Radiation Bunker
#LOC_ConformalDecals_semiotic-variant-31 = Exhaust
// Munar Decals
#LOC_ConformalDecals_munar-title = CDL-3 Surface Base Decal
#LOC_ConformalDecals_munar-description = Munar Industries Ltd. saw the wild success of the CDL-2 decal, and wanted to develop a decal set for their own line of Heluim mining bases. These decals are more explicit than the Semiotic Standard and aimed at the hazards that come with more advanced techonologies. (Based on the work of Gavin Rothery)
#LOC_ConformalDecals_munar-tag = conformal decal sticker Moon munar lunar industries Gavin Rothery Sarang
#LOC_ConformalDecals_munar-variant-severe-danger = Severe Danger
#LOC_ConformalDecals_munar-variant-danger = Danger
#LOC_ConformalDecals_munar-variant-hazard = Hazard
#LOC_ConformalDecals_munar-variant-warning = Warning
#LOC_ConformalDecals_munar-variant-bulkhead = Bulkhead
#LOC_ConformalDecals_munar-variant-hatch = Hatch
#LOC_ConformalDecals_munar-variant-pressure-hatch = Hatch (Pressurized)
#LOC_ConformalDecals_munar-variant-door = Doorway
#LOC_ConformalDecals_munar-variant-door-danger = Do Not Obstruct
#LOC_ConformalDecals_munar-variant-airlock-interior = Airlock (Interior)
#LOC_ConformalDecals_munar-variant-airlock-exterior = Airlock (Exterior)
#LOC_ConformalDecals_munar-variant-check-seals = Check All Seals
#LOC_ConformalDecals_munar-variant-pressure-seal = Pressure Seal
#LOC_ConformalDecals_munar-variant-vacuum = Danger Vacuum
#LOC_ConformalDecals_munar-variant-gas-mask = Breathing Apparatus Required
#LOC_ConformalDecals_munar-variant-oxygen-rich = Oxygen Rich Environment
#LOC_ConformalDecals_munar-variant-robotic-work = Heavy Robotic Work Ahead
#LOC_ConformalDecals_munar-variant-explosion = Explosion Hazard
#LOC_ConformalDecals_munar-variant-radiation = Radiation Hazard
#LOC_ConformalDecals_munar-variant-antimatter = Annihilation Hazard
#LOC_ConformalDecals_munar-variant-high-voltage = High Voltage
#LOC_ConformalDecals_munar-variant-extreme-voltage = Extreme Voltage
#LOC_ConformalDecals_munar-variant-explosive-bolts = Explosive Bolts
#LOC_ConformalDecals_munar-variant-autonomous-device = Autonomous Device
#LOC_ConformalDecals_munar-variant-gravity-adjust = Gravity Adjust
#LOC_ConformalDecals_munar-variant-electromagnetic = Strong EM Field
#LOC_ConformalDecals_munar-variant-mind-step = Mind Step
#LOC_ConformalDecals_munar-variant-class-1 = Class 1 Hazard: Flammable Liquid
#LOC_ConformalDecals_munar-variant-class-2 = Class 2 Hazard: Flammable Solid
#LOC_ConformalDecals_munar-variant-class-3 = Class 3 Hazard: Magnetic Field
#LOC_ConformalDecals_munar-variant-class-4 = Class 4 Hazard: Electric Field
#LOC_ConformalDecals_munar-variant-class-5 = Class 5 Hazard: Pressurized Fuel
#LOC_ConformalDecals_munar-variant-class-6 = Class 6 Hazard: Pressurized Coolant
#LOC_ConformalDecals_munar-variant-class-7 = Class 7 Hazard: Cryogenic Liquid
#LOC_ConformalDecals_munar-variant-class-8 = Class 8 Hazard: Radioactive
#LOC_ConformalDecals_munar-variant-class-9 = Class 9 Hazard: Ionized Gas
#LOC_ConformalDecals_munar-variant-class-10 = Class 10 Hazard: Antimatter
}
}

View File

@ -65,7 +65,12 @@ PART
scaleRange = 0.1, 4
scaleMode = AVERAGE
shader = ConformalDecals/Paint/Specular
shader = ConformalDecals/Decal/Standard
KEYWORD {
name = DECAL_SDF_ALPHA
value = false
}
TEXTURE {
name = _Decal
@ -108,7 +113,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 128, 2, 128, 112
}
}
@ -123,7 +128,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 256, 2, 128, 112
}
}
@ -138,7 +143,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 384, 2, 128, 112
}
}
@ -153,7 +158,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 690, 4, 330, 118
}
}
@ -168,7 +173,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 898, 4, 122, 118
}
}
@ -183,7 +188,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 6, 126, 196, 132
}
}
@ -198,7 +203,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 210, 122, 94, 94
}
}
@ -213,7 +218,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 8, 262, 192, 70
}
}
@ -242,7 +247,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 508, 332, 262, 112
}
}
@ -257,7 +262,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 202, 218, 164, 114
}
}
@ -272,7 +277,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 366, 218, 164, 114
}
}
@ -347,7 +352,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 326, 426, 164, 20
}
}
@ -363,7 +368,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 776, 388, 48, 48
}
}
@ -378,7 +383,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 328, 456, 48, 48
}
}
@ -393,7 +398,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 376, 456, 48, 48
}
}
@ -408,7 +413,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 424, 456, 48, 48
}
}
@ -423,7 +428,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 472, 456, 48, 48
}
}
@ -438,7 +443,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 520, 456, 48, 48
}
}
@ -453,7 +458,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 568, 456, 48, 48
}
}
@ -468,7 +473,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 614, 456, 48, 48
}
}
@ -483,7 +488,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 662, 456, 48, 48
}
}
@ -498,7 +503,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 710, 456, 48, 48
}
}
@ -513,7 +518,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/SpecularSDF
KEYWORD { name = DECAL_SDF_ALPHA }
tile = 758, 456, 48, 48
}
}
@ -528,7 +533,10 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
shader = ConformalDecals/Paint/Diffuse
TEXTURE {
name = _SpecMap
remove = true
}
tile = 826, 360, 196, 150
opacity = 1

Binary file not shown.

View File

@ -0,0 +1,537 @@
PART
{
name = conformaldecals-munar
module = Part
author = Andrew Cassidy
MODEL
{
model = ConformalDecals/Assets/decal-blank
scale = 1.0, 1.0, 1.0
}
rescaleFactor = 1
// Attachment
attachRules = 1,1,0,0,1
node_attach = 0.0, 0.0, 0.05, 0.0, 0.0, -1.0
// Tech
TechRequired = start
// Info
cost = 75
category = Structural
// CDL-3 Surface Base Decal
title = #LOC_ConformalDecals_munar-title
// Peel-N-Stik Adhesive Decals
manufacturer = #LOC_ConformalDecals_agent-peel-n-stick_title
// Munar Industries Ltd. saw the wild success of the CDL-2 decal, and wanted to develop a decal set for their own line of Heluim mining bases. These decals are more explicit than the Semiotic Standard and aimed at the hazards that come with more advanced techonologies. (Based on the work of Gavin Rothery)
description = #LOC_ConformalDecals_munar-description
// conformal decal sticker Moon munar lunar industries Gavin Rothery Sarang
tags = #LOC_ConformalDecals_munar-tags
bulkheadProfiles = srf
// Parameters
mass = 0.0005
dragModel = NONE
angularDrag = 0.0
crashTolerance = 10
maxTemp = 2000
breakingForce = 350
breakingTorque = 150
physicalSignificance = NONE
MODULE
{
name = ModuleConformalDecal
useBaseNormal = true
tile = -1, -1, 0, 0
tileSize = 96, 96
tileIndex = 0
defaultScale = 0.1
defaultDepth = 0.1
defaultOpacity = 0.8
defaultCutoff = 0
scaleRange = 0.05, 0.5
scaleMode = MINIMUM
cutoffAdjustable = false
shader = ConformalDecals/Decal/Standard
TEXTURE {
name = _Decal
textureUrl = ConformalDecals/Parts/Munar/Munar-Atlas
isMain = true
autoTile = true
}
TEXTURE {
name = _SpecMap
textureUrl = ConformalDecals/Assets/Decal-Spec
autoScale = true
}
}
MODULE {
name = ModuleB9PartSwitch
SUBTYPE {
name = severe-danger
title = #LOC_ConformalDecals_munar-variant-severe-danger
primaryColor = #2B250D
secondaryColor = #F78000
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 0 }
}
}
SUBTYPE {
name = danger
title = #LOC_ConformalDecals_munar-variant-danger
primaryColor = #93927E
secondaryColor = #2B250D
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 2 }
}
}
SUBTYPE {
name = hazard
title = #LOC_ConformalDecals_munar-variant-hazard
primaryColor = #2B250D
secondaryColor = #CC1F01
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 6 }
}
}
SUBTYPE {
name = warning
title = #LOC_ConformalDecals_munar-variant-warning
primaryColor = #2B250D
secondaryColor = #93927E
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 5 }
}
}
SUBTYPE {
name = bulkhead
title = #LOC_ConformalDecals_munar-variant-bulkhead
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 7 }
}
}
SUBTYPE {
name = hatch
title = #LOC_ConformalDecals_munar-variant-hatch
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 3 }
}
}
SUBTYPE {
name = pressure-hatch
title = #LOC_ConformalDecals_munar-variant-pressure-hatch
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 4 }
}
}
SUBTYPE {
name = door
title = #LOC_ConformalDecals_munar-variant-door
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 5 }
}
}
SUBTYPE {
name = door-danger
title = #LOC_ConformalDecals_munar-variant-door-danger
primaryColor = #2B250D
secondaryColor = #CC1F01
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
tile = 960, 0, 64, 96
scaleMode = HEIGHT
}
}
}
SUBTYPE {
name = airlock-interior
title = #LOC_ConformalDecals_munar-variant-airlock-interior
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 866, 96, 142, 96 }
}
}
SUBTYPE {
name = airlock-exterior
title = #LOC_ConformalDecals_munar-variant-airlock-exterior
primaryColor = #CC1F01
secondaryColor = #2B250D
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 768, 96, 142, 96 }
}
}
SUBTYPE {
name = check-seals
title = #LOC_ConformalDecals_munar-variant-check-seals
primaryColor = White
secondaryColor = #93927E
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 8 }
}
}
SUBTYPE {
name = pressure-seal
title = #LOC_ConformalDecals_munar-variant-pressure-seal
primaryColor = White
secondaryColor = #93927E
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 9 }
}
}
SUBTYPE {
name = vacuum
title = #LOC_ConformalDecals_munar-variant-vacuum
primaryColor = #93927E
secondaryColor = #2B250D
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 17 }
}
}
SUBTYPE {
name = gas-mask
title = #LOC_ConformalDecals_munar-variant-gas-mask
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 96, 320, 96, 116 }
}
}
SUBTYPE {
name = oxygen-rich
title = #LOC_ConformalDecals_munar-variant-oxygen-rich
primaryColor = #CC1F01
secondaryColor = #2B250D
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 288, 416, 96, 96 }
}
}
SUBTYPE {
name = robotic-work
title = #LOC_ConformalDecals_munar-variant-robotic-work
primaryColor = #F78000
secondaryColor = #2B250D
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 10 }
}
}
SUBTYPE {
name = explosion
title = #LOC_ConformalDecals_munar-variant-explosion
primaryColor = #F78000
secondaryColor = #2B250D
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 0, 320, 96, 116 }
}
}
SUBTYPE {
name = radiation
title = #LOC_ConformalDecals_munar-variant-radiation
primaryColor = #F78000
secondaryColor = #2B250D
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 1 }
}
}
SUBTYPE {
name = antimatter
title = #LOC_ConformalDecals_munar-variant-antimatter
primaryColor = #F78000
secondaryColor = #2B250D
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 11 }
}
}
SUBTYPE {
name = high-voltage
title = #LOC_ConformalDecals_munar-variant-high-voltage
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 13 }
}
}
SUBTYPE {
name = extreme-voltage
title = #LOC_ConformalDecals_munar-variant-extreme-voltage
primaryColor = #2B250D
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 14 }
}
}
SUBTYPE {
name = explosive-bolts
title = #LOC_ConformalDecals_munar-variant-explosive-bolts
primaryColor = #93927E
secondaryColor = #CC1F01
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 15 }
}
}
SUBTYPE {
name = autonomous-device
title = #LOC_ConformalDecals_munar-variant-autonomous-device
primaryColor = #2B250D
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tileIndex = 16 }
}
}
SUBTYPE {
name = gravity-adjust
title = #LOC_ConformalDecals_munar-variant-gravity-adjust
primaryColor = White
secondaryColor = #CC1F01
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 288, 320, 96, 96 }
}
}
SUBTYPE {
name = electromagnetic
title = #LOC_ConformalDecals_munar-variant-electromagnetic
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
tile = 967, 195, 50, 90
scaleMode = HEIGHT
}
}
}
SUBTYPE {
name = mind-step
title = #LOC_ConformalDecals_munar-variant-mind-step
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 1, 447, 230, 64 }
}
}
SUBTYPE {
name = class-1
title = #LOC_ConformalDecals_munar-variant-class-1
primaryColor = #CC1F01
secondaryColor = #93927E
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 0, 192, 96, 128 }
}
}
SUBTYPE {
name = class-2
title = #LOC_ConformalDecals_munar-variant-class-2
primaryColor = #93927E
secondaryColor = #CC1F01
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 96, 192, 96, 128 }
}
}
SUBTYPE {
name = class-3
title = #LOC_ConformalDecals_munar-variant-class-3
primaryColor = #93927E
secondaryColor = #93927E
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 192, 192, 96, 128 }
}
}
SUBTYPE {
name = class-4
title = #LOC_ConformalDecals_munar-variant-class-4
primaryColor = #93927E
secondaryColor = #93927E
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 288, 192, 96, 128 }
}
}
SUBTYPE {
name = class-5
title = #LOC_ConformalDecals_munar-variant-class-5
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 384, 192, 96, 128 }
}
}
SUBTYPE {
name = class-6
title = #LOC_ConformalDecals_munar-variant-class-6
primaryColor = #93927E
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 480, 192, 96, 128 }
}
}
SUBTYPE {
name = class-7
title = #LOC_ConformalDecals_munar-variant-class-7
primaryColor = #F78000
secondaryColor = #93927E
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 576, 192, 96, 128 }
}
}
SUBTYPE {
name = class-8
title = #LOC_ConformalDecals_munar-variant-class-8
primaryColor = #93927E
secondaryColor = #F78000
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 672, 192, 96, 128 }
}
}
SUBTYPE {
name = class-9
title = #LOC_ConformalDecals_munar-variant-class-9
primaryColor = #93927E
secondaryColor = #F78000
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 768, 192, 96, 128 }
}
}
SUBTYPE {
name = class-10
title = #LOC_ConformalDecals_munar-variant-class-10
primaryColor = #F78000
secondaryColor = White
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA { tile = 864, 192, 96, 128 }
}
}
}
}

View File

@ -21,13 +21,13 @@ PART
cost = 75
category = Structural
// CDL-1 Semiotic Standard Decal
// CDL-2 Semiotic Standard Decal
title = #LOC_ConformalDecals_semiotic-title
// Peel-N-Stik Adhesive Decals
manufacturer = #LOC_ConformalDecals_agent-peel-n-stick_title
// After several unfortunate mishaps with confusing signage on spacecraft, The Peel-N-Stik™ Corporation teamed up with Kerland-Mutani to unveil the Semiotic Standard for Kerbal Vessels, a set of standardized icons for use on ships and stations.
// After several unfortunate mishaps with confusing signage on spacecraft, The Peel-N-Stik™ Corporation teamed up with Kerland-Mutani to unveil the Semiotic Standard for Kerbal Vessels, a set of standardized icons for use on ships and stations. (Based on the work of Ron Cobb)
description = #LOC_ConformalDecals_semiotic-description
// conformal decal sticker semiotic standard for kerbal vessels Ron Cobb Alien
@ -62,7 +62,7 @@ PART
scaleRange = 0.05, 0.5
cutoffAdjustable = false
shader = ConformalDecals/Paint/Specular
shader = ConformalDecals/Decal/Standard
TEXTURE {
name = _Decal

View File

@ -53,5 +53,13 @@ PART
defaultDepth = 0.2
defaultCutoff = 0
shader = ConformalDecals/Decal/Standard
TEXTURE {
name = _SpecMap
textureUrl = ConformalDecals/Assets/Decal-Spec
autoScale = true
}
}
}

View File

@ -0,0 +1,69 @@
PART
{
name = conformaldecals-text
module = Part
author = Andrew Cassidy
MODEL
{
model = ConformalDecals/Assets/decal-blank
scale = 1.0, 1.0, 1.0
}
rescaleFactor = 1
// Attachment
attachRules = 1,1,0,0,1
node_attach = 0.0, 0.0, 0.1, 0.0, 0.0, -1.0
// Tech
TechRequired = start
// Info
cost = 75
category = Structural
// CDL-T Text Decal
title = #LOC_ConformalDecals_text-title
// Peel-N-Stik Adhesive Decals
manufacturer = #LOC_ConformalDecals_agent-peel-n-stick_title
// A decal that can display custom text in a variety of fonts
description = #LOC_ConformalDecals_text-description
// conformal decal sticker text font
tags = #LOC_ConformalDecals_text-tags
bulkheadProfiles = srf
// Parameters
mass = 0.0005
dragModel = NONE
angularDrag = 0.0
crashTolerance = 10
maxTemp = 2000
breakingForce = 350
breakingTorque = 150
physicalSignificance = NONE
MODULE
{
name = ModuleConformalText
text = Text
fontName = Calibri SDF
fillColor = #000000FF
outlineColor = #FFFFFFFF
fillEnabled = true
outlineEnabled = false
shader = ConformalDecals/Decal/Text
useBaseNormal = true
scaleMode = MINIMUM
defaultScale = 0.2
defaultDepth = 0.2
defaultCutoff = 0.5
}
}

View File

@ -0,0 +1,17 @@
// Decals are just paint, so they shouldnt affect a vessel's aerodynamics at all
@PART[*]:HAS[@MODULE[ModuleConformalDecal]]:After[FerramAerospaceResearch]
{
!MODULE[GeometryPartModule] {}
}
@PART[*]:HAS[@MODULE[ModuleConformalFlag]]:After[FerramAerospaceResearch]
{
!MODULE[GeometryPartModule] {}
}
@PART[*]:HAS[@MODULE[ModuleConformalText]]:After[FerramAerospaceResearch]
{
!MODULE[GeometryPartModule] {}
}

View File

@ -1,6 +1,7 @@
// Custom category, requires WildBlueTools to work
MODCAT
{
name = conformaldecals
title = #LOC_ConformalDecals_category-decals_title // Decals
folderName = ConformalDecals

View File

@ -20,4 +20,41 @@ CONFORMALDECALS {
shader = KSP/Specular (Transparent)
shader = Solid Color (Alpha)
}
FONT {
name = LiberationSans SDF
title = Liberation Sans
}
FONT {
name = Calibri SDF
title = Calibri
}
FONT {
name = NotoSans-Regular SDF
title = Noto Sans
}
FONT {
name = Waukegan LDO Extended SDF
title = Waukegan Extended
}
FONT {
name = Nasalization SDF
title = Nasalization
}
FONT {
name = Helvetica SDF
title = Helvetica
}
FONT {
name = amarurgt SDF
title = Amarillo USAF
style = 32
styleMask = 4
}
}

Binary file not shown.

View File

@ -5,14 +5,14 @@
"VERSION":
{
"MAJOR":0,
"MINOR":1,
"PATCH":4,
"BUILD":0
"MINOR":2,
"PATCH":6,
"BUILD":1
},
"KSP_VERSION":
{
"MAJOR":1,
"MINOR":9,
"MINOR":10,
"PATCH":1
},
"KSP_VERSION_MIN":{
@ -25,4 +25,4 @@
"MINOR":10,
"PATCH":99
}
}
}

View File

@ -1,4 +1,4 @@
# Conformal Decals v0.1.4
# Conformal Decals v0.2.6
[![Build Status](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals.svg?branch=release)](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals) [![Art: CC BY-SA 4.0](https://img.shields.io/badge/Art%20License-CC%20BY--SA%204.0-orange.svg)](https://creativecommons.org/licenses/by-sa/4.0/) [![Code: GPL v3](https://img.shields.io/badge/Code%20License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
![Screenshot](http://pileof.rocks/KSP/images/ConformalDecalsHeader.png)
@ -10,7 +10,7 @@ Conformal Decals adds a set of decal stickers to KSP, as well as providing a fra
Required:
- KSP (1.8.x to 1.10.x)
- B9 Part Switch (2.16.0). Bundled with release.
- ModuleManager (4.1.3). Bundled with release.
- ModuleManager (4.1.4). Bundled with release.
- Shabby (0.1.2). Bundled with release.
Optional:
@ -20,6 +20,8 @@ Optional:
- Art and Plugin code: Andrew Cassidy (Cineboxandrew)
- Semiotic decal pack based on the work of Ron Cobb
- Munar decal pack based on the work of Gavin Rothery
- Header image by Zorg, featuring parts from Bluedog Design Bureau
## Installation

View File

@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConformalDecals", "ConformalDecals/ConformalDecals.csproj", "{1ea983f9-42e5-494e-9683-fdac9c9121f4}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConformalDecals", "ConformalDecals/ConformalDecals.csproj", "{1EA983F9-42E5-494E-9683-FDAC9C9121F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -8,9 +8,9 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1ea983f9-42e5-494e-9683-fdac9c9121f4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1ea983f9-42e5-494e-9683-fdac9c9121f4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1ea983f9-42e5-494e-9683-fdac9c9121f4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1ea983f9-42e5-494e-9683-fdac9c9121f4}.Release|Any CPU.Build.0 = Release|Any CPU
{1EA983F9-42E5-494E-9683-FDAC9C9121F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1EA983F9-42E5-494E-9683-FDAC9C9121F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1EA983F9-42E5-494E-9683-FDAC9C9121F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1EA983F9-42E5-494E-9683-FDAC9C9121F4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -1,75 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1ea983f9-42e5-494e-9683-fdac9c9121f4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFramework>net48</TargetFramework>
<LangVersion>8</LangVersion>
<RootNamespace>ConformalDecals</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\ConformalDecals.xml</DocumentationFile>
<NoWarn>CS1591</NoWarn>
<IsPackable>false</IsPackable>
<PlatformTarget>x64</PlatformTarget>
<NoWarn>1701;1702;CS0649;CS1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls/Assembly-CSharp.dll</HintPath>
<HintPath>dlls\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Shabby, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls/Shabby.dll</HintPath>
<HintPath>dlls\Shabby.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls\UnityEngine.dll</HintPath>
<HintPath>dlls\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls\UnityEngine.CoreModule.dll</HintPath>
<HintPath>dlls\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls\UnityEngine.PhysicsModule.dll</HintPath>
<HintPath>dlls\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls\UnityEngine.UIModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DecalConfig.cs" />
<Compile Include="DecalIconFixer.cs" />
<Compile Include="DecalPropertyIDs.cs" />
<Compile Include="MaterialProperties\MaterialColorProperty.cs" />
<Compile Include="MaterialProperties\MaterialFloatProperty.cs" />
<Compile Include="MaterialProperties\MaterialProperty.cs" />
<Compile Include="MaterialProperties\MaterialPropertyCollection.cs" />
<Compile Include="MaterialProperties\MaterialTextureProperty.cs" />
<Compile Include="ModuleConformalFlag.cs" />
<Compile Include="ProjectionTarget.cs" />
<Compile Include="ModuleConformalDecal.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Test\TestLayers.cs" />
<Compile Include="Util\Logging.cs" />
<Compile Include="Util\OrientedBounds.cs" />
<Compile Include="Util\ParseUtil.cs" />
<Compile Remove="dlls\**"/>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>sh -e -c "cp -v '$(TargetPath)' '$(SolutionDir)/../GameData/ConformalDecals/Plugins'"</PostBuildEvent>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Remove="dlls\**"/>
</ItemGroup>
<ItemGroup>
<None Remove="dlls\**"/>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="/bin/cp -v '$(OutDir)ConformalDecals.dll' '$(SolutionDir)../GameData/ConformalDecals/Plugins'" IgnoreExitCode="true"/>
<!--Fuck you MSBuild stop trying to run CMD.exe on macOS-->
</Target>
</Project>

View File

@ -1,13 +1,47 @@
using System;
using System.Collections.Generic;
using ConformalDecals.Text;
using ConformalDecals.Util;
using TMPro;
using UniLinq;
using UnityEngine;
namespace ConformalDecals {
public static class DecalConfig {
private static Texture2D _blankNormal;
private static List<string> _shaderBlacklist;
private static int _decalLayer = 31;
private static bool _selectableInFlight = false;
private static Texture2D _blankNormal;
private static List<string> _shaderBlacklist;
private static Dictionary<string, DecalFont> _fontList;
private static int _decalLayer = 31;
private static bool _selectableInFlight;
private struct LegacyShaderEntry {
public string name;
public string[] keywords;
}
private static readonly Dictionary<string, LegacyShaderEntry> LegacyShaderPairs = new Dictionary<string, LegacyShaderEntry>() {
["ConformalDecals/Feature/Bumped"] = new LegacyShaderEntry() {
name = "ConformalDecals/Decal/Standard",
keywords = new[] {"DECAL_BUMPMAP"}
},
["ConformalDecals/Paint/Diffuse"] = new LegacyShaderEntry() {
name = "ConformalDecals/Decal/Standard",
keywords = new string[] { }
},
["ConformalDecals/Paint/Specular"] = new LegacyShaderEntry() {
name = "ConformalDecals/Decal/Standard",
keywords = new[] {"DECAL_SPECMAP"}
},
["ConformalDecals/Paint/DiffuseSDF"] = new LegacyShaderEntry() {
name = "ConformalDecals/Decal/Standard",
keywords = new[] {"DECAL_SDF_ALPHA"}
},
["ConformalDecals/Paint/SpecularSDF"] = new LegacyShaderEntry() {
name = "ConformalDecals/Decal/Standard",
keywords = new[] {"DECAL_SDF_ALPHA", "DECAL_SPECMAP"}
},
};
public static Texture2D BlankNormal => _blankNormal;
@ -15,6 +49,10 @@ namespace ConformalDecals {
public static bool SelectableInFlight => _selectableInFlight;
public static IEnumerable<DecalFont> Fonts => _fontList.Values;
public static DecalFont FallbackFont { get; private set; }
public static bool IsBlacklisted(Shader shader) {
return IsBlacklisted(shader.name);
}
@ -23,19 +61,53 @@ namespace ConformalDecals {
return _shaderBlacklist.Contains(shaderName);
}
public static bool IsLegacy(string shaderName, out string newShader, out string[] keywords) {
if (LegacyShaderPairs.TryGetValue(shaderName, out var entry)) {
newShader = entry.name;
keywords = entry.keywords;
return true;
}
newShader = null;
keywords = null;
return false;
}
public static DecalFont GetFont(string name) {
if (_fontList.TryGetValue(name, out var font)) {
return font;
}
else {
throw new KeyNotFoundException($"Font {name} not found");
}
}
private static void ParseConfig(ConfigNode node) {
ParseUtil.ParseIntIndirect(ref _decalLayer, node, "decalLayer");
ParseUtil.ParseBoolIndirect(ref _selectableInFlight, node, "selectableInFlight");
foreach (var blacklist in node.GetNodes("SHADERBLACKLIST")) {
foreach (var shaderName in blacklist.GetValuesList("shader")) {
_shaderBlacklist.Add(shaderName);
}
}
ParseUtil.ParseIntIndirect(ref _decalLayer, node, "decalLayer");
ParseUtil.ParseBoolIndirect(ref _selectableInFlight, node, "selectableInFlight");
var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
foreach (var fontNode in node.GetNodes("FONT")) {
try {
var font = new DecalFont(fontNode, allFonts);
_fontList.Add(font.Name, font);
}
catch (Exception e) {
Debug.LogException(e);
}
}
}
private static Texture2D MakeBlankNormal() {
Debug.Log("ConformalDecals: Generating neutral normal map texture");
Logging.Log("Generating neutral normal map texture");
var width = 2;
var height = 2;
var color = new Color32(255, 128, 128, 128);
@ -56,11 +128,12 @@ namespace ConformalDecals {
// ReSharper disable once UnusedMember.Global
public static void ModuleManagerPostLoad() {
_shaderBlacklist = new List<string>();
_fontList = new Dictionary<string, DecalFont>();
var configs = GameDatabase.Instance.GetConfigs("CONFORMALDECALS");
if (configs.Length > 0) {
Debug.Log("ConformalDecals: loading config");
Logging.Log("loading config");
foreach (var config in configs) {
ParseConfig(config.config);
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using ConformalDecals.Util;
using UnityEngine;
namespace ConformalDecals {
@ -12,11 +13,11 @@ namespace ConformalDecals {
public void Start() {
foreach (var partName in PartNames) {
Debug.Log($"Unf*&king decal preview on {partName}");
Logging.Log($"Unf*&king decal preview on '{partName}'");
var partInfo = PartLoader.getPartInfoByName(partName);
if (partInfo == null) {
Debug.Log($"Part {partName} not found!");
Logging.LogError($"Part {partName} not found!");
continue;
}
@ -28,12 +29,12 @@ namespace ConformalDecals {
var backTransform = Part.FindHeirarchyTransform(icon.transform, decalModule.decalBack);
if (frontTransform == null) {
Debug.Log($"Part {partName} has no frontTransform");
Logging.Log($"Part '{partName}' has no frontTransform");
continue;
}
if (backTransform == null) {
Debug.Log($"Part {partName} has no backTransform");
Logging.Log($"Part '{partName}' has no backTransform");
continue;
}

View File

@ -1,4 +1,5 @@
using UnityEngine;
// ReSharper disable InconsistentNaming
namespace ConformalDecals {
@ -12,5 +13,6 @@ namespace ConformalDecals {
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 _ZWrite = Shader.PropertyToID("_ZWrite");
}
}

View File

@ -0,0 +1,19 @@
using ConformalDecals.Util;
using UnityEngine;
namespace ConformalDecals.MaterialProperties {
public class MaterialKeywordProperty : MaterialProperty {
[SerializeField] public bool value = true;
public override void ParseNode(ConfigNode node) {
base.ParseNode(node);
ParseUtil.ParseBoolIndirect(ref value, node, "value");
}
public override void Modify(Material material) {
if (value) material.EnableKeyword(_propertyName);
else material.DisableKeyword(_propertyName);
}
}
}

View File

@ -14,13 +14,14 @@ namespace ConformalDecals.MaterialProperties {
[SerializeField] protected int _propertyID;
[SerializeField] protected string _propertyName;
public abstract void Modify(Material material);
public virtual void ParseNode(ConfigNode node) {
if (node == null) throw new ArgumentNullException(nameof(node));
PropertyName = node.GetValue("name");
Debug.Log($"Parsing material property {_propertyName}");
}
public abstract void Modify(Material material);
public virtual void Remove(Material material) { }
}
}

View File

@ -30,12 +30,20 @@ namespace ConformalDecals.MaterialProperties {
public Shader DecalShader => _shader;
public IEnumerable<Material> Materials {
get {
yield return PreviewMaterial;
yield return DecalMaterial;
}
}
public Material DecalMaterial {
get {
if (_decalMaterial == null) {
_decalMaterial = new Material(_shader);
_decalMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Off);
_decalMaterial.SetInt(DecalPropertyIDs._ZWrite, 0);
_decalMaterial.renderQueue = RenderQueue;
}
@ -50,6 +58,7 @@ namespace ConformalDecals.MaterialProperties {
_previewMaterial.EnableKeyword("DECAL_PREVIEW");
_previewMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Back);
_previewMaterial.SetInt(DecalPropertyIDs._ZWrite, 1);
}
return _previewMaterial;
@ -69,7 +78,6 @@ namespace ConformalDecals.MaterialProperties {
public float AspectRatio => MainTexture == null ? 1 : MainTexture.AspectRatio;
public void OnBeforeSerialize() {
Debug.Log($"Serializing MaterialPropertyCollection {this.GetInstanceID()}");
if (_materialProperties == null) throw new SerializationException("Tried to serialize an uninitialized MaterialPropertyCollection");
_serializedNames = _materialProperties.Keys.ToArray();
@ -77,7 +85,6 @@ namespace ConformalDecals.MaterialProperties {
}
public void OnAfterDeserialize() {
Debug.Log($"Deserializing MaterialPropertyCollection {this.GetInstanceID()}");
if (_serializedNames == null) throw new SerializationException("ID array is null");
if (_serializedProperties == null) throw new SerializationException("Property array is null");
if (_serializedProperties.Length != _serializedNames.Length) throw new SerializationException("Material property arrays are different lengths.");
@ -95,7 +102,6 @@ namespace ConformalDecals.MaterialProperties {
}
public void Awake() {
Debug.Log($"MaterialPropertyCollection {this.GetInstanceID()} onAwake");
_materialProperties ??= new Dictionary<string, MaterialProperty>();
}
@ -145,6 +151,20 @@ namespace ConformalDecals.MaterialProperties {
}
}
public bool RemoveProperty(string propertyName) {
if (_materialProperties.TryGetValue(propertyName, out var property)) {
foreach (var material in Materials) {
property.Remove(material);
}
_materialProperties.Remove(propertyName);
Destroy(property);
return true;
}
return false;
}
public MaterialTextureProperty AddTextureProperty(string propertyName, bool isMain = false) {
var newProperty = AddProperty<MaterialTextureProperty>(propertyName);
if (isMain) _mainTexture = newProperty;
@ -167,6 +187,8 @@ namespace ConformalDecals.MaterialProperties {
string propertyName = "";
if (!ParseUtil.ParseStringIndirect(ref propertyName, node, "name")) throw new ArgumentException("node has no name");
if (ParseUtil.ParseBool(node, "remove", true)) RemoveProperty(propertyName);
var newProperty = AddOrGetProperty<T>(propertyName);
newProperty.ParseNode(node);
@ -180,14 +202,23 @@ namespace ConformalDecals.MaterialProperties {
public void SetShader(string shaderName) {
if (string.IsNullOrEmpty(shaderName)) {
if (_shader == null) {
Debug.Log("Using default decal shader");
shaderName = "ConformalDecals/Paint/Diffuse";
Logging.Log("Using default decal shader");
shaderName = "ConformalDecals/Decal/Standard";
}
else {
return;
}
}
if (DecalConfig.IsLegacy(shaderName, out var newShader, out var keywords)) {
Logging.LogWarning($"Part is using shader {shaderName}, which has been replaced by {newShader}.");
shaderName = newShader;
foreach (var keyword in keywords) {
var newProperty = AddOrGetProperty<MaterialKeywordProperty>(keyword);
newProperty.value = true;
}
}
var shader = Shabby.Shabby.FindShader(shaderName);
if (shader == null) throw new FormatException($"Unable to find specified shader '{shaderName}'");
@ -209,8 +240,6 @@ namespace ConformalDecals.MaterialProperties {
if (_mainTexture == null) throw new InvalidOperationException("UpdateTile called but no main texture is specified!");
var mainTexSize = _mainTexture.Dimensions;
Debug.Log($"Main texture is {_mainTexture.PropertyName} and its size is {mainTexSize}");
foreach (var entry in _materialProperties) {
if (entry.Value is MaterialTextureProperty textureProperty && textureProperty.autoTile) {
textureProperty.SetTile(tile, mainTexSize);
@ -244,8 +273,9 @@ namespace ConformalDecals.MaterialProperties {
}
public void UpdateMaterials() {
UpdateMaterial(DecalMaterial);
UpdateMaterial(PreviewMaterial);
foreach (var material in Materials) {
UpdateMaterial(material);
}
}
public void UpdateMaterial(Material material) {

View File

@ -10,7 +10,7 @@ namespace ConformalDecals.MaterialProperties {
[SerializeField] public bool autoTile;
[SerializeField] private string _textureUrl;
[SerializeField] private Texture2D _texture = Texture2D.whiteTexture;
[SerializeField] private Texture2D _texture;
[SerializeField] private bool _hasTile;
[SerializeField] private Rect _tileRect;
@ -19,7 +19,10 @@ namespace ConformalDecals.MaterialProperties {
[SerializeField] private Vector2 _textureOffset;
[SerializeField] private Vector2 _textureScale = Vector2.one;
public Texture2D Texture => _texture;
public Texture2D Texture {
get => _texture;
set => _texture = value;
}
public string TextureUrl {
get => _textureUrl;
@ -38,7 +41,13 @@ namespace ConformalDecals.MaterialProperties {
public Vector2 Dimensions => new Vector2(_texture.width, _texture.height);
public Vector2 MaskedDimensions => _hasTile ? _tileRect.size : Dimensions;
public float AspectRatio => MaskedHeight / (float) MaskedWidth;
public float AspectRatio {
get {
if (_texture == null) return 1;
if (_textureUrl?.Contains("Squad/Flags") == true) return 0.625f;
return MaskedHeight / (float) MaskedWidth;
}
}
public override void ParseNode(ConfigNode node) {
base.ParseNode(node);
@ -55,18 +64,29 @@ namespace ConformalDecals.MaterialProperties {
if (ParseUtil.ParseStringIndirect(ref _textureUrl, node, "textureUrl")) {
_texture = LoadTexture(_textureUrl, isNormal);
}
if (_texture == null) {
_texture = isNormal ? DecalConfig.BlankNormal : Texture2D.whiteTexture;
}
}
public override void Modify(Material material) {
if (material == null) throw new ArgumentNullException(nameof(material));
if (_texture == null) {
_texture = Texture2D.whiteTexture;
throw new NullReferenceException("texture is null, but should not be");
_texture = isNormal ? DecalConfig.BlankNormal : Texture2D.whiteTexture;
}
material.SetTexture(_propertyID, _texture);
material.SetTextureOffset(_propertyID, _textureOffset);
material.SetTextureScale(_propertyID, _textureScale * _scale);
if (_propertyName != "_Decal") material.EnableKeyword("DECAL" + _propertyName.ToUpper());
}
public override void Remove(Material material) {
if (material == null) throw new ArgumentNullException(nameof(material));
base.Remove(material);
if (_propertyName != "_Decal") material.DisableKeyword("DECAL" + _propertyName.ToUpper());
}
public void SetScale(Vector2 scale) {
@ -94,7 +114,7 @@ namespace ConformalDecals.MaterialProperties {
}
private static Texture2D LoadTexture(string textureUrl, bool isNormal) {
Debug.Log($"loading texture '{textureUrl}', isNormalMap = {isNormal}");
//Logging.Log($"loading texture '{textureUrl}', isNormalMap = {isNormal}");
if ((string.IsNullOrEmpty(textureUrl) && isNormal) || textureUrl == "Bump") {
return Texture2D.normalTexture;
}

View File

@ -19,7 +19,7 @@ namespace ConformalDecals {
// CONFIGURABLE VALUES
[KSPField] public string shader = "ConformalDecals/Paint/Diffuse";
[KSPField] public string shader = "ConformalDecals/Decal/Standard";
[KSPField] public string decalFront = "Decal-Front";
[KSPField] public string decalBack = "Decal-Back";
@ -31,7 +31,7 @@ namespace ConformalDecals {
[KSPField] public bool scaleAdjustable = true;
[KSPField] public float defaultScale = 1;
[KSPField] public Vector2 scaleRange = new Vector2(0, 4);
[KSPField] public Vector2 scaleRange = new Vector2(0, 5);
[KSPField] public DecalScaleMode scaleMode = DecalScaleMode.HEIGHT;
@ -60,19 +60,19 @@ namespace ConformalDecals {
// INTERNAL VALUES
[KSPField(guiName = "#LOC_ConformalDecals_gui-scale", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F2", guiUnits = "m"),
UI_FloatRange(stepIncrement = 0.05f)]
UI_FloatRange()]
public float scale = 1.0f;
[KSPField(guiName = "#LOC_ConformalDecals_gui-depth", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F2", guiUnits = "m"),
UI_FloatRange(stepIncrement = 0.02f)]
UI_FloatRange()]
public float depth = 0.2f;
[KSPField(guiName = "#LOC_ConformalDecals_gui-opacity", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
UI_FloatRange(stepIncrement = 0.05f)]
UI_FloatRange()]
public float opacity = 1.0f;
[KSPField(guiName = "#LOC_ConformalDecals_gui-cutoff", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
UI_FloatRange(stepIncrement = 0.05f)]
UI_FloatRange()]
public float cutoff = 0.5f;
[KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"),
@ -130,7 +130,6 @@ namespace ConformalDecals {
/// <inheritdoc />
public override void OnLoad(ConfigNode node) {
this.Log("Loading module");
try {
// SETUP TRANSFORMS
decalFrontTransform = part.FindModelTransform(decalFront);
@ -150,7 +149,6 @@ namespace ConformalDecals {
// SETUP BACK MATERIAL
if (updateBackScale) {
this.Log("Getting material and base scale for back material");
var backRenderer = decalBackTransform.GetComponent<MeshRenderer>();
if (backRenderer == null) {
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
@ -172,6 +170,12 @@ namespace ConformalDecals {
// set shader
materialProperties.SetShader(shader);
materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_BASE_NORMAL").value = useBaseNormal;
// add keyword nodes
foreach (var keywordNode in node.GetNodes("KEYWORD")) {
materialProperties.ParseProperty<MaterialKeywordProperty>(keywordNode);
}
// add texture nodes
foreach (var textureNode in node.GetNodes("TEXTURE")) {
@ -190,7 +194,6 @@ namespace ConformalDecals {
// handle texture tiling parameters
var tileString = node.GetValue("tile");
this.Log(tileString);
if (!string.IsNullOrEmpty(tileString)) {
var tileValid = ParseExtensions.TryParseRect(tileString, out tileRect);
if (!tileValid) throw new FormatException($"Invalid rect value for tile '{tileString}'");
@ -202,9 +205,6 @@ namespace ConformalDecals {
else if (tileIndex >= 0) {
materialProperties.UpdateTile(tileIndex, tileSize);
}
// QUEUE PART FOR ICON FIXING IN VAB
DecalIconFixer.QueuePart(part.name);
}
catch (Exception e) {
this.LogException("Exception parsing partmodule", e);
@ -212,6 +212,10 @@ namespace ConformalDecals {
UpdateMaterials();
foreach (var keyword in _decalMaterial.shaderKeywords) {
this.Log($"keyword: {keyword}");
}
if (HighLogic.LoadedSceneIsEditor) {
UpdateTweakables();
}
@ -225,6 +229,9 @@ namespace ConformalDecals {
opacity = defaultOpacity;
cutoff = defaultCutoff;
wear = defaultWear;
// QUEUE PART FOR ICON FIXING IN VAB
DecalIconFixer.QueuePart(part.name);
}
}
@ -235,14 +242,10 @@ namespace ConformalDecals {
/// <inheritdoc />
public override void OnStart(StartState state) {
this.Log("Starting module");
materialProperties.RenderQueue = DecalQueue;
_boundsRenderer = decalProjectorTransform.GetComponent<MeshRenderer>();
UpdateMaterials();
// handle tweakables
if (HighLogic.LoadedSceneIsEditor) {
GameEvents.onEditorPartEvent.Add(OnEditorEvent);
@ -263,13 +266,13 @@ namespace ConformalDecals {
OnAttach();
}
}
// handle flight events
if (HighLogic.LoadedSceneIsFlight) {
GameEvents.onPartWillDie.Add(OnPartWillDie);
if (part.parent == null) part.explode();
Part.layerMask |= 1 << DecalConfig.DecalLayer;
decalColliderTransform.gameObject.layer = DecalConfig.DecalLayer;
@ -354,8 +357,8 @@ namespace ConformalDecals {
part.Die();
}
}
protected void OnAttach() {
protected virtual void OnAttach() {
if (part.parent == null) {
this.LogError("Attach function called but part has no parent!");
_isAttached = false;
@ -364,8 +367,6 @@ namespace ConformalDecals {
_isAttached = true;
this.Log($"Decal attached to {part.parent.partName}");
// hide model
decalModelTransform.gameObject.SetActive(false);
@ -380,7 +381,7 @@ namespace ConformalDecals {
UpdateScale();
}
protected void OnDetach() {
protected virtual void OnDetach() {
_isAttached = false;
// unhide model
@ -399,16 +400,16 @@ namespace ConformalDecals {
protected void UpdateScale() {
scale = Mathf.Max(0.01f, scale);
depth = Mathf.Max(0.01f, depth);
var aspectRatio = materialProperties.AspectRatio;
var aspectRatio = Mathf.Max(0.01f, materialProperties.AspectRatio);
Vector2 size;
switch (scaleMode) {
default:
case DecalScaleMode.HEIGHT:
size = new Vector2(scale, scale * aspectRatio);
size = new Vector2(scale / aspectRatio, scale);
break;
case DecalScaleMode.WIDTH:
size = new Vector2(scale / aspectRatio, scale);
size = new Vector2(scale, scale * aspectRatio);
break;
case DecalScaleMode.AVERAGE:
var width1 = 2 * scale / (1 + aspectRatio);
@ -453,7 +454,7 @@ namespace ConformalDecals {
}
}
protected void UpdateMaterials() {
protected virtual void UpdateMaterials() {
materialProperties.UpdateMaterials();
materialProperties.SetOpacity(opacity);
materialProperties.SetCutoff(cutoff);
@ -497,7 +498,7 @@ namespace ConformalDecals {
}
}
protected void UpdateTweakables() {
protected virtual void UpdateTweakables() {
// setup tweakable fields
var scaleField = Fields[nameof(scale)];
var depthField = Fields[nameof(depth)];
@ -520,7 +521,7 @@ namespace ConformalDecals {
var scaleEditor = (UI_FloatRange) scaleField.uiControlEditor;
scaleEditor.minValue = minValue;
scaleEditor.maxValue = maxValue;
scaleEditor.stepIncrement = (maxValue - minValue) / steps;
scaleEditor.stepIncrement = 0.01f; //1cm
scaleEditor.onFieldChanged = OnSizeTweakEvent;
}
@ -531,7 +532,7 @@ namespace ConformalDecals {
var depthEditor = (UI_FloatRange) depthField.uiControlEditor;
depthEditor.minValue = minValue;
depthEditor.maxValue = maxValue;
depthEditor.stepIncrement = (maxValue - minValue) / steps;
depthEditor.stepIncrement = 0.01f; //1cm
depthEditor.onFieldChanged = OnSizeTweakEvent;
}

View File

@ -0,0 +1,319 @@
using System.Collections;
using System.Net;
using ConformalDecals.MaterialProperties;
using ConformalDecals.Text;
using ConformalDecals.UI;
using ConformalDecals.Util;
using TMPro;
using UnityEngine;
namespace ConformalDecals {
public class ModuleConformalText : ModuleConformalDecal {
[KSPField] public Vector2 lineSpacingRange = new Vector2(-50, 50);
[KSPField] public Vector2 charSpacingRange = new Vector2(-50, 50);
[KSPField(isPersistant = true)] public bool vertical;
[KSPField(isPersistant = true)] public float lineSpacing;
[KSPField(isPersistant = true)] public float charSpacing;
[KSPField] public string text;
[KSPField] public DecalFont font;
[KSPField] public FontStyles style;
[KSPField] public Color32 fillColor = Color.black;
[KSPField] public Color32 outlineColor = Color.white;
// KSP TWEAKABLES
[KSPEvent(guiName = "#LOC_ConformalDecals_gui-set-text", guiActive = false, guiActiveEditor = true)]
public void SetText() {
if (_textEntryController == null) {
_textEntryController = TextEntryController.Create(text, font, style, vertical, lineSpacing, charSpacing, lineSpacingRange, charSpacingRange, OnTextUpdate);
}
else {
_textEntryController.Close();
}
}
// FILL
[KSPField(guiName = "#LOC_ConformalDecals_gui-fill", groupName = "decal-fill", groupDisplayName = "#LOC_ConformalDecals_gui-group-fill",
guiActive = false, guiActiveEditor = true, isPersistant = true),
UI_Toggle()]
public bool fillEnabled = true;
[KSPEvent(guiName = "#LOC_ConformalDecals_gui-set-fill-color", groupName = "decal-fill", groupDisplayName = "#LOC_ConformalDecals_gui-group-fill",
guiActive = false, guiActiveEditor = true)]
public void SetFillColor() {
if (_fillColorPickerController == null) {
_fillColorPickerController = ColorPickerController.Create(fillColor, OnFillColorUpdate);
}
else {
_fillColorPickerController.Close();
}
}
// OUTLINE
[KSPField(guiName = "#LOC_ConformalDecals_gui-outline", groupName = "decal-outline", groupDisplayName = "#LOC_ConformalDecals_gui-group-outline",
guiActive = false, guiActiveEditor = true, isPersistant = true),
UI_Toggle()]
public bool outlineEnabled;
[KSPField(guiName = "#LOC_ConformalDecals_gui-outline-width", groupName = "decal-outline", groupDisplayName = "#LOC_ConformalDecals_gui-group-outline",
guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F2"),
UI_FloatRange(stepIncrement = 0.05f)]
public float outlineWidth = 0.1f;
[KSPEvent(guiName = "#LOC_ConformalDecals_gui-set-outline-color", groupName = "decal-outline", groupDisplayName = "#LOC_ConformalDecals_gui-group-outline",
guiActive = false, guiActiveEditor = true)]
public void SetOutlineColor() {
if (_outlineColorPickerController == null) {
_outlineColorPickerController = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
}
else {
_outlineColorPickerController.Close();
}
}
private TextEntryController _textEntryController;
private ColorPickerController _fillColorPickerController;
private ColorPickerController _outlineColorPickerController;
private MaterialTextureProperty _decalTextureProperty;
private MaterialKeywordProperty _fillEnabledProperty;
private MaterialColorProperty _fillColorProperty;
private MaterialKeywordProperty _outlineEnabledProperty;
private MaterialColorProperty _outlineColorProperty;
private MaterialFloatProperty _outlineWidthProperty;
private TextRenderJob _currentJob;
private DecalText _currentText;
public override void OnLoad(ConfigNode node) {
base.OnLoad(node);
string textRaw = "";
if (ParseUtil.ParseStringIndirect(ref textRaw, node, "text")) {
text = WebUtility.UrlDecode(textRaw);
}
string fontName = "";
if (ParseUtil.ParseStringIndirect(ref fontName, node, "fontName")) {
font = DecalConfig.GetFont(fontName);
}
else if (font == null) font = DecalConfig.GetFont("Calibri SDF");
int styleInt = 0;
if (ParseUtil.ParseIntIndirect(ref styleInt, node, "style")) {
style = (FontStyles) styleInt;
}
ParseUtil.ParseColor32Indirect(ref fillColor, node, "fillColor");
ParseUtil.ParseColor32Indirect(ref outlineColor, node, "outlineColor");
if (HighLogic.LoadedSceneIsGame) {
// For some reason, rendering doesnt work right on the first frame a scene is loaded
// So delay any rendering until the next frame when called in OnLoad
// This is probably a problem with Unity, not KSP
StartCoroutine(UpdateTextLate());
}
else {
UpdateText();
}
}
public override void OnSave(ConfigNode node) {
node.AddValue("text", WebUtility.UrlEncode(text));
node.AddValue("fontName", font.Name);
node.AddValue("style", (int) style);
node.AddValue("fillColor", fillColor.ToHexString());
node.AddValue("outlineColor", outlineColor.ToHexString());
base.OnSave(node);
}
public override void OnAwake() {
base.OnAwake();
_decalTextureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
_fillEnabledProperty = materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_FILL");
_fillColorProperty = materialProperties.AddOrGetProperty<MaterialColorProperty>("_DecalColor");
_outlineEnabledProperty = materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_OUTLINE");
_outlineColorProperty = materialProperties.AddOrGetProperty<MaterialColorProperty>("_OutlineColor");
_outlineWidthProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_OutlineWidth");
}
public void OnTextUpdate(string newText, DecalFont newFont, FontStyles newStyle, bool newVertical, float newLineSpacing, float newCharSpacing) {
this.text = newText;
this.font = newFont;
this.style = newStyle;
this.vertical = newVertical;
this.lineSpacing = newLineSpacing;
this.charSpacing = newCharSpacing;
UpdateTextRecursive();
}
public void OnFillColorUpdate(Color rgb, Util.ColorHSV hsv) {
fillColor = rgb;
UpdateMaterials();
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalText>();
decal.fillColor = fillColor;
decal.UpdateMaterials();
}
}
public void OnOutlineColorUpdate(Color rgb, Util.ColorHSV hsv) {
outlineColor = rgb;
UpdateMaterials();
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalText>();
decal.outlineColor = outlineColor;
decal.UpdateMaterials();
}
}
public void OnFillToggle(BaseField field, object obj) {
// fill and outline cant both be disabled
outlineEnabled = outlineEnabled || (!outlineEnabled && !fillEnabled);
UpdateTweakables();
UpdateMaterials();
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalText>();
decal.fillEnabled = fillEnabled;
decal.outlineEnabled = outlineEnabled;
decal.UpdateTweakables();
decal.UpdateMaterials();
}
}
public void OnOutlineToggle(BaseField field, object obj) {
// fill and outline cant both be disabled
fillEnabled = fillEnabled || (!fillEnabled && !outlineEnabled);
UpdateTweakables();
UpdateMaterials();
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalText>();
decal.fillEnabled = fillEnabled;
decal.outlineEnabled = outlineEnabled;
decal.UpdateTweakables();
decal.UpdateMaterials();
}
}
public void OnOutlineWidthUpdate(BaseField field, object obj) {
UpdateMaterials();
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalText>();
decal.outlineWidth = outlineWidth;
decal.UpdateMaterials();
}
}
public override void OnDestroy() {
if (HighLogic.LoadedSceneIsGame && _currentText != null) TextRenderer.UnregisterText(_currentText);
// close all UIs
if (_textEntryController != null) _textEntryController.Close();
if (_fillColorPickerController != null) _fillColorPickerController.Close();
if (_outlineColorPickerController != null) _outlineColorPickerController.Close();
base.OnDestroy();
}
protected override void OnDetach() {
// close all UIs
if (_textEntryController != null) _textEntryController.Close();
if (_fillColorPickerController != null) _fillColorPickerController.Close();
if (_outlineColorPickerController != null) _outlineColorPickerController.Close();
base.OnDetach();
}
private void UpdateTextRecursive() {
UpdateText();
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalText>();
decal.text = text;
decal.font = font;
decal.style = style;
decal.vertical = vertical;
decal.charSpacing = charSpacing;
decal.lineSpacing = lineSpacing;
decal._currentJob = _currentJob;
decal._currentText = _currentText;
decal.UpdateText();
}
}
private IEnumerator UpdateTextLate() {
yield return null;
UpdateText();
}
private void UpdateText() {
// Render text
var newText = new DecalText(text, font, style, vertical, lineSpacing, charSpacing);
var output = TextRenderer.UpdateTextNow(_currentText, newText);
_currentText = newText;
UpdateTexture(output);
// TODO: ASYNC RENDERING
// var newText = new DecalText(text, _font, _style);
// _currentJob = TextRenderer.UpdateText(_currentText, newText, UpdateTexture);
// _currentText = newText;
}
public void UpdateTexture(TextRenderOutput output) {
_decalTextureProperty.Texture = output.Texture;
_decalTextureProperty.SetTile(output.Window);
UpdateMaterials();
UpdateScale();
}
protected override void UpdateMaterials() {
_fillEnabledProperty.value = fillEnabled;
_fillColorProperty.color = fillColor;
_outlineEnabledProperty.value = outlineEnabled;
_outlineColorProperty.color = outlineColor;
_outlineWidthProperty.value = outlineWidth;
base.UpdateMaterials();
}
protected override void UpdateTweakables() {
var fillEnabledField = Fields[nameof(fillEnabled)];
var fillColorEvent = Events["SetFillColor"];
var outlineEnabledField = Fields[nameof(outlineEnabled)];
var outlineWidthField = Fields[nameof(outlineWidth)];
var outlineColorEvent = Events["SetOutlineColor"];
fillColorEvent.guiActiveEditor = fillEnabled;
outlineWidthField.guiActiveEditor = outlineEnabled;
outlineColorEvent.guiActiveEditor = outlineEnabled;
((UI_Toggle) fillEnabledField.uiControlEditor).onFieldChanged = OnFillToggle;
((UI_Toggle) outlineEnabledField.uiControlEditor).onFieldChanged = OnOutlineToggle;
((UI_FloatRange) outlineWidthField.uiControlEditor).onFieldChanged = OnOutlineWidthUpdate;
base.UpdateTweakables();
}
}
}

View File

@ -1,38 +1 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Conformal Decals")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Cineboxandrew")]
[assembly: AssemblyProduct("ConformalDecals")]
[assembly: AssemblyCopyright("Copyright © Andrew Cassidy 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1ea983f9-42e5-494e-9683-fdac9c9121f4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: KSPAssembly("ConformalDecals", 0, 1, 0)]
[assembly: KSPAssembly("ConformalDecals", 0, 2, 6)]

View File

@ -1,34 +0,0 @@
using System;
using UnityEngine;
namespace ConformalDecals.Test {
public class TestLayers : PartModule {
[KSPField(guiActive = true)]
public int layer = 2;
public override void OnStart(StartState state) {
base.OnStart(state);
Part.layerMask.value |= (1 << 3);
}
public void Update() {
foreach (var collider in GameObject.FindObjectsOfType<Collider>()) {
if (collider.gameObject.layer == 3) {
Debug.Log($"Has layer 3: {collider.gameObject.name}");
}
}
}
[KSPEvent(guiActive = true, guiActiveEditor = true, guiName = "switch layers")]
public void Switch() {
Debug.Log(Part.layerMask.value);
var cube = part.FindModelTransform("test");
layer = (layer + 1) % 32;
cube.gameObject.layer = layer;
}
}
}

View File

@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using ConformalDecals.Util;
using TMPro;
using UniLinq;
using UnityEngine;
namespace ConformalDecals.Text {
public class DecalFont : ScriptableObject, ISerializationCallbackReceiver, IEquatable<DecalFont> {
[SerializeField] private string _title;
[SerializeField] private TMP_FontAsset _fontAsset;
[SerializeField] private FontStyles _fontStyle;
[SerializeField] private FontStyles _fontStyleMask;
/// Human-readable name for the font
public string Title => _title;
/// Internal name for the font
public string Name => _fontAsset.name;
/// The font asset itself
public TMP_FontAsset FontAsset => _fontAsset;
/// Styles that are forced on for this font,
/// e.g. smallcaps for a font without lower case characters
public FontStyles FontStyle => _fontStyle;
public bool Bold => (_fontStyle & FontStyles.Bold) != 0;
public bool Italic => (_fontStyle & FontStyles.Italic) != 0;
public bool Underline => (_fontStyle & FontStyles.Underline) != 0;
public bool SmallCaps => (_fontStyle & FontStyles.SmallCaps) != 0;
/// Styles that are forced off for this font,
/// e.g. underline for a font with no underscore character
public FontStyles FontStyleMask => _fontStyleMask;
public bool BoldMask => (_fontStyleMask & FontStyles.Bold) != 0;
public bool ItalicMask => (_fontStyleMask & FontStyles.Italic) != 0;
public bool UnderlineMask => (_fontStyleMask & FontStyles.Underline) != 0;
public bool SmallCapsMask => (_fontStyleMask & FontStyles.SmallCaps) != 0;
public DecalFont(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) {
if (node == null) throw new ArgumentNullException(nameof(node));
if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets));
var name = ParseUtil.ParseString(node, "name");
_fontAsset = fontAssets.First(o => o.name == name);
if (FontAsset == null) {
throw new FormatException($"Could not find font asset named {name}");
}
_title = ParseUtil.ParseString(node, "title", true, name);
_fontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true);
_fontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true);
}
public void SetupSample(TMP_Text tmp) {
if (tmp == null) throw new ArgumentNullException(nameof(tmp));
if (FontAsset == null) throw new InvalidOperationException("DecalFont has not been initialized and Font is null.");
tmp.text = Title;
tmp.font = FontAsset;
tmp.fontStyle = FontStyle;
}
public bool Equals(DecalFont other) {
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Title == other.Title && Equals(FontAsset, other.FontAsset) && FontStyle == other.FontStyle && FontStyleMask == other.FontStyleMask;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((DecalFont) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (Title != null ? Title.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (FontAsset != null ? FontAsset.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (int) FontStyle;
hashCode = (hashCode * 397) ^ (int) FontStyleMask;
return hashCode;
}
}
public static bool operator ==(DecalFont left, DecalFont right) {
return Equals(left, right);
}
public static bool operator !=(DecalFont left, DecalFont right) {
return !Equals(left, right);
}
public void OnBeforeSerialize() { }
public void OnAfterDeserialize() { }
}
}

View File

@ -0,0 +1,90 @@
using System;
using System.Text.RegularExpressions;
using TMPro;
namespace ConformalDecals.Text {
public class DecalText : IEquatable<DecalText> {
private readonly string _text;
private readonly DecalFont _font;
private readonly FontStyles _style;
private readonly bool _vertical;
private readonly float _lineSpacing;
private readonly float _charSpacing;
/// Raw text contents
public string Text => _text;
/// Font asset used by this text snippet
public DecalFont Font => _font;
/// Style used by this text snippet
public FontStyles Style => _style;
/// If this text snippet is vertical
public bool Vertical => _vertical;
/// The text snippet's line spacing
public float LineSpacing => _lineSpacing;
/// The text snippet's character spacing
public float CharSpacing => _charSpacing;
/// The text formatted with newlines for vertical text
public string FormattedText {
get {
if (string.IsNullOrWhiteSpace(Text)) return "•";
if (Vertical) {
return Regex.Replace(Text, @"(.)", "$1\n");
}
else {
return Text;
}
}
}
public DecalText(string text, DecalFont font, FontStyles style, bool vertical, float linespacing, float charspacing) {
if (font == null) throw new ArgumentNullException(nameof(font));
_text = text;
_font = font;
_style = style;
_vertical = vertical;
_lineSpacing = linespacing;
_charSpacing = charspacing;
}
public bool Equals(DecalText other) {
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return _text == other._text && Equals(_font, other._font) && _style == other._style && _vertical == other._vertical && _lineSpacing.Equals(other._lineSpacing) &&
_charSpacing.Equals(other._charSpacing);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((DecalText) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (_text != null ? _text.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_font != null ? _font.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (int) _style;
hashCode = (hashCode * 397) ^ _vertical.GetHashCode();
hashCode = (hashCode * 397) ^ _lineSpacing.GetHashCode();
hashCode = (hashCode * 397) ^ _charSpacing.GetHashCode();
return hashCode;
}
}
public static bool operator ==(DecalText left, DecalText right) {
return Equals(left, right);
}
public static bool operator !=(DecalText left, DecalText right) {
return !Equals(left, right);
}
}
}

View File

@ -0,0 +1,38 @@
using System.IO;
using System.Collections;
using System.Collections.Generic;
using ConformalDecals.Util;
using TMPro;
using UniLinq;
using UnityEngine;
namespace ConformalDecals.Text {
/// KSP database loader for KSPFont files which contain TextMeshPro font assets
[DatabaseLoaderAttrib(new[] {"decalfont"})]
public class FontLoader : DatabaseLoader<GameDatabase.TextureInfo> {
private const string FallbackName = "NotoSans-Regular SDF";
private static TMP_FontAsset _fallbackFont;
public override IEnumerator Load(UrlDir.UrlFile urlFile, FileInfo fileInfo) {
if (_fallbackFont == null) {
_fallbackFont = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().First(o => o.name == FallbackName);
if (_fallbackFont == null) Logging.LogError($"Could not find fallback font '{FallbackName}'");
}
Logging.Log($"Loading font file '{urlFile.fullPath}'");
var bundle = AssetBundle.LoadFromFile(urlFile.fullPath);
if (!bundle) {
Logging.Log($"Could not load font asset {urlFile.fullPath}");
}
else {
var loadedFonts = bundle.LoadAllAssets<TMP_FontAsset>();
foreach (var font in loadedFonts) {
Logging.Log($"Adding font {font.name}");
font.fallbackFontAssets.Add(_fallbackFont);
}
}
yield break;
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using UnityEngine.Events;
namespace ConformalDecals.Text {
public class TextRenderJob {
public DecalText OldText { get; }
public DecalText NewText { get; }
public bool Needed { get; private set; }
public bool IsStarted { get; private set; }
public bool IsDone { get; private set; }
public readonly TextRenderer.TextRenderEvent onRenderFinished = new TextRenderer.TextRenderEvent();
public TextRenderJob(DecalText oldText, DecalText newText, UnityAction<TextRenderOutput> renderFinishedCallback) {
OldText = oldText;
NewText = newText ?? throw new ArgumentNullException(nameof(newText));
Needed = true;
if (renderFinishedCallback != null) onRenderFinished.AddListener(renderFinishedCallback);
}
public void Cancel() {
Needed = false;
}
public void Start() {
IsStarted = true;
}
public void Finish(TextRenderOutput output) {
IsDone = true;
onRenderFinished.Invoke(output);
}
}
}

View File

@ -0,0 +1,20 @@
using UnityEngine;
namespace ConformalDecals.Text {
/// Texture render output, used for cacheing and is the datastructure returned to the ModuleConformalText class
public class TextRenderOutput {
/// Texture with the rendered text
public Texture2D Texture { get; private set; }
/// The rectangle that the rendered text takes up within the texture
public Rect Window { get; private set; }
/// The number of users for this render output. If 0, it can be discarded from the cache and the texture reused
public int UserCount { get; set; }
public TextRenderOutput(Texture2D texture, Rect window) {
Texture = texture;
Window = window;
}
}
}

View File

@ -0,0 +1,298 @@
using System;
using System.Collections.Generic;
using ConformalDecals.Util;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
namespace ConformalDecals.Text {
// TODO: Testing shows the job system is unnecessary, so remove job system code.
/// Class handing text rendering.
/// Is a singleton referencing a single gameobject in the scene which contains the TextMeshPro component
[KSPAddon(KSPAddon.Startup.Instantly, true)]
public class TextRenderer : MonoBehaviour {
/// Texture format used for returned textures.
/// Unfortunately due to how Unity textures work, this cannot be R8 or Alpha8,
/// so theres always a superfluous green channel using memory
public static TextureFormat textTextureFormat = TextureFormat.RG16;
/// Render Texture format used when rendering
/// Overriden below to be ARGB32 on DirectX because DirectX is dumb
public static RenderTextureFormat textRenderTextureFormat = RenderTextureFormat.R8;
/// The text renderer object within the scene which contains the TextMeshPro component used for rendering.
public static TextRenderer Instance {
get {
if (!_instance._isSetup) {
_instance.Setup();
}
return _instance;
}
}
/// Text Render unityevent, used with the job system to signal render completion
[Serializable]
public class TextRenderEvent : UnityEvent<TextRenderOutput> { }
private const string ShaderName = "ConformalDecals/Text Blit";
private const int MaxTextureSize = 4096;
private const float FontSize = 100;
private const float PixelDensity = 5;
private static TextRenderer _instance;
private bool _isSetup;
private TextMeshPro _tmp;
private Shader _blitShader;
private static readonly Dictionary<DecalText, TextRenderOutput> RenderCache = new Dictionary<DecalText, TextRenderOutput>();
private static readonly Queue<TextRenderJob> RenderJobs = new Queue<TextRenderJob>();
/// Update text using the job queue
public static TextRenderJob UpdateText(DecalText oldText, DecalText newText, UnityAction<TextRenderOutput> renderFinishedCallback) {
if (newText == null) throw new ArgumentNullException(nameof(newText));
var job = new TextRenderJob(oldText, newText, renderFinishedCallback);
RenderJobs.Enqueue(job);
return job;
}
/// Update text immediately without using job queue
public static TextRenderOutput UpdateTextNow(DecalText oldText, DecalText newText) {
if (newText == null) throw new ArgumentNullException(nameof(newText));
return Instance.RunJob(new TextRenderJob(oldText, newText, null), out _);
}
/// Unregister a user of a piece of text
public static void UnregisterText(DecalText text) {
if (RenderCache.TryGetValue(text, out var renderedText)) {
renderedText.UserCount--;
if (renderedText.UserCount <= 0) {
RenderCache.Remove(text);
Destroy(renderedText.Texture);
}
}
}
private void Start() {
if (_instance != null) {
Logging.LogError("Duplicate TextRenderer created???");
}
Logging.Log("Creating TextRenderer Object");
_instance = this;
DontDestroyOnLoad(gameObject);
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12) {
textRenderTextureFormat = RenderTextureFormat.ARGB32; // DirectX is dumb
}
if (!SystemInfo.SupportsTextureFormat(textTextureFormat)) {
Logging.LogError($"Text texture format {textTextureFormat} not supported on this platform.");
}
if (!SystemInfo.SupportsRenderTextureFormat(textRenderTextureFormat)) {
Logging.LogError($"Text texture format {textRenderTextureFormat} not supported on this platform.");
}
}
/// Setup this text renderer instance for rendering
private void Setup() {
if (_isSetup) return;
Logging.Log("Setting Up TextRenderer Object");
_tmp = gameObject.AddComponent<TextMeshPro>();
_tmp.renderer.enabled = false; // dont automatically render
_blitShader = Shabby.Shabby.FindShader(ShaderName);
if (_blitShader == null) Logging.LogError($"Could not find text blit shader named '{ShaderName}'");
_isSetup = true;
}
/// Run a text render job
private TextRenderOutput RunJob(TextRenderJob job, out bool renderNeeded) {
if (!job.Needed) {
renderNeeded = false;
return null;
}
job.Start();
Texture2D texture = null;
if (job.OldText != null && RenderCache.TryGetValue(job.OldText, out var oldRender)) {
// old output still exists
oldRender.UserCount--;
if (oldRender.UserCount <= 0) {
// this is the only usage of this output, so we are free to re-render into the texture
texture = oldRender.Texture;
RenderCache.Remove(job.OldText);
}
}
// now that all old references are handled, begin rendering the new output
if (RenderCache.TryGetValue(job.NewText, out var renderOutput)) {
renderNeeded = false;
}
else {
renderNeeded = true;
renderOutput = RenderText(job.NewText, texture);
RenderCache.Add(job.NewText, renderOutput);
}
renderOutput.UserCount++;
job.Finish(renderOutput);
return renderOutput;
}
/// Render a piece of text to a given texture
public TextRenderOutput RenderText(DecalText text, Texture2D texture) {
if (text == null) throw new ArgumentNullException(nameof(text));
if (_tmp == null) throw new InvalidOperationException("TextMeshPro object not yet created.");
// SETUP TMP OBJECT FOR RENDERING
_tmp.text = text.FormattedText;
_tmp.font = text.Font.FontAsset;
_tmp.fontStyle = text.Style | text.Font.FontStyle;
_tmp.lineSpacing = text.LineSpacing;
_tmp.characterSpacing = text.CharSpacing;
_tmp.extraPadding = true;
_tmp.enableKerning = true;
_tmp.enableWordWrapping = false;
_tmp.overflowMode = TextOverflowModes.Overflow;
_tmp.alignment = TextAlignmentOptions.Center;
_tmp.fontSize = FontSize;
// GENERATE MESH
_tmp.ClearMesh(false);
_tmp.ForceMeshUpdate();
var meshFilters = gameObject.GetComponentsInChildren<MeshFilter>();
var meshes = new Mesh[meshFilters.Length];
var materials = new Material[meshFilters.Length];
var bounds = new Bounds();
// SETUP MATERIALS AND BOUNDS
for (int i = 0; i < meshFilters.Length; i++) {
var renderer = meshFilters[i].gameObject.GetComponent<MeshRenderer>();
meshes[i] = meshFilters[i].mesh;
if (i == 0) meshes[i] = _tmp.mesh;
materials[i] = Instantiate(renderer.material);
materials[i].shader = _blitShader;
if (renderer == null) throw new FormatException($"Object {meshFilters[i].gameObject.name} has filter but no renderer");
if (meshes[i] == null) throw new FormatException($"Object {meshFilters[i].gameObject.name} has a null mesh");
if (i == 0) {
bounds = meshes[i].bounds;
}
else {
bounds.Encapsulate(meshes[i].bounds);
}
}
// CALCULATE SIZES
var size = bounds.size * PixelDensity;
size.x = Mathf.Max(size.x, 0.1f);
size.y = Mathf.Max(size.y, 0.1f);
var textureSize = new Vector2Int {
x = Mathf.NextPowerOfTwo((int) size.x),
y = Mathf.NextPowerOfTwo((int) size.y)
};
if (textureSize.x == 0 || textureSize.y == 0) {
Logging.LogWarning("No text present or error in texture size calculation. Aborting.");
return new TextRenderOutput(Texture2D.blackTexture, Rect.zero);
}
// make sure texture isnt too big, scale it down if it is
// this is just so you dont crash the game by pasting in the entire script of The Bee Movie
if (textureSize.x > MaxTextureSize) {
textureSize.y /= textureSize.x / MaxTextureSize;
textureSize.x = MaxTextureSize;
}
if (textureSize.y > MaxTextureSize) {
textureSize.x /= textureSize.y / MaxTextureSize;
textureSize.y = MaxTextureSize;
}
// scale up everything to fit the texture for maximum usage
float sizeRatio = Mathf.Min(textureSize.x / size.x, textureSize.y / size.y);
// calculate where in the texture the used area actually is
var window = new Rect {
size = size * sizeRatio,
center = (Vector2) textureSize / 2
};
// SETUP TEXTURE
if (texture == null) {
texture = new Texture2D(textureSize.x, textureSize.y, textTextureFormat, true);
}
else if (texture.width != textureSize.x || texture.height != textureSize.y || texture.format != textTextureFormat) {
texture.Resize(textureSize.x, textureSize.y, textTextureFormat, true);
}
// GENERATE PROJECTION MATRIX
var halfSize = (Vector2) textureSize / PixelDensity / 2 / sizeRatio;
var matrix = Matrix4x4.Ortho(bounds.center.x - halfSize.x, bounds.center.x + halfSize.x,
bounds.center.y - halfSize.y, bounds.center.y + halfSize.y, -1, 1);
// GET RENDERTEX
var renderTex = new RenderTexture(textureSize.x, textureSize.y, 0, textRenderTextureFormat, RenderTextureReadWrite.Linear) {autoGenerateMips = false};
// RENDER
Graphics.SetRenderTarget(renderTex);
GL.PushMatrix();
GL.LoadProjectionMatrix(matrix);
GL.LoadIdentity();
GL.Clear(false, true, Color.black);
for (var i = 0; i < meshes.Length; i++) {
if (meshes[i].vertexCount >= 3) {
materials[i].SetPass(0);
Graphics.DrawMeshNow(meshes[i], Matrix4x4.identity);
}
}
// COPY TEXTURE BACK INTO RAM
var prevRT = RenderTexture.active;
RenderTexture.active = renderTex;
texture.ReadPixels(new Rect(0, 0, textureSize.x, textureSize.y), 0, 0, true);
texture.Apply();
RenderTexture.active = prevRT;
GL.PopMatrix();
// RELEASE RENDERTEX
renderTex.Release();
RenderTexture.Destroy(renderTex);
// CLEAR SUBMESHES
_tmp.text = "";
for (int i = 0; i < transform.childCount; i++) {
var child = transform.GetChild(i);
Destroy(child.gameObject);
}
return new TextRenderOutput(texture, window);
}
}
}

View File

@ -0,0 +1,176 @@
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace ConformalDecals.UI {
[AddComponentMenu("UI/BoxSlider", 35)]
[RequireComponent(typeof(RectTransform))]
public class BoxSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement {
[Serializable]
public class BoxSliderEvent : UnityEvent<Vector2> { }
[SerializeField] private RectTransform _handleRect;
[SerializeField] private Vector2 _value = Vector2.zero;
public RectTransform HandleRect {
get => _handleRect;
set {
if (value == null) throw new ArgumentNullException(nameof(value));
if (value != _handleRect) {
_handleRect = value;
UpdateCachedReferences();
UpdateVisuals();
}
}
}
public Vector2 Value {
get => _value;
set {
_value = value;
_onValueChanged.Invoke(value);
UpdateVisuals();
}
}
[Space(6)]
// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
[SerializeField]
private BoxSliderEvent _onValueChanged = new BoxSliderEvent();
public BoxSliderEvent OnValueChanged {
get => _onValueChanged;
set => _onValueChanged = value;
}
// Private fields
private Transform _handleTransform;
private RectTransform _handleContainerRect;
// The offset from handle position to mouse down position
private Vector2 _offset = Vector2.zero;
#if UNITY_EDITOR
protected override void OnValidate() {
base.OnValidate();
//Onvalidate is called before OnEnabled. We need to make sure not to touch any other objects before OnEnable is run.
if (IsActive()) {
UpdateCachedReferences();
// Update rects since other things might affect them even if value didn't change.
UpdateVisuals();
}
#if UNITY_2018_3_OR_NEWER
if (!UnityEditor.PrefabUtility.IsPartOfPrefabAsset(this) && !Application.isPlaying)
CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this);
#else
var prefabType = UnityEditor.PrefabUtility.GetPrefabType(this);
if (prefabType != UnityEditor.PrefabType.Prefab && !Application.isPlaying)
CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this);
#endif
}
#endif // if UNITY_EDITOR
public virtual void Rebuild(CanvasUpdate executing) {
#if UNITY_EDITOR
if (executing == CanvasUpdate.Prelayout)
OnValueChanged.Invoke(Value);
#endif
}
public void LayoutComplete() { }
public void GraphicUpdateComplete() { }
protected override void OnEnable() {
base.OnEnable();
UpdateCachedReferences();
// Update rects since they need to be initialized correctly.
UpdateVisuals();
}
private void UpdateCachedReferences() {
if (_handleRect) {
_handleTransform = _handleRect.transform;
if (_handleTransform.parent != null)
_handleContainerRect = _handleTransform.parent.GetComponent<RectTransform>();
}
else {
_handleContainerRect = null;
}
}
protected override void OnRectTransformDimensionsChange() {
base.OnRectTransformDimensionsChange();
UpdateVisuals();
}
// Force-update the slider. Useful if you've changed the properties and want it to update visually.
private void UpdateVisuals() {
if (_handleContainerRect != null) {
_handleRect.anchorMin = _value;
_handleRect.anchorMax = _value;
}
}
// Update the slider's position based on the mouse.
private void UpdateDrag(PointerEventData eventData, Camera cam) {
var clickRect = _handleContainerRect;
if (clickRect != null && clickRect.rect.size[0] > 0) {
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, out var localCursor))
return;
var rect = clickRect.rect;
localCursor -= rect.position;
Vector2 newVal;
newVal.x = Mathf.Clamp01((localCursor - _offset).x / rect.size.x);
newVal.y = Mathf.Clamp01((localCursor - _offset).y / rect.size.y);
Value = newVal;
}
}
private bool MayDrag(PointerEventData eventData) {
return IsActive() && IsInteractable() && eventData.button == PointerEventData.InputButton.Left;
}
public override void OnPointerDown(PointerEventData eventData) {
if (!MayDrag(eventData))
return;
base.OnPointerDown(eventData);
_offset = Vector2.zero;
if (_handleContainerRect != null && RectTransformUtility.RectangleContainsScreenPoint(_handleRect, eventData.position, eventData.enterEventCamera)) {
Vector2 localMousePos;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(_handleRect, eventData.position, eventData.pressEventCamera, out localMousePos))
_offset = localMousePos;
_offset.y = -_offset.y;
}
else {
// Outside the slider handle - jump to this point instead
UpdateDrag(eventData, eventData.pressEventCamera);
}
}
public virtual void OnDrag(PointerEventData eventData) {
if (!MayDrag(eventData))
return;
UpdateDrag(eventData, eventData.pressEventCamera);
}
public virtual void OnInitializePotentialDrag(PointerEventData eventData) {
eventData.useDragThreshold = false;
}
}
}

View File

@ -0,0 +1,63 @@
using UnityEngine;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class ColorBoxSlider : MonoBehaviour {
[SerializeField] public ColorPickerController.SVUpdateEvent onValueChanged = new ColorPickerController.SVUpdateEvent();
[SerializeField] private Vector2 _value;
[SerializeField] private BoxSlider _slider;
[SerializeField] private Image _image;
private bool _ignoreUpdates;
public Vector2 Value {
get => _value;
set {
_value.x = Mathf.Clamp01(value.x);
_value.y = Mathf.Clamp01(value.y);
UpdateSlider();
UpdateChannels();
}
}
public void OnColorUpdate(Color rgb, Util.ColorHSV hsv) {
if (_ignoreUpdates) return;
_image.material.SetColor(PropertyIDs._Color, (Vector4) hsv);
_value.x = hsv.s;
_value.y = hsv.v;
UpdateSlider();
}
public void OnSliderUpdate(Vector2 value) {
if (_ignoreUpdates) return;
_value = value;
UpdateChannels();
}
private void Awake() {
var boxSlider = gameObject.GetComponentInChildren<BoxSlider>();
boxSlider.OnValueChanged.AddListener(OnSliderUpdate);
}
private void UpdateChannels() {
_ignoreUpdates = true;
onValueChanged.Invoke(_value);
_ignoreUpdates = false;
}
private void UpdateSlider() {
_ignoreUpdates = true;
_slider.Value = _value;
_ignoreUpdates = false;
}
}
}

View File

@ -0,0 +1,79 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class ColorChannelSlider : MonoBehaviour {
[SerializeField] public ColorPickerController.ChannelUpdateEvent onChannelChanged = new ColorPickerController.ChannelUpdateEvent();
[SerializeField] private float _value;
[SerializeField] private int _channel;
[SerializeField] private bool _hsv;
[SerializeField] private Selectable _textBox;
[SerializeField] private Slider _slider;
[SerializeField] private Image _image;
private bool _ignoreUpdates;
public float Value {
get => _value;
set {
_value = Mathf.Clamp01(value);
UpdateSlider();
UpdateTextbox();
UpdateChannel();
}
}
public void OnColorUpdate(Color rgb, Util.ColorHSV hsv) {
if (_ignoreUpdates) return;
_image.material.SetColor(PropertyIDs._Color, _hsv ? (Color) (Vector4) hsv : rgb);
_value = _hsv ? hsv[_channel] : rgb[_channel];
UpdateSlider();
UpdateTextbox();
}
public void OnTextBoxUpdate(string text) {
if (_ignoreUpdates) return;
if (byte.TryParse(text, out byte byteValue)) {
_value = (float) byteValue / 255;
UpdateSlider();
UpdateChannel();
}
else {
// value is invalid, reset value
UpdateTextbox();
}
}
public void OnSliderUpdate(float value) {
if (_ignoreUpdates) return;
_value = value;
UpdateTextbox();
UpdateChannel();
}
private void UpdateChannel() {
onChannelChanged.Invoke(_value, _channel, _hsv);
}
private void UpdateSlider() {
_ignoreUpdates = true;
_slider.value = _value;
_ignoreUpdates = false;
}
private void UpdateTextbox() {
if (_textBox == null) return;
_ignoreUpdates = true;
((TMP_InputField) _textBox).text = ((byte) (255 * _value)).ToString();
_ignoreUpdates = false;
}
}
}

View File

@ -0,0 +1,117 @@
using System;
using ConformalDecals.Util;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class ColorPickerController : MonoBehaviour {
[Serializable]
public class ColorUpdateEvent : UnityEvent<Color, Util.ColorHSV> { }
[Serializable]
public class ChannelUpdateEvent : UnityEvent<float, int, bool> { }
[Serializable]
public class SVUpdateEvent : UnityEvent<Vector2> { }
[SerializeField] public ColorUpdateEvent onColorChanged = new ColorUpdateEvent();
[SerializeField] private Color _value;
[SerializeField] private Image _previewImage;
[SerializeField] private Selectable _hexTextBox;
private bool _ignoreUpdate;
public Color RGB {
get => _value;
set {
_value = value;
OnColorUpdate();
}
}
public Util.ColorHSV HSV {
get => Util.ColorHSV.RGB2HSV(_value);
set {
_value = Util.ColorHSV.HSV2RGB(value);
OnColorUpdate();
}
}
public static ColorPickerController Create(Color rgb, UnityAction<Color, Util.ColorHSV> colorUpdateCallback) {
var menu = Instantiate(UILoader.ColorPickerPrefab, MainCanvasUtil.MainCanvas.transform, true);
menu.AddComponent<DragPanel>();
MenuNavigation.SpawnMenuNavigation(menu, Navigation.Mode.Automatic, true);
var controller = menu.GetComponent<ColorPickerController>();
controller.RGB = rgb;
controller.onColorChanged.AddListener(colorUpdateCallback);
return controller;
}
public void Close() {
Destroy(gameObject);
}
public void OnChannelUpdate(float value, int channel, bool hsv) {
if (hsv) {
var newHSV = HSV;
newHSV[channel] = value;
HSV = newHSV;
}
else {
var newRGB = RGB;
newRGB[channel] = value;
RGB = newRGB;
}
}
public void OnSVUpdate(Vector2 sv) {
var newHSV = HSV;
newHSV.s = sv.x;
newHSV.v = sv.y;
HSV = newHSV;
}
public void OnColorUpdate() {
onColorChanged.Invoke(RGB, HSV);
_previewImage.material.SetColor(PropertyIDs._Color, RGB);
UpdateHexColor();
}
public void OnHexColorUpdate(string text) {
if (_ignoreUpdate) return;
if (ParseUtil.TryParseHexColor(text, out var newRGB)) {
RGB = newRGB;
OnColorUpdate();
}
else {
UpdateHexColor();
}
}
private void Awake() {
foreach (var slider in gameObject.GetComponentsInChildren<ColorChannelSlider>()) {
slider.onChannelChanged.AddListener(OnChannelUpdate);
onColorChanged.AddListener(slider.OnColorUpdate);
}
foreach (var box in gameObject.GetComponentsInChildren<ColorBoxSlider>()) {
box.onValueChanged.AddListener(OnSVUpdate);
onColorChanged.AddListener(box.OnColorUpdate);
}
}
private void UpdateHexColor() {
_ignoreUpdate = true;
var byteColor = (Color32) RGB;
var hexColor = $"{byteColor.r:x2}{byteColor.g:x2}{byteColor.b:x2}";
((TMP_InputField) _hexTextBox).text = hexColor;
_ignoreUpdate = false;
}
}
}

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using ConformalDecals.Text;
using UniLinq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class FontMenuController : MonoBehaviour {
[Serializable]
public class FontUpdateEvent : UnityEvent<DecalFont> { }
[SerializeField] public FontUpdateEvent onFontChanged = new FontUpdateEvent();
[SerializeField] private GameObject _menuItem;
[SerializeField] private GameObject _menuList;
private DecalFont _currentFont;
public static FontMenuController Create(IEnumerable<DecalFont> fonts, DecalFont currentFont, UnityAction<DecalFont> fontUpdateCallback) {
var menu = Instantiate(UILoader.FontMenuPrefab, MainCanvasUtil.MainCanvas.transform, true);
menu.AddComponent<DragPanel>();
MenuNavigation.SpawnMenuNavigation(menu, Navigation.Mode.Automatic, true);
var controller = menu.GetComponent<FontMenuController>();
controller._currentFont = currentFont;
controller.onFontChanged.AddListener(fontUpdateCallback);
controller.Populate(fonts);
return controller;
}
public void Close() {
Destroy(gameObject);
}
public void OnFontSelected(DecalFont font) {
_currentFont = font ?? throw new ArgumentNullException(nameof(font));
onFontChanged.Invoke(_currentFont);
}
public void Populate(IEnumerable<DecalFont> fonts) {
if (fonts == null) throw new ArgumentNullException(nameof(fonts));
Toggle active = null;
foreach (var font in fonts.OrderBy(x => x.Title)) {
var listItem = GameObject.Instantiate(_menuItem, _menuList.transform);
listItem.name = font.Title;
listItem.SetActive(true);
var fontItem = listItem.AddComponent<FontMenuItem>();
fontItem.Font = font;
fontItem.fontSelectionCallback = OnFontSelected;
if (font == _currentFont) active = fontItem.toggle;
}
if (active != null) active.isOn = true;
}
}
}

View File

@ -0,0 +1,36 @@
using System;
using ConformalDecals.Text;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class FontMenuItem : MonoBehaviour {
public DecalFont Font {
get => _font;
set {
_font = value;
_font.SetupSample(_label);
}
}
public delegate void FontSelectionReceiver(DecalFont font);
public FontSelectionReceiver fontSelectionCallback;
public Toggle toggle;
private DecalFont _font;
private TMP_Text _label;
private void Awake() {
_label = gameObject.GetComponentInChildren<TextMeshProUGUI>();
toggle = gameObject.GetComponent<Toggle>();
toggle.isOn = false;
toggle.onValueChanged.AddListener(delegate { OnToggle(toggle); });
}
public void OnToggle(Toggle change) {
if (change.isOn) fontSelectionCallback?.Invoke(_font);
}
}
}

View File

@ -0,0 +1,315 @@
using System;
using ConformalDecals.Text;
using ConformalDecals.Util;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class TextEntryController : MonoBehaviour {
[Serializable]
public delegate void TextUpdateDelegate(string newText, DecalFont newFont, FontStyles style, bool vertical, float linespacing, float charspacing);
[SerializeField] private Selectable _textBox;
[SerializeField] private Button _fontButton;
[SerializeField] private Slider _lineSpacingSlider;
[SerializeField] private Selectable _lineSpacingTextBox;
[SerializeField] private Slider _charSpacingSlider;
[SerializeField] private Selectable _charSpacingTextBox;
[SerializeField] private Toggle _boldButton;
[SerializeField] private Toggle _italicButton;
[SerializeField] private Toggle _underlineButton;
[SerializeField] private Toggle _smallCapsButton;
[SerializeField] private Toggle _verticalButton;
private string _text;
private DecalFont _font;
private FontStyles _style;
private bool _vertical;
private float _lineSpacing;
private float _charSpacing;
private Vector2 _lineSpacingRange;
private Vector2 _charSpacingRange;
private TMP_InputField _textBoxTMP;
private TextUpdateDelegate _onValueChanged;
private FontMenuController _fontMenu;
private bool _ignoreUpdates;
private bool _isLocked;
private string _lockString;
private static int _lockCounter;
public static TextEntryController Create(
string text, DecalFont font, FontStyles style, bool vertical, float linespacing, float charspacing,
Vector2 lineSpacingRange, Vector2 charSpacingRange,
TextUpdateDelegate textUpdateCallback) {
var window = Instantiate(UILoader.TextEntryPrefab, MainCanvasUtil.MainCanvas.transform, true);
window.AddComponent<DragPanel>();
MenuNavigation.SpawnMenuNavigation(window, Navigation.Mode.Automatic, true);
var controller = window.GetComponent<TextEntryController>();
controller._text = text;
controller._font = font;
controller._style = style;
controller._vertical = vertical;
controller._lineSpacing = linespacing;
controller._charSpacing = charspacing;
controller._lineSpacingRange = lineSpacingRange;
controller._charSpacingRange = charSpacingRange;
controller._onValueChanged = textUpdateCallback;
return controller;
}
public void Close() {
if (_fontMenu != null) _fontMenu.Close();
Destroy(gameObject);
}
public void SetControlLock(string value = null) {
if (_isLocked) return;
InputLockManager.SetControlLock(_lockString);
_isLocked = true;
}
public void RemoveControlLock(string value = null) {
if (!_isLocked) return;
InputLockManager.RemoveControlLock(_lockString);
_isLocked = false;
}
public void OnTextUpdate(string newText) {
this._text = newText;
OnValueChanged();
}
public void OnFontMenu() {
if (_fontMenu == null) _fontMenu = FontMenuController.Create(DecalConfig.Fonts, _font, OnFontUpdate);
}
public void OnFontUpdate(DecalFont font) {
if (_ignoreUpdates) return;
_font = font;
font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
_textBoxTMP.text = _text;
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
_textBoxTMP.fontAsset = _font.FontAsset;
UpdateStyleButtons();
OnValueChanged();
}
public void OnLineSpacingUpdate(float value) {
if (_ignoreUpdates) return;
_lineSpacing = Mathf.Lerp(_lineSpacingRange.x, _lineSpacingRange.y, value);
UpdateLineSpacing();
OnValueChanged();
}
public void OnLineSpacingUpdate(string text) {
if (_ignoreUpdates) return;
if (float.TryParse(text, out var value)) {
_lineSpacing = Mathf.Clamp(value, _lineSpacingRange.x, _lineSpacingRange.y);
}
else {
Logging.LogWarning("Line spacing value '{text}' could not be parsed.");
}
UpdateLineSpacing();
OnValueChanged();
}
public void OnCharSpacingUpdate(float value) {
if (_ignoreUpdates) return;
_charSpacing = Mathf.Lerp(_charSpacingRange.x, _charSpacingRange.y, value);
UpdateCharSpacing();
OnValueChanged();
}
public void OnCharSpacingUpdate(string text) {
if (_ignoreUpdates) return;
if (float.TryParse(text, out var value)) {
_charSpacing = Mathf.Clamp(value, _charSpacingRange.x, _charSpacingRange.y);
}
else {
Logging.LogWarning("Char spacing value '{text}' could not be parsed.");
}
UpdateCharSpacing();
OnValueChanged();
}
public void OnBoldUpdate(bool state) {
if (_ignoreUpdates) return;
if (state)
_style |= FontStyles.Bold;
else
_style &= ~FontStyles.Bold;
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
OnValueChanged();
}
public void OnItalicUpdate(bool state) {
if (_ignoreUpdates) return;
if (state)
_style |= FontStyles.Italic;
else
_style &= ~FontStyles.Italic;
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
OnValueChanged();
}
public void OnUnderlineUpdate(bool state) {
if (_ignoreUpdates) return;
if (state)
_style |= FontStyles.Underline;
else
_style &= ~FontStyles.Underline;
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
OnValueChanged();
}
public void OnSmallCapsUpdate(bool state) {
if (_ignoreUpdates) return;
if (state)
_style |= FontStyles.SmallCaps;
else
_style &= ~FontStyles.SmallCaps;
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
OnValueChanged();
}
public void OnVerticalUpdate(bool state) {
if (_ignoreUpdates) return;
_vertical = state;
OnValueChanged();
}
private void Start() {
_lockString = $"ConformalDecals_TextEditor_{_lockCounter++}";
_textBoxTMP = ((TMP_InputField) _textBox);
_textBoxTMP.text = _text;
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
_textBoxTMP.fontAsset = _font.FontAsset;
_textBoxTMP.onSelect.AddListener(SetControlLock);
_textBoxTMP.onDeselect.AddListener(RemoveControlLock);
_font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
UpdateStyleButtons();
UpdateLineSpacing();
UpdateCharSpacing();
}
private void OnDestroy() {
RemoveControlLock();
}
private void OnValueChanged() {
_onValueChanged(_text, _font, _style, _vertical, _lineSpacing, _charSpacing);
}
private void UpdateStyleButtons() {
_ignoreUpdates = true;
if (_font.Bold) {
_boldButton.interactable = false;
_boldButton.isOn = true;
}
else if (_font.BoldMask) {
_boldButton.interactable = false;
_boldButton.isOn = false;
}
else {
_boldButton.interactable = true;
_boldButton.isOn = (_style & FontStyles.Bold) != 0;
}
if (_font.Italic) {
_italicButton.interactable = false;
_italicButton.isOn = true;
}
else if (_font.ItalicMask) {
_italicButton.interactable = false;
_italicButton.isOn = false;
}
else {
_italicButton.interactable = true;
_italicButton.isOn = (_style & FontStyles.Italic) != 0;
}
if (_font.Underline) {
_underlineButton.interactable = false;
_underlineButton.isOn = true;
}
else if (_font.UnderlineMask) {
_underlineButton.interactable = false;
_underlineButton.isOn = false;
}
else {
_underlineButton.interactable = true;
_underlineButton.isOn = (_style & FontStyles.Underline) != 0;
}
if (_font.SmallCaps) {
_smallCapsButton.interactable = false;
_smallCapsButton.isOn = true;
}
else if (_font.SmallCapsMask) {
_smallCapsButton.interactable = false;
_smallCapsButton.isOn = false;
}
else {
_smallCapsButton.interactable = true;
_smallCapsButton.isOn = (_style & FontStyles.SmallCaps) != 0;
}
_verticalButton.isOn = _vertical;
_ignoreUpdates = false;
}
private void UpdateLineSpacing() {
_ignoreUpdates = true;
_lineSpacingSlider.value = Mathf.InverseLerp(_lineSpacingRange.x, _lineSpacingRange.y, _lineSpacing);
((TMP_InputField) _lineSpacingTextBox).text = $"{_lineSpacing:F1}";
_ignoreUpdates = false;
}
private void UpdateCharSpacing() {
_ignoreUpdates = true;
_charSpacingSlider.value = Mathf.InverseLerp(_charSpacingRange.x, _charSpacingRange.y, _charSpacing);
((TMP_InputField) _charSpacingTextBox).text = $"{_charSpacing:F1}";
_ignoreUpdates = false;
}
}
}

View File

@ -0,0 +1,140 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace ConformalDecals.UI {
[KSPAddon(KSPAddon.Startup.Instantly, true)]
public class UILoader : MonoBehaviour {
private static string _path;
private static GameObject _textEntryPrefab;
private static GameObject _fontMenuPrefab;
private static GameObject _colorPickerPrefab;
public static GameObject FontMenuPrefab => _fontMenuPrefab;
public static GameObject TextEntryPrefab => _textEntryPrefab;
public static GameObject ColorPickerPrefab => _colorPickerPrefab;
private void Awake() {
_path = KSPUtil.ApplicationRootPath + "GameData/ConformalDecals/Resources/";
var prefabs = AssetBundle.LoadFromFile(_path + "ui.conformaldecals");
_textEntryPrefab = prefabs.LoadAsset("TextEntryPanel") as GameObject;
_fontMenuPrefab = prefabs.LoadAsset("FontMenuPanel") as GameObject;
_colorPickerPrefab = prefabs.LoadAsset("ColorPickerPanel") as GameObject;
ProcessWindow(_textEntryPrefab);
ProcessWindow(_fontMenuPrefab);
ProcessWindow(_colorPickerPrefab);
}
private static void ProcessWindow(GameObject window) {
var skin = UISkinManager.defaultSkin;
var font = UISkinManager.TMPFont;
var background = window.GetComponent<Image>();
background.sprite = skin.window.normal.background;
background.type = Image.Type.Sliced;
var texts = window.GetComponentsInChildren<TextMeshProUGUI>(true);
foreach (var text in texts) {
ProcessText(text, font, Color.white);
}
var tags = window.GetComponentsInChildren<UITag>(true);
foreach (var tag in tags) {
switch (tag.type) {
case UITag.UIType.Window:
ProcessImage(tag.gameObject, skin.window);
break;
case UITag.UIType.Button:
ProcessSelectable(tag.gameObject, skin.button);
break;
case UITag.UIType.ButtonToggle:
ProcessToggleButton(tag.gameObject, skin.button);
break;
case UITag.UIType.RadioToggle:
ProcessSelectable(tag.gameObject, skin.toggle);
break;
case UITag.UIType.BoxSlider:
case UITag.UIType.Slider:
ProcessSlider(tag.gameObject, skin.horizontalSlider, skin.horizontalSliderThumb);
break;
case UITag.UIType.Box:
ProcessSelectable(tag.gameObject, skin.box);
break;
case UITag.UIType.Dropdown:
ProcessDropdown(tag.gameObject, skin.button, skin.window);
break;
case UITag.UIType.Label:
ProcessText(tag.GetComponent<TextMeshProUGUI>(), font, new Color(0.718f, 0.996f, 0.000f, 1.000f), 14);
break;
case UITag.UIType.Header:
ProcessText(tag.GetComponent<TextMeshProUGUI>(), font, new Color(0.718f, 0.996f, 0.000f, 1.000f), 16);
break;
}
}
}
private static void ProcessImage(GameObject gameObject, UIStyle style) {
var image = gameObject.GetComponent<Image>();
if (image != null) {
ProcessImage(image, style.normal);
}
}
private static void ProcessImage(Image image, UIStyleState state) {
image.sprite = state.background;
image.color = Color.white;
image.type = Image.Type.Sliced;
}
private static void ProcessSelectable(GameObject gameObject, UIStyle style) {
var selectable = gameObject.GetComponent<Selectable>();
if (selectable == null) {
ProcessImage(gameObject, style);
}
else {
ProcessImage(selectable.image, style.normal);
selectable.transition = Selectable.Transition.SpriteSwap;
var state = selectable.spriteState;
state.highlightedSprite = style.highlight.background;
state.selectedSprite = style.highlight.background;
state.pressedSprite = style.active.background;
state.disabledSprite = style.disabled.background;
selectable.spriteState = state;
}
}
private static void ProcessToggleButton(GameObject gameObject, UIStyle style) {
ProcessSelectable(gameObject, style);
var toggle = gameObject.GetComponent<Toggle>();
if (toggle != null) ProcessImage(toggle.graphic as Image, style.active);
}
private static void ProcessSlider(GameObject gameObject, UIStyle backgroundStyle, UIStyle thumbStyle) {
ProcessSelectable(gameObject, thumbStyle);
var background = gameObject.transform.Find("Background");
if (background != null) ProcessImage(background.gameObject, backgroundStyle);
}
private static void ProcessDropdown(GameObject gameObject, UIStyle buttonStyle, UIStyle windowStyle) {
ProcessSelectable(gameObject, buttonStyle);
var template = gameObject.transform.Find("Template").gameObject;
if (template != null) ProcessImage(template, windowStyle);
}
private static void ProcessText(TextMeshProUGUI text, TMP_FontAsset font, Color color, int size = -1) {
text.font = font;
text.color = color;
if (size > 0) text.fontSize = size;
}
}
}

View File

@ -0,0 +1,21 @@
using UnityEngine;
namespace ConformalDecals.UI {
public class UITag : MonoBehaviour {
public enum UIType {
None,
Window,
Box,
Button,
ButtonToggle,
RadioToggle,
Slider,
Dropdown,
Label,
Header,
BoxSlider
}
[SerializeField] public UIType type = UIType.None;
}
}

View File

@ -0,0 +1,161 @@
using System;
using System.Globalization;
using UnityEngine;
namespace ConformalDecals.Util {
public struct ColorHSL : IEquatable<Color> {
public float h;
public float s;
public float l;
public float a;
public ColorHSL(float h, float s = 1, float l = 0.5f, float a = 1) {
this.h = h;
this.s = s;
this.l = l;
this.a = a;
}
public override string ToString() {
return $"HSLA({this.h:F3}, {this.s:F3}, {this.l:F3}, {this.a:F3})";
}
public string ToString(string format) {
return
"HSLA(" +
$"{this.h.ToString(format, CultureInfo.InvariantCulture.NumberFormat)}, " +
$"{this.s.ToString(format, CultureInfo.InvariantCulture.NumberFormat)}, " +
$"{this.l.ToString(format, CultureInfo.InvariantCulture.NumberFormat)}, " +
$"{this.a.ToString(format, CultureInfo.InvariantCulture.NumberFormat)})";
}
public bool Equals(ColorHSL other) {
return (this.h.Equals(other.h) && this.s.Equals(other.s) && this.l.Equals(other.l) && this.a.Equals(other.a));
}
public bool Equals(Color other) {
var rgb = HSL2RGB(this);
return rgb.Equals(other);
}
public override bool Equals(object obj) {
if (obj is ColorHSL otherHSL) return Equals(otherHSL);
if (obj is Color otherRGB) return Equals(otherRGB);
return false;
}
public override int GetHashCode() {
return ((Vector4) this).GetHashCode();
}
public float this[int index] {
get {
switch (index) {
case 0:
return this.h;
case 1:
return this.s;
case 2:
return this.l;
case 3:
return this.a;
default:
throw new IndexOutOfRangeException("Invalid Vector3 index!");
}
}
set {
switch (index) {
case 0:
this.h = value;
break;
case 1:
this.s = value;
break;
case 2:
this.l = value;
break;
case 3:
this.a = value;
break;
default:
throw new IndexOutOfRangeException("Invalid Vector3 index!");
}
}
}
public static bool operator ==(ColorHSL lhs, ColorHSL rhs) {
return lhs.Equals(rhs);
}
public static bool operator !=(ColorHSL lhs, ColorHSL rhs) {
return !(lhs == rhs);
}
public static implicit operator Vector4(ColorHSL c) {
return new Vector4(c.h, c.s, c.l, c.a);
}
public static implicit operator ColorHSL(Vector4 v) {
return new ColorHSL(v.x, v.y, v.z, v.w);
}
public static implicit operator ColorHSL(Color rgb) {
return RGB2HSL(rgb);
}
public static implicit operator Color(ColorHSL hsl) {
return HSL2RGB(hsl);
}
public static Color HSL2RGB(ColorHSL hsl) {
float a = hsl.s * Mathf.Min(hsl.l, 1 - hsl.l);
float Component(int n) {
float k = (n + hsl.h * 12) % 12;
return hsl.l - a * Mathf.Max(-1, Mathf.Min(k - 3, Mathf.Min(9 - k, 1)));
}
return new Color(Component(0), Component(8), Component(4), hsl.a);
}
public static ColorHSL RGB2HSL(Color rgb) {
float h = 0;
float s = 0;
float l = 0;
if (rgb.r >= rgb.g && rgb.r >= rgb.b) {
float xMin = Mathf.Min(rgb.g, rgb.b);
l = (rgb.r + xMin) / 2;
s = (rgb.r - l) / Mathf.Min(l, 1 - l);
float c = rgb.r - xMin;
if (c > Mathf.Epsilon) h = (rgb.g - rgb.b) / (6 * c);
}
else if (rgb.g >= rgb.r && rgb.g >= rgb.b) {
float xMin = Mathf.Min(rgb.r, rgb.b);
l = (rgb.g + xMin) / 2;
s = (rgb.g - l) / Mathf.Min(l, 1 - l);
float c = rgb.g - xMin;
if (c > Mathf.Epsilon) h = (2 + ((rgb.b - rgb.r) / c)) / 6;
}
else if (rgb.b >= rgb.r && rgb.b >= rgb.g) {
float xMin = Mathf.Min(rgb.r, rgb.g);
l = (rgb.b + xMin) / 2;
s = (rgb.b - l) / Mathf.Min(l, 1 - l);
float c = rgb.g - xMin;
if (c > Mathf.Epsilon) h = (4 + ((rgb.r - rgb.g) / c)) / 6;
}
return new ColorHSL(h, s, l, rgb.a);
}
}
}

View File

@ -0,0 +1,123 @@
using System;
using System.Globalization;
using UnityEngine;
namespace ConformalDecals.Util {
public struct ColorHSV : IEquatable<Color> {
public float h;
public float s;
public float v;
public float a;
public ColorHSV(float h, float s = 1, float v = 1, float a = 1) {
this.h = h;
this.s = s;
this.v = v;
this.a = a;
}
public override string ToString() {
return $"HSVA({this.h:F3}, {this.s:F3}, {this.v:F3}, {this.a:F3})";
}
public string ToString(string format) {
return
"HSVA(" +
$"{this.h.ToString(format, CultureInfo.InvariantCulture.NumberFormat)}, " +
$"{this.s.ToString(format, CultureInfo.InvariantCulture.NumberFormat)}, " +
$"{this.v.ToString(format, CultureInfo.InvariantCulture.NumberFormat)}, " +
$"{this.a.ToString(format, CultureInfo.InvariantCulture.NumberFormat)})";
}
public bool Equals(ColorHSL other) {
return (this.h.Equals(other.h) && this.s.Equals(other.s) && this.v.Equals(other.l) && this.a.Equals(other.a));
}
public bool Equals(Color other) {
var rgb = HSV2RGB(this);
return rgb.Equals(other);
}
public override bool Equals(object obj) {
if (obj is ColorHSL otherHSL) return Equals(otherHSL);
if (obj is Color otherRGB) return Equals(otherRGB);
return false;
}
public override int GetHashCode() {
return ((Vector4) this).GetHashCode();
}
public float this[int index] {
get {
switch (index) {
case 0:
return this.h;
case 1:
return this.s;
case 2:
return this.v;
case 3:
return this.a;
default:
throw new IndexOutOfRangeException("Invalid Vector3 index!");
}
}
set {
switch (index) {
case 0:
this.h = value;
break;
case 1:
this.s = value;
break;
case 2:
this.v = value;
break;
case 3:
this.a = value;
break;
default:
throw new IndexOutOfRangeException("Invalid Vector3 index!");
}
}
}
public static bool operator ==(ColorHSV lhs, ColorHSV rhs) {
return lhs.Equals(rhs);
}
public static bool operator !=(ColorHSV lhs, ColorHSV rhs) {
return !(lhs == rhs);
}
public static implicit operator Vector4(ColorHSV c) {
return new Vector4(c.h, c.s, c.v, c.a);
}
public static implicit operator ColorHSV(Vector4 v) {
return new ColorHSV(v.x, v.y, v.z, v.w);
}
public static implicit operator ColorHSV(Color rgb) {
return RGB2HSV(rgb);
}
public static implicit operator Color(ColorHSV hsv) {
return HSV2RGB(hsv);
}
public static Color HSV2RGB(ColorHSV hsv) {
var rgb = Color.HSVToRGB(hsv.h, hsv.s, hsv.v, false);
rgb.a = hsv.a;
return rgb;
}
public static ColorHSV RGB2HSV(Color rgb) {
var hsv = new ColorHSV {a = rgb.a};
Color.RGBToHSV(rgb, out hsv.h, out hsv.s, out hsv.v);
return hsv;
}
}
}

View File

@ -0,0 +1,22 @@
using UnityEngine;
namespace ConformalDecals.Util {
public static class ColorUtil {
/// Returns an RGBA 32-bit hex string
public static string ToHexString(this Color32 color) {
return $"#{color.r:x2}{color.g:x2}{color.b:x2}{color.a:x2}";
}
// Returns an RGBA 32-bit unsigned integer representation of the color
public static uint ToUint(this Color32 color) {
uint rgba = color.r;
rgba <<= 8;
rgba |= color.g;
rgba <<= 8;
rgba |= color.b;
rgba <<= 8;
rgba |= color.a;
return rgba;
}
}
}

View File

@ -3,18 +3,23 @@ using UnityEngine;
namespace ConformalDecals.Util {
public static class Logging {
public static void Log(string message) => Debug.Log("[ConformalDecals] " + message);
public static void Log(this PartModule module, string message) => Debug.Log(FormatMessage(module, message));
public static void LogWarning(this PartModule module, string message) =>
Debug.LogWarning(FormatMessage(module, message));
public static void LogWarning(string message) => Debug.LogWarning("[ConformalDecals] " + message);
public static void LogError(this PartModule module, string message) =>
Debug.LogError(FormatMessage(module, message));
public static void LogWarning(this PartModule module, string message) => Debug.LogWarning(FormatMessage(module, message));
public static void LogError(string message) => Debug.LogError("[ConformalDecals] " + message);
public static void LogError(this PartModule module, string message) => Debug.LogError(FormatMessage(module, message));
public static void LogException(string message, Exception exception) => Debug.LogException(new Exception("[ConformalDecals] " + message, exception));
public static void LogException(this PartModule module, string message, Exception exception) =>
Debug.LogException(new Exception(FormatMessage(module, message), exception));
private static string FormatMessage(PartModule module, string message) =>
$"[{GetPartName(module.part)} {module.GetType()}] {message}";

View File

@ -30,9 +30,15 @@ namespace ConformalDecals.Util {
}
public static string ParseString(ConfigNode node, string valueName, bool isOptional = false, string defaultValue = "") {
if (!node.HasValue(valueName)) throw new FormatException($"Missing value for {valueName}");
if (node.HasValue(valueName)) return node.GetValue(valueName);
if (isOptional) {
return defaultValue;
}
else {
throw new FormatException($"Missing value for {valueName}");
}
return node.GetValue(valueName);
}
public static bool ParseStringIndirect(ref string value, ConfigNode node, string valueName) {
@ -139,44 +145,53 @@ namespace ConformalDecals.Util {
throw new FormatException($"Improperly formatted {typeof(T)} value for {valueName} : '{valueString}");
}
public static bool TryParseHexColor(string valueString, out Color32 value) {
value = new Color32(0, 0, 0, byte.MaxValue);
if (!uint.TryParse(valueString, System.Globalization.NumberStyles.HexNumber, null, out var hexColor)) return false;
switch (valueString.Length) {
case 8: // RRGGBBAA
value.a = (byte) (hexColor & 0xFF);
hexColor >>= 8;
goto case 6;
case 6: // RRGGBB
value.b = (byte) (hexColor & 0xFF);
hexColor >>= 8;
value.g = (byte) (hexColor & 0xFF);
hexColor >>= 8;
value.r = (byte) (hexColor & 0xFF);
return true;
case 4: // RGBA
value.a = (byte) ((hexColor & 0xF) << 4);
hexColor >>= 4;
goto case 3;
case 3: // RGB
value.b = (byte) (hexColor & 0xF << 4);
hexColor >>= 4;
value.g = (byte) (hexColor & 0xF << 4);
hexColor >>= 4;
value.r = (byte) (hexColor & 0xF << 4);
return true;
default:
return false;
}
}
public static bool TryParseColor32(string valueString, out Color32 value) {
value = new Color32(0, 0, 0, byte.MaxValue);
// HTML-style hex color
// hex color
if (valueString[0] == '#') {
var hexColorString = valueString.Substring(1);
if (!int.TryParse(hexColorString, System.Globalization.NumberStyles.HexNumber, null, out var hexColor)) return false;
switch (hexColorString.Length) {
case 8: // RRGGBBAA
value.a = (byte) (hexColor & 0xFF);
hexColor >>= 8;
goto case 6;
case 6: // RRGGBB
value.b = (byte) (hexColor & 0xFF);
hexColor >>= 8;
value.g = (byte) (hexColor & 0xFF);
hexColor >>= 8;
value.r = (byte) (hexColor & 0xFF);
return true;
case 4: // RGBA
value.a = (byte) ((hexColor & 0xF) << 4);
hexColor >>= 4;
goto case 3;
case 3: // RGB
value.b = (byte) (hexColor & 0xF << 4);
hexColor >>= 4;
value.g = (byte) (hexColor & 0xF << 4);
hexColor >>= 4;
value.r = (byte) (hexColor & 0xF << 4);
return true;
default:
return false;
if (TryParseHexColor(hexColorString, out var hexColor)) {
value = hexColor;
return true;
}
}
@ -207,7 +222,14 @@ namespace ConformalDecals.Util {
value.g = (byte) (green * 0xFF);
value.b = (byte) (blue * 0xFF);
return true;
case 1: // try again for hex color
if (TryParseHexColor(split[0], out var hexcolor)) {
value = hexcolor;
return true;
}
else {
return false;
}
default:
return false;
}

View File

@ -1,3 +1,68 @@
v0.2.6
------
- Fixes:
- Fixed stock flags appearing stretched by forcing their aspect ratio to be correct.
- Another attempted fix for the planet text glitch.
v0.2.5
------
- Fixes:
- Fixed line spacing, character spacing, and vertical settings not applying to symmetry counterparts
v0.2.4
------
- Fixes:
- Fixed red text appearing on planets due to KSP bug by clearing render textures afterwards.
- Fixed fonts not saving correctly.
- Changes:
- Lowered step size for decal size and depth to 1cm.
- Changed default max size to 5m.
- Changed default text decal size to 0.2m
- Text decals now show as a circle if they contain only whitespace.
v0.2.3
------
- Fixes:
- Fixed TMP subobjects being deleted, causing fallback fonts to fail in some situations.
- Started using URL-style encoding for text decals behind the scenes to prevent issues with certain characters.
- Fixed text decals having zero size when they had only whitespace or an empty string.
- Fixed decals having drag and causing issues when using FAR.
- Fixed broken saving of text decals in certain circumstances.
v0.2.2
------
- Fixes:
- Fixed corrupted text rendering when a vessel loads during a scene change.
v0.2.1
------
- Changes:
- Pressing enter in the text entry window now types a newline.
- Fixes:
- Renamed font assetbundle. The old extension was causing the game to try to load it twice on Windows due to legacy compatability features.
- Fixed text rendering on DirectX resulting in black boxes by using ARGB32 instead of RG16 for the render texture in DirectX.
v0.2.0
------
- New Parts:
- CDL-3 Surface Base Decal: A set of conformal decals based on the symbols from the movie Moon (2009) designed by Gavin Rothery
- CDL-T Custom Text Decal: A customizable text decal with a variety of fonts
- Changes:
- New ModuleConformalText module for customizable text
- Text, font, and style can all be customized, as well as text fill and outline colors and widths
- Same projection and opacity options as other conformal decals
- New StandardText decal shader supporting the text module
- Unified all decal shaders into a single "StandardDecal" shader with variants supporting any combination of bump, specular and emissive maps, plus SDF alphas.
- Old shaders are remapped to Standard shader plus keywords automatically.
- New SDF-based antialiasing for when decals extend to their borders, e.g. on opaque flags.
- New "KEYWORD" material modifier, allowing for shader features to be enabled and disabled.
- Material modifiers can now be removed in variants by setting `remove = true` inside them.
- Fixes:
- Fixed WIDTH and HEIGHT scale modes being flipped
- Removed some debug log statements
- Dependencies:
- Updated ModuleManager to version 4.1.4
v0.1.4
------
- Supported KSP versions: 1.8.x to 1.10.x