diff --git a/.gitignore b/.gitignore index ed40554..452d783 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,8 @@ # Unity Project Directories Assets/* -!Assets/Shaders/ -!Assets/Textures/ -!Assets/Scripts/ -!Assets/UI/ -!Assets/ConformalDecals/ +!Assets/ConformalDecals +Assets/ConformalDecals/Fonts +Assets/ConformalDecals/Parts KSP/ Library/ Logs/ @@ -12,6 +10,9 @@ Packages/ ProjectSettings/ Temp/ +# Autogenerated shaders +Assets/ConformalDecals/Shaders/Generated/*.shader + # Unity Assetbundle Manifest Files GameData/ConformalDecals/Resources/Resources GameData/ConformalDecals/Resources/*.manifest @@ -41,9 +42,6 @@ ExportedObj/ *.opendb *.VC.db -# Autogenerated shaders -Assets/Shaders/Generated/*.shader - # Binaries and support files Source/ConformalDecals/dlls Source/ConformalDecals/bin @@ -58,3 +56,4 @@ Source/ConformalDecals/bin obj *.swp @thumbs + diff --git a/Assets/Shaders/DecalBack.shader b/Assets/ConformalDecals/Shaders/DecalBack.shader similarity index 100% rename from Assets/Shaders/DecalBack.shader rename to Assets/ConformalDecals/Shaders/DecalBack.shader diff --git a/Assets/Shaders/DecalsCommon.cginc b/Assets/ConformalDecals/Shaders/DecalsCommon.cginc similarity index 95% rename from Assets/Shaders/DecalsCommon.cginc rename to Assets/ConformalDecals/Shaders/DecalsCommon.cginc index 81de188..7d57353 100644 --- a/Assets/Shaders/DecalsCommon.cginc +++ b/Assets/ConformalDecals/Shaders/DecalsCommon.cginc @@ -1,6 +1,4 @@ #ifndef DECALS_COMMON_INCLUDED -// Upgrade NOTE: excluded shader from DX11; has structs without semantics (struct v2f members screenUV) -#pragma exclude_renderers d3d11 #define DECALS_COMMON_INCLUDED #include "AutoLight.cginc" @@ -117,10 +115,6 @@ struct v2f #ifdef UNITY_PASS_FORWARDADD UNITY_LIGHTING_COORDS(5,6) #endif //UNITY_PASS_FORWARDADD - - #ifdef UNITY_PASS_DEFERRED - float3 screenUV : TEXCOORD5; - #endif }; @@ -138,6 +132,8 @@ inline float CalcMipLevel(float2 texture_coord) { return 0.5 * log2(delta_max_sqr); } +// Decal bounds distance function +// takes in a world position, world normal, and projector normal and outputs a unitless signed distance from the 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 @@ -212,14 +208,6 @@ v2f vert(appdata_decal v) // pass shadow and, possibly, light cookie coordinates to pixel shader UNITY_TRANSFER_LIGHTING(o, 0.0); - - #ifdef UNITY_PASS_DEFERRED - o.screenUV = o.pos.xyw; - - // Correct flip when rendering with a flipped projection matrix. - // (I've observed this differing between the Unity scene & game views) - o.screenUV.y *= _ProjectionParams.x; - #endif return o; } @@ -279,14 +267,21 @@ SurfaceOutput frag_common(v2f IN, out float3 viewDir, out UnityGI gi) { // initialize surface output o.Albedo = 0.0; o.Emission = 0.0; - o.Specular = 0.0; - o.Alpha = 0.0; + o.Specular = 0.4; + o.Alpha = _DecalOpacity; o.Gloss = 0.0; o.Normal = fixed3(0,0,1); // call surface function surf(i, o); + // apply KSP fog. In the deferred pass this is a no-op + o.Albedo = UnderwaterFog(i.worldPosition, o.Albedo).rgb; + + // apply KSP rim lighting + half rim = 1.0 - saturate(dot(normalize(i.viewDir), o.Normal)); + o.Emission += o.Emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a; + // compute world normal float3 worldN; worldN.x = dot(_unity_tbn_0, o.Normal); diff --git a/Assets/Shaders/Generated/StandardDecal.cginc b/Assets/ConformalDecals/Shaders/Generated/StandardDecal.cginc similarity index 77% rename from Assets/Shaders/Generated/StandardDecal.cginc rename to Assets/ConformalDecals/Shaders/Generated/StandardDecal.cginc index f8c2e63..982a744 100644 --- a/Assets/Shaders/Generated/StandardDecal.cginc +++ b/Assets/ConformalDecals/Shaders/Generated/StandardDecal.cginc @@ -3,15 +3,13 @@ void surf(DecalSurfaceInput IN, inout SurfaceOutput o) { float4 color = tex2D(_Decal, IN.uv_decal); + o.Albedo = color.rgb; o.Specular = 0.4; o.Gloss = _Shininess; - 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 @@ -24,10 +22,6 @@ void surf(DecalSurfaceInput IN, inout SurfaceOutput o) { o.Specular = specular; #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 diff --git a/Assets/Shaders/Generated/StandardDecal.shader.template b/Assets/ConformalDecals/Shaders/Generated/StandardDecal.shader.template similarity index 97% rename from Assets/Shaders/Generated/StandardDecal.shader.template rename to Assets/ConformalDecals/Shaders/Generated/StandardDecal.shader.template index 64950c2..770904d 100644 --- a/Assets/Shaders/Generated/StandardDecal.shader.template +++ b/Assets/ConformalDecals/Shaders/Generated/StandardDecal.shader.template @@ -136,6 +136,10 @@ #pragma multi_compile_local __ DECAL_BASE_NORMAL //{{ self.pragmas() }} + //{% block prepass_skip_variants %} + #pragma skip_variants DECAL_SPECMAP DECAL_EMISSIVE + //{% endblock %} + #define DECAL_PREPASS //{{ self.body() }} diff --git a/Assets/Shaders/LegacyToStandard.cginc b/Assets/ConformalDecals/Shaders/LegacyToStandard.cginc similarity index 100% rename from Assets/Shaders/LegacyToStandard.cginc rename to Assets/ConformalDecals/Shaders/LegacyToStandard.cginc diff --git a/Assets/Shaders/LightingKSP.cginc b/Assets/ConformalDecals/Shaders/LightingKSP.cginc similarity index 100% rename from Assets/Shaders/LightingKSP.cginc rename to Assets/ConformalDecals/Shaders/LightingKSP.cginc diff --git a/Assets/Shaders/LightingKSPDeferred.cginc b/Assets/ConformalDecals/Shaders/LightingKSPDeferred.cginc similarity index 100% rename from Assets/Shaders/LightingKSPDeferred.cginc rename to Assets/ConformalDecals/Shaders/LightingKSPDeferred.cginc diff --git a/Assets/Shaders/SDF.cginc b/Assets/ConformalDecals/Shaders/SDF.cginc similarity index 100% rename from Assets/Shaders/SDF.cginc rename to Assets/ConformalDecals/Shaders/SDF.cginc diff --git a/Assets/Shaders/SelectionGlow.shader b/Assets/ConformalDecals/Shaders/SelectionGlow.shader similarity index 100% rename from Assets/Shaders/SelectionGlow.shader rename to Assets/ConformalDecals/Shaders/SelectionGlow.shader diff --git a/Assets/Shaders/TextBlit.shader b/Assets/ConformalDecals/Shaders/TextBlit.shader similarity index 100% rename from Assets/Shaders/TextBlit.shader rename to Assets/ConformalDecals/Shaders/TextBlit.shader diff --git a/Assets/Shaders/TextDecal.cginc b/Assets/ConformalDecals/Shaders/TextDecal.cginc similarity index 100% rename from Assets/Shaders/TextDecal.cginc rename to Assets/ConformalDecals/Shaders/TextDecal.cginc diff --git a/Assets/Shaders/TextDecal.shader b/Assets/ConformalDecals/Shaders/TextDecal.shader similarity index 100% rename from Assets/Shaders/TextDecal.shader rename to Assets/ConformalDecals/Shaders/TextDecal.shader diff --git a/Assets/Shaders/UI/ColorSlider.shader b/Assets/ConformalDecals/Shaders/UI/ColorSlider.shader similarity index 100% rename from Assets/Shaders/UI/ColorSlider.shader rename to Assets/ConformalDecals/Shaders/UI/ColorSlider.shader diff --git a/Assets/Shaders/UI/ColorSquare.shader b/Assets/ConformalDecals/Shaders/UI/ColorSquare.shader similarity index 100% rename from Assets/Shaders/UI/ColorSquare.shader rename to Assets/ConformalDecals/Shaders/UI/ColorSquare.shader diff --git a/Assets/Shaders/UI/ColorSwatch.shader b/Assets/ConformalDecals/Shaders/UI/ColorSwatch.shader similarity index 100% rename from Assets/Shaders/UI/ColorSwatch.shader rename to Assets/ConformalDecals/Shaders/UI/ColorSwatch.shader diff --git a/Assets/Shaders/UI/HSL.cginc b/Assets/ConformalDecals/Shaders/UI/HSL.cginc similarity index 100% rename from Assets/Shaders/UI/HSL.cginc rename to Assets/ConformalDecals/Shaders/UI/HSL.cginc diff --git a/Assets/Textures/Decal-Back-spec.png b/Assets/ConformalDecals/Textures/Decal-Back-spec.png similarity index 100% rename from Assets/Textures/Decal-Back-spec.png rename to Assets/ConformalDecals/Textures/Decal-Back-spec.png diff --git a/Assets/Textures/Decal-Back.png b/Assets/ConformalDecals/Textures/Decal-Back.png similarity index 100% rename from Assets/Textures/Decal-Back.png rename to Assets/ConformalDecals/Textures/Decal-Back.png diff --git a/Assets/ConformalDecals/Textures/Decal-Spec.tif b/Assets/ConformalDecals/Textures/Decal-Spec.tif new file mode 100644 index 0000000..96f5162 Binary files /dev/null and b/Assets/ConformalDecals/Textures/Decal-Spec.tif differ diff --git a/Assets/Textures/Munar-Atlas.png b/Assets/ConformalDecals/Textures/Munar-Atlas.png similarity index 100% rename from Assets/Textures/Munar-Atlas.png rename to Assets/ConformalDecals/Textures/Munar-Atlas.png diff --git a/Assets/ConformalDecals/Textures/Paper-Wrinkle-n.png b/Assets/ConformalDecals/Textures/Paper-Wrinkle-n.png new file mode 100644 index 0000000..0b8b23b Binary files /dev/null and b/Assets/ConformalDecals/Textures/Paper-Wrinkle-n.png differ diff --git a/Assets/Textures/Peel-N-Stik-scaled.png b/Assets/ConformalDecals/Textures/Peel-N-Stik-scaled.png similarity index 100% rename from Assets/Textures/Peel-N-Stik-scaled.png rename to Assets/ConformalDecals/Textures/Peel-N-Stik-scaled.png diff --git a/Assets/Textures/Peel-N-Stik.png b/Assets/ConformalDecals/Textures/Peel-N-Stik.png similarity index 100% rename from Assets/Textures/Peel-N-Stik.png rename to Assets/ConformalDecals/Textures/Peel-N-Stik.png diff --git a/Assets/Textures/Peel-N-Stik.svg b/Assets/ConformalDecals/Textures/Peel-N-Stik.svg similarity index 100% rename from Assets/Textures/Peel-N-Stik.svg rename to Assets/ConformalDecals/Textures/Peel-N-Stik.svg diff --git a/Assets/Textures/Peel-N-Stik@2x.png b/Assets/ConformalDecals/Textures/Peel-N-Stik@2x.png similarity index 100% rename from Assets/Textures/Peel-N-Stik@2x.png rename to Assets/ConformalDecals/Textures/Peel-N-Stik@2x.png diff --git a/Assets/Textures/Semiotic-Atlas.png b/Assets/ConformalDecals/Textures/Semiotic-Atlas.png similarity index 100% rename from Assets/Textures/Semiotic-Atlas.png rename to Assets/ConformalDecals/Textures/Semiotic-Atlas.png diff --git a/Assets/Textures/UI.png b/Assets/ConformalDecals/Textures/UI.png similarity index 100% rename from Assets/Textures/UI.png rename to Assets/ConformalDecals/Textures/UI.png diff --git a/Assets/Textures/blank.png b/Assets/ConformalDecals/Textures/blank.png similarity index 100% rename from Assets/Textures/blank.png rename to Assets/ConformalDecals/Textures/blank.png diff --git a/Assets/Textures/decals-selected.png b/Assets/ConformalDecals/Textures/decals-selected.png similarity index 100% rename from Assets/Textures/decals-selected.png rename to Assets/ConformalDecals/Textures/decals-selected.png diff --git a/Assets/Textures/decals-unselected.png b/Assets/ConformalDecals/Textures/decals-unselected.png similarity index 100% rename from Assets/Textures/decals-unselected.png rename to Assets/ConformalDecals/Textures/decals-unselected.png diff --git a/Assets/UI/BSlider.mat b/Assets/ConformalDecals/UI/BSlider.mat similarity index 100% rename from Assets/UI/BSlider.mat rename to Assets/ConformalDecals/UI/BSlider.mat diff --git a/Assets/UI/ColorPickerPanel.prefab b/Assets/ConformalDecals/UI/ColorPickerPanel.prefab similarity index 100% rename from Assets/UI/ColorPickerPanel.prefab rename to Assets/ConformalDecals/UI/ColorPickerPanel.prefab diff --git a/Assets/UI/FontMenuPanel.prefab b/Assets/ConformalDecals/UI/FontMenuPanel.prefab similarity index 100% rename from Assets/UI/FontMenuPanel.prefab rename to Assets/ConformalDecals/UI/FontMenuPanel.prefab diff --git a/Assets/UI/GSlider.mat b/Assets/ConformalDecals/UI/GSlider.mat similarity index 100% rename from Assets/UI/GSlider.mat rename to Assets/ConformalDecals/UI/GSlider.mat diff --git a/Assets/UI/HSLSlider.mat b/Assets/ConformalDecals/UI/HSLSlider.mat similarity index 100% rename from Assets/UI/HSLSlider.mat rename to Assets/ConformalDecals/UI/HSLSlider.mat diff --git a/Assets/UI/HSLSquare.mat b/Assets/ConformalDecals/UI/HSLSquare.mat similarity index 100% rename from Assets/UI/HSLSquare.mat rename to Assets/ConformalDecals/UI/HSLSquare.mat diff --git a/Assets/UI/RSlider.mat b/Assets/ConformalDecals/UI/RSlider.mat similarity index 100% rename from Assets/UI/RSlider.mat rename to Assets/ConformalDecals/UI/RSlider.mat diff --git a/Assets/UI/Swatch.mat b/Assets/ConformalDecals/UI/Swatch.mat similarity index 100% rename from Assets/UI/Swatch.mat rename to Assets/ConformalDecals/UI/Swatch.mat diff --git a/Assets/UI/TextEntryPanel.prefab b/Assets/ConformalDecals/UI/TextEntryPanel.prefab similarity index 100% rename from Assets/UI/TextEntryPanel.prefab rename to Assets/ConformalDecals/UI/TextEntryPanel.prefab diff --git a/Assets/Scripts/DecalProjectorTest.cs b/Assets/Scripts/DecalProjectorTest.cs deleted file mode 100644 index 0fb32c1..0000000 --- a/Assets/Scripts/DecalProjectorTest.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using UnityEngine; - -[ExecuteInEditMode] -public class DecalProjectorTest : MonoBehaviour -{ - public GameObject target = null; - public Material targetMaterial = null; - public MeshRenderer targetRenderer; - - - public float aspectRatio = 1.0f; - public float size = 1.0f; - public float factor = 1.0f; - - private Matrix4x4 _projectionMatrix; - private Matrix4x4 _OrthoMatrix; - - private int _matrixID; - private int _normalID; - public int _tangentID; - - // Start is called before the first frame update - void Awake() - { - _projectionMatrix = Matrix4x4.identity; - targetRenderer = target.GetComponent(); - } - - // Update is called once per frame - void Update() - { - Vector3 pos =new Vector3( 0.5f ,0.5f, 0); - Vector3 scale = new Vector3(1 / size, 1 / (aspectRatio * size), 1); - _OrthoMatrix.SetTRS(pos, Quaternion.identity, scale); - //Debug.Log(_OrthoMatrix); - var targetToProjector = transform.worldToLocalMatrix * targetRenderer.localToWorldMatrix; - 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); - } - -} diff --git a/Assets/Scripts/TextRenderTest.cs b/Assets/Scripts/TextRenderTest.cs deleted file mode 100644 index 75df98f..0000000 --- a/Assets/Scripts/TextRenderTest.cs +++ /dev/null @@ -1,119 +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()); - var thing = new GameObject(); - thing.AddComponent(); - } - - // 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); - } -} \ No newline at end of file