Skip to content

Commit 9f65304

Browse files
Stephen HodgsonStephen Hodgson
authored andcommitted
Updated font shader to correctly handle uGUI stencil operations and color changes through the text component's color property.
1 parent c976302 commit 9f65304

File tree

5 files changed

+94
-162
lines changed

5 files changed

+94
-162
lines changed

Assets/HoloToolkit/UI/Materials/3DTextSelawik_white.mat renamed to Assets/HoloToolkit/UI/Materials/3DTextSelawik.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Material:
66
m_ObjectHideFlags: 0
77
m_PrefabParentObject: {fileID: 0}
88
m_PrefabInternal: {fileID: 0}
9-
m_Name: 3DTextSelawik_white
9+
m_Name: 3DTextSelawik
1010
m_Shader: {fileID: 4800000, guid: cfe12bbf45a06fb4b8fce6adb726485f, type: 3}
1111
m_ShaderKeywords:
1212
m_LightmapFlags: 5

Assets/HoloToolkit/UI/Materials/3DTextSelawik_white.mat.meta renamed to Assets/HoloToolkit/UI/Materials/3DTextSelawik.mat.meta

File renamed without changes.

Assets/HoloToolkit/UI/Materials/3DTextSelawik_black.mat

Lines changed: 0 additions & 136 deletions
This file was deleted.

Assets/HoloToolkit/UI/Materials/3DTextSelawik_black.mat.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 93 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,94 @@
1-
Shader "HoloToolkit/3DTextShader"{
2-
Properties{
3-
_MainTex("Font Texture", 2D) = "white" {}
4-
_Color("Text Color", Color) = (1,1,1,1)
5-
}
6-
7-
SubShader{
8-
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
9-
Lighting Off Cull Off ZWrite Off Fog{ Mode Off }
10-
Blend SrcAlpha OneMinusSrcAlpha
11-
Pass{
12-
Color[_Color]
13-
SetTexture[_MainTex]{
14-
combine primary, texture * primary
15-
}
16-
}
17-
}
1+
Shader "HoloToolkit/3DTextShader"
2+
{
3+
Properties
4+
{
5+
_MainTex ("Alpha (A)", 2D) = "white" {}
6+
7+
[HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
8+
[HideInInspector] _StencilComp ("Stencil Comparison", Float) = 8
9+
[HideInInspector] _Stencil ("Stencil ID", Float) = 0
10+
[HideInInspector] _StencilOp ("Stencil Operation", Float) = 0
11+
[HideInInspector] _StencilWriteMask ("Stencil Write Mask", Float) = 255
12+
[HideInInspector] _StencilReadMask ("Stencil Read Mask", Float) = 255
13+
[HideInInspector] _ColorMask ("Color Mask", Float) = 15
14+
}
15+
16+
SubShader
17+
{
18+
LOD 200
19+
20+
Tags
21+
{
22+
"Queue" = "Transparent"
23+
"IgnoreProjector" = "True"
24+
"RenderType" = "Transparent"
25+
"PreviewType"="Plane"
26+
}
27+
28+
Stencil
29+
{
30+
Ref [_Stencil]
31+
Comp [_StencilComp]
32+
Pass [_StencilOp]
33+
ReadMask [_StencilReadMask]
34+
WriteMask [_StencilWriteMask]
35+
}
36+
37+
Cull Off
38+
Lighting Off
39+
ZWrite Off
40+
ZTest [unity_GUIZTestMode]
41+
Offset -1, -1
42+
Fog { Mode Off }
43+
Blend SrcAlpha OneMinusSrcAlpha
44+
ColorMask [_ColorMask]
45+
46+
Pass
47+
{
48+
CGPROGRAM
49+
#pragma vertex vert
50+
#pragma fragment frag
51+
#include "UnityCG.cginc"
52+
53+
struct appdata_t
54+
{
55+
float4 vertex : POSITION;
56+
half4 color : COLOR;
57+
float2 texcoord : TEXCOORD0;
58+
};
59+
60+
struct v2f
61+
{
62+
float4 vertex : POSITION;
63+
half4 color : COLOR;
64+
float2 texcoord : TEXCOORD0;
65+
};
66+
67+
sampler2D _MainTex;
68+
float4 _MainTex_ST;
69+
fixed4 _Color;
70+
71+
v2f vert (appdata_t v)
72+
{
73+
v2f o;
74+
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
75+
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
76+
o.color = v.color;
77+
#ifdef UNITY_HALF_TEXEL_OFFSET
78+
o.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
79+
#endif
80+
return o;
81+
}
82+
83+
half4 frag (v2f i) : COLOR
84+
{
85+
half4 col = i.color;
86+
col.a *= tex2D(_MainTex, i.texcoord).a;
87+
col = col * _Color;
88+
clip (col.a - 0.01);
89+
return col;
90+
}
91+
ENDCG
92+
}
93+
}
1894
}

0 commit comments

Comments
 (0)