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 "AutoLight.cginc"
|
||||||
#include "Lighting.cginc"
|
#include "Lighting.cginc"
|
||||||
|
|
||||||
#define CLIP_MARGIN 0.1
|
#define CLIP_MARGIN 0.05
|
||||||
#define EDGE_MARGIN 0.01
|
#define EDGE_MARGIN 0.01
|
||||||
|
|
||||||
// UNIFORM VARIABLES
|
// UNIFORM VARIABLES
|
||||||
@ -85,7 +85,7 @@ struct DecalSurfaceInput
|
|||||||
|
|
||||||
#ifdef DECAL_BASE_NORMAL
|
#ifdef DECAL_BASE_NORMAL
|
||||||
float3 normal;
|
float3 normal;
|
||||||
#endif
|
#endif //DECAL_BASE_NORMAL
|
||||||
|
|
||||||
float3 vertex_normal;
|
float3 vertex_normal;
|
||||||
float3 viewDir;
|
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 dist = max(max(q.x, q.y), q.z); // pseudo SDF
|
||||||
float ndist = EDGE_MARGIN - dot(normal, projNormal); // SDF to normal
|
float ndist = EDGE_MARGIN - dot(normal, projNormal); // SDF to normal
|
||||||
return 10 * max(dist, ndist); // return intersection
|
return 10 * max(dist, ndist); // return intersection
|
||||||
#endif
|
#endif //DECAL_PREVIEW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -4,7 +4,14 @@ Shader "ConformalDecals/Text Blit"
|
|||||||
{
|
{
|
||||||
_MainTex("_MainTex (RGB spec(A))", 2D) = "white" {}
|
_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
|
SubShader
|
||||||
{
|
{
|
||||||
Tags { "Queue" = "Transparent" }
|
Tags { "Queue" = "Transparent" }
|
||||||
@ -21,27 +28,41 @@ Shader "ConformalDecals/Text Blit"
|
|||||||
|
|
||||||
sampler2D _MainTex;
|
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 "UnityCG.cginc"
|
||||||
#include "Lighting.cginc"
|
#include "Lighting.cginc"
|
||||||
#include "AutoLight.cginc"
|
#include "AutoLight.cginc"
|
||||||
|
|
||||||
struct v2f {
|
struct v2f {
|
||||||
float4 pos : SV_POSITION;
|
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;
|
v2f o;
|
||||||
o.pos = UnityObjectToClipPos(vertex);
|
o.pos = UnityObjectToClipPos(vertex);
|
||||||
o.uv = uv;
|
o.uv = float4(uv0.x, uv0.y, bias, 0);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed4 frag (v2f i) : SV_Target {
|
fixed4 frag (v2f i) : SV_Target {
|
||||||
|
float2 uv = i.uv.xy;
|
||||||
|
float bias = i.uv.z;
|
||||||
|
|
||||||
fixed4 c = 0;
|
fixed4 c = 0;
|
||||||
|
c.r = saturate(tex2D(_MainTex,(uv)).a - bias);
|
||||||
c.r = tex2D(_MainTex,(i.uv)).a;
|
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
float4 _DecalColor;
|
float4 _DecalColor;
|
||||||
float _Weight;
|
|
||||||
|
|
||||||
float4 _OutlineColor;
|
float4 _OutlineColor;
|
||||||
float _OutlineWidth;
|
float _OutlineWidth;
|
||||||
|
|
||||||
void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
|
void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
|
||||||
float4 color = _DecalColor;
|
float4 color = _DecalColor;
|
||||||
float bias = _Cutoff - (_Weight / 4);
|
float dist = _Cutoff - tex2D(_Decal, IN.uv_decal).r; // text distance
|
||||||
float dist = bias - tex2D(_Decal, IN.uv_decal).r; // text distance
|
|
||||||
float ddist = SDFdDist(dist); // distance gradient magnitude
|
float ddist = SDFdDist(dist); // distance gradient magnitude
|
||||||
|
|
||||||
#ifdef DECAL_OUTLINE
|
#ifdef DECAL_OUTLINE
|
||||||
|
@ -78,7 +78,6 @@ namespace ConformalDecals {
|
|||||||
private ColorPickerController _outlineColorPickerController;
|
private ColorPickerController _outlineColorPickerController;
|
||||||
|
|
||||||
private MaterialTextureProperty _decalTextureProperty;
|
private MaterialTextureProperty _decalTextureProperty;
|
||||||
private MaterialFloatProperty _decalTextWeightProperty;
|
|
||||||
|
|
||||||
private MaterialKeywordProperty _fillEnabledProperty;
|
private MaterialKeywordProperty _fillEnabledProperty;
|
||||||
private MaterialColorProperty _fillColorProperty;
|
private MaterialColorProperty _fillColorProperty;
|
||||||
@ -112,7 +111,6 @@ namespace ConformalDecals {
|
|||||||
base.OnAwake();
|
base.OnAwake();
|
||||||
|
|
||||||
_decalTextureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
_decalTextureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
||||||
_decalTextWeightProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_Weight");
|
|
||||||
|
|
||||||
_fillEnabledProperty = materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_FILL");
|
_fillEnabledProperty = materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_FILL");
|
||||||
_fillColorProperty = materialProperties.AddOrGetProperty<MaterialColorProperty>("_DecalColor");
|
_fillColorProperty = materialProperties.AddOrGetProperty<MaterialColorProperty>("_DecalColor");
|
||||||
@ -194,12 +192,12 @@ namespace ConformalDecals {
|
|||||||
style = (int) _style.FontStyle;
|
style = (int) _style.FontStyle;
|
||||||
vertical = _style.Vertical;
|
vertical = _style.Vertical;
|
||||||
lineSpacing = _style.LineSpacing;
|
lineSpacing = _style.LineSpacing;
|
||||||
characterSpacing = _style.CharacterSpacing;
|
charSpacing = _style.CharSpacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAfterDeserialize() {
|
public void OnAfterDeserialize() {
|
||||||
_font = DecalConfig.GetFont(fontName);
|
_font = DecalConfig.GetFont(fontName);
|
||||||
_style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, characterSpacing);
|
_style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, charSpacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDestroy() {
|
public override void OnDestroy() {
|
||||||
@ -210,9 +208,9 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
protected override void OnDetach() {
|
protected override void OnDetach() {
|
||||||
// close all UIs
|
// close all UIs
|
||||||
if (_textEntryController != null) _textEntryController.OnClose();
|
if (_textEntryController != null) _textEntryController.Close();
|
||||||
if (_fillColorPickerController != null) _fillColorPickerController.OnClose();
|
if (_fillColorPickerController != null) _fillColorPickerController.Close();
|
||||||
if (_outlineColorPickerController != null) _outlineColorPickerController.OnClose();
|
if (_outlineColorPickerController != null) _outlineColorPickerController.Close();
|
||||||
|
|
||||||
base.OnDetach();
|
base.OnDetach();
|
||||||
}
|
}
|
||||||
@ -283,7 +281,5 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
base.UpdateTweakables();
|
base.UpdateTweakables();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UpdateCachedProperties() { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ namespace ConformalDecals.Text {
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class TextRenderEvent : UnityEvent<TextRenderOutput> { }
|
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 int MaxTextureSize = 4096;
|
||||||
private const float FontSize = 100;
|
private const float FontSize = 100;
|
||||||
private const float PixelDensity = 5;
|
private const float PixelDensity = 5;
|
||||||
@ -90,9 +90,8 @@ namespace ConformalDecals.Text {
|
|||||||
_tmp = gameObject.AddComponent<TextMeshPro>();
|
_tmp = gameObject.AddComponent<TextMeshPro>();
|
||||||
_tmp.renderer.enabled = false; // dont automatically render
|
_tmp.renderer.enabled = false; // dont automatically render
|
||||||
|
|
||||||
var shader = Shabby.Shabby.FindShader(BlitShader);
|
_blitShader = Shabby.Shabby.FindShader(ShaderName);
|
||||||
if (shader == null) Debug.LogError($"[ConformalDecals] could not find text blit shader named '{shader}'");
|
if (_blitShader == null) Debug.LogError($"[ConformalDecals] could not find text blit shader named '{ShaderName}'");
|
||||||
_blitShader = Shabby.Shabby.FindShader(BlitShader);
|
|
||||||
|
|
||||||
_isSetup = true;
|
_isSetup = true;
|
||||||
}
|
}
|
||||||
@ -157,7 +156,7 @@ namespace ConformalDecals.Text {
|
|||||||
_tmp.font = text.Font.FontAsset;
|
_tmp.font = text.Font.FontAsset;
|
||||||
_tmp.fontStyle = text.Style.FontStyle | text.Font.FontStyle;
|
_tmp.fontStyle = text.Style.FontStyle | text.Font.FontStyle;
|
||||||
_tmp.lineSpacing = text.Style.LineSpacing;
|
_tmp.lineSpacing = text.Style.LineSpacing;
|
||||||
_tmp.characterSpacing = text.Style.CharacterSpacing;
|
_tmp.characterSpacing = text.Style.CharSpacing;
|
||||||
|
|
||||||
_tmp.extraPadding = true;
|
_tmp.extraPadding = true;
|
||||||
_tmp.enableKerning = true;
|
_tmp.enableKerning = true;
|
||||||
@ -236,10 +235,10 @@ namespace ConformalDecals.Text {
|
|||||||
|
|
||||||
// SETUP TEXTURE
|
// SETUP TEXTURE
|
||||||
if (texture == null) {
|
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) {
|
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
|
// GENERATE PROJECTION MATRIX
|
||||||
@ -268,7 +267,7 @@ namespace ConformalDecals.Text {
|
|||||||
|
|
||||||
// COPY TEXTURE BACK INTO RAM
|
// COPY TEXTURE BACK INTO RAM
|
||||||
RenderTexture.active = renderTex;
|
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();
|
texture.Apply();
|
||||||
|
|
||||||
// RELEASE RENDERTEX
|
// RELEASE RENDERTEX
|
||||||
|
Loading…
Reference in New Issue
Block a user