mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Fix text rendering more
This commit is contained in:
parent
ae351c021f
commit
93c3ff8a49
@ -4,7 +4,7 @@
|
||||
#include "AutoLight.cginc"
|
||||
#include "Lighting.cginc"
|
||||
|
||||
#define CLIP_MARGIN 0.1
|
||||
#define CLIP_MARGIN 0.05
|
||||
#define EDGE_MARGIN 0.01
|
||||
|
||||
// UNIFORM VARIABLES
|
||||
@ -85,7 +85,7 @@ struct DecalSurfaceInput
|
||||
|
||||
#ifdef DECAL_BASE_NORMAL
|
||||
float3 normal;
|
||||
#endif
|
||||
#endif //DECAL_BASE_NORMAL
|
||||
|
||||
float3 vertex_normal;
|
||||
float3 viewDir;
|
||||
@ -150,9 +150,7 @@ inline float BoundsDist(float3 p, float3 normal, float3 projNormal) {
|
||||
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
|
||||
#endif //DECAL_PREVIEW
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -3,8 +3,15 @@ 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" }
|
||||
@ -20,6 +27,15 @@ Shader "ConformalDecals/Text Blit"
|
||||
#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"
|
||||
@ -27,21 +43,26 @@ Shader "ConformalDecals/Text Blit"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 uv : TEXCOORD0; // u, v, bias, 0
|
||||
};
|
||||
|
||||
v2f vert(float4 vertex : POSITION, float2 uv : TEXCOORD0) {
|
||||
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 = uv;
|
||||
o.uv = float4(uv0.x, uv0.y, bias, 0);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target {
|
||||
float2 uv = i.uv.xy;
|
||||
float bias = i.uv.z;
|
||||
|
||||
fixed4 c = 0;
|
||||
|
||||
c.r = tex2D(_MainTex,(i.uv)).a;
|
||||
|
||||
c.r = saturate(tex2D(_MainTex,(uv)).a - bias);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
float4 _DecalColor;
|
||||
float _Weight;
|
||||
|
||||
float4 _OutlineColor;
|
||||
float _OutlineWidth;
|
||||
|
||||
void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
|
||||
float4 color = _DecalColor;
|
||||
float bias = _Cutoff - (_Weight / 4);
|
||||
float dist = bias - tex2D(_Decal, IN.uv_decal).r; // text distance
|
||||
float dist = _Cutoff - tex2D(_Decal, IN.uv_decal).r; // text distance
|
||||
float ddist = SDFdDist(dist); // distance gradient magnitude
|
||||
|
||||
#ifdef DECAL_OUTLINE
|
||||
|
@ -78,7 +78,6 @@ namespace ConformalDecals {
|
||||
private ColorPickerController _outlineColorPickerController;
|
||||
|
||||
private MaterialTextureProperty _decalTextureProperty;
|
||||
private MaterialFloatProperty _decalTextWeightProperty;
|
||||
|
||||
private MaterialKeywordProperty _fillEnabledProperty;
|
||||
private MaterialColorProperty _fillColorProperty;
|
||||
@ -112,7 +111,6 @@ namespace ConformalDecals {
|
||||
base.OnAwake();
|
||||
|
||||
_decalTextureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
||||
_decalTextWeightProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_Weight");
|
||||
|
||||
_fillEnabledProperty = materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_FILL");
|
||||
_fillColorProperty = materialProperties.AddOrGetProperty<MaterialColorProperty>("_DecalColor");
|
||||
@ -194,12 +192,12 @@ namespace ConformalDecals {
|
||||
style = (int) _style.FontStyle;
|
||||
vertical = _style.Vertical;
|
||||
lineSpacing = _style.LineSpacing;
|
||||
characterSpacing = _style.CharacterSpacing;
|
||||
charSpacing = _style.CharSpacing;
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize() {
|
||||
_font = DecalConfig.GetFont(fontName);
|
||||
_style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, characterSpacing);
|
||||
_style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, charSpacing);
|
||||
}
|
||||
|
||||
public override void OnDestroy() {
|
||||
@ -210,9 +208,9 @@ namespace ConformalDecals {
|
||||
|
||||
protected override void OnDetach() {
|
||||
// close all UIs
|
||||
if (_textEntryController != null) _textEntryController.OnClose();
|
||||
if (_fillColorPickerController != null) _fillColorPickerController.OnClose();
|
||||
if (_outlineColorPickerController != null) _outlineColorPickerController.OnClose();
|
||||
if (_textEntryController != null) _textEntryController.Close();
|
||||
if (_fillColorPickerController != null) _fillColorPickerController.Close();
|
||||
if (_outlineColorPickerController != null) _outlineColorPickerController.Close();
|
||||
|
||||
base.OnDetach();
|
||||
}
|
||||
@ -283,7 +281,5 @@ namespace ConformalDecals {
|
||||
|
||||
base.UpdateTweakables();
|
||||
}
|
||||
|
||||
protected void UpdateCachedProperties() { }
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ namespace ConformalDecals.Text {
|
||||
[Serializable]
|
||||
public class TextRenderEvent : UnityEvent<TextRenderOutput> { }
|
||||
|
||||
private const string BlitShader = "ConformalDecals/Text Blit";
|
||||
private const string ShaderName = "ConformalDecals/Text Blit";
|
||||
private const int MaxTextureSize = 4096;
|
||||
private const float FontSize = 100;
|
||||
private const float PixelDensity = 5;
|
||||
@ -90,9 +90,8 @@ namespace ConformalDecals.Text {
|
||||
_tmp = gameObject.AddComponent<TextMeshPro>();
|
||||
_tmp.renderer.enabled = false; // dont automatically render
|
||||
|
||||
var shader = Shabby.Shabby.FindShader(BlitShader);
|
||||
if (shader == null) Debug.LogError($"[ConformalDecals] could not find text blit shader named '{shader}'");
|
||||
_blitShader = Shabby.Shabby.FindShader(BlitShader);
|
||||
_blitShader = Shabby.Shabby.FindShader(ShaderName);
|
||||
if (_blitShader == null) Debug.LogError($"[ConformalDecals] could not find text blit shader named '{ShaderName}'");
|
||||
|
||||
_isSetup = true;
|
||||
}
|
||||
@ -157,7 +156,7 @@ namespace ConformalDecals.Text {
|
||||
_tmp.font = text.Font.FontAsset;
|
||||
_tmp.fontStyle = text.Style.FontStyle | text.Font.FontStyle;
|
||||
_tmp.lineSpacing = text.Style.LineSpacing;
|
||||
_tmp.characterSpacing = text.Style.CharacterSpacing;
|
||||
_tmp.characterSpacing = text.Style.CharSpacing;
|
||||
|
||||
_tmp.extraPadding = true;
|
||||
_tmp.enableKerning = true;
|
||||
@ -236,10 +235,10 @@ namespace ConformalDecals.Text {
|
||||
|
||||
// SETUP TEXTURE
|
||||
if (texture == null) {
|
||||
texture = new Texture2D(textureSize.x, textureSize.y, TextTextureFormat, false);
|
||||
texture = new Texture2D(textureSize.x, textureSize.y, TextTextureFormat, true);
|
||||
}
|
||||
else if (texture.width != textureSize.x || texture.height != textureSize.y || texture.format != TextTextureFormat) {
|
||||
texture.Resize(textureSize.x, textureSize.y, TextTextureFormat, false);
|
||||
texture.Resize(textureSize.x, textureSize.y, TextTextureFormat, true);
|
||||
}
|
||||
|
||||
// GENERATE PROJECTION MATRIX
|
||||
@ -268,7 +267,7 @@ namespace ConformalDecals.Text {
|
||||
|
||||
// COPY TEXTURE BACK INTO RAM
|
||||
RenderTexture.active = renderTex;
|
||||
texture.ReadPixels(new Rect(0, 0, textureSize.x, textureSize.y), 0, 0, false);
|
||||
texture.ReadPixels(new Rect(0, 0, textureSize.x, textureSize.y), 0, 0, true);
|
||||
texture.Apply();
|
||||
|
||||
// RELEASE RENDERTEX
|
||||
|
Loading…
Reference in New Issue
Block a user