Skip to content

Commit 659f10e

Browse files
authored
Create UI-Default-With-Occlusion-Pass.shader
1 parent ff7fdc0 commit 659f10e

File tree

1 file changed

+187
-0
lines changed

1 file changed

+187
-0
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
// used for world space UI elements, to hide point cloud points behind it
2+
// https://github.com/unitycoder/UnityPointCloudViewer
3+
4+
Shader "UI/Default-With-Occlusion-Pass"
5+
{
6+
Properties
7+
{
8+
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
9+
_Color ("Tint", Color) = (1,1,1,1)
10+
11+
_StencilComp ("Stencil Comparison", Float) = 8
12+
_Stencil ("Stencil ID", Float) = 0
13+
_StencilOp ("Stencil Operation", Float) = 0
14+
_StencilWriteMask ("Stencil Write Mask", Float) = 255
15+
_StencilReadMask ("Stencil Read Mask", Float) = 255
16+
17+
_ColorMask ("Color Mask", Float) = 15
18+
19+
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
20+
}
21+
22+
SubShader
23+
{
24+
Pass
25+
{
26+
Tags { "Queue"="Geometry-1" }
27+
28+
ZWrite On
29+
ZTest LEqual
30+
//ColorMask 0
31+
32+
CGPROGRAM
33+
#pragma vertex vert
34+
#pragma fragment frag
35+
#pragma target 2.0
36+
37+
#include "UnityCG.cginc"
38+
#include "UnityUI.cginc"
39+
40+
#pragma multi_compile __ UNITY_UI_ALPHACLIP
41+
42+
struct appdata_t
43+
{
44+
float4 vertex : POSITION;
45+
float4 color : COLOR;
46+
float2 texcoord : TEXCOORD0;
47+
UNITY_VERTEX_INPUT_INSTANCE_ID
48+
};
49+
50+
struct v2f
51+
{
52+
float4 vertex : SV_POSITION;
53+
fixed4 color : COLOR;
54+
float2 texcoord : TEXCOORD0;
55+
float4 worldPosition : TEXCOORD1;
56+
UNITY_VERTEX_OUTPUT_STEREO
57+
};
58+
59+
fixed4 _Color;
60+
fixed4 _TextureSampleAdd;
61+
float4 _ClipRect;
62+
63+
v2f vert(appdata_t IN)
64+
{
65+
v2f OUT;
66+
UNITY_SETUP_INSTANCE_ID(IN);
67+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
68+
OUT.worldPosition = IN.vertex;
69+
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
70+
71+
OUT.texcoord = IN.texcoord;
72+
73+
OUT.color = IN.color;// * _Color;
74+
return OUT;
75+
}
76+
77+
sampler2D _MainTex;
78+
79+
fixed4 frag(v2f IN) : SV_Target
80+
{
81+
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
82+
83+
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
84+
85+
//#ifdef UNITY_UI_ALPHACLIP
86+
clip (color.a - 0.001);
87+
//#endif
88+
89+
return color;
90+
}
91+
ENDCG
92+
}
93+
94+
95+
// draw actual text
96+
Pass
97+
{
98+
Tags
99+
{
100+
"Queue"="Transparent"
101+
"IgnoreProjector"="True"
102+
"RenderType"="Transparent"
103+
"PreviewType"="Plane"
104+
"CanUseSpriteAtlas"="True"
105+
}
106+
107+
Stencil
108+
{
109+
Ref [_Stencil]
110+
Comp [_StencilComp]
111+
Pass [_StencilOp]
112+
ReadMask [_StencilReadMask]
113+
WriteMask [_StencilWriteMask]
114+
}
115+
116+
Cull Off
117+
Lighting Off
118+
ZWrite Off
119+
ZTest [unity_GUIZTestMode]
120+
Blend SrcAlpha OneMinusSrcAlpha
121+
ColorMask [_ColorMask]
122+
123+
124+
Name "Default"
125+
CGPROGRAM
126+
#pragma vertex vert
127+
#pragma fragment frag
128+
#pragma target 2.0
129+
130+
#include "UnityCG.cginc"
131+
#include "UnityUI.cginc"
132+
133+
#pragma multi_compile __ UNITY_UI_ALPHACLIP
134+
135+
struct appdata_t
136+
{
137+
float4 vertex : POSITION;
138+
float4 color : COLOR;
139+
float2 texcoord : TEXCOORD0;
140+
UNITY_VERTEX_INPUT_INSTANCE_ID
141+
};
142+
143+
struct v2f
144+
{
145+
float4 vertex : SV_POSITION;
146+
fixed4 color : COLOR;
147+
float2 texcoord : TEXCOORD0;
148+
float4 worldPosition : TEXCOORD1;
149+
UNITY_VERTEX_OUTPUT_STEREO
150+
};
151+
152+
fixed4 _Color;
153+
fixed4 _TextureSampleAdd;
154+
float4 _ClipRect;
155+
156+
v2f vert(appdata_t IN)
157+
{
158+
v2f OUT;
159+
UNITY_SETUP_INSTANCE_ID(IN);
160+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
161+
OUT.worldPosition = IN.vertex;
162+
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
163+
164+
OUT.texcoord = IN.texcoord;
165+
166+
OUT.color = IN.color * _Color;
167+
return OUT;
168+
}
169+
170+
sampler2D _MainTex;
171+
172+
fixed4 frag(v2f IN) : SV_Target
173+
{
174+
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
175+
176+
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
177+
178+
#ifdef UNITY_UI_ALPHACLIP
179+
clip (color.a - 0.001);
180+
#endif
181+
182+
return color;
183+
}
184+
ENDCG
185+
}
186+
}
187+
}

0 commit comments

Comments
 (0)