Fix text rendering more

This commit is contained in:
2020-08-21 23:44:58 -07:00
parent ae351c021f
commit 93c3ff8a49
5 changed files with 44 additions and 32 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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