1 Commits

Author SHA1 Message Date
0281759d5f SDF experiments 2020-06-22 01:43:47 -07:00
112 changed files with 1801 additions and 18089 deletions

View File

@ -1,23 +0,0 @@
name: Fast-Forward Release Branch
on:
release:
types: [created]
jobs:
fast-forward:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: release
fetch-depth: 0
- name: Merge into Release
run: git merge ${{github.ref_name}} --ff-only
- name: Push Changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: release

View File

@ -1,139 +0,0 @@
name: Build and Release
on: [ push ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: '6.0.x'
- name: Install Python Tools
run: |
python -m pip install --upgrade pip
python -m pip install yaclog yaclog-ksp
- name: Generate Version Info
run: |
echo "VERSION_TITLE=$(yaclog show -n)" >> $GITHUB_ENV
python Scripts/version.py
yaclog-ksp -n "Conformal Decals"
- name: Validate Version Info
uses: DasSkelett/AVC-VersionFileValidator@master
- name: Download DLL Dependencies
working-directory: Source
run: |
wget --user drewcassidy --password ${{ secrets.PILE_OF_ROCKS_PASS }} https://pileof.rocks/Secret/conformal-decals-dependencies-1.zip
unzip conformal-decals-dependencies-*.zip -d ConformalDecals/dlls
- name: Build DLL
working-directory: Source
run: |
mkdir -p ../GameData/ConformalDecals/Plugins
dotnet build --configuration Release ConformalDecals.sln
- name: Download KSP Dependencies
run: |
wget http://pileof.rocks/KSP/Shabby_v0.2.0.zip
wget https://ksp.sarbian.com/jenkins/job/ModuleManager/161/artifact/ModuleManager.4.2.1.dll
wget https://github.com/blowfishpro/B9PartSwitch/releases/download/v2.19.0/B9PartSwitch_v2.19.0.zip
wget https://github.com/KSPModdingLibs/HarmonyKSP/releases/download/2.0.4.0/HarmonyKSP_2.0.4.0_for_KSP1.8+.zip
unzip -d Shabby Shabby*.zip
unzip -d B9PartSwitch B9PartSwitch*.zip
unzip -d HarmonyKSP HarmonyKSP*.zip
mv Shabby/GameData/Shabby GameData/
mv ModuleManager*.dll GameData/
mv B9PartSwitch/GameData/B9PartSwitch GameData/
mv HarmonyKSP/GameData/000_Harmony GameData/
- name: Upload Unbundled Build
uses: actions/upload-artifact@v3
with:
name: ConformalDecals-unbundled
path: |
GameData/ConformalDecals
README.md
CHANGELOG.md
LICENSE-ART.md
LICENSE-SOURCE.md
- name: Upload Bundled Build
uses: actions/upload-artifact@v3
with:
name: ConformalDecals
path: |
GameData
README.md
CHANGELOG.md
LICENSE-ART.md
LICENSE-SOURCE.md
deploy:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install Python Tools
run: |
python -m pip install --upgrade pip
python -m pip install yaclog
- name: Get version name and body
run: |
echo "VERSION_TITLE=$(yaclog show -n)" >> $GITHUB_ENV
echo "$(yaclog show -mb)" >> RELEASE.md
- name: Download Build Artifacts
uses: actions/download-artifact@v3
- name: Zip Download Packages
run: |
mkdir bundled
mkdir unbundled
zip -r bundled/ConformalDecals-$VERSION_TITLE.zip ConformalDecals/*
zip -r unbundled/ConformalDecals-$VERSION_TITLE.zip ConformalDecals-unbundled/*
ls
- name: Publish to Spacedock
run: |
curl -F "username=drewcassidy" -F "password=${{ secrets.SPACEDOCK_PASS }}" \
-c ./cookies "https://spacedock.info/api/login"
curl -c ./cookies -b ./cookies \
-F "version=$VERSION_TITLE" \
-F "changelog=$(yaclog show -mb)" \
-F "game-version=1.12.3" \
-F "notify-followers=yes" \
-F "zipball=@bundled/ConformalDecals-$VERSION_TITLE.zip" \
"https://spacedock.info/api/mod/2451/update"
- name: Publish to Github
uses: softprops/action-gh-release@v1
with:
files: |
bundled/ConformalDecals-*.zip
ConformalDecals/GameData/ConformalDecals/Versioning/ConformalDecals.version
name: Conformal Decals ${{ env.VERSION_TITLE }}
body_path: RELEASE.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

14
.gitignore vendored
View File

@ -2,22 +2,15 @@
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/*.manifest
# DLLs
GameData/ConformalDecals/Plugins
GameData/ConformalDecals/Resources/Resources.manifest
GameData/ConformalDecals/Resources/conformaldecals.shab.manifest
# Unity Project Files
PartTools.cfg
@ -52,7 +45,4 @@ Source/ConformalDecals/bin
.ds_store
*.sublime*
.idea
.vs
obj
*.swp
@thumbs

View File

@ -12,19 +12,15 @@ package:
dependencies: # Configure dependencies
ModuleManager:
location: url
url: https://ksp.sarbian.com/jenkins/job/ModuleManager/159/artifact/ModuleManager.4.1.4.dll
url: https://ksp.sarbian.com/jenkins/job/ModuleManager/157/artifact/ModuleManager.4.1.3.dll
zip: false
B9PartSwitch:
location: url
url: http://pileof.rocks/KSP/B9PartSwitch-v2.18.0.zip
url: http://pileof.rocks/KSP/B9PartSwitch-v2.16.0.zip
zip: true
Shabby:
location: url
url: http://pileof.rocks/KSP/Shabby_v0.2.0.zip
zip: true
HarmonyKSP:
location: url
url: https://github.com/KSPModdingLibs/HarmonyKSP/releases/download/2.0.4.0/HarmonyKSP_2.0.4.0_for_KSP1.8+.zip
url: http://taniwha.org/~bill/Shabby_v0.1.2.zip
zip: true
deploy:
SpaceDock:

27
.travis.yml Normal file
View File

@ -0,0 +1,27 @@
language: python
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
- cd build-deploy
- git checkout master
- cd ..
- pytest -s --testpath "GameData/" build-deploy/src/tests/ # run the deploy tests
- python build-deploy/src/package.py --f ".mod_data.yml" # Build package
before_deploy:
- python build-deploy/src/stage.py --f ".mod_data.yml" # Run the staging script
deploy:
- provider: script
script: python build-deploy/src/deploy.py --f ".mod_data.yml" # Deploy package to spacedock, curse, github
skip_cleanup: true
on:
branch: release

View File

@ -1,36 +0,0 @@
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

@ -1,13 +0,0 @@
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

@ -1,18 +0,0 @@
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

@ -1,17 +0,0 @@
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

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

View File

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

View File

@ -1,37 +0,0 @@
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

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

View File

@ -1,5 +1,4 @@
using System;
using UnityEngine;
using UnityEngine;
[ExecuteInEditMode]
public class DecalProjectorTest : MonoBehaviour
@ -24,6 +23,9 @@ 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>();
}
@ -38,9 +40,8 @@ public class DecalProjectorTest : MonoBehaviour
var projectorToTarget = targetRenderer.worldToLocalMatrix * transform.localToWorldMatrix;
_projectionMatrix = _OrthoMatrix * targetToProjector;
targetMaterial.SetMatrix("_ProjectionMatrix", _projectionMatrix);
targetMaterial.SetVector("_DecalNormal", projectorToTarget.MultiplyVector(Vector3.back).normalized);
targetMaterial.SetVector("_DecalTangent", projectorToTarget.MultiplyVector(Vector3.right).normalized);
targetMaterial.SetMatrix(_matrixID, _projectionMatrix);
targetMaterial.SetVector(_normalID, projectorToTarget.MultiplyVector(Vector3.back).normalized);
targetMaterial.SetVector(_tangentID, projectorToTarget.MultiplyVector(Vector3.right).normalized);
}
}

View File

@ -1,117 +0,0 @@
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

@ -1,143 +0,0 @@
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

@ -1,122 +0,0 @@
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

@ -1,120 +0,0 @@
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

@ -0,0 +1,130 @@
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" }
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

@ -0,0 +1,143 @@
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" }
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

@ -0,0 +1,159 @@
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" }
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

@ -0,0 +1,165 @@
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" }
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

@ -0,0 +1,180 @@
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" }
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,93 +1,26 @@
#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_BUMPMAP
float2 uv_bumpmap;
#endif //DECAL_BUMPMAP
#ifdef DECAL_NORMAL
float2 uv_bump;
#endif //DECAL_NORMAL
#ifdef DECAL_SPECMAP
float2 uv_specmap;
#endif //DECAL_SPECMAP
#ifdef DECAL_SPECULAR
float2 uv_spec;
#endif //DECAL_SPECULAR
#ifdef DECAL_EMISSIVE
float2 uv_emissive;
float2 uv_glow;
#endif //DECAL_EMISSIVE
#ifdef DECAL_BASE_NORMAL
float3 normal;
#endif //DECAL_BASE_NORMAL
float3 vertex_normal;
#endif
float3 viewDir;
float3 worldPosition;
};
@ -126,6 +59,20 @@ 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
@ -141,16 +88,200 @@ inline float CalcMipLevel(float2 texture_coord) {
return 0.5 * log2(delta_max_sqr);
}
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
return 10 * max(q.x, q.y); // 2D pseudo SDF
#else
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
// 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;
}
#endif
// 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
{
// 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

View File

@ -1,33 +0,0 @@
#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

@ -1,183 +0,0 @@
#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

View File

@ -1,17 +0,0 @@
#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

View File

@ -1,45 +0,0 @@
#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,76 @@
Shader "ConformalDecals/SDF4test"
{
Properties
{
_MainTex("_MainTex (RGB spec(A))", 2D) = "white" {}
_Color1("Color 1", Color) = (0,0,0,0)
_Color2("Color 2", Color) = (0,0,0,0)
_Color3("Color 3", Color) = (0,0,0,0)
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_Smoothness ("SDF smoothness", Range(0,1)) = 0.15
}
SubShader
{
Tags { "Queue" = "Transparent" }
Cull Back
ZWrite On
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
float4 _Color1;
float4 _Color2;
float4 _Color3;
float _Smoothness;
float _Cutoff;
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float3 worldPosition : TEXCOORD1;
half3 worldNormal : TEXCOORD2;
};
v2f vert(float4 vertex : POSITION, float2 uv : TEXCOORD0) {
v2f o;
o.pos = UnityObjectToClipPos(vertex);
o.uv = uv;
o.worldPosition = mul(unity_ObjectToWorld, vertex).xyz;
return o;
}
fixed4 frag (v2f i) : SV_Target {
fixed4 c = 0;
float4 s = tex2D(_MainTex,(i.uv));
s.rgb = s.rbg;
c = lerp(c, _Color1, smoothstep(_Cutoff, saturate(_Smoothness+ _Cutoff), s.r + s.g + s.b));
c = lerp(c, _Color2, smoothstep(_Cutoff, saturate(_Smoothness+ _Cutoff), s.g + s.b ));
c = lerp(c, _Color3, smoothstep(_Cutoff, saturate(_Smoothness+ _Cutoff), s.b ));
// if (s.r + s.g + s.b > 0.5) {
// if (s.r > s.g && s.r > s.b) c = _Color1;
// if (s.g > s.r && s.g > s.b) c = _Color2;
// if (s.b > s.g && s.b > s.r) c = _Color3;
// }
return c;
}
ENDCG
}
}
}

View File

@ -12,7 +12,7 @@ Shader "ConformalDecals/SelectionGlow"
}
SubShader
{
Tags { "Queue" = "Transparent" "IgnoreProjector" = "true" }
Tags { "Queue" = "Transparent" }
Cull Back
ZWrite Off

View File

@ -1,38 +0,0 @@
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

@ -1,111 +0,0 @@
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

@ -1,73 +0,0 @@
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

@ -1,49 +0,0 @@
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

@ -1,112 +0,0 @@
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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 470 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

View File

@ -1,93 +0,0 @@
%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

View File

@ -1,93 +0,0 @@
%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}

View File

@ -1,93 +0,0 @@
%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}

View File

@ -1,89 +0,0 @@
%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}

View File

@ -1,93 +0,0 @@
%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}

View File

@ -1,92 +0,0 @@
%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

@ -1,193 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file
| modName | Conformal Decals |
| ------- |:-------------------------------------------------------------------------------------|
| license | CC-By-SA & GPL3 |
| website | https://forum.kerbalspaceprogram.com/index.php?/topic/194802-18-111-conformal-decals |
| author | Andrew Cassidy |
## 0.2.10 - 2022-03-14
### Fixed
- Fixed decals not projecting on loading prefabs
### Changed
- Re-enabled projecting onto TransparentFX layer
### Added
- Allowed for regular expressions to be used when blacklisting shaders
- Added all Waterfall shaders to the shader blacklist when Waterfall is present
## 0.2.9 - 2022-03-12
### Fixed
- Fixed text decals breaking when used in symmetry
- Fixed decals projecting onto the TransparentFX layer, such as Waterfall plumes
## 0.2.8
- Update bundled Shabby to support Harmony 2 for compatibility with other mods
- Update bundled B9PartSwitch to 2.18.0
## 0.2.7
- Supported KSP versions: 1.8.x to 1.11.x
### Notes:
- Attaching decal parts in flight using engineer kerbals is not supported.
### Fixed:
- Fixed certain non-ascii strings not rendering correctly under certain circumstances.
- Yet another attempted fix for the planet text glitch.
## 0.2.6
### Fixed:
- Fixed stock flags appearing stretched by forcing their aspect ratio to be correct.
- Another attempted fix for the planet text glitch.
## 0.2.5
### Fixed:
- Fixed line spacing, character spacing, and vertical settings not applying to symmetry counterparts
## 0.2.4
### Fixed:
- Fixed red text appearing on planets due to KSP bug by clearing render textures afterwards.
- Fixed fonts not saving correctly.
### Changed:
- 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.
## 0.2.3
### Fixed:
- 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.
## 0.2.2
### Fixed:
- Fixed corrupted text rendering when a vessel loads during a scene change.
## 0.2.1
### Changed:
- Pressing enter in the text entry window now types a newline.
### Fixed:
- 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.
## 0.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
### Changed:
- 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.
### Fixed:
- Fixed WIDTH and HEIGHT scale modes being flipped
- Removed some debug log statements
- Dependencies:
- Updated ModuleManager to version 4.1.4
## 0.1.4
Supported KSP versions: 1.8.x to 1.10.x
### Fixed:
- Fixed decals rendering onto disabled B9PS part variants
- Decals will still not update whan their parent part's B9PS variant is changed, both in flight and in the editor. This is known and awaiting a change to B9PS to be fixed.
- Fixed decal bounds rendering as dark cubes when shadowed by EVE clouds.
- Fixed decals being shadowed by EVE clouds, causing the part underneath to appear overly dark.
## 0.1.3
### Fixe:
- Fixed decals being able to be scaled down to 0
### Changed:
- Made decal bounds no longer collide in flight, this is done by repurposing layer 31 (which is configurable in the ConformalDecals.cfg file)
- Decals will now be unselectable in flight by default. This can be disabled with the `selectableInFlight` value in ConformalDecals.cfg, or in the module config itself.
- Decal parts will now destroy themselves automatically when the parent part is destroyed
- Small refactor of node parsing code
- Colors can now be specified in hex (#RGB, #RGBA, #RRGGBB, or #RRGGBBAA) or using the colors specified in the XKCDColors class
## 0.1.2
### Fixed:
- Disabled writing to the zbuffer in the decal bounds shader. Should fix any issues with Scatterer or EVE.
## 0.1.1
### Fixed:
- Fixed flag decal not adjusting to new texture sizes immediately.
- Fixed decal bounds being visible on launch.
- Fixed decal bounds being visible in the part icon.
## 0.1.0
Initial release!
### New Parts:
- CDL-F Flag Decal: Conformal flag decal, which uses either the mission flag or a flag of your choosing.
- CDL-1 Generic Decal: A set of conformal generic decals for planes and rockets
- CDL-2 Semiotic Standard Decal: A set of conformal decals based on the Semiotic Standard for All Commercial Trans-Stellar Utility Lifter and Transport Spacecraft designed by Ron Cobb for the movie Alien

View File

@ -15,17 +15,9 @@ Localization
#LOC_ConformalDecals_gui-opacity = Opacity
#LOC_ConformalDecals_gui-cutoff = Cutoff
#LOC_ConformalDecals_gui-wear = Edge Wear
#LOC_ConformalDecals_gui-multiproject = Project onto Multiple
#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
@ -34,11 +26,6 @@ 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.
@ -77,7 +64,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. (Based on the work of Ron Cobb)
#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-tags = conformal decal sticker semiotic standard for kerbal vessels Ron Cobb Alien
#LOC_ConformalDecals_semiotic-variant-00 = Hazard
#LOC_ConformalDecals_semiotic-variant-01 = Blank
@ -111,47 +98,5 @@ 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,12 +65,7 @@ PART
scaleRange = 0.1, 4
scaleMode = AVERAGE
shader = ConformalDecals/Decal/Standard
KEYWORD {
name = DECAL_SDF_ALPHA
value = false
}
shader = ConformalDecals/Paint/Specular
TEXTURE {
name = _Decal
@ -98,7 +93,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/DiffuseSDF
tile = 0, 2, 128, 112
}
}
@ -113,7 +108,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 128, 2, 128, 112
}
}
@ -128,7 +123,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 256, 2, 128, 112
}
}
@ -143,7 +138,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 384, 2, 128, 112
}
}
@ -158,7 +153,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 690, 4, 330, 118
}
}
@ -173,7 +168,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 898, 4, 122, 118
}
}
@ -188,7 +183,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 6, 126, 196, 132
}
}
@ -203,7 +198,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 210, 122, 94, 94
}
}
@ -218,7 +213,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 8, 262, 192, 70
}
}
@ -247,7 +242,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 508, 332, 262, 112
}
}
@ -262,7 +257,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 202, 218, 164, 114
}
}
@ -277,7 +272,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 366, 218, 164, 114
}
}
@ -352,7 +347,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 326, 426, 164, 20
}
}
@ -368,7 +363,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 776, 388, 48, 48
}
}
@ -383,7 +378,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 328, 456, 48, 48
}
}
@ -398,7 +393,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 376, 456, 48, 48
}
}
@ -413,7 +408,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 424, 456, 48, 48
}
}
@ -428,7 +423,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 472, 456, 48, 48
}
}
@ -443,7 +438,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 520, 456, 48, 48
}
}
@ -458,7 +453,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 568, 456, 48, 48
}
}
@ -473,7 +468,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 614, 456, 48, 48
}
}
@ -488,7 +483,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 662, 456, 48, 48
}
}
@ -503,7 +498,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 710, 456, 48, 48
}
}
@ -518,7 +513,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
KEYWORD { name = DECAL_SDF_ALPHA }
shader = ConformalDecals/Paint/SpecularSDF
tile = 758, 456, 48, 48
}
}
@ -533,10 +528,7 @@ PART
MODULE {
IDENTIFIER { name = ModuleConformalDecal }
DATA {
TEXTURE {
name = _SpecMap
remove = true
}
shader = ConformalDecals/Paint/Diffuse
tile = 826, 360, 196, 150
opacity = 1

View File

@ -1,537 +0,0 @@
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-2 Semiotic Standard Decal
// CDL-1 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. (Based on the work of Ron Cobb)
// 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.
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/Decal/Standard
shader = ConformalDecals/Paint/Specular
TEXTURE {
name = _Decal

View File

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

View File

@ -1,69 +0,0 @@
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

@ -1,17 +0,0 @@
// 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,7 +0,0 @@
// Prevent projection onto Waterfall plumes
CONFORMALDECALS:NEEDS[Waterfall] {
SHADERBLACKLIST {
shaderRegex = Waterfall/.*
}
}

Binary file not shown.

View File

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

View File

@ -4,49 +4,20 @@ CONFORMALDECALS {
SHADERBLACKLIST {
shader = DepthMask
shader = KSP/Alpha/Cutoff
shader = KSP/Alpha/Cutoff Bumped
shader = KSP/Alpha/Translucent
shader = KSP/Alpha/Translucent Additive
shader = KSP/Alpha/Translucent Specular
shader = KSP/Alpha/Unlit Transparent
shader = KSP/Bumped Specular (Transparent)
shader = KSP/FX/ScrollingUnlit
shader = KSP/Particles/Additive
shader = KSP/Particles/Additive (Soft)
shader = KSP/Particles/Alpha Blended
shader = KSP/Particles/Alpha Blended Emissive Cutout
shader = KSP/Specular (Cutoff)
shader = KSP/Specular (Transparent)
shader = Solid Color (Alpha)
shaderRegex = KSP/Alpha/.*
shaderRegex = KSP/Particles/.*
}
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
}
}

View File

@ -1,24 +1,28 @@
{
"NAME": "ConformalDecals",
"URL": "https://github.com/drewcassidy/KSP-Conformal-Decals/releases/latest/download/ConformalDecals.version",
"DOWNLOAD": "https://github.com/drewcassidy/KSP-Conformal-Decals/releases/latest",
"CHANGE_LOG_URL": "https://raw.githubusercontent.com/drewcassidy/KSP-Conformal-Decals/release/CHANGELOG.md",
"VERSION": {
"MAJOR": 9,
"MINOR": 9,
"PATCH": 9,
"BUILD": 100000
"NAME":"ConformalDecals",
"URL":"https://raw.githubusercontent.com/drewcassidy/KSP-Conformal-Decals/release/GameData/ConformalDecals/Versioning/ConformalDecals.version",
"DOWNLOAD":"https://github.com/drewcassidy/KSP-Conformal-Decals/releases",
"VERSION":
{
"MAJOR":0,
"MINOR":1,
"PATCH":3,
"BUILD":0
},
"KSP_VERSION": {
"MAJOR": 1,
"MINOR": 12
"KSP_VERSION":
{
"MAJOR":1,
"MINOR":9,
"PATCH":1
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
"MINOR": 8
"KSP_VERSION_MIN":{
"MAJOR":1,
"MINOR":8,
"PATCH":0
},
"KSP_VERSION_MAX": {
"MAJOR": 1,
"MINOR": 12
"KSP_VERSION_MAX":{
"MAJOR":1,
"MINOR":9,
"PATCH":99
}
}

View File

@ -1,5 +1,5 @@
# 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)
# Conformal Decals v0.1.3
[![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)
@ -8,11 +8,10 @@ Conformal Decals adds a set of decal stickers to KSP, as well as providing a fra
## Dependencies
Required:
- KSP (1.8.x to 1.10.x)
- B9 Part Switch (2.18.0). Bundled with release.
- ModuleManager (4.1.4). Bundled with release.
- Shabby (0.2.0 unofficial build). Bundled with release.
- HarmonyKSP (2.0.4.0). Bundled with release.
- KSP (1.8.x to 1.9.x)
- B9 Part Switch (2.16.0). Bundled with release.
- ModuleManager (4.1.3). Bundled with release.
- Shabby (0.1.2). Bundled with release.
Optional:
- Wild Blue Tools. For custom decals category in the VAB and SPH.
@ -21,8 +20,6 @@ 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,61 +0,0 @@
import yaclog
import yaclog.version
import git as gp
import os
import xml.dom.minidom as minidom
import json
def run():
repo = gp.Repo(os.curdir)
cl = yaclog.Changelog('CHANGELOG.md')
version = str(cl.current_version(released=True).version)
release = False
for tag in repo.tags:
if tag.commit == repo.head.commit:
release = True
build = 100000
break
if not release:
build = int.from_bytes(repo.head.commit.binsha[0:2], byteorder='big')
version = yaclog.version.increment_version(version, 2)
print(f'Setting up version {version} build {build}')
version_path = 'GameData/ConformalDecals/Versioning/ConformalDecals.version'
with open(version_path, 'r+') as version_file:
print('Updating version file')
segments = version.split('.')
# print(version_file.read())
decoded = json.load(version_file)
decoded['VERSION']['MAJOR'] = int(segments[0])
decoded['VERSION']['MINOR'] = int(segments[1])
decoded['VERSION']['PATCH'] = int(segments[2])
decoded['VERSION']['BUILD'] = build
version_file.seek(0)
json.dump(decoded, version_file, indent=4)
version_file.truncate()
project_path = 'Source/ConformalDecals/ConformalDecals.csproj'
with open(project_path, 'r+') as project_file:
print('Updating csproj file')
segments = version.split('.')
decoded = minidom.parse(project_file)
version_node = decoded.getElementsByTagName('AssemblyVersion')[0]
if release:
version_node.firstChild.nodeValue = f'{version}'
else:
version_node.firstChild.nodeValue = f'{version}.{build}'
# version_node.value = f'{version}.{build}'
project_file.seek(0)
decoded.writexml(project_file)
project_file.truncate()
print('Done!')
if __name__ == '__main__':
run()

View File

@ -1,12 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConformalDecals", "ConformalDecals\ConformalDecals.csproj", "{1EA983F9-42E5-494E-9683-FDAC9C9121F4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C2564402-B081-479B-B723-D5C065BC884E}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConformalDecals", "ConformalDecals/ConformalDecals.csproj", "{1ea983f9-42e5-494e-9683-fdac9c9121f4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -14,33 +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
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
$0.DotNetNamingPolicy = $1
$1.DirectoryNamespaceAssociation = PrefixedHierarchical
$0.TextStylePolicy = $2
$2.FileWidth = 80
$2.TabsToSpaces = True
$2.scope = text/x-csharp
$2.NoTabsAfterNonTabs = True
$2.EolMarker = Unix
$0.CSharpFormattingPolicy = $3
$3.NewLinesForBracesInTypes = False
$3.NewLinesForBracesInMethods = False
$3.NewLinesForBracesInProperties = False
$3.NewLinesForBracesInAccessors = False
$3.NewLinesForBracesInAnonymousMethods = False
$3.NewLinesForBracesInControlBlocks = False
$3.NewLinesForBracesInAnonymousTypes = False
$3.NewLinesForBracesInObjectCollectionArrayInitializers = False
$3.NewLinesForBracesInLambdaExpressionBody = False
$3.scope = text/x-csharp
$3.SpaceAfterCast = True
$0.StandardHeader = $4
{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,58 +1,75 @@
<?xml version="1.0" encoding="utf-8"?><Project Sdk="Microsoft.NET.Sdk">
<?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')" />
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<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>
<LangVersion>8</LangVersion>
<IsPackable>false</IsPackable>
<PlatformTarget>x64</PlatformTarget>
<NoWarn>1701;1702;CS0649;CS1591</NoWarn>
<AssemblyVersion>9.9.9</AssemblyVersion>
<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>
</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>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>dlls\UnityEngine.AssetBundleModule.dll</HintPath>
<HintPath>dlls\UnityEngine.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>
</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>
<HintPath>dlls\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Remove="dlls\**" />
<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" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="dlls\**" />
</ItemGroup>
<ItemGroup>
<None Remove="dlls\**" />
</ItemGroup>
<ItemGroup>
<None Include="..\.editorconfig" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="/bin/cp -v '$(OutDir)ConformalDecals.dll' '$(SolutionDir)../GameData/ConformalDecals/Plugins/ConformalDecals.dll'" IgnoreExitCode="true" />
<!--Fuck you MSBuild stop trying to run CMD.exe on macOS-->
</Target>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>sh -e -c "cp -v '$(TargetPath)' '$(SolutionDir)/../GameData/ConformalDecals/Plugins'"</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@ -1,48 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using ConformalDecals.Text;
using ConformalDecals.Util;
using TMPro;
using UnityEngine;
namespace ConformalDecals {
public static class DecalConfig {
private static Texture2D _blankNormal;
private static List<string> _shaderBlacklist;
private static List<Regex> _shaderRegexBlacklist;
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"}
},
};
private static Texture2D _blankNormal;
private static List<string> _shaderBlacklist;
private static int _decalLayer = 31;
private static bool _selectableInFlight = false;
public static Texture2D BlankNormal => _blankNormal;
@ -50,85 +15,39 @@ namespace ConformalDecals {
public static bool SelectableInFlight => _selectableInFlight;
public static IEnumerable<DecalFont> Fonts => _fontList.Values;
public static bool IsBlacklisted(Shader shader) {
return IsBlacklisted(shader.name);
}
public static bool IsBlacklisted(string shaderName) {
if (_shaderBlacklist.Contains(shaderName)) return true;
foreach (var regex in _shaderRegexBlacklist) {
if (regex.IsMatch(shaderName)) {
_shaderBlacklist.Add(shaderName);
Logging.Log($"Caching blacklisted shader name '{shaderName}' which matches '{regex}'");
return true;
}
}
return false;
}
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");
}
return _shaderBlacklist.Contains(shaderName);
}
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);
}
foreach (var shaderRegex in blacklist.GetValuesList("shaderRegex")) {
_shaderRegexBlacklist.Add(new Regex(shaderRegex));
}
}
var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
foreach (var fontNode in node.GetNodes("FONT")) {
try {
var font = DecalFont.Parse(fontNode, allFonts);
_fontList.Add(font.Name, font);
}
catch (Exception e) {
Debug.LogException(e);
}
ParseUtil.ParseIntIndirect(ref _decalLayer, node, "decalLayer");
ParseUtil.ParseBoolIndirect(ref _selectableInFlight, node, "selectableInFlight");
}
}
private static Texture2D MakeBlankNormal() {
Logging.Log("Generating neutral normal map texture");
Debug.Log("ConformalDecals: Generating neutral normal map texture");
var width = 2;
var height = 2;
var color = new Color32(255, 128, 128, 128);
var colors = new[] {color, color, color, color};
var tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
for (var x = 0; x <= width; x++) {
for (var y = 0; y < height; y++) {
tex.SetPixels32(colors);
}
}
tex.SetPixels32(colors);
tex.Apply();
return tex;
@ -137,14 +56,12 @@ namespace ConformalDecals {
// ReSharper disable once UnusedMember.Global
public static void ModuleManagerPostLoad() {
_shaderBlacklist = new List<string>();
_shaderRegexBlacklist = new List<Regex>();
_fontList = new Dictionary<string, DecalFont>();
var configs = GameDatabase.Instance.GetConfigs("CONFORMALDECALS");
if (configs.Length > 0) {
Debug.Log("ConformalDecals: loading config");
foreach (var config in configs) {
Logging.Log($"loading config node '{config.url}'");
ParseConfig(config.config);
}
}
@ -160,4 +77,4 @@ namespace ConformalDecals {
_blankNormal = MakeBlankNormal();
}
}
}
}

View File

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

View File

@ -1,5 +1,4 @@
using UnityEngine;
// ReSharper disable InconsistentNaming
namespace ConformalDecals {
@ -13,6 +12,5 @@ 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

@ -1,19 +0,0 @@
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);
value = ParseUtil.ParseBool(node, "value", true, true);
}
public override void Modify(Material material) {
if (value) material.EnableKeyword(_propertyName);
else material.DisableKeyword(_propertyName);
}
}
}

View File

@ -14,14 +14,13 @@ 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 virtual void Remove(Material material) { }
public abstract void Modify(Material material);
}
}

View File

@ -30,20 +30,12 @@ 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;
}
@ -58,7 +50,6 @@ namespace ConformalDecals.MaterialProperties {
_previewMaterial.EnableKeyword("DECAL_PREVIEW");
_previewMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Back);
_previewMaterial.SetInt(DecalPropertyIDs._ZWrite, 1);
}
return _previewMaterial;
@ -78,6 +69,7 @@ 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();
@ -85,6 +77,7 @@ 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,38 +88,17 @@ namespace ConformalDecals.MaterialProperties {
var property = MaterialProperty.Instantiate(_serializedProperties[i]);
_materialProperties.Add(_serializedNames[i], property);
if (property is MaterialTextureProperty {isMain: true} textureProperty) {
if (property is MaterialTextureProperty textureProperty && textureProperty.isMain) {
_mainTexture = textureProperty;
}
}
}
public void Awake() {
Debug.Log($"MaterialPropertyCollection {this.GetInstanceID()} onAwake");
_materialProperties ??= new Dictionary<string, MaterialProperty>();
}
public void Load(ConfigNode node) {
// add keyword nodes
foreach (var keywordNode in node.GetNodes("KEYWORD")) {
ParseProperty<MaterialKeywordProperty>(keywordNode);
}
// add texture nodes
foreach (var textureNode in node.GetNodes("TEXTURE")) {
ParseProperty<MaterialTextureProperty>(textureNode);
}
// add float nodes
foreach (var floatNode in node.GetNodes("FLOAT")) {
ParseProperty<MaterialTextureProperty>(floatNode);
}
// add color nodes
foreach (var colorNode in node.GetNodes("COLOR")) {
ParseProperty<MaterialColorProperty>(colorNode);
}
}
public void OnDestroy() {
if (_decalMaterial != null) Destroy(_decalMaterial);
if (_previewMaterial != null) Destroy(_previewMaterial);
@ -173,20 +145,6 @@ 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;
@ -209,12 +167,10 @@ 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);
if (newProperty is MaterialTextureProperty {isMain: true} textureProperty) {
if (newProperty is MaterialTextureProperty textureProperty && textureProperty.isMain) {
_mainTexture = textureProperty;
}
@ -224,23 +180,14 @@ namespace ConformalDecals.MaterialProperties {
public void SetShader(string shaderName) {
if (string.IsNullOrEmpty(shaderName)) {
if (_shader == null) {
Logging.Log("Using default decal shader");
shaderName = "ConformalDecals/Decal/Standard";
Debug.Log("Using default decal shader");
shaderName = "ConformalDecals/Paint/Diffuse";
}
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}'");
@ -252,7 +199,7 @@ namespace ConformalDecals.MaterialProperties {
public void UpdateScale(Vector2 scale) {
foreach (var entry in _materialProperties) {
if (entry.Value is MaterialTextureProperty {autoScale: true} textureProperty) {
if (entry.Value is MaterialTextureProperty textureProperty && textureProperty.autoScale) {
textureProperty.SetScale(scale);
}
}
@ -262,8 +209,10 @@ 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 {autoTile: true} textureProperty) {
if (entry.Value is MaterialTextureProperty textureProperty && textureProperty.autoTile) {
textureProperty.SetTile(tile, mainTexSize);
}
}
@ -280,10 +229,23 @@ namespace ConformalDecals.MaterialProperties {
UpdateTile(tile);
}
public void SetOpacity(float opacity) {
DecalMaterial.SetFloat(DecalPropertyIDs._DecalOpacity, opacity);
PreviewMaterial.SetFloat(DecalPropertyIDs._DecalOpacity, opacity);
}
public void SetCutoff(float cutoff) {
DecalMaterial.SetFloat(DecalPropertyIDs._Cutoff, cutoff);
PreviewMaterial.SetFloat(DecalPropertyIDs._Cutoff, cutoff);
}
public void SetWear(float wear) {
DecalMaterial.SetFloat(DecalPropertyIDs._EdgeWearStrength, wear);
}
public void UpdateMaterials() {
foreach (var material in Materials) {
UpdateMaterial(material);
}
UpdateMaterial(DecalMaterial);
UpdateMaterial(PreviewMaterial);
}
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;
[SerializeField] private Texture2D _texture = Texture2D.whiteTexture;
[SerializeField] private bool _hasTile;
[SerializeField] private Rect _tileRect;
@ -19,15 +19,11 @@ namespace ConformalDecals.MaterialProperties {
[SerializeField] private Vector2 _textureOffset;
[SerializeField] private Vector2 _textureScale = Vector2.one;
public Texture2D Texture {
get => _texture;
set => _texture = value;
}
public Texture2D Texture => _texture;
public string TextureUrl {
get => _textureUrl;
set {
if (_textureUrl == value) return; // URL hasnt changed
_texture = LoadTexture(value, isNormal);
_textureUrl = value;
}
@ -42,13 +38,7 @@ namespace ConformalDecals.MaterialProperties {
public Vector2 Dimensions => new Vector2(_texture.width, _texture.height);
public Vector2 MaskedDimensions => _hasTile ? _tileRect.size : Dimensions;
public float AspectRatio {
get {
if (_texture == null) return 1;
if (_textureUrl?.Contains("Squad/Flags") == true) return 0.625f; // squad flags are slightly stretched, so unstretch them
return MaskedHeight / (float) MaskedWidth;
}
}
public float AspectRatio => MaskedHeight / (float) MaskedWidth;
public override void ParseNode(ConfigNode node) {
base.ParseNode(node);
@ -65,29 +55,18 @@ 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 = isNormal ? DecalConfig.BlankNormal : Texture2D.whiteTexture;
_texture = Texture2D.whiteTexture;
throw new NullReferenceException("texture is null, but should not be");
}
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) {
@ -115,7 +94,7 @@ namespace ConformalDecals.MaterialProperties {
}
private static Texture2D LoadTexture(string textureUrl, bool isNormal) {
//Logging.Log($"loading texture '{textureUrl}', isNormalMap = {isNormal}");
Debug.Log($"loading texture '{textureUrl}', isNormalMap = {isNormal}");
if ((string.IsNullOrEmpty(textureUrl) && isNormal) || textureUrl == "Bump") {
return Texture2D.normalTexture;
}

View File

@ -2,9 +2,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using ConformalDecals.MaterialProperties;
using ConformalDecals.Targets;
using ConformalDecals.Util;
using UniLinq;
using UnityEngine;
namespace ConformalDecals {
@ -21,7 +19,7 @@ namespace ConformalDecals {
// CONFIGURABLE VALUES
[KSPField] public string shader = "ConformalDecals/Decal/Standard";
[KSPField] public string shader = "ConformalDecals/Paint/Diffuse";
[KSPField] public string decalFront = "Decal-Front";
[KSPField] public string decalBack = "Decal-Back";
@ -33,7 +31,7 @@ namespace ConformalDecals {
[KSPField] public bool scaleAdjustable = true;
[KSPField] public float defaultScale = 1;
[KSPField] public Vector2 scaleRange = new Vector2(0, 5);
[KSPField] public Vector2 scaleRange = new Vector2(0, 4);
[KSPField] public DecalScaleMode scaleMode = DecalScaleMode.HEIGHT;
@ -62,34 +60,26 @@ namespace ConformalDecals {
// INTERNAL VALUES
[KSPField(guiName = "#LOC_ConformalDecals_gui-scale", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F2", guiUnits = "m"),
UI_FloatRange()]
UI_FloatRange(stepIncrement = 0.05f)]
public float scale = 1.0f;
[KSPField(guiName = "#LOC_ConformalDecals_gui-depth", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F2", guiUnits = "m"),
UI_FloatRange()]
UI_FloatRange(stepIncrement = 0.02f)]
public float depth = 0.2f;
[KSPField(guiName = "#LOC_ConformalDecals_gui-opacity", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
UI_FloatRange()]
UI_FloatRange(stepIncrement = 0.05f)]
public float opacity = 1.0f;
private MaterialFloatProperty _opacityProperty;
[KSPField(guiName = "#LOC_ConformalDecals_gui-cutoff", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
UI_FloatRange()]
UI_FloatRange(stepIncrement = 0.05f)]
public float cutoff = 0.5f;
private MaterialFloatProperty _cutoffProperty;
[KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"),
UI_FloatRange()]
public float wear = 100;
private MaterialFloatProperty _wearProperty;
[KSPField(guiName = "#LOC_ConformalDecals_gui-multiproject", guiActive = false, guiActiveEditor = true, isPersistant = true),
UI_Toggle()]
public bool projectMultiple = true;
[KSPField(isPersistant = true)] public bool projectMultiple; // reserved for future features. do not modify
[KSPField] public MaterialPropertyCollection materialProperties;
@ -106,7 +96,7 @@ namespace ConformalDecals {
private const int DecalQueueMax = 2400;
private static int _decalQueueCounter = -1;
private readonly Dictionary<Part, ProjectionPartTarget> _targets = new Dictionary<Part, ProjectionPartTarget>();
private List<ProjectionTarget> _targets;
private bool _isAttached;
private Matrix4x4 _orthoMatrix;
@ -126,51 +116,145 @@ namespace ConformalDecals {
}
}
// EVENTS
/// <inheritdoc />
public override void OnAwake() {
base.OnAwake();
if (materialProperties == null) {
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
} else {
}
else {
materialProperties = ScriptableObject.Instantiate(materialProperties);
}
_opacityProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_DecalOpacity");
_cutoffProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_Cutoff");
_wearProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_EdgeWearStrength");
}
/// <inheritdoc />
public override void OnLoad(ConfigNode node) {
// Load
this.Log("Loading module");
try {
LoadDecal(node);
} catch (Exception e) {
this.LogException("Error loading decal", e);
// SETUP TRANSFORMS
decalFrontTransform = part.FindModelTransform(decalFront);
if (decalFrontTransform == null) throw new FormatException($"Could not find decalFront transform: '{decalFront}'.");
decalBackTransform = part.FindModelTransform(decalBack);
if (decalBackTransform == null) throw new FormatException($"Could not find decalBack transform: '{decalBack}'.");
decalModelTransform = part.FindModelTransform(decalModel);
if (decalModelTransform == null) throw new FormatException($"Could not find decalModel transform: '{decalModel}'.");
decalProjectorTransform = part.FindModelTransform(decalProjector);
if (decalProjectorTransform == null) throw new FormatException($"Could not find decalProjector transform: '{decalProjector}'.");
decalColliderTransform = part.FindModelTransform(decalCollider);
if (decalColliderTransform == null) throw new FormatException($"Could not find decalCollider transform: '{decalCollider}'.");
// 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.");
updateBackScale = false;
}
else {
backMaterial = backRenderer.material;
if (backMaterial == null) {
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
updateBackScale = false;
}
else {
if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
}
}
}
// PARSE MATERIAL PROPERTIES
// set shader
materialProperties.SetShader(shader);
// add texture nodes
foreach (var textureNode in node.GetNodes("TEXTURE")) {
materialProperties.ParseProperty<MaterialTextureProperty>(textureNode);
}
// add float nodes
foreach (var floatNode in node.GetNodes("FLOAT")) {
materialProperties.ParseProperty<MaterialTextureProperty>(floatNode);
}
// add color nodes
foreach (var colorNode in node.GetNodes("COLOR")) {
materialProperties.ParseProperty<MaterialColorProperty>(colorNode);
}
// 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}'");
}
if (tileRect.x >= 0) {
materialProperties.UpdateTile(tileRect);
}
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);
}
// Setup
try {
SetupDecal();
} catch (Exception e) {
this.LogException("Error setting up decal", e);
UpdateMaterials();
if (HighLogic.LoadedSceneIsEditor) {
UpdateTweakables();
}
if (HighLogic.LoadedSceneIsGame) {
UpdateScale();
}
else {
scale = defaultScale;
depth = defaultDepth;
opacity = defaultOpacity;
cutoff = defaultCutoff;
wear = defaultWear;
}
}
/// <inheritdoc />
public override void OnIconCreate() {
UpdateAll();
UpdateScale();
}
/// <inheritdoc />
public override void OnStart(StartState state) {
this.Log("Starting module");
materialProperties.RenderQueue = DecalQueue;
_boundsRenderer = decalProjectorTransform.GetComponent<MeshRenderer>();
UpdateMaterials();
if (HighLogic.LoadedSceneIsGame) {
// set initial attachment state
if (part.parent == null) {
OnDetach();
}
else {
OnAttach();
}
}
// handle tweakables
if (HighLogic.LoadedSceneIsEditor) {
GameEvents.onEditorPartEvent.Add(OnEditorEvent);
@ -178,38 +262,22 @@ namespace ConformalDecals {
UpdateTweakables();
}
}
/// Called after OnStart is finished for all parts
/// This is mostly used to make sure all B9 variants are already in place for the rest of the vessel
public override void OnStartFinished(StartState state) {
// handle game events
if (HighLogic.LoadedSceneIsGame) {
// set initial attachment state
if (part.parent == null) {
OnDetach();
} else {
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;
if (!selectableInFlight || !DecalConfig.SelectableInFlight) {
decalColliderTransform.GetComponent<Collider>().enabled = false;
_boundsRenderer.enabled = false;
}
if (part.parent == null) part.explode();
}
}
/// Called by Unity when the decal is destroyed
public virtual void OnDestroy() {
// remove GameEvents
if (HighLogic.LoadedSceneIsEditor) {
@ -228,107 +296,64 @@ namespace ConformalDecals {
Destroy(materialProperties);
}
/// Called when the decal's projection and scale is modified through a tweakable
protected void OnProjectionTweakEvent(BaseField field, object obj) {
protected void OnSizeTweakEvent(BaseField field, object obj) {
// scale or depth values have been changed, so update scale
// and update projection matrices if attached
UpdateProjection();
UpdateScale();
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalDecal>();
decal.UpdateProjection();
decal.UpdateScale();
}
}
/// Called when the decal's material is modified through a tweakable
protected void OnMaterialTweakEvent(BaseField field, object obj) {
UpdateMaterials();
materialProperties.SetOpacity(opacity);
materialProperties.SetCutoff(cutoff);
if (useBaseNormal) {
materialProperties.SetWear(wear);
}
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalDecal>();
decal.UpdateMaterials();
decal.materialProperties.SetOpacity(opacity);
decal.materialProperties.SetCutoff(cutoff);
if (useBaseNormal) {
decal.materialProperties.SetWear(wear);
}
}
}
/// Called by KSP when a new variant is applied in the editor
protected void OnVariantApplied(Part eventPart, PartVariant variant) {
if (_isAttached && eventPart != null && (projectMultiple || eventPart == part.parent)) {
_targets.Remove(eventPart);
UpdateProjection();
if (_isAttached && eventPart == part.parent) {
UpdateTargets();
}
}
/// Called by KSP when an editor event occurs
protected void OnEditorEvent(ConstructionEventType eventType, Part eventPart) {
if (this.part != eventPart && !part.symmetryCounterparts.Contains(eventPart)) return;
switch (eventType) {
case ConstructionEventType.PartAttached:
OnPartAttached(eventPart);
OnAttach();
break;
case ConstructionEventType.PartDetached:
OnPartDetached(eventPart);
OnDetach();
break;
case ConstructionEventType.PartOffsetting:
case ConstructionEventType.PartRotating:
OnPartTransformed(eventPart);
UpdateScale();
break;
}
}
/// Called when a part is transformed in the editor
protected void OnPartTransformed(Part eventPart, bool firstcall = true) {
if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) {
// if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this
UpdateProjection();
} else if (_isAttached) {
UpdatePartTarget(eventPart, _boundsRenderer.bounds);
// recursively call for child parts
foreach (var child in eventPart.children) {
OnPartTransformed(child, false);
}
}
}
/// Called when a part is attached in the editor
protected void OnPartAttached(Part eventPart, bool firstcall = true) {
if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) {
// if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this
OnAttach();
} else {
UpdatePartTarget(eventPart, _boundsRenderer.bounds);
// recursively call for child parts
foreach (var child in eventPart.children) {
OnPartAttached(child, false);
}
}
}
/// Called when a part is detached in the editor
protected void OnPartDetached(Part eventPart, bool firstcall = true) {
if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) {
// if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this
OnDetach();
} else if (_isAttached) {
_targets.Remove(eventPart);
// recursively call for child parts
foreach (var child in eventPart.children) {
OnPartDetached(child, false);
}
}
}
/// Called when part `willDie` will be destroyed
protected void OnPartWillDie(Part willDie) {
if (willDie == part.parent && willDie != null) {
if (willDie == part.parent) {
this.Log("Parent part about to be destroyed! Killing decal part.");
part.Die();
} else if (_isAttached && projectMultiple) {
_targets.Remove(willDie);
}
}
/// Called when decal is attached to a new part
protected virtual void OnAttach() {
if (_isAttached) return;
protected void OnAttach() {
if (part.parent == null) {
this.LogError("Attach function called but part has no parent!");
_isAttached = false;
@ -336,7 +361,8 @@ namespace ConformalDecals {
}
_isAttached = true;
_targets.Clear();
this.Log($"Decal attached to {part.parent.partName}");
// hide model
decalModelTransform.gameObject.SetActive(false);
@ -348,12 +374,11 @@ namespace ConformalDecals {
Camera.onPreCull += Render;
UpdateMaterials();
UpdateProjection();
UpdateTargets();
UpdateScale();
}
/// Called when decal is detached from its parent part
protected virtual void OnDetach() {
if (!_isAttached) return;
protected void OnDetach() {
_isAttached = false;
// unhide model
@ -366,100 +391,117 @@ namespace ConformalDecals {
Camera.onPreCull -= Render;
UpdateMaterials();
UpdateProjection();
UpdateScale();
}
// FUNCTIONS
protected void UpdateScale() {
scale = Mathf.Max(0.01f, scale);
depth = Mathf.Max(0.01f, depth);
var aspectRatio = materialProperties.AspectRatio;
Vector2 size;
/// Load any settings from the decal config
protected virtual void LoadDecal(ConfigNode node) {
// PARSE TRANSFORMS
if (!HighLogic.LoadedSceneIsGame) {
decalFrontTransform = part.FindModelTransform(decalFront);
if (decalFrontTransform == null) throw new FormatException($"Could not find decalFront transform: '{decalFront}'.");
switch (scaleMode) {
default:
case DecalScaleMode.HEIGHT:
size = new Vector2(scale, scale * aspectRatio);
break;
case DecalScaleMode.WIDTH:
size = new Vector2(scale / aspectRatio, scale);
break;
case DecalScaleMode.AVERAGE:
var width1 = 2 * scale / (1 + aspectRatio);
size = new Vector2(width1, width1 * aspectRatio);
break;
case DecalScaleMode.AREA:
var width2 = Mathf.Sqrt(scale / aspectRatio);
size = new Vector2(width2, width2 * aspectRatio);
break;
case DecalScaleMode.MINIMUM:
if (aspectRatio > 1) goto case DecalScaleMode.WIDTH;
else goto case DecalScaleMode.HEIGHT;
case DecalScaleMode.MAXIMUM:
if (aspectRatio > 1) goto case DecalScaleMode.HEIGHT;
else goto case DecalScaleMode.WIDTH;
}
decalBackTransform = part.FindModelTransform(decalBack);
if (decalBackTransform == null) throw new FormatException($"Could not find decalBack transform: '{decalBack}'.");
// update material scale
materialProperties.UpdateScale(size);
decalModelTransform = part.FindModelTransform(decalModel);
if (decalModelTransform == null) throw new FormatException($"Could not find decalModel transform: '{decalModel}'.");
if (_isAttached) {
// update orthogonal matrix
_orthoMatrix = Matrix4x4.identity;
_orthoMatrix[0, 3] = 0.5f;
_orthoMatrix[1, 3] = 0.5f;
decalProjectorTransform = part.FindModelTransform(decalProjector);
if (decalProjectorTransform == null) throw new FormatException($"Could not find decalProjector transform: '{decalProjector}'.");
decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth);
decalColliderTransform = part.FindModelTransform(decalCollider);
if (decalColliderTransform == null) throw new FormatException($"Could not find decalCollider transform: '{decalCollider}'.");
// SETUP BACK MATERIAL
if (updateBackScale) {
var backRenderer = decalBackTransform.GetComponent<MeshRenderer>();
if (backRenderer == null) {
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
updateBackScale = false;
} else {
backMaterial = backRenderer.material;
if (backMaterial == null) {
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
updateBackScale = false;
} else {
if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
}
}
// update projection
foreach (var target in _targets) {
target.Project(_orthoMatrix, decalProjectorTransform, _boundsRenderer.bounds, useBaseNormal);
}
}
else {
// rescale preview model
decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2);
// PARSE MATERIAL PROPERTIES
// set shader
materialProperties.SetShader(shader);
materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_BASE_NORMAL").value = useBaseNormal;
materialProperties.Load(node);
// handle texture tiling parameters
var tileString = node.GetValue("tile");
if (!string.IsNullOrEmpty(tileString)) {
var tileValid = ParseExtensions.TryParseRect(tileString, out tileRect);
if (!tileValid) throw new FormatException($"Invalid rect value for tile '{tileString}'");
}
if (tileRect.x >= 0) {
materialProperties.UpdateTile(tileRect);
} else if (tileIndex >= 0) {
materialProperties.UpdateTile(tileIndex, tileSize);
// update back material scale
if (updateBackScale) {
backMaterial.SetTextureScale(PropertyIDs._MainTex, new Vector2(size.x * backTextureBaseScale.x, size.y * backTextureBaseScale.y));
}
}
}
/// Setup decal by calling update functions relevent for the current situation
protected virtual void SetupDecal() {
if (HighLogic.LoadedSceneIsEditor) {
// Update tweakables in editor mode
UpdateTweakables();
protected void UpdateMaterials() {
materialProperties.UpdateMaterials();
materialProperties.SetOpacity(opacity);
materialProperties.SetCutoff(cutoff);
if (useBaseNormal) {
materialProperties.SetWear(wear);
}
if (HighLogic.LoadedSceneIsGame) {
UpdateAll();
} else {
scale = defaultScale;
depth = defaultDepth;
opacity = defaultOpacity;
cutoff = defaultCutoff;
wear = defaultWear;
_decalMaterial = materialProperties.DecalMaterial;
_previewMaterial = materialProperties.PreviewMaterial;
UpdateAll();
if (!_isAttached) decalFrontTransform.GetComponent<MeshRenderer>().material = _previewMaterial;
}
// QUEUE PART FOR ICON FIXING IN VAB
DecalIconFixer.QueuePart(part.name);
protected void UpdateTargets() {
if (_targets == null) {
_targets = new List<ProjectionTarget>();
}
else {
_targets.Clear();
}
// find all valid renderers
var renderers = part.parent.FindModelComponents<MeshRenderer>();
foreach (var renderer in renderers) {
// skip disabled renderers
if (renderer.gameObject.activeInHierarchy == false) continue;
// skip blacklisted shaders
if (DecalConfig.IsBlacklisted(renderer.material.shader)) continue;
var meshFilter = renderer.GetComponent<MeshFilter>();
if (meshFilter == null) continue; // object has a meshRenderer with no filter, invalid
var mesh = meshFilter.mesh;
if (mesh == null) continue; // object has a null mesh, invalid
// create new ProjectionTarget to represent the renderer
var target = new ProjectionTarget(renderer, mesh);
// add the target to the list
_targets.Add(target);
}
}
/// Update decal editor tweakables
protected virtual void UpdateTweakables() {
protected void UpdateTweakables() {
// setup tweakable fields
var scaleField = Fields[nameof(scale)];
var depthField = Fields[nameof(depth)];
var opacityField = Fields[nameof(opacity)];
var cutoffField = Fields[nameof(cutoff)];
var wearField = Fields[nameof(wear)];
var multiprojectField = Fields[nameof(projectMultiple)];
scaleField.guiActiveEditor = scaleAdjustable;
depthField.guiActiveEditor = depthAdjustable;
@ -476,8 +518,8 @@ namespace ConformalDecals {
var scaleEditor = (UI_FloatRange) scaleField.uiControlEditor;
scaleEditor.minValue = minValue;
scaleEditor.maxValue = maxValue;
scaleEditor.stepIncrement = 0.01f; //1cm
scaleEditor.onFieldChanged = OnProjectionTweakEvent;
scaleEditor.stepIncrement = (maxValue - minValue) / steps;
scaleEditor.onFieldChanged = OnSizeTweakEvent;
}
if (depthAdjustable) {
@ -487,8 +529,8 @@ namespace ConformalDecals {
var depthEditor = (UI_FloatRange) depthField.uiControlEditor;
depthEditor.minValue = minValue;
depthEditor.maxValue = maxValue;
depthEditor.stepIncrement = 0.01f; //1cm
depthEditor.onFieldChanged = OnProjectionTweakEvent;
depthEditor.stepIncrement = (maxValue - minValue) / steps;
depthEditor.onFieldChanged = OnSizeTweakEvent;
}
if (opacityAdjustable) {
@ -525,127 +567,13 @@ namespace ConformalDecals {
wearEditor.stepIncrement = (maxValue - minValue) / steps;
wearEditor.onFieldChanged = OnMaterialTweakEvent;
}
var multiprojectEditor = (UI_Toggle) multiprojectField.uiControlEditor;
multiprojectEditor.onFieldChanged = OnProjectionTweakEvent;
}
/// Updates materials, scale and targets
protected virtual void UpdateAll() {
UpdateMaterials();
UpdateProjection();
}
/// Update decal materials
protected virtual void UpdateMaterials() {
_opacityProperty.value = opacity;
_cutoffProperty.value = cutoff;
_wearProperty.value = wear;
materialProperties.UpdateMaterials();
_decalMaterial = materialProperties.DecalMaterial;
_previewMaterial = materialProperties.PreviewMaterial;
if (!_isAttached) decalFrontTransform.GetComponent<MeshRenderer>().material = _previewMaterial;
}
/// Update decal scale and projection
protected void UpdateProjection() {
// Update scale and depth
scale = Mathf.Max(0.01f, scale);
depth = Mathf.Max(0.01f, depth);
var aspectRatio = Mathf.Max(0.01f, materialProperties.AspectRatio);
Vector2 size;
switch (scaleMode) {
default:
case DecalScaleMode.HEIGHT:
size = new Vector2(scale / aspectRatio, scale);
break;
case DecalScaleMode.WIDTH:
size = new Vector2(scale, scale * aspectRatio);
break;
case DecalScaleMode.AVERAGE:
var width1 = 2 * scale / (1 + aspectRatio);
size = new Vector2(width1, width1 * aspectRatio);
break;
case DecalScaleMode.AREA:
var width2 = Mathf.Sqrt(scale / aspectRatio);
size = new Vector2(width2, width2 * aspectRatio);
break;
case DecalScaleMode.MINIMUM:
if (aspectRatio > 1) goto case DecalScaleMode.WIDTH;
else goto case DecalScaleMode.HEIGHT;
case DecalScaleMode.MAXIMUM:
if (aspectRatio > 1) goto case DecalScaleMode.HEIGHT;
else goto case DecalScaleMode.WIDTH;
}
// update material scale
materialProperties.UpdateScale(size);
decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth);
if (_isAttached) {
// update orthogonal matrix
_orthoMatrix = Matrix4x4.identity;
_orthoMatrix[0, 3] = 0.5f;
_orthoMatrix[1, 3] = 0.5f;
var projectionBounds = _boundsRenderer.bounds;
// disable all targets
foreach (var target in _targets.Values) {
target.enabled = false;
}
// collect list of potential targets
IEnumerable<Part> targetParts;
if (projectMultiple) {
targetParts = HighLogic.LoadedSceneIsFlight ? part.vessel.parts : EditorLogic.fetch.ship.parts;
} else {
targetParts = new[] {part.parent};
}
foreach (var targetPart in targetParts) {
UpdatePartTarget(targetPart, projectionBounds);
}
} else {
// rescale preview model
decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2);
// update back material scale
if (updateBackScale) {
backMaterial.SetTextureScale(PropertyIDs._MainTex, new Vector2(size.x * backTextureBaseScale.x, size.y * backTextureBaseScale.y));
}
}
}
protected void UpdatePartTarget(Part targetPart, Bounds projectionBounds) {
if (targetPart.GetComponent<ModuleConformalDecal>() != null) return; // skip other decals
if (!_targets.TryGetValue(targetPart, out var target)) {
var rendererList = targetPart.FindModelComponents<MeshRenderer>();
if (rendererList.Any(o => projectionBounds.Intersects(o.bounds))) {
target = new ProjectionPartTarget(targetPart, useBaseNormal);
_targets.Add(targetPart, target);
} else {
return;
}
}
target.Project(_orthoMatrix, decalProjectorTransform, projectionBounds);
}
/// Render the decal
public void Render(Camera camera) {
if (!_isAttached) return;
// render on each target object
foreach (var target in _targets.Values) {
foreach (var target in _targets) {
target.Render(_decalMaterial, part.mpb, camera);
}
}

View File

@ -1,3 +1,4 @@
using ConformalDecals.Util;
using UnityEngine;
namespace ConformalDecals {
@ -18,103 +19,92 @@ namespace ConformalDecals {
return string.IsNullOrEmpty(part.flagURL) ? HighLogic.CurrentGame.flagURL : part.flagURL;
}
// If we are not in game, use the default flag (for icon rendering)
return DefaultFlag;
}
}
public override void OnStart(StartState state) {
if (HighLogic.LoadedSceneIsEditor) {
// Register flag change event
GameEvents.onMissionFlagSelect.Add(OnEditorFlagSelected);
public override void OnLoad(ConfigNode node) {
base.OnLoad(node);
// Register reset button event
Events[nameof(ResetFlagButton)].guiActiveEditor = useCustomFlag;
if (useCustomFlag) {
SetFlag(flagUrl);
}
else {
SetFlag(MissionFlagUrl);
}
}
public override void OnStart(StartState state) {
base.OnStart(state);
if (HighLogic.LoadedSceneIsGame) {
GameEvents.onMissionFlagSelect.Add(OnEditorFlagSelected);
}
base.OnStart(state);
if (HighLogic.LoadedSceneIsEditor) {
Events[nameof(ResetFlag)].guiActiveEditor = useCustomFlag;
}
if (useCustomFlag) {
SetFlag(flagUrl);
}
else {
SetFlag(MissionFlagUrl);
}
}
public override void OnDestroy() {
if (HighLogic.LoadedSceneIsEditor) {
// Unregister flag change event
GameEvents.onMissionFlagSelect.Remove(OnEditorFlagSelected);
}
GameEvents.onMissionFlagSelect.Remove(SetFlag);
base.OnDestroy();
}
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
public void SelectFlagButton() {
// Button for selecting a flag
// This is a bit of a hack to bring up the stock flag selection menu
// When its done, it calls OnCustomFlagSelected()
// ReSharper disable once PossibleNullReferenceException
public void SelectFlag() {
var flagBrowser = (Instantiate((Object) (new FlagBrowserGUIButton(null, null, null, null)).FlagBrowserPrefab) as GameObject).GetComponent<FlagBrowser>();
flagBrowser.OnFlagSelected = OnCustomFlagSelected;
}
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-reset-flag")]
public void ResetFlagButton() {
// we are no longer using a custom flag, so instead use the mission or agency flag
SetFlag("Mission", false, true);
public void ResetFlag() {
SetFlag(MissionFlagUrl);
SetFlagSymmetryCounterparts(MissionFlagUrl);
// disable the reset button, since it no longer makes sense
Events[nameof(ResetFlagButton)].guiActiveEditor = false;
useCustomFlag = false;
Events[nameof(ResetFlag)].guiActiveEditor = false;
}
private void OnCustomFlagSelected(FlagBrowser.FlagEntry newFlagEntry) {
// Callback for when a flag is selected in the menu spawned by SelectFlag()
SetFlag(newFlagEntry.textureInfo.name);
SetFlagSymmetryCounterparts(newFlagEntry.textureInfo.name);
// we are now using a custom flag with the URL of the new flag entry
SetFlag(newFlagEntry.textureInfo.name, true, true);
// make sure the reset button is now available
Events[nameof(ResetFlagButton)].guiActiveEditor = true;
useCustomFlag = true;
Events[nameof(ResetFlag)].guiActiveEditor = true;
}
private void OnEditorFlagSelected(string newFlagUrl) {
// Callback for when a new mission flag is selected in the editor
// Since this callback is called for all modules, we only need to update this module
// Updating symmetry counterparts would be redundent
// if we are using the mission flag, update it. otherwise ignore the call
if (!useCustomFlag) {
SetFlag(newFlagUrl, false, false);
SetFlag(newFlagUrl);
SetFlagSymmetryCounterparts(newFlagUrl);
}
}
private void SetFlag(string newFlagUrl, bool isCustom, bool recursive) {
// Function to set the flag URL, the custom flag
// Set values
private void SetFlag(string newFlagUrl) {
this.Log($"Loading flag texture '{newFlagUrl}'.");
flagUrl = newFlagUrl;
useCustomFlag = isCustom;
// Update material and projection
UpdateAll();
// Update symmetry counterparts if called to
if (recursive) {
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalFlag>();
decal.SetFlag(newFlagUrl, isCustom, false);
}
}
materialProperties.AddOrGetTextureProperty("_Decal", true).TextureUrl = newFlagUrl;
UpdateMaterials();
UpdateScale();
}
protected override void UpdateMaterials() {
// get the decal material property for the decal texture
var textureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
private void SetFlagSymmetryCounterparts(string newFlagUrl) {
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalFlag>();
if (useCustomFlag) { // set the texture to the custom flag
textureProperty.TextureUrl = flagUrl;
} else { // set the texture to the mission flag
textureProperty.TextureUrl = MissionFlagUrl;
decal.SetFlag(newFlagUrl);
decal.useCustomFlag = useCustomFlag;
}
base.UpdateMaterials();
}
}
}

View File

@ -1,302 +0,0 @@
using System.Collections;
using System.Net;
using ConformalDecals.MaterialProperties;
using ConformalDecals.Text;
using ConformalDecals.UI;
using ConformalDecals.Util;
using TMPro;
using UniLinq;
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 DecalText _currentText;
// EVENTS
/// <inheritdoc />
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) {
text = newText;
font = newFont;
style = newStyle;
vertical = newVertical;
lineSpacing = newLineSpacing;
charSpacing = newCharSpacing;
UpdateAll();
foreach (var decal in part.symmetryCounterparts.Select(o => o.GetComponent<ModuleConformalText>())) {
decal.text = newText;
decal.font = newFont;
decal.style = newStyle;
decal.vertical = newVertical;
decal.lineSpacing = newLineSpacing;
decal.charSpacing = newCharSpacing;
decal.UpdateAll();
}
}
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();
}
// FUNCTIONS
protected override void LoadDecal(ConfigNode node) {
base.LoadDecal(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");
}
protected override void SetupDecal() {
if (HighLogic.LoadedSceneIsGame) {
// For some reason text rendering fails on the first frame of a scene, so this is my workaround
StartCoroutine(UpdateTextLate());
} else {
base.SetupDecal();
}
}
private IEnumerator UpdateTextLate() {
yield return null;
UpdateAll();
}
protected override void UpdateMaterials() {
// Render text
var newText = new DecalText(text, font, style, vertical, lineSpacing, charSpacing);
if (newText != _currentText) {
var output = TextRenderer.UpdateText(_currentText, newText);
// update the _currentText state variable
// this is the ONLY place this variable should be set! otherwise the current state is lost
_currentText = newText;
_decalTextureProperty.Texture = output.Texture;
_decalTextureProperty.SetTile(output.Window);
}
_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

@ -0,0 +1,68 @@
using UnityEngine;
using UnityEngine.Rendering;
namespace ConformalDecals {
public class ProjectionTarget {
// Target object data
public readonly Transform target;
private readonly Renderer _targetRenderer;
private readonly Mesh _targetMesh;
private bool _projectionEnabled;
// property block
private readonly MaterialPropertyBlock _decalMPB;
public ProjectionTarget(MeshRenderer targetRenderer, Mesh targetMesh) {
target = targetRenderer.transform;
_targetRenderer = targetRenderer;
_targetMesh = targetMesh;
_decalMPB = new MaterialPropertyBlock();
}
public void Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectorBounds, bool useBaseNormal) {
if (projectorBounds.Intersects(_targetRenderer.bounds)) {
_projectionEnabled = true;
var targetMaterial = _targetRenderer.sharedMaterial;
var projectorToTargetMatrix = target.worldToLocalMatrix * projector.localToWorldMatrix;
var projectionMatrix = orthoMatrix * projectorToTargetMatrix.inverse;
var decalNormal = projectorToTargetMatrix.MultiplyVector(Vector3.back).normalized;
var decalTangent = projectorToTargetMatrix.MultiplyVector(Vector3.right).normalized;
_decalMPB.SetMatrix(DecalPropertyIDs._ProjectionMatrix, projectionMatrix);
_decalMPB.SetVector(DecalPropertyIDs._DecalNormal, decalNormal);
_decalMPB.SetVector(DecalPropertyIDs._DecalTangent, decalTangent);
if (useBaseNormal && targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) {
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap));
var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap);
var normalOffset = targetMaterial.GetTextureOffset(DecalPropertyIDs._BumpMap);
_decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y));
}
else {
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal);
}
}
else {
_projectionEnabled = false;
}
}
public bool Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
if (_projectionEnabled) {
_decalMPB.SetFloat(PropertyIDs._RimFalloff, partMPB.GetFloat(PropertyIDs._RimFalloff));
_decalMPB.SetColor(PropertyIDs._RimColor, partMPB.GetColor(PropertyIDs._RimColor));
Graphics.DrawMesh(_targetMesh, target.localToWorldMatrix, decalMaterial, 0, camera, 0, _decalMPB, ShadowCastingMode.Off, true);
return true;
}
return false;
}
}
}

View File

@ -1 +1,38 @@
[assembly: KSPAssembly("ConformalDecals", 0, 2)]
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)]

View File

@ -1,8 +0,0 @@
using UnityEngine;
namespace ConformalDecals.Targets {
public interface IProjectionTarget {
bool Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectionBounds);
void Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera);
}
}

View File

@ -1,93 +0,0 @@
using UnityEngine;
using UnityEngine.Rendering;
namespace ConformalDecals.Targets {
public class ProjectionMeshTarget : IProjectionTarget {
public const string NodeName = "MESH_TARGET";
// enabled flag
public bool enabled;
// Target object data
public readonly Transform target;
public readonly Transform root;
public readonly Mesh mesh;
public readonly MeshRenderer renderer;
// Projection data
private Matrix4x4 _decalMatrix;
private Vector3 _decalNormal;
private Vector3 _decalTangent;
// property block
private readonly MaterialPropertyBlock _decalMPB;
public ProjectionMeshTarget(Transform target, Transform root, MeshRenderer renderer, Mesh mesh, bool useBaseNormal) {
this.root = root;
this.target = target;
this.renderer = renderer;
this.mesh = mesh;
_decalMPB = new MaterialPropertyBlock();
SetNormalMap(renderer.sharedMaterial, useBaseNormal);
}
private void SetNormalMap(Material targetMaterial, bool useBaseNormal) {
if (useBaseNormal && targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) {
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap));
var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap);
var normalOffset = targetMaterial.GetTextureOffset(DecalPropertyIDs._BumpMap);
_decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y));
}
else {
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal);
}
}
public bool Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectionBounds) {
if (projectionBounds.Intersects(renderer.bounds)) {
enabled = true;
var projectorToTargetMatrix = target.worldToLocalMatrix * projector.localToWorldMatrix;
_decalMatrix = orthoMatrix * projectorToTargetMatrix.inverse;
_decalNormal = projectorToTargetMatrix.MultiplyVector(Vector3.back).normalized;
_decalTangent = projectorToTargetMatrix.MultiplyVector(Vector3.right).normalized;
_decalMPB.SetMatrix(DecalPropertyIDs._ProjectionMatrix, _decalMatrix);
_decalMPB.SetVector(DecalPropertyIDs._DecalNormal, _decalNormal);
_decalMPB.SetVector(DecalPropertyIDs._DecalTangent, _decalTangent);
}
else {
enabled = false;
}
return enabled;
}
public void Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
if (!enabled) return;
_decalMPB.SetFloat(PropertyIDs._RimFalloff, partMPB.GetFloat(PropertyIDs._RimFalloff));
_decalMPB.SetColor(PropertyIDs._RimColor, partMPB.GetColor(PropertyIDs._RimColor));
Graphics.DrawMesh(mesh, target.localToWorldMatrix, decalMaterial, 0, camera, 0, _decalMPB, ShadowCastingMode.Off, true);
}
public static bool ValidateTarget(Transform target, MeshRenderer renderer, MeshFilter filter) {
if (renderer == null) return false;
if (filter == null) return false;
if (!target.gameObject.activeInHierarchy) return false;
var material = renderer.material;
if (material == null) return false;
if (DecalConfig.IsBlacklisted(material.shader)) return false;
if (filter.sharedMesh == null) return false;
return true;
}
}
}

View File

@ -1,50 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
namespace ConformalDecals.Targets {
public class ProjectionPartTarget : IProjectionTarget {
public const string NodeName = "PART_TARGET";
// enabled flag
public bool enabled;
public readonly Part part;
public readonly List<ProjectionMeshTarget> meshTargets = new List<ProjectionMeshTarget>();
public ProjectionPartTarget(Part part, bool useBaseNormal) {
this.part = part;
foreach (var renderer in part.FindModelComponents<MeshRenderer>()) {
var target = renderer.transform;
var filter = target.GetComponent<MeshFilter>();
// check if the target has any missing data
if (!ProjectionMeshTarget.ValidateTarget(target, renderer, filter)) continue;
// create new ProjectionTarget to represent the renderer
var projectionTarget = new ProjectionMeshTarget(target, part.transform, renderer, filter.sharedMesh, useBaseNormal);
// add the target to the list
meshTargets.Add(projectionTarget);
}
}
public bool Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectionBounds) {
enabled = false;
foreach (var meshTarget in meshTargets) {
enabled |= meshTarget.Project(orthoMatrix, projector, projectionBounds);
}
return enabled;
}
public void Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
if (!enabled) return;
foreach (var target in meshTargets) {
target.Render(decalMaterial, partMPB, camera);
}
}
}
}

View File

@ -0,0 +1,34 @@
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

@ -1,117 +0,0 @@
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 static DecalFont Parse(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) {
if (node == null) throw new ArgumentNullException(nameof(node));
if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets));
var font = ScriptableObject.CreateInstance<DecalFont>();
var name = ParseUtil.ParseString(node, "name");
var fontAsset = fontAssets.First(o => o.name == name);
if (fontAsset == null) {
throw new FormatException($"Could not find font asset named {name}");
}
font._fontAsset = fontAsset;
font._title = ParseUtil.ParseString(node, "title", true, name);
font._fontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true);
font._fontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true);
return font;
}
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() { }
public override string ToString() {
return _title;
}
}
}

View File

@ -1,94 +0,0 @@
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);
}
public override string ToString() {
return $"{nameof(_text)}: {_text}, {nameof(_font)}: {_font}, {nameof(_style)}: {_style}, {nameof(_vertical)}: {_vertical}, {nameof(_lineSpacing)}: {_lineSpacing}, {nameof(_charSpacing)}: {_charSpacing}";
}
}
}

View File

@ -1,37 +0,0 @@
using System.IO;
using System.Collections;
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

@ -1,20 +0,0 @@
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
public int UserCount { get; set; }
public TextRenderOutput(Texture2D texture, Rect window) {
Texture = texture;
Window = window;
}
}
}

View File

@ -1,214 +0,0 @@
using System;
using System.Collections.Generic;
using ConformalDecals.Util;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using Object = UnityEngine.Object;
namespace ConformalDecals.Text {
/// Class handing text rendering.
public static class TextRenderer {
/// 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;
private const string ShaderName = "ConformalDecals/Text Blit";
private const int MaxTextureSize = 4096;
private const float FontSize = 100;
private const float PixelDensity = 5;
private static Shader _blitShader;
private static Texture2D _blankTexture;
private static readonly Dictionary<DecalText, TextRenderOutput> RenderCache = new Dictionary<DecalText, TextRenderOutput>();
/// Update text immediately without using job queue
public static TextRenderOutput UpdateText(DecalText oldText, DecalText newText) {
if (newText == null) throw new ArgumentNullException(nameof(newText));
if (!(oldText is null)) UnregisterText(oldText);
// now that all old references are handled, begin rendering the new output
if (!RenderCache.TryGetValue(newText, out var renderOutput)) {
renderOutput = RenderText(newText);
RenderCache.Add(newText, renderOutput);
}
renderOutput.UserCount++;
return renderOutput;
}
/// Unregister a user of a piece of text
public static void UnregisterText(DecalText text) {
if (text == null) throw new ArgumentNullException(nameof(text));
if (RenderCache.TryGetValue(text, out var renderedText)) {
renderedText.UserCount--;
if (renderedText.UserCount <= 0) {
RenderCache.Remove(text);
var texture = renderedText.Texture;
if (texture != _blankTexture) Object.Destroy(texture);
}
}
}
/// Render a piece of text to a given texture
public static TextRenderOutput RenderText(DecalText text) {
if (text == null) throw new ArgumentNullException(nameof(text));
var tmpObject = new GameObject("Text Mesh Pro renderer");
var tmp = tmpObject.AddComponent<TextMeshPro>();
// 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 = tmpObject.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] = Object.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.LogError("No text present or error in texture size calculation. Aborting.");
Object.Destroy(tmpObject);
return new TextRenderOutput(_blankTexture, 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
var texture = new Texture2D(textureSize.x, textureSize.y, textTextureFormat, false);
// 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 = RenderTexture.GetTemporary(textureSize.x, textureSize.y, 0, textRenderTextureFormat, RenderTextureReadWrite.Linear);
// 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 RENDERTEX INTO TEXTURE
var prevRT = RenderTexture.active;
RenderTexture.active = renderTex;
texture.ReadPixels(new Rect(0, 0, textureSize.x, textureSize.y), 0, 0, false);
texture.Apply(false, true);
RenderTexture.active = prevRT;
GL.PopMatrix();
// RELEASE RENDERTEX
RenderTexture.ReleaseTemporary(renderTex);
// DESTROY THE RENDERER OBJECT
Object.Destroy(tmpObject);
return new TextRenderOutput(texture, window);
}
/// Setup shader and texture
public static void ModuleManagerPostLoad() {
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.");
}
_blankTexture = Texture2D.blackTexture;
_blitShader = Shabby.Shabby.FindShader(ShaderName);
if (_blitShader == null) Logging.LogError($"Could not find text blit shader named '{ShaderName}'");
}
}
}

View File

@ -1,33 +0,0 @@
using System;
using ConformalDecals.Util;
using UnityEngine;
namespace ConformalDecals.Tweakables {
[AttributeUsage(AttributeTargets.Field)]
public abstract class TweakableData : System.Attribute, ISerializationCallbackReceiver {
public string name;
public bool adjustable = true;
public string adjustableKey;
// public string fieldChangedCallback;
public bool useSymmetry = true;
protected TweakableData(string name) {
this.name = name;
adjustableKey = name + "Adjustable";
}
public virtual void Load(ConfigNode node) {
ParseUtil.ParseBoolIndirect(ref adjustable, node, adjustableKey);
}
public virtual void Apply(BaseField baseField, PartModule module) {
baseField.guiActiveEditor = adjustable;
}
public void OnBeforeSerialize() { }
public void OnAfterDeserialize() { }
}
}

View File

@ -1,30 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UniLinq;
using UnityEngine;
namespace ConformalDecals.Tweakables {
public class TweakableDataCollection : IEnumerable<TweakableData>, ISerializationCallbackReceiver {
public readonly Dictionary<string, TweakableData> tweakables = new Dictionary<string, TweakableData>();
[SerializeField] private TweakableData[] _serializedTweakables;
public IEnumerator<TweakableData> GetEnumerator() {
return tweakables.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
public void OnBeforeSerialize() {
_serializedTweakables = tweakables.Values.ToArray();
}
public void OnAfterDeserialize() {
foreach (var tweakable in _serializedTweakables) {
tweakables.Add(tweakable.name, tweakable);
}
}
}
}

View File

@ -1,56 +0,0 @@
using System;
using ConformalDecals.Util;
using UnityEngine;
namespace ConformalDecals.Tweakables {
[AttributeUsage(AttributeTargets.Field)]
public class TweakableSlider : TweakableData {
// The default value for the slider
public float defaultValue;
public string defaultValueKey;
// The range of the slider as a vector of <min, max>
public float min = 0;
public float max = 1;
public string rangeKey;
// The step size of the slider
public float step;
public string stepKey;
public TweakableSlider(string name) : base(name) {
defaultValueKey = name + "Default";
rangeKey = name + "Range";
stepKey = name + "Step";
}
public override void Load(ConfigNode node) {
base.Load(node);
var range = new Vector2(min, max);
ParseUtil.ParseVector2Indirect(ref range, node, rangeKey);
min = Mathf.Max(Mathf.Epsilon, range.x);
max = Mathf.Max(min, range.y);
ParseUtil.ParseFloatIndirect(ref step, node, stepKey);
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
ParseUtil.ParseFloatIndirect(ref defaultValue, node, defaultValueKey);
}
}
public override void Apply(BaseField baseField, PartModule module) {
base.Apply(baseField, module);
var uiControlEditor = (UI_FloatRange) baseField.uiControlEditor;
uiControlEditor.minValue = min;
uiControlEditor.maxValue = max;
uiControlEditor.stepIncrement = step;
// Set the default value on first load
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
baseField.FieldInfo.SetValue(module, defaultValue);
}
}
}
}

View File

@ -1,34 +0,0 @@
using System;
using System.Reflection;
using ConformalDecals.Util;
namespace ConformalDecals.Tweakables {
[AttributeUsage(AttributeTargets.Field)]
public class TweakableToggle : TweakableData {
// The default value for the toggle
public bool defaultValue;
public string defaultValueKey;
public TweakableToggle(string name) : base(name) {
defaultValueKey = name + "Default";
}
public override void Load(ConfigNode node) {
base.Load(node);
// Set the default value on first load
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
ParseUtil.ParseBoolIndirect(ref defaultValue, node, defaultValueKey);
}
}
public override void Apply(BaseField baseField, PartModule module) {
base.Apply(baseField, module);
// Set the default value on first load
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
baseField.FieldInfo.SetValue(module, defaultValue);
}
}
}
}

View File

@ -1,176 +0,0 @@
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

@ -1,63 +0,0 @@
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

@ -1,79 +0,0 @@
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;
}
}
}

Some files were not shown because too many files have changed in this diff Show More